You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ri...@apache.org on 2002/05/01 20:40:47 UTC

cvs commit: xml-axis/java/test/functional FunctionalTests.java TestAttachmentsSample.java

rineholt    02/05/01 11:40:47

  Modified:    java/src/org/apache/axis/transport/http
                        NonBlockingBufferedInputStream.java
                        SimpleAxisServer.java
               java/test/functional FunctionalTests.java
                        TestAttachmentsSample.java
  Added:       java/samples/attachments leaveempty.txt
  Log:
  Added attachment support for SimpleAxisServer.
  Completed the work to attachments tests to functional test.
  
  Revision  Changes    Path
  1.1                  xml-axis/java/samples/attachments/leaveempty.txt
  
  	<<Binary file>>
  
  
  1.8       +13 -0     xml-axis/java/src/org/apache/axis/transport/http/NonBlockingBufferedInputStream.java
  
  Index: NonBlockingBufferedInputStream.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/transport/http/NonBlockingBufferedInputStream.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- NonBlockingBufferedInputStream.java	27 Nov 2001 20:48:13 -0000	1.7
  +++ NonBlockingBufferedInputStream.java	1 May 2002 18:40:47 -0000	1.8
  @@ -198,5 +198,18 @@
       public void close() throws IOException {
           setInputStream(null);
       }
  +
  +    /**
  +     * Just like read except byte is not removed from the buffer. 
  +     * the data is buffered for efficiency.
  +     * Was added to support multiline http headers. ;-)
  +     * @return the byte read
  +     */
  +    public int peek() throws IOException {
  +        if (in == null) return -1;
  +        if (offset >= numbytes) refillBuffer();
  +        if (offset >= numbytes) return -1;
  +        return buffer[offset];
  +    }
   }
   
  
  
  
  1.56      +56 -14    xml-axis/java/src/org/apache/axis/transport/http/SimpleAxisServer.java
  
  Index: SimpleAxisServer.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/transport/http/SimpleAxisServer.java,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- SimpleAxisServer.java	6 Mar 2002 23:39:17 -0000	1.55
  +++ SimpleAxisServer.java	1 May 2002 18:40:47 -0000	1.56
  @@ -191,6 +191,8 @@
           StringBuffer cookie = new StringBuffer();
           StringBuffer cookie2 = new StringBuffer();
           StringBuffer authInfo = new StringBuffer();
  +        StringBuffer contentType= new StringBuffer();
  +        StringBuffer contentLocation= new StringBuffer();
           
           Message responseMsg = null;
   
  @@ -242,7 +244,8 @@
                       // read headers
                       is.setInputStream(socket.getInputStream());
                       // parse all headers into hashtable
  -                    int contentLength = parseHeaders(is, soapAction,
  +                    int contentLength = parseHeaders(is, contentType,
  +                                                     contentLocation, soapAction,
                                                        httpRequest, fileName,
                                                        cookie, cookie2, authInfo);
                       is.setContentLength(contentLength);
  @@ -345,7 +348,11 @@
                           msgContext.setUseSOAPAction(true);
                           msgContext.setSOAPActionURI(soapActionString);
                       }
  -                    requestMsg = new Message(is);
  +                    requestMsg = new Message(is,
  +                                             false,
  +                                             contentType.toString(),
  +                                             contentLocation.toString()
  +                                            );
                       msgContext.setRequestMessage(requestMsg);
   
                       // set up session, if any
  @@ -431,24 +438,27 @@
                   OutputStream out = socket.getOutputStream();
                   out.write(HTTP);
                   out.write(status);
  -                out.write(XML_MIME_STUFF);
  -                putInt(out, response.length);
  +                //out.write(XML_MIME_STUFF);
  +                out.write(("\n" + HTTPConstants.HEADER_CONTENT_TYPE + ": " + responseMsg.getContentType()).getBytes()); 
  +                out.write(("\n" + HTTPConstants.HEADER_CONTENT_LENGTH + ": " + responseMsg.getContentLength()).getBytes()); 
  +                // putInt(out, response.length);
   
  -                if (doSessions) {
  +                if (doSessions && null != cooky && 0 != cooky.trim().length()) {
                       // write cookie headers, if any
                       // don't sweat efficiency *too* badly
                       // optimize at will
                       StringBuffer cookieOut = new StringBuffer();
  -                    cookieOut.append("\r\nSet-Cookie: ")
  +                    cookieOut.append("\nSet-Cookie: ")
                           .append(cooky)
  -                        .append("\r\nSet-Cookie2: ")
  +                        .append("\nSet-Cookie2: ")
                           .append(cooky);
                       // OH, THE HUMILITY!  yes this is inefficient.
                       out.write(cookieOut.toString().getBytes());
                   }
   
                   out.write(SEPARATOR);
  -                out.write(response);
  +                responseMsg.writeContentToStream(out);
  +               // out.write(response);
                   out.flush();
   
                   if (msgContext.getProperty(msgContext.QUIT_REQUESTED) != null) {
  @@ -488,6 +498,14 @@
       private static final byte lenHeader[] = "content-length: ".getBytes();
       private static final int lenLen = lenHeader.length;
   
  +    // mime header for content type
  +    private static final byte typeHeader[] = (HTTPConstants.HEADER_CONTENT_TYPE.toLowerCase() +": ").getBytes();
  +    private static final int typeLen = typeHeader.length;
  +
  +    // mime header for content location
  +    private static final byte locationHeader[] = (HTTPConstants.HEADER_CONTENT_LOCATION.toLowerCase()+": ").getBytes();
  +    private static final int locationLen = locationHeader.length;
  +
       // mime header for soap action
       private static final byte actionHeader[] = "soapaction: ".getBytes();
       private static final int actionLen = actionHeader.length;
  @@ -527,15 +545,21 @@
        * @param off       starting offset into the byte array
        * @param len       maximum number of bytes to read
        */
  -    private int readLine(InputStream is, byte[] b, int off, int len)
  +    private int readLine(NonBlockingBufferedInputStream is, byte[] b, int off, int len)
           throws IOException
       {
           int count = 0, c;
   
           while ((c = is.read()) != -1) {
  -            b[off++] = (byte)c;
  -            count++;
  -            if (c == '\n' || count == len) break;
  +            if(c != '\n' && c != '\r'){
  +              b[off++] = (byte)c;
  +              count++;
  +            }
  +            if (count == len) break;
  +            if( '\n' == c ){
  +              int peek= is.peek(); //If the next line begins with tab or space then this is a continuation.
  +              if(peek != ' ' && peek != '\t') break;
  +            }
           }
           return count > 0 ? count : -1;
       }
  @@ -544,13 +568,17 @@
        * Read all mime headers, returning the value of Content-Length and
        * SOAPAction.
        * @param is         InputStream to read from
  +     * @param contentType The content type. 
  +     * @param contentLocation The content location
        * @param soapAction StringBuffer to return the soapAction into
        * @param httpRequest StringBuffer for GET / POST
        * @param cookie first cookie header (if doSessions)
        * @param cookie2 second cookie header (if doSessions)
        * @return Content-Length
        */
  -    private int parseHeaders(InputStream is,
  +    private int parseHeaders(NonBlockingBufferedInputStream is,
  +                             StringBuffer contentType,
  +                             StringBuffer contentLocation,
                                StringBuffer soapAction,
                                StringBuffer httpRequest,
                                StringBuffer fileName,
  @@ -572,6 +600,8 @@
           // which does it begin with?
           httpRequest.delete(0, httpRequest.length());
           fileName.delete(0, fileName.length());
  +        contentType.delete(0, contentType.length());
  +        contentLocation.delete(0, contentLocation.length());
   
           if (buf[0] == getHeader[0]) {
               httpRequest.append("GET");
  @@ -596,9 +626,9 @@
               throw new IOException(JavaUtils.getMessage("badRequest00"));
           }
   
  +        StringBuffer lastbuf=null; 
           while ((n=readLine(is,buf,0,buf.length)) > 0) {
   
  -            // if we are at the separator blank line, bail right now
               if ((n<=2) && (buf[0]=='\n'||buf[0]=='\r') && (len>0)) break;
   
               // RobJ gutted the previous logic; it was too hard to extend for more headers.
  @@ -670,6 +700,18 @@
                       throw new IOException(
                               JavaUtils.getMessage("badAuth00"));
                   }
  +            }
  +            else if (endHeaderIndex == locationLen && matches(buf, locationHeader)) {
  +                    while (++i<n && (buf[i]!='\r') && (buf[i]!='\n')) {
  +                        if (buf[i]==' ') continue;
  +                        contentLocation.append((char)(buf[i] & 0x7f));
  +                    }
  +            }
  +            else if (endHeaderIndex == typeLen&& matches(buf, typeHeader)) {
  +                    while (++i<n && (buf[i]!='\r') && (buf[i]!='\n')) {
  +                        if (buf[i]==' ') continue;
  +                        contentType.append((char)(buf[i] & 0x7f));
  +                    }
               }
   
           }
  
  
  
  1.18      +6 -2      xml-axis/java/test/functional/FunctionalTests.java
  
  Index: FunctionalTests.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/functional/FunctionalTests.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- FunctionalTests.java	19 Apr 2002 18:42:30 -0000	1.17
  +++ FunctionalTests.java	1 May 2002 18:40:47 -0000	1.18
  @@ -53,8 +53,12 @@
           suite.addTestSuite(TestMessageSample.class);
   
           // Attachments service test.
  -        // Commented out for now since SimpleAxisServer doesn't support this
  -        // suite.addTestSuite(TestAttachmentsSample.class);
  +        try{
  +          if( null !=  Class.forName("javax.activation.DataHandler") &&
  +              null != Class.forName("javax.mail.internet.MimeMultipart")){
  +                suite.addTestSuite(TestAttachmentsSample.class);
  +          }
  +        }catch( Throwable t){;}
   
           return suite;
       }
  
  
  
  1.2       +1 -1      xml-axis/java/test/functional/TestAttachmentsSample.java
  
  Index: TestAttachmentsSample.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/functional/TestAttachmentsSample.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestAttachmentsSample.java	19 Apr 2002 18:42:30 -0000	1.1
  +++ TestAttachmentsSample.java	1 May 2002 18:40:47 -0000	1.2
  @@ -86,7 +86,7 @@
       
       public void doTestAttachments2() throws Exception {
           Options opts = new Options( new String[]{});
  -        boolean res = new EchoAttachment(opts).echo("samples/attachments");
  +        boolean res = new EchoAttachment(opts).echoDir("samples/attachments");
           assertEquals("Didn't process attachments correctly", res, true);
       }