I'm getting the following exception while placing webclient POST
Response:
java.lang.NoClassDefFoundError: Could not initialize class reactor.netty.http.client.HttpClientConfiguration
DBServiceRequest dbServiceRq = new DBServiceRequest();
Map<String, Object> criteria = new HashMap<>();
criteria.put("CKTNAME", "8249");
criteria.put("REGION", "NE");
Gson gson = new Gson();
dbServiceRq.setRequestQuery(cdmCktdetailsGivenCktWithRegion);
dbServiceRq.setCriteria(criteria);
BodyInserter<Object, ReactiveHttpOutputMessage> inserter = BodyInserters.fromValue(dbServiceRq);
ResponseEntity<String> response = webClient.post().uri(getDataServiceUri()).body(inserter)
.accept(MediaType.APPLICATION_JSON).exchange().block().toEntity(String.class).block();
Related
I need to convert the json string to nested Map and access the same.
Following Json String is in form of Map given below
Map<String,Map<String,String>>
{"0":{"1551874690005":"2","1551874722124":"2","1551874810817":"2","1551874681110":"2","1551874739821":"2","1551874763604":"2","1551874692381":"2","1551874816028":"2","1551874708292":"2","1551874804308":"2","1551874694205":"2","1551874696644":"2","1551874729332":"2","1551874749950":"2","1551874767786":"2"},"1":{"1551948649643":"0","1551948733576":"0","1551948601167":"0","1551948592816":"0","1551948699297":"0","1551874822043":"2","1551948681513":"0","1551948531568":"0","1551948577374":"0","1551948719758":"0","1552370125650":"0","1551948549863":"0","1551948564519":"0","1551948631000":"0","1551953956716":"0"},"2":{"1551875011432":"0","1551875020618":"0","1551874991952":"0","1551875091300":"0","1551875073622":"0","1551875032851":"0","1551874827691":"0","1551948658122":"0","1551874846523":"0","null":"0","1552545417127":"0","1551875083856":"0","1551874929076":"0","1552545972738":"0"},"3":{"1552651031695":"0"},"4":{"1551875144268":"0","1551875157028":"0","1551875115211":"0","1551875124660":"0"}}
Getting following error while trying using my code:
Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Map<String, String>' in type cast
Map offlineExeStatus = jsonDecode(prefs.getString("offlineExeStatus"));
Map<String,Map<String,String>> exeStatusFinalJson = new Map();
exeStatusFinalJson = offlineExeStatus.cast<String,Map<String,String>();
Need to cast the given json in "exeStatusFinalJson" Map and access like:
exeStatusFinalJson["0"] should give the output like:
{"1551874690005":"2","1551874722124":"2","1551874810817":"2","1551874681110":"2","1551874739821":"2","1551874763604":"2","1551874692381":"2","1551874816028":"2","1551874708292":"2","1551874804308":"2","1551874694205":"2","1551874696644":"2","1551874729332":"2","1551874749950":"2","1551874767786":"2"}
Try to declare your map as Map<String, dynamic> rather than Map<String, Map<String, String>>.
Finally figured out the way to do it!
Map offlineExeStatus = jsonDecode(prefs.getString("onlineExeStatus"));
Map<String, dynamic> exeStatusJson = new Map();
Map<String, Map<String, String>> exeStatusFinalJson = new Map();
List<String> mapKeyExe = new List();
mapKeyExe = offlineExeStatus.keys.cast<String>().toList();
exeStatusJson = offlineExeStatus.cast<String, dynamic>();
for (int i = 0; i < mapKeyExe.length; i++) {
Map<String, String> exeStatusInsideJson = new Map();
exeStatusInsideJson = offlineExeStatus[mapKeyExe[i].toString()]
.cast<String, String>();
exeStatusFinalJson[i.toString()] = exeStatusInsideJson;
print(exeStatusFinalJson);
}
My problem is in the drilldown. I want to create a drilldown on loop but all drilldown series show in one serie, the result is when I click on column, all drilldowns series show in that char.
ArrayList<Object> dataMinorAlarms = new ArrayList<>();
ArrayList<Object> dataMajorAlarms = new ArrayList<>();
ArrayList<Object> dataCriticalAlarms = new ArrayList<>();
ArrayList<Object> dataDrilldownlAlarms = new ArrayList<>();
ArrayList<Object> DrilldownlAlarms = new ArrayList<>();
for (ResumenGraph data:resumenGraphs){
HashMap<String, Object> minor = new HashMap<>();
minor.put("name", data.getName());
minor.put("y", data.getData().getMinor());
minor.put("drilldown", data.getName());
HashMap<String, Object> major = new HashMap<>();
major.put("name", data.getName());
major.put("y", data.getData().getMajor());
major.put("drilldown", data.getName());
HashMap<String, Object> critical = new HashMap<>();
critical.put("name", data.getName());
critical.put("y", data.getData().getCritical());
critical.put("drilldown", data.getName());
for (int i = 0; i < data.getDrilldown().size(); i++) {
HIColumn series4 = new HIColumn();
series4.setName(data.getName());
series4.setId(data.getName());
Object[] object2 = new Object[]{data.getDrilldown().get(i).getName(),data.getDrilldown().get(i).getData().getMajor()};
dataDrilldownlAlarms.add(object2);
DrilldownlAlarms.add(series4);
}
dataMinorAlarms.add(minor);
dataMajorAlarms.add(major);
dataCriticalAlarms.add(critical);
}
You need to use real x and y values from the Point class, there is not someting like index property.
You can find a similar example in the highcharts-android wrapper documentation.
API: https://api.highcharts.com/class-reference/Highcharts.Point#toc3
Docs: https://github.com/highcharts/highcharts-android/blob/master/README.md
I am having a weird problem with apache tika.When I am getting the filetype first and then parsing I am not getting the content. code:-
public static void main(String[] args) throws IOException, SAXException, TikaException {
File file = new File("sample.txt");
InputStream is = new FileInputStream(file);
TikaInputStream objectData = TikaInputStream.get(is);
Parser parser = new AutoDetectParser();
BodyContentHandler handler = new BodyContentHandler(-1);
Metadata metadata = new Metadata();
ParseContext context = new ParseContext();
metadata.set(Metadata.RESOURCE_NAME_KEY, file.getName());
TikaConfig config = TikaConfig.getDefaultConfig();
Detector detector = config.getDetector();
System.out.println("Hello : " + detector.detect(objectData, metadata).toString());
parser.parse(is, handler, metadata, context);
System.out.println("File Content :" + handler.toString());
}
But when I parse first and then get the filetype i am getting the correct content.code:-
public static void main(String[] args) throws IOException, SAXException, TikaException {
File file = new File("sample.txt");
InputStream is = new FileInputStream(file);
TikaInputStream objectData = TikaInputStream.get(is);
Parser parser = new AutoDetectParser();
BodyContentHandler handler = new BodyContentHandler(-1);
Metadata metadata = new Metadata();
ParseContext context = new ParseContext();
parser.parse(is, handler, metadata, context);
System.out.println("File Content :" + handler.toString());
metadata.set(Metadata.RESOURCE_NAME_KEY, file.getName());
TikaConfig config = TikaConfig.getDefaultConfig();
Detector detector = config.getDetector();
System.out.println("Hello : " + detector.detect(objectData, metadata).toString());
}
Why is this happening? Is there any way around it? Because I need to manipulate the text according to the given mime type.
Edit:- I think this is a problem with dependency.What are the dependencies required for tika detect to work in terms of referenced library?
I'm following the tutorial found here to create a JWT token to access the REST API of JIRA. I do not have any problem accessing endpoints without passing query strings like /rest/api/2/project and /rest/api/2/issue/ISSUE-KEY but I get 401 Unauthorized when trying to pass query strings, say /rest/api/2/user/assignable/search?project=PROJECT-KEY
I'm guessing I'm missing out something, specificially the generation of canonical URL,
Here is the code that generates the get request and JWT token:
#Override
public CloseableHttpResponse get(String url) throws HttpException,
IOException, NoSuchAlgorithmException, ParseException,
JOSEException {
CloseableHttpClient client = HttpClientBuilder.create()
.setUserAgent("Kevin 6.9").build();
String token = createToken(url, JIRAClient.Method.GET);
HttpGet method = new HttpGet(jwt.getBaseUrl() + url);
method.setHeader("Authorization", "JWT " + token);
return client.execute(method);
}
/**
* Create JWT token
*
* #return
* #throws UnsupportedEncodingException
* #throws NoSuchAlgorithmException
*/
private String createToken(String apiPath, JIRAClient.Method method)
throws UnsupportedEncodingException, NoSuchAlgorithmException {
long issuedAt = System.currentTimeMillis() / 1000L;
long expiresAt = issuedAt + 1000L;
String httpMethod = method.toString();
System.out.println(httpMethod);
String contextPath = "/jira";
JwtJsonBuilder jwtBuilder = new JsonSmartJwtJsonBuilder()
.issuedAt(issuedAt).expirationTime(expiresAt)
.issuer(jwt.getKey());
HashMap<String, String[]> parameters = new HashMap<String, String[]>();
CanonicalHttpUriRequest canonical = new CanonicalHttpUriRequest(
httpMethod, apiPath, contextPath, parameters);
System.out.println("Canonical : " + canonical.getRelativePath());
JwtClaimsBuilder.appendHttpRequestClaims(jwtBuilder, canonical);
JwtWriterFactory jwtWriterFactory = new NimbusJwtWriterFactory();
String jwtbuilt = jwtBuilder.build();
String jwtToken = jwtWriterFactory.macSigningWriter(
SigningAlgorithm.HS256, jwt.getSharedSecret()).jsonToJwt(
jwtbuilt);
return jwtToken;
}
Note that I am passing an empty HashMap<String, String[]> to the CanonicalHttpUriRequest... is this correct?
Apparently the Map<String, String[]> is required to generate the appropriate canonical URI.
Note that I am passing an empty HashMap<String, String[]> to the
CanonicalHttpUriRequest... is this correct?
I modified my method signature so I can pass it as a parameter. Note: createQueryString is a method inside my class that manually creates the query String from the parameter map.
#Override
public CloseableHttpResponse get(String url,
#SuppressWarnings("rawtypes") Map parameters) throws Exception {
CloseableHttpClient client = HttpClientBuilder.create()
.setUserAgent("Kevin 5.0").build();
String token = createToken(url, JIRAClient.Method.GET, parameters);
HttpGet method = new HttpGet(jwt.getBaseUrl() + url
+ createQueryString(parameters));
method.setHeader("Authorization", "JWT " + token);
return client.execute(method);
}
And it works.
#Test
public void testJQL() throws Exception {
HashMap param = new HashMap();
param.put("jql", new String[] {"project=COR"});
param.put("startAt", new String[] {"0"});
HttpResponse response = client.get("/rest/api/2/search", param);
Assert.assertTrue(response.getStatusLine().getStatusCode() == 200);
}
I try to save the object into sessionmap but it is giving me an exception
public class testclass {
public static void main(String[] args) throws IOException
{
UserInfo ui = new UserInfo();
UserLogin ul= new UserLogin();
ui.setAdds("India");
ui.setEId("someone#yahoo.com");
ui.setFName("someone");
ui.setLName("someone2");
ui.setStatus("single");
ul.setPswd("somename");
ul.setUserId("121");
ul.setUserinfo(ui);
AnnotationConfiguration config = new AnnotationConfiguration();
config.configure("hibernate.cfg.xml");
//new SchemaExport(config).create(true, true);
SessionFactory factory = config.buildSessionFactory();
Session session = factory.getCurrentSession();
System.out.println("Session configured");
session.beginTransaction();
session.save(ul);
System.out.println("object saved");
Query q = session.createQuery("from UserLogin where UserId='121'");
UserLogin user = (UserLogin)q.uniqueResult();
if(user!=null)
{
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
Map<String, Object> sessionMap = externalContext.getSessionMap();
sessionMap.put("User",user);
UserLogin hd = (UserLogin)sessionMap.get("User");
System.out.println("the user id is "+hd.getUserId());
}
session.getTransaction().commit();
}
Exception:
Exception in thread "main" java.lang.NullPointerException at BeanMngr.testclass.main(testclass.java:58) Java Result: 1 BUILD SUCCESSFUL (total time: 4 seconds)
How is this problem caused and how can I solve it?
If you want to store an object in jsf session do the following:
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("yourKey", yourObject);
The SessionMap is a Map<String, Object> and you can access your stored objects with the help of the get(Object key) method.