I am trying to create a command line Java program which has to access some REST services. I referred one of the springs webapp which does the same using autowiring. I could see the below in the spring config file of the webapp.
<bean id="jacksonJsonProvider" class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider" />
<util:list id="webClientProviders">
<ref bean="jacksonJsonProvider"/>
</util:list>
<bean id="jsonWebClient" class="org.apache.cxf.jaxrs.client.WebClient" factory-method="create">
<constructor-arg type="java.lang.String" value="http://localhost:8080/"/>
<constructor-arg ref="webClientProviders" />
</bean>
This tells me that spring will create an instance of WbClient using the arguments 'http://localhost:8080/' and a List having an instance of JacksonJsonProvider. Is my understand correct?
I also see the below usage in the webapp code.
@Controller
public class ABController {
@Autowired
@Qualifier("jsonWebClient")
private WebClient webclient;
@RequestMapping(value = "/abc.action", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public String getABCD(HttpServletRequest request, HttpServletResponse response) {
...
...
WebClient wc = WebClient.create(webclient.getBaseURI());
wc.path("abcdservices/rest/restservices/cart/gettotal");
Response res = wc.get();
...
...
}
}
But when I do the same in my Java program, as shown below (and some variants):
List<Object> providers = new ArrayList<Object>();
JacksonJsonProvider j = new JacksonJsonProvider();
providers.add(j);
WebClient webclient = WebClient.create("http://localhost:8080/",
providers);
WebClient wc = webclient.create(webclient.getBaseURI());
wc.path("crmitsm/rest/cirestservices/crmitsm/warrantystatus");
Response res = wc.get();
I get the below exception / error.
java -jar target/CmdLine-0.0.1-SNAPSHOT-jar-with-dependencies.jar
Exception in thread "main" java.lang.NullPointerException
at org.apache.cxf.jaxrs.client.AbstractClient.setupOutInterceptorChain(AbstractClient.java:887)
at org.apache.cxf.jaxrs.client.AbstractClient.createMessage(AbstractClient.java:958)
at org.apache.cxf.jaxrs.client.WebClient.finalizeMessage(WebClient.java:1118)
at org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1091)
at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:894)
at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:865)
at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:331)
at org.apache.cxf.jaxrs.client.WebClient.get(WebClient.java:357)
at org.CmdLine.App.main(App.java:37)
Could anybody please help me here. I am not able to understand what I am missing here.