[jboss-cvs] JBossRemoting/src/main/org/jboss/remoting/transport/http ...

Tom Elrod tom.elrod at jboss.com
Mon Jul 17 00:54:01 EDT 2006


  User: telrod  
  Date: 06/07/17 00:54:01

  Modified:    src/main/org/jboss/remoting/transport/http  
                        HTTPClientInvoker.java HTTPMetadataConstants.java
  Log:
  JBREM-544 - changed http client invoker to throw exception upon web server error by default.  Can be configured to not throw exception and just return as response if desired.
  
  Revision  Changes    Path
  1.25      +44 -3     JBossRemoting/src/main/org/jboss/remoting/transport/http/HTTPClientInvoker.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: HTTPClientInvoker.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/transport/http/HTTPClientInvoker.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -b -r1.24 -r1.25
  --- HTTPClientInvoker.java	15 Jul 2006 04:40:11 -0000	1.24
  +++ HTTPClientInvoker.java	17 Jul 2006 04:54:00 -0000	1.25
  @@ -37,6 +37,7 @@
   import org.jboss.remoting.marshal.http.HTTPMarshaller;
   import org.jboss.remoting.marshal.serializable.SerializableUnMarshaller;
   import org.jboss.remoting.transport.web.WebUtil;
  +import org.jboss.test.remoting.transport.http.WebServerError;
   import org.jboss.util.Base64;
   
   import java.io.IOException;
  @@ -92,9 +93,11 @@
      }
   
      private Object useHttpURLConnection(String url, Object invocation, Map metadata,
  -                                       Marshaller marshaller, UnMarshaller unmarshaller)
  +                                       Marshaller marshaller, UnMarshaller unmarshaller) throws WebServerError
      {
         Object result = null;
  +      int responseCode = -1;
  +
         try
         {
            // need to check the url and make sure it compatible protocol
  @@ -184,7 +187,7 @@
   
               OutputStream stream = conn.getOutputStream();
               marshaller.write(invocation, stream);
  -            int responseCode = conn.getResponseCode();
  +            responseCode = conn.getResponseCode();
               InputStream is = (responseCode < 400) ? conn.getInputStream() : conn.getErrorStream();
               Map headers = conn.getHeaderFields();
               if (metadata == null)
  @@ -216,7 +219,7 @@
               }
               metadata.putAll(headers);
               metadata.put(HTTPMetadataConstants.RESPONSE_CODE_MESSAGE, conn.getResponseMessage());
  -            int responseCode = conn.getResponseCode();
  +            responseCode = conn.getResponseCode();
               metadata.put(HTTPMetadataConstants.RESPONSE_CODE, new Integer(responseCode));
            }
         }
  @@ -226,6 +229,44 @@
            throw new CannotConnectException("Can not connect http client invoker.", e);
         }
   
  +      // now check for error response and throw exception unless configured to not do so
  +      if(responseCode >= 400)
  +      {
  +         if(metadata != null)
  +         {
  +            Object configObj = metadata.get(HTTPMetadataConstants.NO_THROW_ON_ERROR);
  +            if(configObj != null && configObj instanceof String)
  +            {
  +               boolean doNotThrow = Boolean.valueOf((String)configObj).booleanValue();
  +               if(doNotThrow)
  +               {
  +                  if(result instanceof String)
  +                  {
  +                     // this is a html error page displayed by web server, need to conver to exception
  +                     WebServerError ex = new WebServerError((String)result);
  +                     return ex;
  +                  }
  +                  else
  +                  {
  +                     return result;
  +                  }
  +               }
  +            }
  +         }
  +         // if got here, wasn't configured to not throw exception, so will throw it
  +         if(result instanceof String)
  +         {
  +            WebServerError ex = new WebServerError((String)result);
  +            throw ex;
  +         }
  +         else
  +         {
  +            WebServerError ex = new WebServerError("Error received when calling on web server.  Error returned was " + responseCode);
  +            throw ex;
  +         }
  +
  +      }
  +
         return result;
      }
   
  
  
  
  1.8       +7 -0      JBossRemoting/src/main/org/jboss/remoting/transport/http/HTTPMetadataConstants.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: HTTPMetadataConstants.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/transport/http/HTTPMetadataConstants.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -b -r1.7 -r1.8
  --- HTTPMetadataConstants.java	8 Apr 2006 02:44:50 -0000	1.7
  +++ HTTPMetadataConstants.java	17 Jul 2006 04:54:00 -0000	1.8
  @@ -39,4 +39,11 @@
      public static final String RESPONSE_CODE_MESSAGE = "ResponseCodeMessage";
      public static final String REMOTING_VERSION_HEADER = "JBoss-Remoting-Version";
      public static final String REMOTING_USER_AGENT = "User-Agent";
  +
  +   /**
  +    * Configuration key for indicating if http client invoker should
  +    * throw exception on error from server or just return the error
  +    * as the response.
  +    */
  +   public static final String NO_THROW_ON_ERROR = "NoThrowOnError";
   }
  \ No newline at end of file
  
  
  



More information about the jboss-cvs-commits mailing list