Hey Jeff,

I'm trying to duplicate your problem. I adapted your code in the attached TimeoutTest, but it runs fine.


Could you fiddle with TimeoutTest and get it to throw the NPE?

Thanks,
Ron

On 03/20/2015 03:40 PM, Jeff Ramin wrote:
Hi folks.

Using resteasy 3.0.5, and I need to set connection and read timeouts on
a request.
Here's the code:

          org.apache.http.impl.client.DefaultHttpClient httpClient = new
org.apache.http.impl.client.DefaultHttpClient();
          HttpParams params = new org.apache.http.params.BasicHttpParams();

org.apache.http.params.HttpConnectionParams.setConnectionTimeout(params,
4000);
org.apache.http.params.HttpConnectionParams.setSoTimeout(params, 2000);
          httpClient.setParams(params);

          executor = new
org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor(httpClient);

          ClientRequest clientRequest = new ClientRequest(newPath, executor);
          clientRequest = clientRequest.accept(getResponseMediaType())
.body(getRequestMediaType(), request)
.followRedirects(false);
          clientRequest = clientRequest.header("headerKey", "headerVal");
          T out = clientRequest.post(responseClassType).getEntity();

I'm seeing an NPE when this code is run:

       [java] java.lang.NullPointerException
       [java]     at
org.jboss.resteasy.spi.ResteasyProviderFactory.toHeaderString(ResteasyProviderFactory.java:1263)
       [java]     at
org.jboss.resteasy.client.ClientRequest.toHeaderString(ClientRequest.java:204)
       [java]     at
org.jboss.resteasy.client.ClientRequest.getHeaders(ClientRequest.java:329)
       [java]     at
org.jboss.resteasy.plugins.interceptors.encoding.AcceptEncodingGZIPInterceptor.execute(AcceptEncodingGZIPInterceptor.java:27)
       [java]     at
org.jboss.resteasy.core.interception.ClientExecutionContextImpl.proceed(ClientExecutionContextImpl.java:47)
       [java]     at
org.jboss.resteasy.client.ClientRequest.execute(ClientRequest.java:441)
       [java]     at
org.jboss.resteasy.client.ClientRequest.httpMethod(ClientRequest.java:682)
       [java]     at
org.jboss.resteasy.client.ClientRequest.post(ClientRequest.java:566)
       [java]     at
org.jboss.resteasy.client.ClientRequest.post(ClientRequest.java:571)


Any ideas on what I'm doing wrong? I get the error whether I include the
ClientRequest.header() call or not.

Thanks!



package org.jboss.resteasy.test.client;

import javax.ws.rs.POST;
import javax.ws.rs.Path;

import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.jboss.resteasy.client.ClientRequest;
import org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor;
import org.jboss.resteasy.core.Dispatcher;
import org.jboss.resteasy.spi.ResteasyDeployment;
import org.jboss.resteasy.test.EmbeddedContainer;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

public class TimeoutTest
{
   protected static ResteasyDeployment deployment;
   protected static Dispatcher dispatcher;

   @Path("/test")
   public static class MyResourceImpl
   {
      @Path("post")
      @POST
      public String post(String s)
      {
         return s;
      }
   }

   @BeforeClass
   public static void before() throws Exception
   {
      deployment = EmbeddedContainer.start();
      dispatcher = deployment.getDispatcher();
      deployment.getRegistry().addPerRequestResource(MyResourceImpl.class);
   }

   @AfterClass
   public static void after() throws Exception
   {
      EmbeddedContainer.stop();
      dispatcher = null;
      deployment = null;
   }

   @Test
   public void testTimeout() throws Exception
   {
      DefaultHttpClient httpClient = new DefaultHttpClient();
      HttpParams params = new BasicHttpParams();
      HttpConnectionParams.setConnectionTimeout(params, 4000);
      HttpConnectionParams.setSoTimeout(params, 2000);
      httpClient.setParams(params);
      ApacheHttpClient4Executor executor = new ApacheHttpClient4Executor(httpClient);
      ClientRequest clientRequest = new ClientRequest("http://localhost:8081/test/post";, executor);
      clientRequest = clientRequest.accept("*/*").body("text/plain", "abc").followRedirects(false);
      clientRequest = clientRequest.header("headerKey", "headerVal");
      String out = clientRequest.post(String.class).getEntity();
      System.out.println("out: " + out);
   }
}
------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Resteasy-users mailing list
Resteasy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/resteasy-users

Reply via email to