axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rineh...@apache.org
Subject cvs commit: xml-axis/java/src/org/apache/axis/transport/http HTTPConstants.java HTTPSender.java
Date Mon, 22 Jul 2002 20:00:36 GMT
rineholt    2002/07/22 13:00:36

  Modified:    java/samples/attachments EchoAttachment.java
               java/src/org/apache/axis/transport/http HTTPConstants.java
                        HTTPSender.java
  Log:
  By specifying the Expect 100-continue HTTP header wait to process this
  response.  Ultimately, we should also handle the case were we don't
  explicitly set this-- but that's a bit harder to handle.  This was needed
  not require getting the content size.  I beleive this *should* remedy the
  case for servers that *may* send this anyway in http 1.1. :-(
  
  Revision  Changes    Path
  1.18      +11 -2     xml-axis/java/samples/attachments/EchoAttachment.java
  
  Index: EchoAttachment.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/samples/attachments/EchoAttachment.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- EchoAttachment.java	1 Jul 2002 12:20:52 -0000	1.17
  +++ EchoAttachment.java	22 Jul 2002 20:00:35 -0000	1.18
  @@ -210,12 +210,21 @@
   
           Call     call    = (Call) service.createCall(); //Create a call to the service.
   
  -        //call.setScopedProperty(MessageContext.HTTP_TRANSPORT_VERSION,HTTPConstants.HEADER_PROTOCOL_V11);
  +        /*Un comment the below statement to do HTTP/1.1 protocol*/
  +      //call.setScopedProperty(MessageContext.HTTP_TRANSPORT_VERSION,HTTPConstants.HEADER_PROTOCOL_V11);
           Hashtable myhttp= new Hashtable();
           myhttp.put("dddd","yyy");     //Send extra soap headers
           myhttp.put("SOAPAction","dyyy");
           myhttp.put("SOAPActions","prova");
  -        //myhttp.put(HTTPConstants.HEADER_TRANSFER_ENCODING,HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED);
  +
  +        /*Un comment the below to do http chunking to avoid the need to calculate content-length.
(Needs HTTP/1.1)*/
  +      //myhttp.put(HTTPConstants.HEADER_TRANSFER_ENCODING, HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED);
  +
  +        /*Un comment the below to force a 100-Continue... This will cause  httpsender to
wait for
  +         * this response on a post.  If HTTP 1.1 and this is not set, *SOME* servers *MAY*
reply with this anyway.
  +         *  Currently httpsender won't handle this situation, this will require the resp.
which it will handle.
  +         */
  +      //myhttp.put(HTTPConstants.HEADER_EXPECT, HTTPConstants.HEADER_EXPECT_100_Continue);
           call.setScopedProperty(HTTPConstants.REQUEST_HEADERS,myhttp);
   
           call.setTargetEndpointAddress( new URL(opts.getURL()) ); //Set the target service
host and service location, 
  
  
  
  1.23      +11 -0     xml-axis/java/src/org/apache/axis/transport/http/HTTPConstants.java
  
  Index: HTTPConstants.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/transport/http/HTTPConstants.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- HTTPConstants.java	29 Jun 2002 21:55:40 -0000	1.22
  +++ HTTPConstants.java	22 Jul 2002 20:00:35 -0000	1.23
  @@ -84,6 +84,12 @@
       public static final String HEADER_SOAP_ACTION = "SOAPAction";
       public static final String HEADER_AUTHORIZATION = "Authorization";
       public static final String HEADER_PROXY_AUTHORIZATION = "Proxy-Authorization";
  +    public static final String HEADER_EXPECT = "Expect";
  +    public static final String HEADER_EXPECT_100_Continue = "100-continue";
  +    public static final String HEADER_USER_AGENT = "User-Agent";
  +    public static final String HEADER_CACHE_CONTROL = "Cache-Control";
  +    public static final String HEADER_CACHE_CONTROL_NOCACHE = "no-cache";
  +    public static final String HEADER_PRAGMA = "Pragma";
   
   
   
  @@ -98,6 +104,11 @@
       public static final String HEADER_CONNECTION = "Connection";
       public static final String HEADER_CONNECTION_CLOSE = "close".intern();
       public static final String HEADER_CONNECTION_KEEPALIVE = "Keep-Alive".intern();//The
default don't send.
  +
  +    public static final String HEADER_ACCEPT = "Accept";
  +    public static final String HEADER_ACCEPT_TEXT_ALL = "text/*";
  +    public static final String HEADER_ACCEPT_MULTIPART_RELATED = "multipart/related";
  +    public static final String HEADER_ACCEPT_APPLICATION_DIME = "application/dime";
       
   
       /**
  
  
  
  1.79      +122 -30   xml-axis/java/src/org/apache/axis/transport/http/HTTPSender.java
  
  Index: HTTPSender.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/transport/http/HTTPSender.java,v
  retrieving revision 1.78
  retrieving revision 1.79
  diff -u -r1.78 -r1.79
  --- HTTPSender.java	17 Jul 2002 18:13:05 -0000	1.78
  +++ HTTPSender.java	22 Jul 2002 20:00:35 -0000	1.79
  @@ -108,31 +108,25 @@
               int port = targetURL.getPort();
               Socket sock = null;
   
  -            try {
   
  -                // create socket based on the url protocol type
  -                if (targetURL.getProtocol().equalsIgnoreCase("https")) {
  -                    sock = getSecureSocket(host, port, otherHeaders, useFullURL);
  -                } else {
  -                    sock = getSocket(host, port, otherHeaders, useFullURL);
  -                }
  +            // create socket based on the url protocol type
  +            if (targetURL.getProtocol().equalsIgnoreCase("https")) {
  +                sock = getSecureSocket(host, port, otherHeaders, useFullURL);
  +            } else {
  +                sock = getSocket(host, port, otherHeaders, useFullURL);
  +            }
   
  -                // optionally set a timeout for the request
  -                if (msgContext.getTimeout() != 0) {
  -                    sock.setSoTimeout(msgContext.getTimeout());
  -                }
  +            // optionally set a timeout for the request
  +            if (msgContext.getTimeout() != 0) {
  +                sock.setSoTimeout(msgContext.getTimeout());
  +            }
   
  -                // Send the SOAP request to the server
  -                writeToSocket(sock, msgContext, targetURL,
  +            // Send the SOAP request to the server
  +            InputStream  inp= writeToSocket(sock, msgContext, targetURL,
                           otherHeaders, host, port, useFullURL);
  -            } finally {
  -                // FIXME (DIMS): IS THIS REALLY NEEDED? SalesRankNPrice fails
  -                // for a direct (non-proxy) connection if this is enabled.
  -                //if(null != sock) sock.shutdownOutput(); //need to change for http 1.1
  -            }
   
               // Read the response back from the server
  -            readFromSocket(sock, msgContext);
  +            readFromSocket(sock, msgContext, inp, null);
           } catch (Exception e) {
               log.debug(e);
               throw AxisFault.makeFault(e);
  @@ -192,7 +186,7 @@
        *
        * @throws IOException
        */
  -    private void writeToSocket(
  +    private InputStream writeToSocket(
               Socket sock, MessageContext msgContext, URL tmpURL,
               StringBuffer otherHeaders, String host, int port,
               BooleanHolder useFullURL)
  @@ -201,6 +195,7 @@
           String userID = null;
           String passwd = null;
           String reqEnv = null;
  +        InputStream inp= null;  //In case it is necessary to read before the full respose.
   
           userID = msgContext.getUsername();
           passwd = msgContext.getPassword();
  @@ -266,10 +261,15 @@
                       ? "/"
                       : tmpURL.getFile()));
           }
  +
  +
  +
           Message reqMessage = msgContext.getRequestMessage();
   
  -        boolean http10 = true;
  -        boolean httpChunkStream = false;
  +        boolean http10 = true; //True if this is to use HTTP 1.0 / false HTTP 1.1
  +        boolean httpChunkStream = false; //Use HTTP chunking or not.
  +        boolean httpContinueExpected = false; //Under HTTP 1.1 if false you *MAY* need
to wait for a 100 rc,
  +                                              //  if true the server MUST reply with 100
continue.
           String httpConnection = null;
   
           String httpver = msgContext.getStrProp(MessageContext.HTTP_TRANSPORT_VERSION);
  @@ -325,6 +325,12 @@
                       //HTTP 1.0 will always close.
                       //HTTP 1.1 will use persistent. //no need to specify
                   } else {
  +                    if( !http10 && key.equalsIgnoreCase(HTTPConstants.HEADER_EXPECT))
{
  +                        String val = me.getValue().toString();
  +                        if (null != val && val.trim().equalsIgnoreCase(HTTPConstants.HEADER_EXPECT_100_Continue))
  +                            httpContinueExpected = true;
  +                    }        
  +
                       otherHeaders.append(key).append(": ").append(me.getValue()).append("\r\n");
                   }
               }
  @@ -337,16 +343,36 @@
           header.append(http10 ? HTTPConstants.HEADER_PROTOCOL_10 :
                   HTTPConstants.HEADER_PROTOCOL_11)
                   .append("\r\n")
  -                .append(HTTPConstants.HEADER_HOST)
  +                .append(HTTPConstants.HEADER_CONTENT_TYPE)
  +                .append(": ")
  +                .append(reqMessage.getContentType())
  +                .append("\r\n")
  +                .append( HTTPConstants.HEADER_ACCEPT ) //Limit to the types that are meaningful
to us.
  +                .append( ": ")
  +                .append( HTTPConstants.HEADER_ACCEPT_APPLICATION_DIME)
  +                .append( ", ")
  +                .append( HTTPConstants.HEADER_ACCEPT_MULTIPART_RELATED)
  +                .append( ", ")
  +                .append( HTTPConstants.HEADER_ACCEPT_TEXT_ALL)
  +                .append("\r\n")
  +                .append(HTTPConstants.HEADER_USER_AGENT)   //Tell who we are.
  +                .append( ": ")
  +                .append("Axis/beta3")
  +                .append("\r\n")
  +                .append(HTTPConstants.HEADER_HOST)  //used for virtual connections
                   .append(": ")
                   .append(host)
                   .append((port == -1)?(""):(":" + port))
                   .append("\r\n")
  -                .append(HTTPConstants.HEADER_CONTENT_TYPE)
  +                .append(HTTPConstants.HEADER_CACHE_CONTROL)   //Stop caching proxies from
caching SOAP reqeuest.
                   .append(": ")
  -                .append(reqMessage.getContentType())
  +                .append(HTTPConstants.HEADER_CACHE_CONTROL_NOCACHE)
                   .append("\r\n")
  -                .append(HTTPConstants.HEADER_SOAP_ACTION)
  +                .append(HTTPConstants.HEADER_PRAGMA)
  +                .append(": ")
  +                .append(HTTPConstants.HEADER_CACHE_CONTROL_NOCACHE)
  +                .append("\r\n")
  +                .append(HTTPConstants.HEADER_SOAP_ACTION)  //The SOAP action.
                   .append(": \"")
                   .append(action)
                   .append("\"\r\n");
  @@ -375,6 +401,7 @@
           if (null != otherHeaders)
               header.append(otherHeaders); //Add other headers to the end.
   
  +
           header.append("\r\n"); //The empty line to start the BODY.
   
           OutputStream out = sock.getOutputStream();
  @@ -382,7 +409,32 @@
           if (httpChunkStream) {
               out.write(header.toString()
                       .getBytes(HTTPConstants.HEADER_DEFAULT_CHAR_ENCODING));
  -            out.flush();
  +            if(httpContinueExpected ){ //We need to get a reply from the server as to whether
  +                                      // it wants us send anything more.
  +                out.flush();
  +                Hashtable cheaders= new Hashtable (); 
  +                inp=readFromSocket(sock, msgContext, null, cheaders);
  +                int returnCode= -1;
  +                Integer Irc= (Integer)msgContext.getProperty(HTTPConstants.MC_HTTP_STATUS_CODE);
  +                if(null != Irc) returnCode= Irc.intValue();
  +                if(100 == returnCode){  // got 100 we may continue.
  +                    //Need todo a little msgContext house keeping....
  +                    msgContext.removeProperty(HTTPConstants.MC_HTTP_STATUS_CODE);
  +                    msgContext.removeProperty(HTTPConstants.MC_HTTP_STATUS_MESSAGE);
  +                }
  +                else{ //If no 100 Continue then we must not send anything!
  +                    String statusMessage= (String) 
  +                        msgContext.getProperty(HTTPConstants.MC_HTTP_STATUS_MESSAGE);
  +
  +                    AxisFault fault = new AxisFault("HTTP", "(" + returnCode+ ")" + statusMessage,
null, null);
  +
  +                    fault.setFaultDetailString(JavaUtils.getMessage("return01",
  +                            "" + returnCode, ""));
  +                    throw fault;
  +               }
  +
  +
  +            }
               ChunkedOutputStream chunkedOutputStream = new ChunkedOutputStream(out);
               out = new BufferedOutputStream(chunkedOutputStream, 8 * 1024);
               try {
  @@ -393,6 +445,35 @@
               out.flush();
               chunkedOutputStream.eos();
           } else {
  +            //No chunking...
  +            if(httpContinueExpected ){ //We need to get a reply from the server as to whether
  +                                      // it wants us send anything more.
  +                out.flush();
  +                Hashtable cheaders= new Hashtable (); 
  +                inp=readFromSocket(sock, msgContext, null, cheaders);
  +                int returnCode= -1;
  +                Integer Irc=  (Integer) msgContext.getProperty(HTTPConstants.MC_HTTP_STATUS_CODE);
  +                if(null != Irc) returnCode= Irc.intValue();
  +                if(100 == returnCode){  // got 100 we may continue.
  +                    //Need todo a little msgContext house keeping....
  +                    msgContext.setProperty(HTTPConstants.MC_HTTP_STATUS_CODE,
  +                            null);
  +                    msgContext.setProperty(HTTPConstants.MC_HTTP_STATUS_MESSAGE,
  +                            null);
  +                }
  +                else{ //If no 100 Continue then we must not send anything!
  +                    String statusMessage= (String)
  +                        msgContext.getProperty(HTTPConstants.MC_HTTP_STATUS_MESSAGE);
  +
  +                    AxisFault fault = new AxisFault("HTTP", "(" + returnCode+ ")" + statusMessage,
null, null);
  +
  +                    fault.setFaultDetailString(JavaUtils.getMessage("return01",
  +                            "" + returnCode, ""));
  +                    throw fault;
  +               }
  +
  +
  +            }
               out = new BufferedOutputStream(out, 8 * 1024);
               try {
                   out.write(header.toString()
  @@ -409,6 +490,7 @@
               log.debug("---------------------------------------------------");
               log.debug(header + reqEnv);
           }
  +        return inp;
       }
   
       /**
  @@ -419,17 +501,22 @@
        *
        * @throws IOException
        */
  -    private void readFromSocket(Socket sock, MessageContext msgContext)
  +    private InputStream readFromSocket(Socket sock, MessageContext msgContext,InputStream
 inp, Hashtable headers )
               throws IOException {
           Message outMsg = null;
           byte b;
           int len = 0;
           int colonIndex = -1;
  -        Hashtable headers = new Hashtable();
  +        boolean headersOnly= false;
  +        if(null != headers){
  +            headersOnly= true;
  +        }else{
  +            headers=  new Hashtable();
  +        }
           String name, value;
           String statusMessage = "";
           int returnCode = 0;
  -        InputStream inp = new BufferedInputStream(sock.getInputStream());
  +        if(null == inp) inp = new BufferedInputStream(sock.getInputStream());
   
           // Should help performance. Temporary fix only till its all stream oriented.
           // Need to add logic for getting the version # and the return code
  @@ -511,6 +598,10 @@
               }
           }
   
  +        if(headersOnly){
  +           return inp;
  +        }
  +
           /* All HTTP headers have been read. */
           String contentType =
                   (String) headers
  @@ -588,6 +679,7 @@
               handleCookie(HTTPConstants.HEADER_COOKIE2,
                       HTTPConstants.HEADER_SET_COOKIE2, headers, msgContext);
           }
  +        return inp;
       }
   
       /**
  
  
  

Mime
View raw message