Examples of BaseClientResponse


Examples of org.jboss.resteasy.client.core.BaseClientResponse

      this.method = method;
   }

   public Object extractEntity(ClientRequestContext context, Object... args)
   {
      final BaseClientResponse response = context.getClientResponse();
      try
      {
         response.checkFailureStatus();
      }
      catch (RuntimeException e)
      {
         context.getErrorHandler().clientErrorHandling(response, e);
      }

      // only release connection if it is not an instance of an
      // InputStream
      boolean releaseConnectionAfter = true;
      try
      {
         // void methods should be handled before this method gets called, but it's worth being defensive  
         if (method.getReturnType() == null)
         {
            throw new RuntimeException(
                    "No type information to extract entity with.  You use other getEntity() methods");
         }
         Object obj = response.getEntity(method.getReturnType(), method.getGenericReturnType());
         if (obj instanceof InputStream)
            releaseConnectionAfter = false;
         return obj;
      }
      catch (RuntimeException e)
      {
         context.getErrorHandler().clientErrorHandling(response, e);
      }
      finally
      {
         if (releaseConnectionAfter)
            response.releaseConnection();
      }
      throw new RuntimeException("Should be unreachable");
   }
View Full Code Here

Examples of org.jboss.resteasy.client.core.BaseClientResponse

      final HttpRequestBase httpMethod = createHttpMethod(uri, request.getHttpMethod());
      loadHttpMethod(request, httpMethod);

      final HttpResponse res = httpClient.execute(httpMethod);

      BaseClientResponse response = new BaseClientResponse(new BaseClientResponseStreamFactory()
      {
         InputStream stream;

         public InputStream getInputStream() throws IOException
         {
            if (stream == null)
            {
               HttpEntity entity = res.getEntity();
               if (entity == null) return null;
               stream = new SelfExpandingBufferredInputStream(entity.getContent());
            }
            return stream;
         }

         public void performReleaseConnection()
         {
            // Apache Client 4 is stupid,  You have to get the InputStream and close it if there is an entity
            // otherwise the connection is never released.  There is, of course, no close() method on response
            // to make this easier.
            try
            {
               if (stream != null)
               {
                  stream.close();
               }
               else
               {
                  InputStream is = getInputStream();
                  if (is != null)
                  {
                     is.close();
                  }
               }
            }
            catch (Exception ignore)
            {
            }
         }
      }, this);
      response.setStatus(res.getStatusLine().getStatusCode());
      response.setHeaders(extractHeaders(res));
      response.setProviderFactory(request.getProviderFactory());
      return response;
   }
View Full Code Here

Examples of org.jboss.resteasy.client.core.BaseClientResponse

   }

   protected BaseClientResponse createResponse(ClientRequest request, final MockHttpResponse mockResponse)
   {
      BaseClientResponseStreamFactory streamFactory = createStreamFactory(mockResponse);
      BaseClientResponse response = new BaseClientResponse(streamFactory, this);
      response.setStatus(mockResponse.getStatus());
      setHeaders(mockResponse, response);
      response.setProviderFactory(request.getProviderFactory());
      return response;
   }
View Full Code Here

Examples of org.jboss.resteasy.client.core.BaseClientResponse

      final HttpMethodBase httpMethod = createHttpMethod(uri, request.getHttpMethod());
      loadHttpMethod(request, httpMethod);

      int status = httpClient.executeMethod(httpMethod);

      BaseClientResponse response = new BaseClientResponse(new BaseClientResponseStreamFactory()
      {
         InputStream stream;

         public InputStream getInputStream() throws IOException
         {
            if (stream == null)
            {
               stream = new SelfExpandingBufferredInputStream(httpMethod.getResponseBodyAsStream());
            }
            return stream;
         }

         public void performReleaseConnection()
         {
            try
            {
               httpMethod.releaseConnection();
            }
            catch (Exception ignored)
            {}
            try
            {
               stream.close();
            }
            catch (Exception ignored)
            {}
         }
      }, this);
      response.setStatus(status);
      response.setHeaders(extractHeaders(httpMethod));
      response.setProviderFactory(request.getProviderFactory());
      return response;
   }
View Full Code Here

Examples of org.jboss.resteasy.client.core.BaseClientResponse

   private ClientResponse execute(ClientRequest request, final HttpURLConnection connection) throws IOException
   {
      outputBody(request, connection);
      final int status = connection.getResponseCode();
      BaseClientResponse response = new BaseClientResponse(new BaseClientResponseStreamFactory()
      {
         public InputStream getInputStream() throws IOException
         {
            return (status < 300) ? connection.getInputStream() : connection.getErrorStream();
         }

         public void performReleaseConnection()
         {
            try
            {
               getInputStream().close();
            }
            catch (IOException e)
            {
            }
            connection.disconnect();
         }
      }, this);
      response.setProviderFactory(request.getProviderFactory());
      response.setStatus(status);
      response.setHeaders(getHeaders(connection));
      return response;
   }
View Full Code Here

Examples of org.jboss.resteasy.client.core.BaseClientResponse

   }

   private BaseClientResponse createClientResponse(ClientRequest request, BrowserCache.Entry entry)
   {
      BaseClientResponse response = new BaseClientResponse(new CachedStreamFactory(entry));
      response.setStatus(200);
      response.setHeaders(entry.getHeaders());
      response.setProviderFactory(request.getProviderFactory());
      return response;
   }
View Full Code Here

Examples of org.jboss.resteasy.client.core.BaseClientResponse

      {
         setExecutionInterceptors(providerFactory
                 .getClientExecutionInterceptorRegistry().bindForList(null, null));
      }

      BaseClientResponse response = null;
      if (getExecutionInterceptorList().isEmpty())
      {
         response = (BaseClientResponse) executor.execute(this);
      }
      else
      {
         ClientExecutionContextImpl ctx = new ClientExecutionContextImpl(
                 getExecutionInterceptorList(), executor, this);
         response = (BaseClientResponse) ctx.proceed();
      }
      response.setAttributes(attributes);
      response.setMessageBodyReaderInterceptors(getReaderInterceptors());
      return response;
   }
View Full Code Here

Examples of org.jboss.resteasy.client.core.BaseClientResponse

    * @return
    * @throws Exception
    */
   public <T> ClientResponse<T> get(Class<T> returnType) throws Exception
   {
      BaseClientResponse response = (BaseClientResponse) get();
      response.setReturnType(returnType);
      return response;
   }
View Full Code Here

Examples of org.jboss.resteasy.client.core.BaseClientResponse

   }

   public <T> ClientResponse<T> get(Class<T> returnType, Type genericType)
           throws Exception
   {
      BaseClientResponse response = (BaseClientResponse) get();
      response.setReturnType(returnType);
      response.setGenericReturnType(genericType);
      return response;
   }
View Full Code Here

Examples of org.jboss.resteasy.client.core.BaseClientResponse

      return response;
   }

   public <T> ClientResponse<T> get(GenericType type) throws Exception
   {
      BaseClientResponse response = (BaseClientResponse) get();
      response.setReturnType(type.getType());
      response.setGenericReturnType(type.getGenericType());
      return response;
   }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.