2013-07-15 65 views
2

我需要制定使用JSON數據的URL看起來像拋出:IllegalArgumentException用JSON字符串解析URL時抓住

http://someurl.com/passfail?parameter= { 「DATA1」: 「123456789」, 「數據2」: 「123456789」},和我將需要通過它使用JBoss的ClientResponse來獲得響應狀態。 我第一次嘗試通過在文字字符串數據

ClientRequest clientrequest = new ClientRequest("http://someurl.com/passfail?parameter={\"data1\":\"123456789\",\"data2\":\"123456789\"});// assuming the "\" is formulated correctly 

,但它給出了一個例外。 因此,我也嘗試使用URL url = new URL(url),但它不起作用。

我有以下異常,抓住試圖,我感覺非常困難,並希望如果有人能幫助。

拋出:IllegalArgumentException:

org.jboss.resteasy.specimpl.UriBuilderImpl.buildFromMap(UriBuilderImpl.java:408)> 
org.jboss.resteasy.specimpl.UriBuilderImpl.buildFromValues(UriBuilderImpl.java:558)> 
org.jboss.resteasy.specimpl.UriBuilderImpl.build(UriBuilderImpl.java:539)> 
org.jboss.resteasy.client.ClientRequest.getUri(ClientRequest.java:786)> 
org.jboss.resteasy.client.core.executors.ApacheHttpClientExecutor.execute(ApacheHttpClientExecutor.java:77)> 
org.jboss.resteasy.core.interception.ClientExecutionContextImpl.proceed(ClientExecutionContextImpl.java:39)> 
org.jboss.resteasy.plugins.interceptors.encoding.AcceptEncodingGZIPInterceptor.execute(AcceptEncodingGZIPInterceptor.java:40)> 
org.jboss.resteasy.core.interception.ClientExecutionContextImpl.proceed(ClientExecutionContextImpl.java:45)> 
org.jboss.resteasy.client.ClientRequest.execute(ClientRequest.java:473)> 
org.jboss.resteasy.client.ClientRequest.httpMethod(ClientRequest.java:704)> 
org.jboss.resteasy.client.ClientRequest.get(ClientRequest.java:509)> 
org.jboss.resteasy.client.ClientRequest.get(ClientRequest.java:537)> 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX at line personal Servlet 
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)> 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX at line personal Servlet 
javax.servlet.http.HttpServlet.service(HttpServlet.java:820)> 
weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)> 
weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)> 
weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)> 
weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)> 
weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:505)> 
weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:251)> 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX at line personal Servlet JSP 
weblogic.servlet.jsp.JspBase.service(JspBase.java:34)> 
weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)> 
weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)> 
weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)> 
weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)> 
weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:505)> 
weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:251)> 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX at line personal Servlet 
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)> 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX at line personal Servlet 
javax.servlet.http.HttpServlet.service(HttpServlet.java:820)> 
weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)> 
weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)> 
weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)> 
weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)> 
weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:505)> 
weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:251)> 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX at line personal Servlet 
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)> 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX at line personal Servlet 
javax.servlet.http.HttpServlet.service(HttpServlet.java:820)> 
weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)> 
weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)> 
weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)> 
weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)> 
weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3498)> 
weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)> 
weblogic.security.service.SecurityManager.runAs(Unknown Source)> 
weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2180)> 
weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2086)> 
weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406)> 
weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)> 
weblogic.work.ExecuteThread.run(ExecuteThread.java:173)> 
Caused by: java.lang.IllegalArgumentException> 
java.net.URI.create(URI.java:842)> 
org.jboss.resteasy.specimpl.UriBuilderImpl.buildFromMap(UriBuilderImpl.java:404)> 
... 60 more> 
Caused by: java.net.URISyntaxException: Illegal character in query index 77: http://someurl.com/passfail?parameter={"data1":"123456789","data2":"123456789"}> 
java.net.URI$Parser.fail(URI.java:2809)> 
java.net.URI$Parser.checkChars(URI.java:2982)> 
java.net.URI$Parser.parseHierarchical(URI.java:3072)> 
java.net.URI$Parser.parse(URI.java:3014)> 
java.net.URI.<init>(URI.java:578)> 
java.net.URI.create(URI.java:840)> 
... 61 more> 

回答

4

的問題是,你傳遞非法字符在URI字符串:Java - Convert String to valid URI object

http://someurl.com/passfail?parameter={"data1":"123456789","data2":"123456789"}>

你需要在你的URI 「逃離」 有問題的字符。

這裏有一些選擇:

,以及最後但並非最不重要:

PS:關於 「>」 在您的網址是什麼?

+0

你好保羅,不是。 –

2

感謝保羅,

我已經通過閱讀和做新一輪的研究,這和我使用

String url ="http://someurl.com/passfail?parameter={"data1":"123456789","data2":"123456789"}"; 
String encodedURL = URIUtil.encodeQuery(url); 

,它給了我200的地位,這是成功的。

我使用的API是從org.apache.commons.httpclient.util.URIUtil