我有一个非常简单的Restlet服务器,我正在使用一个非常简单的Restlet客户端进行测试,所有这些服务器都使用具有以下扩展名的Restlet-2.1.0:xstream-1.4,jettison-1.3。
在我的Mac上一切正常,但是当尝试在SunOS 5.10上运行时,客户端在连接到服务器时会挂起。从浏览器或telnet访问服务器时,我可以得到响应,并且当连接到Restlet服务器以外的任何其他资源时,同样的客户端也能正常工作。
查看线程转储我看到了:
"main" prio=3 tid=0x08070800 nid=0x2 waiting on condition [0xfe0eb000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0xbbe827e8> (a java.util.concurrent.CountDownLatch$Sync)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:156)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:811)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(AbstractQueuedSynchronizer.java:969)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1281)
at java.util.concurrent.CountDownLatch.await(CountDownLatch.java:207)
at org.restlet.engine.connector.ClientConnectionHelper.handle(ClientConnectionHelper.java:517)
at org.restlet.Client.handle(Client.java:180)
at org.restlet.Restlet.handle(Restlet.java:284)
at com.redprairie.task.common.TempClient.main(TempClient.java:17)
我尝试使用ClientResource.get()和Client.handle(请求)并且都挂起。
服务器代码:
server = new Server(Protocol.HTTP, SERVER_PORT, TestServerResource.class);
Context ctx = new Context();
server.setContext(ctx);
server.start();
客户代码:
Request request = new Request(Method.GET, "http://localhost:8188/retrieve");
Client client = new Client(Protocol.HTTP);
Response response = client.handle(request);
response.getEntity().write(System.out);
资源:
public class TestServerResource extends ServerResource {
private static volatile Customer bernard = Customer.createSample();
@Get("json")
public Customer retrieve() {
System.out.println("GET request received");
return bernard;
}
}
xstream和jettison扩展完美地将java对象转换为JSON,反之亦然,再次,这在我的Mac OS X上工作正常,但是在Sun上挂起......
我是Restlet的新手,所以也许我做错了,但这些都是从可用文档中提取的简单示例。
答案 0 :(得分:0)
我认为这可能与此问题有关:https://github.com/restlet/restlet-framework-java/issues/669#issuecomment-9174819
然而,这并不能解释为什么服务器不回复restlet而是回复其他人。 你在服务器上有任何例外吗?我有一个类似的情况,我实际上在服务器上得到了这个例外:
The connection was broken. It was probably closed by the client.
org.eclipse.jetty.io.EofException
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.blockWritable(SelectChannelEndPoint.java:435)
at org.eclipse.jetty.http.AbstractGenerator.blockForOutput(AbstractGenerator.java:512)
at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:159)
at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:101)
at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
at sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:282)
at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:125)
at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:135)
at java.io.OutputStreamWriter.write(OutputStreamWriter.java:220)
at java.io.Writer.write(Writer.java:157)
at org.restlet.representation.StringRepresentation.write(StringRepresentation.java:237)
at org.restlet.representation.CharacterRepresentation.write(CharacterRepresentation.java:76)
at org.restlet.engine.adapter.ServerCall.writeResponseBody(ServerCall.java:509)
at org.restlet.engine.adapter.ServerCall.sendResponse(ServerCall.java:453)
at org.restlet.ext.jetty.internal.JettyCall.sendResponse(JettyCall.java:312)
at org.restlet.engine.adapter.ServerAdapter.commit(ServerAdapter.java:196)
at org.restlet.engine.adapter.HttpServerHelper.handle(HttpServerHelper.java:153)
at org.restlet.ext.jetty.JettyServerHelper$WrappedServer.handle(JettyServerHelper.java:170)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:452)
at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:894)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:948)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:943)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:77)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:622)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:46)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:603)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:538)
at java.lang.Thread.run(Thread.java:722)