NPE while trying to retrieve a work item
When I try to retrieve an RTC work item, I get an NPE. The code is as follows (in doGet() of my RestService):
//*********************************************
// Get credentials from request
Map<String> params = RequestParams.getParameterMap(request.getParams());
String workItemId = HttpRequestUtil.getFirstNonNullParamValue(params, "workitem");
// Initialize HTTP client, if not done yet
if (httpClient == null) {
httpClient = new JazzHttpClient();
defaultHttpContext = httpClient.createDefaultHttpContext();
}
//Create a functional user context
OAuthContextUtil.setOAuthAccessToken(defaultHttpContext,new OAuthAccessToken(HttpConstants.EMPTY, HttpConstants.EMPTY));
BootstrapConfig config = BootstrapConfig.getInstance();
OAuthContextUtil.setOAuthConsumerProperties(defaultHttpContext, config.getOAuthConsumerProperties());
HttpResponse jfsResponse = null;
try {
String uri = "https://localhost:9443/ccm/resource/com.ibm.team.workitem.WorkItem/"+workItemId;
HttpGet getCurrentUserRequest = new HttpGet(uri);
getCurrentUserRequest.addHeader(HttpConstants.ACCEPT, HttpConstants.CT_APPLICATION_RDF_XML);
jfsResponse = httpClient.execute(getCurrentUserRequest, defaultHttpContext);
//Parse the work item representation
RDFEntity entity = new RDFEntity(jfsResponse.getEntity());
Model model = entity.getModel();
if(model != null){
Resource res = model.getResource(uri);
if (res != null) {
}
}
} catch (OAuthInvalidOrExpiredTokenException e) {
response.setStatusCode(HttpStatus.SC_UNAUTHORIZED);
response.setEntity(new StringEntity("invalid username or password"));
} catch (Exception e) {
e.printStackTrace();
response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
response.setEntity(new StringEntity(e.getMessage()));
}
//*********************************************
During the execution of
RDFEntity entity = new RDFEntity(jfsResponse.getEntity());
I get the following NPE. Can someone help me what's wrong here? When I execute the same query in my browser, I can see the work item details in html format (though I am not sure why it is shown in html and not in RDF).
Also, I am not able to use discovery mechanism for discovering work items because of an existing defect in RTC. Please see https://jazz.net/forums/viewtopic.php?t=17227
java.lang.NullPointerException
at com.ibm.team.jfs.app.resource.entity.RDFEntity.<init>(RDFEntity.java:108)
at com.ibm.team.jfs.sdk.samples.capitalloginhandler.Retriever.doGet(Retriever.java:119)
at com.ibm.team.jfs.app.servlet.AppContainerServlet.dispatchRequest(AppContainerServlet.java:164)
at com.ibm.team.jfs.app.servlet.AppContainerServlet.service(AppContainerServlet.java:276)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
//*********************************************
// Get credentials from request
Map<String> params = RequestParams.getParameterMap(request.getParams());
String workItemId = HttpRequestUtil.getFirstNonNullParamValue(params, "workitem");
// Initialize HTTP client, if not done yet
if (httpClient == null) {
httpClient = new JazzHttpClient();
defaultHttpContext = httpClient.createDefaultHttpContext();
}
//Create a functional user context
OAuthContextUtil.setOAuthAccessToken(defaultHttpContext,new OAuthAccessToken(HttpConstants.EMPTY, HttpConstants.EMPTY));
BootstrapConfig config = BootstrapConfig.getInstance();
OAuthContextUtil.setOAuthConsumerProperties(defaultHttpContext, config.getOAuthConsumerProperties());
HttpResponse jfsResponse = null;
try {
String uri = "https://localhost:9443/ccm/resource/com.ibm.team.workitem.WorkItem/"+workItemId;
HttpGet getCurrentUserRequest = new HttpGet(uri);
getCurrentUserRequest.addHeader(HttpConstants.ACCEPT, HttpConstants.CT_APPLICATION_RDF_XML);
jfsResponse = httpClient.execute(getCurrentUserRequest, defaultHttpContext);
//Parse the work item representation
RDFEntity entity = new RDFEntity(jfsResponse.getEntity());
Model model = entity.getModel();
if(model != null){
Resource res = model.getResource(uri);
if (res != null) {
}
}
} catch (OAuthInvalidOrExpiredTokenException e) {
response.setStatusCode(HttpStatus.SC_UNAUTHORIZED);
response.setEntity(new StringEntity("invalid username or password"));
} catch (Exception e) {
e.printStackTrace();
response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
response.setEntity(new StringEntity(e.getMessage()));
}
//*********************************************
During the execution of
RDFEntity entity = new RDFEntity(jfsResponse.getEntity());
I get the following NPE. Can someone help me what's wrong here? When I execute the same query in my browser, I can see the work item details in html format (though I am not sure why it is shown in html and not in RDF).
Also, I am not able to use discovery mechanism for discovering work items because of an existing defect in RTC. Please see https://jazz.net/forums/viewtopic.php?t=17227
java.lang.NullPointerException
at com.ibm.team.jfs.app.resource.entity.RDFEntity.<init>(RDFEntity.java:108)
at com.ibm.team.jfs.sdk.samples.capitalloginhandler.Retriever.doGet(Retriever.java:119)
at com.ibm.team.jfs.app.servlet.AppContainerServlet.dispatchRequest(AppContainerServlet.java:164)
at com.ibm.team.jfs.app.servlet.AppContainerServlet.service(AppContainerServlet.java:276)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)