Package org.jboss.resteasy.client.jaxrs.internal

Examples of org.jboss.resteasy.client.jaxrs.internal.ClientResponse


   }

   public Object invoke(Object[] args)
   {
      ClientInvocation request = createRequest(args);
      ClientResponse response = (ClientResponse)request.invoke();
      ClientContext context = new ClientContext(request, response, entityExtractorFactory);
      return extractor.extractEntity(context, null);
   }
View Full Code Here


      this.method = method;
   }

   public Object extractEntity(ClientContext context, Object... args)
   {
      ClientResponse response = context.getClientResponse();

      // only release connection if it is not an instance of an
      // InputStream
      boolean releaseConnectionAfter = response.getStatus() >=200 && response.getStatus() < 300;
      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");
         }
         GenericType gt = null;
         if (method.getGenericReturnType() != null)
         {
            gt = new GenericType(method.getGenericReturnType());
         }
         else
         {
            gt = new GenericType(method.getReturnType());
         }
         Object obj = ClientInvocation.extractResult(gt, response, method.getAnnotations());
         if (obj instanceof InputStream || obj instanceof Reader)
            releaseConnectionAfter = false;
         return obj;
      }
      finally
      {
         if (releaseConnectionAfter)
            response.close();
      }
   }
View Full Code Here

   {
      return new EntityExtractor()
      {
         public Object extractEntity(ClientContext context, Object... args)
         {
            ClientResponse response = context.getClientResponse();
            int status = response.getStatus();
            if (status >= 400)
            {
               response.bufferEntity();
               response.close();
               ClientInvocation.handleErrorStatus(response);
            }
            response.close();
            return null;
         }
      };
   }
View Full Code Here

      finally
      {
         cleanUpAfterExecute(httpMethod);
      }

      ClientResponse response = new ClientResponse(request.getClientConfiguration())
      {
         InputStream stream;
         InputStream hc4Stream;

         @Override
         protected void setInputStream(InputStream is)
         {
            stream = is;
         }

         public InputStream getInputStream()
         {
            if (stream == null)
            {
               HttpEntity entity = res.getEntity();
               if (entity == null) return null;
               try
               {
                  hc4Stream = entity.getContent();
                  stream = createBufferedStream(hc4Stream);
               }
               catch (IOException e)
               {
                  throw new RuntimeException(e);
               }
            }
            return stream;
         }

         public void releaseConnection() throws IOException
         {
            // 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 {
               // Another stupid thing...TCK is testing a specific exception from stream.close()
               // so, we let it propagate up.
               if (stream != null)
               {
                  stream.close();
               }
               else
               {
                  InputStream is = getInputStream();
                  if (is != null)
                  {
                     is.close();
                  }
               }
            }
            finally {
               // just in case the input stream was entirely replaced and not wrapped, we need
               // to close the apache client input stream.
               if (hc4Stream != null)
               {
                  try {
                     hc4Stream.close();
                  }
                  catch (IOException ignored) {

                  }
               }
               else
               {
                  try
                  {
                     HttpEntity entity = res.getEntity();
                     if (entity != null) entity.getContent().close();
                  }
                  catch (IOException ignored)
                  {
                  }

               }

            }
          }
      };
      response.setProperties(request.getMutableProperties());
      response.setStatus(res.getStatusLine().getStatusCode());
      response.setHeaders(extractHeaders(res));
      response.setClientConfiguration(request.getClientConfiguration());
      return response;
   }
View Full Code Here

        {
            throw new ProcessingException("Unable to invoke request", e);
        }

        //Creating response with stream content
        ClientResponse response = new ClientResponse(request.getClientConfiguration())
        {
            private InputStream stream;

            @Override
            protected InputStream getInputStream()
            {
                if (stream == null)
                {
                    try
                    {
                        stream = (status < 300) ? connection.getInputStream() : connection.getErrorStream();
                    }
                    catch (IOException e)
                    {
                        throw new RuntimeException(e);
                    }
                }

                return stream;
            }

            @Override
            protected void setInputStream(InputStream is)
            {
                stream = is;
            }

            @Override
            protected void releaseConnection() throws IOException
            {
                getInputStream().close();
                connection.disconnect();
            }
        };

        //Setting attributes
        response.setStatus(status);
        response.setHeaders(getHeaders(connection));

        return response;
    }
View Full Code Here

TOP

Related Classes of org.jboss.resteasy.client.jaxrs.internal.ClientResponse

Copyright © 2018 www.massapicom. 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.