Return-Path: Delivered-To: apmail-xml-axis-dev-archive@xml.apache.org Received: (qmail 79729 invoked by uid 500); 1 May 2002 18:58:23 -0000 Mailing-List: contact axis-dev-help@xml.apache.org; run by ezmlm Precedence: bulk Reply-To: axis-dev@xml.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list axis-dev@xml.apache.org Received: (qmail 79569 invoked from network); 1 May 2002 18:58:22 -0000 Importance: Normal Sensitivity: Subject: Re: cvs commit: xml-axis/java/test/functional FunctionalTests.java TestAttachmentsSample.java To: axis-dev@xml.apache.org X-Mailer: Lotus Notes Release 5.0.7 March 21, 2001 Message-ID: From: "Russell Butek" Date: Wed, 1 May 2002 13:49:43 -0500 X-MIMETrack: Serialize by Router on D04NM203/04/M/IBM(Release 5.0.9a |January 7, 2002) at 05/01/2002 02:58:25 PM MIME-Version: 1.0 Content-type: text/plain; charset=us-ascii X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Yay! An attachment test! Thanks, Rick. Russell Butek butek@us.ibm.com rineholt@apache.org on 05/01/2002 01:40:47 PM Please respond to axis-dev@xml.apache.org To: xml-axis-cvs@apache.org cc: Subject: 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 <> 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