java.net.ConnectException:发送消息时连接超时

时间:2015-10-05 06:08:26

标签: java eclipse apache web-services restful-architecture

 Oct 05, 2015 11:16:46 AM org.apache.catalina.core.StandardWrapperValve
 invoke SEVERE: Servlet.service() for servlet
 [javax.ws.rs.core.Application] in context with path [/FunkyApp] threw
 exception org.jboss.resteasy.spi.UnhandledException:
 java.net.ConnectException: Connection timed out    at
 org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:76)
    at
 org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:212)
    at
 org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:149)
    at
 org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:372)
    at
 org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179)
    at
 org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)
    at
 org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
    at
 org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)     at
 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at
 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at
 org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at
 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at
 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at
 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at
 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at
 org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at
 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
    at
 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at
 org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
    at
 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at
 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
    at
 org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
    at
 org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
    at
 org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1526)
    at
 org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1482)
    at
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at
 org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745) Caused by:
 java.net.ConnectException: Connection timed out    at
 java.net.PlainSocketImpl.socketConnect(Native Method)  at
 java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at
 java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at
 java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)   at
 java.net.Socket.connect(Socket.java:589)   at
 java.net.Socket.connect(Socket.java:538)   at
 sun.net.NetworkClient.doConnect(NetworkClient.java:180)    at
 sun.net.www.http.HttpClient.openServer(HttpClient.java:432)    at
 sun.net.www.http.HttpClient.openServer(HttpClient.java:527)    at
 sun.net.www.http.HttpClient.<init(HttpClient.java:211)     at
 sun.net.www.http.HttpClient.New(HttpClient.java:308)   at
 sun.net.www.http.HttpClient.New(HttpClient.java:326)   at
 sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1168)
    at
 sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1104)
    at
 sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:998)
    at
 sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:932)
    at
 obl.funkey.service.FunkeyServiceImpl.getLanguageInfo(FunkeyServiceImpl.java:480)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at
 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at
 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)     at
 org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:137)
    at
 org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:296)
    at
 org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:250)
    at
 org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:237)
    at
 org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356)
    ... 26 more

我开发了Restful Web服务,然后使用maven进行项目构建。我尝试连接java代码

URL url = new URL(requestURL);
StringReader  requestReader = new StringReader(calloutRequest);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestProperty( "Content-Type", "multipart/form-data" );
connection.connect();
Writer connWriter = new OutputStreamWriter(connection.getOutputStream());
int c;
StringBuffer ResponserStr =new StringBuffer();

while ( (c = requestReader.read()) != -1 ){  
    connWriter.write( (char)c );
}

connWriter.flush();
connection.getOutputStream().close();
java.lang.Object response2 = connection.getContent();
Reader connReader = new InputStreamReader((InputStream) response2 );

while ( (c = connReader.read()) != -1 ){
    ResponserStr .append(""+(char)c);
    System.out.print((char)c);
}

在开发Restful Web服务时,如何解决这种错误?

0 个答案:

没有答案