vmassol     2002/08/28 12:47:49

  Modified:    framework/src/java/share/org/apache/cactus/client
                        HttpClientConnectionHelper.java
  Log:
  new coding conventions
  
  Revision  Changes    Path
  1.3       +51 -32    
jakarta-cactus/framework/src/java/share/org/apache/cactus/client/HttpClientConnectionHelper.java
  
  Index: HttpClientConnectionHelper.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/client/HttpClientConnectionHelper.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- HttpClientConnectionHelper.java   25 Aug 2002 13:41:20 -0000      1.2
  +++ HttpClientConnectionHelper.java   28 Aug 2002 19:47:48 -0000      1.3
  @@ -56,20 +56,21 @@
    */
   package org.apache.cactus.client;
   
  -import java.net.URL;
  -import java.net.HttpURLConnection;
  -import java.util.Enumeration;
  -import java.io.InputStream;
  -import java.io.IOException;
   import java.io.ByteArrayOutputStream;
  +import java.io.IOException;
  +import java.io.InputStream;
   
  -import org.apache.commons.httpclient.HttpClient;
  -import org.apache.commons.httpclient.methods.PostMethod;
  -import org.apache.commons.httpclient.methods.GetMethod;
  +import java.net.HttpURLConnection;
  +import java.net.URL;
  +
  +import java.util.Enumeration;
   
   import org.apache.cactus.WebRequest;
  -import org.apache.cactus.util.UrlUtil;
   import org.apache.cactus.client.authentication.AbstractAuthentication;
  +import org.apache.cactus.util.UrlUtil;
  +import org.apache.commons.httpclient.HttpClient;
  +import org.apache.commons.httpclient.methods.GetMethod;
  +import org.apache.commons.httpclient.methods.PostMethod;
   
   /**
    * Implementation of <code>ConnectionHelper</code> using Jakarta Commons
  @@ -103,8 +104,7 @@
       /**
        * @see ConnectionHelper#connect(WebRequest)
        */
  -    public HttpURLConnection connect(WebRequest theRequest)
  -        throws Throwable
  +    public HttpURLConnection connect(WebRequest theRequest) throws Throwable
       {
           URL url = new URL(this.url);
   
  @@ -112,7 +112,9 @@
           // step to allow authentication to add extra headers, HTTP parameters,
           // etc.
           AbstractAuthentication authentication = theRequest.getAuthentication();
  -        if (authentication != null) {
  +
  +        if (authentication != null)
  +        {
               authentication.configure(theRequest);
           }
   
  @@ -123,12 +125,13 @@
           // - If at least one parameter is to be sent in the request body, then
           //   we are doing a POST.
           // - If user data has been specified, then we are doing a POST
  -
           if (theRequest.getParameterNamesPost().hasMoreElements()
  -            || (theRequest.getUserData() != null)) {
  -
  +            || (theRequest.getUserData() != null))
  +        {
               this.method = new PostMethod();
  -        } else {
  +        }
  +        else
  +        {
               this.method = new GetMethod();
           }
   
  @@ -138,7 +141,7 @@
           this.method.setQueryString(UrlUtil.getQuery(url));
   
           // Sets the content type
  -        this.method.setRequestHeader("Content-type",
  +        this.method.setRequestHeader("Content-type", 
               theRequest.getContentType());
   
           // Add the other header fields
  @@ -146,20 +149,26 @@
   
           // Add the cookies
           String cookieString = getCookieString(theRequest, url);
  -        if (cookieString != null) {
  +
  +        if (cookieString != null)
  +        {
               this.method.addRequestHeader("Cookie", cookieString);
           }
   
           // Add the POST parameters if no user data has been specified (user data
           // overried post parameters)
  -        if (theRequest.getUserData() != null) {
  +        if (theRequest.getUserData() != null)
  +        {
               addUserData(theRequest);
  -        } else {
  +        }
  +        else
  +        {
               addParametersPost(theRequest);
           }
   
           // Open the connection and get the result
           HttpClient client = new HttpClient();
  +
           client.startSession(url.getHost(), url.getPort());
           client.executeMethod(this.method);
   
  @@ -176,15 +185,20 @@
       private void addParametersPost(WebRequest theRequest)
       {
           // If no parameters, then exit
  -        if (!theRequest.getParameterNamesPost().hasMoreElements()) {
  +        if (!theRequest.getParameterNamesPost().hasMoreElements())
  +        {
               return;
           }
   
           Enumeration keys = theRequest.getParameterNamesPost();
  -        if (keys.hasMoreElements()) {
  +
  +        if (keys.hasMoreElements())
  +        {
               String key = (String) keys.nextElement();
               String[] values = theRequest.getParameterValuesPost(key);
  -            for (int i = 0; i < values.length; i++) {
  +
  +            for (int i = 0; i < values.length; i++)
  +            {
                   ((PostMethod) this.method).addParameter(key, values[i]);
               }
           }
  @@ -200,14 +214,18 @@
       {
           Enumeration keys = theRequest.getHeaderNames();
   
  -        while (keys.hasMoreElements()) {
  +        while (keys.hasMoreElements())
  +        {
               String key = (String) keys.nextElement();
               String[] values = theRequest.getHeaderValues(key);
   
               StringBuffer fullHeaderValue = new StringBuffer(values[0]);
  -            for (int i = 1; i < values.length; i++) {
  +
  +            for (int i = 1; i < values.length; i++)
  +            {
                   fullHeaderValue.append("," + values[i]);
               }
  +
               this.method.addRequestHeader(key, fullHeaderValue.toString());
           }
       }
  @@ -219,11 +237,11 @@
        *        redirector.
        * @exception IOException if we fail to read the user data
        */
  -    private void addUserData(WebRequest theRequest)
  -        throws IOException
  +    private void addUserData(WebRequest theRequest) throws IOException
       {
           // If no user data, then exit
  -        if (theRequest.getUserData() == null) {
  +        if (theRequest.getUserData() == null)
  +        {
               return;
           }
   
  @@ -232,11 +250,12 @@
   
           byte[] buffer = new byte[2048];
           int length;
  -        while ((length = stream.read(buffer)) != -1) {
  +
  +        while ((length = stream.read(buffer)) != -1)
  +        {
               baos.write(buffer, 0, length);
           }
   
           ((PostMethod) this.method).setRequestBody(baos.toString());
       }
  -
  -}
  +}
  \ No newline at end of file
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to