Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] SPDYClient within a Servlet

Hi Espen,

could you please also try to set NPN to debug and see if that tells us anything: http://www.eclipse.org/jetty/documentation/current/npn-chapter.html#npn-debugging ?

Cheers,
Thomas

Am 9/9/13 8:30 AM, schrieb Espen A. Fossen:
Using 1.7.0_u25 with the npn-boot 1.1.5.v20130313 in the bootclasspath.

Setting org.eclipse.jetty.spdy=DEBUG does not give me anything. As
SPDYClient.Factory* and SPDYClient.connect doesn't actually log anything
before I gets to the TimeoutException.

While tracing the code to where it throws the exception I can see that
it enters the SPDYClient.connect method:

             Session session = client.connect(new
InetSocketAddress("www.googleapis.com", 443), null).get(5,
TimeUnit.SECONDS);

Finishes it up, and then goes to
org.eclipse.jetty.util.FuturePromise#get, there it waits in
if(!_latch.wait(timeout,unit)) for the given set of seconds, then throws
an TimeoutException.

The obvious solution should have been that the server never actually
answers within the given time, but increasing the time doesn't help, and
while running the same code in a main class it works great by going to:

         if (_cause==COMPLETED)

Espen

On 09/06/13 17:09, Thomas Becker wrote:
Hi Espen,

which JVM are you running this with and is the npn jar in the
bootclasspath?
Have you tried setting org.eclipse.jetty.spdy to debug loglevel and
checked the output?

Cheers,
Thomas

Am 9/6/13 9:59 AM, schrieb Espen A. Fossen:
Hi

Have been toying around with SPDYClient to make a simple spdy based call
to a public Google REST API. The code is based upon examples found in
http://wiki.eclipse.org/Jetty/Feature/SPDY and
SSLExternalServerTest.java (spdy-http-server).

The code runs just fine in a main() method, but when trying the same
code wrapped in a simple Servlet, StreamFrameListenere.onData() is never
called:

@WebServlet(urlPatterns = {"/rest"})
public class SPDYBasedRestCallServlet extends HttpServlet {

      private static final long serialVersionUID = 1L;
      private SPDYClient client;

      @Override
      public void init() throws ServletException {

          QueuedThreadPool threadPool = new QueuedThreadPool();
          SslContextFactory sslContextFactory = new SslContextFactory();
          sslContextFactory.setIncludeProtocols("TLSv1");
          sslContextFactory.setEndpointIdentificationAlgorithm("");
          SPDYClient.Factory clientFactory = new
SPDYClient.Factory(threadPool, null, sslContextFactory, 30000);

          try {
              clientFactory.start();
          } catch (Exception e) {
              throw new ServletException(e);
          }
          client = clientFactory.newSPDYClient(SPDY.V3);
      }

      @Override
      protected void doGet(HttpServletRequest request,
HttpServletResponse
response) throws IOException {

          final PrintWriter out = response.getWriter();
          response.setContentType("text/html;charset=UTF-8");

          StreamFrameListener streamListener = new
StreamFrameListener.Adapter()
          {
              public void onData(Stream stream, DataInfo dataInfo)
              {
                  // Data received from server
                  String content = dataInfo.asString("UTF-8", true);
                  out.append(content);
              }
          };

          try {
              Session session = client.connect(new
InetSocketAddress("www.googleapis.com", 443), null).get(5,
TimeUnit.SECONDS);

              Fields headers = new Fields();
              headers.put(HTTPSPDYHeader.SCHEME.name(SPDY.V3), "https");
              headers.put(HTTPSPDYHeader.HOST.name(SPDY.V3),
"www.googleapis.com" + ":" + "443");
              headers.put(HTTPSPDYHeader.METHOD.name(SPDY.V3), "GET");
              headers.put(HTTPSPDYHeader.URI.name(SPDY.V3),
"/urlshortener/v1/url?shortUrl=http://goo.gl/fbsS";);
              headers.put(HTTPSPDYHeader.VERSION.name(SPDY.V3),
"HTTP/1.1");

              // Start a new session, and configure the stream listener
              session.syn(new SynInfo(headers, true), streamListener);
          } catch (ExecutionException | InterruptedException |
TimeoutException e) {
              e.printStackTrace();
          }
      }
}

The servlet return a page, but a TimeoutException is thrown in the logs,
which I guess is because the StreamFrameListenere.onData() is never
called.

java.util.concurrent.TimeoutException
      at org.eclipse.jetty.util.FuturePromise.get(FuturePromise.java:130)
      at
com.test.SPDYBasedRestCallServlet.doGet(SPDYBasedRestCallServlet.java:65)

      at javax.servlet.http.HttpServlet.service(HttpServlet.java:735)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
      at
org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:698)
      at
org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:505)

      at
org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:138)

      at
org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:564)

      at
org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:213)

      at
org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1096)

      at
org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:432)

      at
org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175)

      at
org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1030)

      at
org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)

      at
org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:201)

      at
org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:109)

      at
org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)

      at org.eclipse.jetty.server.Server.handle(Server.java:445)
      at
org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:268)
      at
org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:229)

      at
org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358)

      at
org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601)

      at
org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:532)

      at java.lang.Thread.run(Thread.java:724)

While the webapp runs using jetty-maven-plugin:run (9.0.5.v20130815),
both the main method test and webapp shares the same dependencies to:

* org.eclipse.jetty:jetty-server:9.0.5.v20130815
* org.eclipse.jetty.spdy:spdy-core:9.0.5.v20130815
* org.eclipse.jetty.spdy:spdy-client:9.0.5.v20130815
* org.eclipse.jetty.spdy:spdy-http-server:9.0.5.v20130815
* org.eclipse.jetty.npn:npn-api:1.1.0.v20120525

Any help would be appreciated.

Regards,
Espen

_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-users


_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-users

_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-users




Back to the top