1

我有一个非常简单的 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(Request) 并且都挂起。

服务器代码:

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 的新手,所以也许我做错了什么,但这些是从可用文档中获取的简单示例。

4

1 回答 1

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)
于 2012-10-12T14:43:34.410 回答