2016-11-30 104 views
0

我嘗試使用REST API並嘗試連接到服務器並使用Java獲取數據。 我開發了一些代碼;通過REST API獲取數據時java.lang.IllegalArgumentException的問題

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); 

我在上面最後一句之後得到一個異常;

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 

我使用的應用「捲曲」,也就是在命令行上爲REST-API有用,並用相同的URL容易得到的數據。但是,我無法在Java上做到這一點。網址有問題嗎?請糾正我,因爲我沒有看到任何錯誤的代碼。

+2

你不需要在查詢參數前的末尾添加'backslash',即它應該像'https:// XXX/0/devices/2c5a7b88-1eca-48b3-ae68-cdcb011a84d9/s /汽車存在?最新= 2' – Satendra

回答

3

從URL中刪除\\。它不應該在那裏。只使用?來啓動查詢字符串。

相關問題