séan35 séan35 - 11 days ago 6
reST (reStructuredText) Question

Issue about java.lang.IllegalArgumentException while getting data via REST-API

I try to use REST API and try to connect to the server and get data in Java.
I develop some code like;

Client client = Client.create();
WebResource webResource = client.resource("https://XXXX/0/devices/2c5a7b88-1eca-48b3-ae68-cdcb011a84d9/s/car-exists\\?latest=2");
WebResource.Builder builder = webResource.getRequestBuilder();
for (NewCookie c : cookies)
builder = builder.cookie(c);
ClientResponse response = builder.accept("application/json").get(ClientResponse.class);


I get an exception after the last sentence above;

javax.faces.FacesException: #{XXX}: java.lang.IllegalArgumentException: Illegal character in path at index 117: https://XXX/0/devices/2c5a7b88-1eca-48b3-ae68-cdcb011a84d9/s/car-exists\?latest=2
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
at org.primefaces.application.DialogActionListener.processAction(DialogActionListener.java:45)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at filter.NoCacheFilter.doFilter(NoCacheFilter.java:46)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: javax.faces.el.EvaluationException: java.lang.IllegalArgumentException: Illegal character in path at index 117: https://XXX/0/devices/2c5a7b88-1eca-48b3-ae68-cdcb011a84d9/s/car-exists\?latest=2
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
... 27 more


I used the application "curl" that is useful for REST-API on command line and got data easily with the same url. But, I can't do it on Java. Is there any problem on URL? Please correct me because I see nothing wrong on that code.

Answer

Remove the \\ from the URL. It shouldn't be there. Use only ? to start the query string.