You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-user@ws.apache.org by Tim Almdal <Ti...@accessbc.com> on 2001/02/26 21:24:57 UTC

Solution to: Soap 2.1 + Tomcat 3.2.1 + IIS]

Did I blow it... The problem is not in the class
javax.mail.internet.InternetHeaders.hdr, but in the class
org.apache.soap.util.net.HTTPUtils, in the method post.

The changes are highlighted below:

  /**
   * POST something to the given URL. The headers are put in as
   * HTTP headers, the content length is calculated and the content
   * byte array is sent as the POST content.
   *
   * @param url the url to post to
   * @param request the message
   * @param timeout the amount of time, in ms, to block on reading data
   * @param httpProxyHost the HTTP proxy host or null if no proxy
   * @param httpProxyPort the HTTP proxy port, if the proxy host is not null
   */
  public static TransportMessage post(URL url, TransportMessage request,
                                      int timeout,
                                      String httpProxyHost, int
httpProxyPort)
      throws IllegalArgumentException, IOException, SOAPException {
      /* Open the connection */
      OutputStream outStream = null;
      InputStream inStream = null;
      BufferedReader in = null;
      int port;
      Socket s;
      try {
          port = getPort(url);

          s = buildSocket(url, port, httpProxyHost, httpProxyPort);

          if (timeout > 0)  // Should be redundant but not every JVM likes
this
              s.setSoTimeout(timeout);

          outStream = s.getOutputStream ();
          inStream = s.getInputStream ();
      }
      catch (Exception e) {
          e.printStackTrace();  // DEBUG - remove me
          throw new IllegalArgumentException("Error opening socket: " +
                                             e.getMessage ());
      }

      /* Construct the HTTP header. */
      StringBuffer headerbuf = new StringBuffer();
      headerbuf.append(Constants.HEADER_POST).append(' ')
          .append(httpProxyHost == null ? url.getFile() : url.toString())
          .append(" HTTP/").append(HTTP_VERSION).append("\r\n")
          .append(Constants.HEADER_HOST).append(": ").append(url.getHost())
          .append(':').append(port).append("\r\n")
          .append(Constants.HEADER_CONTENT_TYPE).append(": ")
          .append(request.getContentType()).append("\r\n")
          .append(Constants.HEADER_CONTENT_LENGTH).append(": ")
          .append(request.getContentLength()).append("\r\n");
      for (Enumeration e = request.getHeaderNames(); e.hasMoreElements(); )
{
          Object key = e.nextElement();
          headerbuf.append(key).append(": ")
              .append(request.getHeader((String)key)).append("\r\n");
      }
      headerbuf.append("\r\n");

      try {                    // DEBUG - remove me
      /* Send the request. */
      BufferedOutputStream bOutStream = new BufferedOutputStream(outStream);
      bOutStream.write(
 
headerbuf.toString().getBytes(Constants.HEADERVAL_DEFAULT_CHARSET));
      request.writeTo(bOutStream);
      //bOutStream.write('\r'); bOutStream.write('\n');
      //bOutStream.write('\r'); bOutStream.write('\n');
      bOutStream.flush();
      outStream.flush();

      BufferedInputStream bInStream = new BufferedInputStream(inStream);
      /* Read the response status line. */
      int statusCode = 0;
      String statusString = null;
      StringBuffer linebuf = new StringBuffer();
      int b = 0;
      while (b != '\n' && b != -1) {
          b = bInStream.read();
          if (b != '\n' && b != '\r' && b != -1)
              linebuf.append((char)b);
      }
      String line = linebuf.toString();
      try {
          StringTokenizer st = new StringTokenizer(line);
          st.nextToken(); // ignore version part
          statusCode = Integer.parseInt (st.nextToken());
          StringBuffer sb = new StringBuffer();
          while (st.hasMoreTokens()) {
              sb.append (st.nextToken());
              if (st.hasMoreTokens()) {
                  sb.append(" ");
              }
          }
          statusString = sb.toString();
      }
      catch (Exception e) {
          throw new IllegalArgumentException(
              "Error parsing HTTP status line \"" + line + "\": " + e);
      }

      /* Read the entire response (following the status line)
       * into a byte array. */
      ByteArrayDataSource ds = new ByteArrayDataSource(bInStream,
                          Constants.HEADERVAL_DEFAULT_CHARSET);

      /* Extract the headers, content type and content length. */
      byte[] bytes = ds.toByteArray();
      Hashtable respHeaders = new Hashtable();
      int respContentLength = -1;
      String respContentType = null;
      StringBuffer namebuf = new StringBuffer();
      StringBuffer valuebuf = new StringBuffer();
      boolean parsingName = true;
      int offset;
      for (offset = 0; offset < bytes.length; offset++) {
          if (bytes[offset] == '\n') {
              if (namebuf.length() == 0)
                  break;
              String name = namebuf.toString();
 
/*  original line  
              String value = valuebuf.toString();

	replace using the trim function to remove any leading blanks
*/
              String value = valuebuf.toString().trim();
              if (name.equalsIgnoreCase(Constants.HEADER_CONTENT_LENGTH))
                  respContentLength = Integer.parseInt(value);
              else if (name.equalsIgnoreCase(Constants.HEADER_CONTENT_TYPE))
                  respContentType = value;
              else
                  respHeaders.put(name, value);
              namebuf = new StringBuffer();
              valuebuf = new StringBuffer();
              parsingName = true;
          }
          else if (bytes[offset] != '\r') {
              if (parsingName) {
                  if (bytes[offset] == ':') {
                      parsingName = false;
/*  original line  
                      offset++;

	Remove this line as it assumes a blank after the colon
*/
                  }
                  else
                      namebuf.append((char)bytes[offset]);
              }
              else
                  valuebuf.append((char)bytes[offset]);
          }
      }
      InputStream is = ds.getInputStream();
      is.skip(offset + 1);
      if (respContentLength < 0)
          respContentLength = ds.getSize() - offset - 1;

      /* Construct the response object. */
      SOAPContext ctx;
      TransportMessage response;
      try {
          // Create response SOAPContext.
          ctx = new SOAPContext();
          // Read content.
          response = new TransportMessage(is, respContentLength,
                                          respContentType, ctx,
respHeaders);
          // Extract envelope and SOAPContext
          response.read();
      } catch (MessagingException me) {
          throw new IllegalArgumentException("Error parsing response: " +
me);
      }

      /* All done here! */
      bOutStream.close();
      outStream.close();
      bInStream.close();
      inStream.close();
      s.close();
      return response;
      } catch (IOException ioe) { ioe.printStackTrace(); throw ioe; }  //
DEBUG - remove me
  }

Re: Solution to: Soap 2.1 + Tomcat 3.2.1 + IIS]

Posted by Sanjiva Weerawarana <sa...@watson.ibm.com>.
Hi Tim,

I also spent sometime looking at this and found this problem .. I'm
ready to commit the fix! I am glad you came to the same src; that
gives me confidence that that's in fact the problem!

The fix will be committed in a few minutes.

Bye,

Sanjiva.

----- Original Message -----
From: "Tim Almdal" <Ti...@accessbc.com>
To: <so...@xml.apache.org>
Sent: Monday, February 26, 2001 3:24 PM
Subject: Solution to: Soap 2.1 + Tomcat 3.2.1 + IIS]


> Did I blow it... The problem is not in the class
> javax.mail.internet.InternetHeaders.hdr, but in the class
> org.apache.soap.util.net.HTTPUtils, in the method post.
>
> The changes are highlighted below:
>
>   /**
>    * POST something to the given URL. The headers are put in as
>    * HTTP headers, the content length is calculated and the content
>    * byte array is sent as the POST content.
>    *
>    * @param url the url to post to
>    * @param request the message
>    * @param timeout the amount of time, in ms, to block on reading data
>    * @param httpProxyHost the HTTP proxy host or null if no proxy
>    * @param httpProxyPort the HTTP proxy port, if the proxy host is not null
>    */
>   public static TransportMessage post(URL url, TransportMessage request,
>                                       int timeout,
>                                       String httpProxyHost, int
> httpProxyPort)
>       throws IllegalArgumentException, IOException, SOAPException {
>       /* Open the connection */
>       OutputStream outStream = null;
>       InputStream inStream = null;
>       BufferedReader in = null;
>       int port;
>       Socket s;
>       try {
>           port = getPort(url);
>
>           s = buildSocket(url, port, httpProxyHost, httpProxyPort);
>
>           if (timeout > 0)  // Should be redundant but not every JVM likes
> this
>               s.setSoTimeout(timeout);
>
>           outStream = s.getOutputStream ();
>           inStream = s.getInputStream ();
>       }
>       catch (Exception e) {
>           e.printStackTrace();  // DEBUG - remove me
>           throw new IllegalArgumentException("Error opening socket: " +
>                                              e.getMessage ());
>       }
>
>       /* Construct the HTTP header. */
>       StringBuffer headerbuf = new StringBuffer();
>       headerbuf.append(Constants.HEADER_POST).append(' ')
>           .append(httpProxyHost == null ? url.getFile() : url.toString())
>           .append(" HTTP/").append(HTTP_VERSION).append("\r\n")
>           .append(Constants.HEADER_HOST).append(": ").append(url.getHost())
>           .append(':').append(port).append("\r\n")
>           .append(Constants.HEADER_CONTENT_TYPE).append(": ")
>           .append(request.getContentType()).append("\r\n")
>           .append(Constants.HEADER_CONTENT_LENGTH).append(": ")
>           .append(request.getContentLength()).append("\r\n");
>       for (Enumeration e = request.getHeaderNames(); e.hasMoreElements(); )
> {
>           Object key = e.nextElement();
>           headerbuf.append(key).append(": ")
>               .append(request.getHeader((String)key)).append("\r\n");
>       }
>       headerbuf.append("\r\n");
>
>       try {                    // DEBUG - remove me
>       /* Send the request. */
>       BufferedOutputStream bOutStream = new BufferedOutputStream(outStream);
>       bOutStream.write(
>
> headerbuf.toString().getBytes(Constants.HEADERVAL_DEFAULT_CHARSET));
>       request.writeTo(bOutStream);
>       //bOutStream.write('\r'); bOutStream.write('\n');
>       //bOutStream.write('\r'); bOutStream.write('\n');
>       bOutStream.flush();
>       outStream.flush();
>
>       BufferedInputStream bInStream = new BufferedInputStream(inStream);
>       /* Read the response status line. */
>       int statusCode = 0;
>       String statusString = null;
>       StringBuffer linebuf = new StringBuffer();
>       int b = 0;
>       while (b != '\n' && b != -1) {
>           b = bInStream.read();
>           if (b != '\n' && b != '\r' && b != -1)
>               linebuf.append((char)b);
>       }
>       String line = linebuf.toString();
>       try {
>           StringTokenizer st = new StringTokenizer(line);
>           st.nextToken(); // ignore version part
>           statusCode = Integer.parseInt (st.nextToken());
>           StringBuffer sb = new StringBuffer();
>           while (st.hasMoreTokens()) {
>               sb.append (st.nextToken());
>               if (st.hasMoreTokens()) {
>                   sb.append(" ");
>               }
>           }
>           statusString = sb.toString();
>       }
>       catch (Exception e) {
>           throw new IllegalArgumentException(
>               "Error parsing HTTP status line \"" + line + "\": " + e);
>       }
>
>       /* Read the entire response (following the status line)
>        * into a byte array. */
>       ByteArrayDataSource ds = new ByteArrayDataSource(bInStream,
>                           Constants.HEADERVAL_DEFAULT_CHARSET);
>
>       /* Extract the headers, content type and content length. */
>       byte[] bytes = ds.toByteArray();
>       Hashtable respHeaders = new Hashtable();
>       int respContentLength = -1;
>       String respContentType = null;
>       StringBuffer namebuf = new StringBuffer();
>       StringBuffer valuebuf = new StringBuffer();
>       boolean parsingName = true;
>       int offset;
>       for (offset = 0; offset < bytes.length; offset++) {
>           if (bytes[offset] == '\n') {
>               if (namebuf.length() == 0)
>                   break;
>               String name = namebuf.toString();
>
> /*  original line
>               String value = valuebuf.toString();
>
> replace using the trim function to remove any leading blanks
> */
>               String value = valuebuf.toString().trim();
>               if (name.equalsIgnoreCase(Constants.HEADER_CONTENT_LENGTH))
>                   respContentLength = Integer.parseInt(value);
>               else if (name.equalsIgnoreCase(Constants.HEADER_CONTENT_TYPE))
>                   respContentType = value;
>               else
>                   respHeaders.put(name, value);
>               namebuf = new StringBuffer();
>               valuebuf = new StringBuffer();
>               parsingName = true;
>           }
>           else if (bytes[offset] != '\r') {
>               if (parsingName) {
>                   if (bytes[offset] == ':') {
>                       parsingName = false;
> /*  original line
>                       offset++;
>
> Remove this line as it assumes a blank after the colon
> */
>                   }
>                   else
>                       namebuf.append((char)bytes[offset]);
>               }
>               else
>                   valuebuf.append((char)bytes[offset]);
>           }
>       }
>       InputStream is = ds.getInputStream();
>       is.skip(offset + 1);
>       if (respContentLength < 0)
>           respContentLength = ds.getSize() - offset - 1;
>
>       /* Construct the response object. */
>       SOAPContext ctx;
>       TransportMessage response;
>       try {
>           // Create response SOAPContext.
>           ctx = new SOAPContext();
>           // Read content.
>           response = new TransportMessage(is, respContentLength,
>                                           respContentType, ctx,
> respHeaders);
>           // Extract envelope and SOAPContext
>           response.read();
>       } catch (MessagingException me) {
>           throw new IllegalArgumentException("Error parsing response: " +
> me);
>       }
>
>       /* All done here! */
>       bOutStream.close();
>       outStream.close();
>       bInStream.close();
>       inStream.close();
>       s.close();
>       return response;
>       } catch (IOException ioe) { ioe.printStackTrace(); throw ioe; }  //
> DEBUG - remove me
>   }


Japanese Charset

Posted by Ramakrishna Srinivasa <ra...@wipro.com>.
My Response returns Japanese Charset ..where should I set the encoding?? any idea?

I get an exception saying Invalid Unicode Character in the Response.


org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x1b) was found in
the element content of the document.
 at org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:910)
 at
org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocument
Scanner.java, Compiled Code)
 at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java,
Compiled Code)
 at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:802)
 at org.apache.soap.util.xml.XercesParserLiaison.read(XercesParserLiaison.java:85)
 at org.apache.soap.rpc.Call.invoke(Call.java:76)
 at PartList.main(PartList.java:81)


I tried setting it at various points..but it didnt work..basically the charset is
2022-jp.

TIA.


Japanese Charset

Posted by Ramakrishna Srinivasa <ra...@wipro.com>.
My Response returns Japanese Charset ..where should I set the encoding?? any idea?

I get an exception saying Invalid Unicode Character in the Response.


org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x1b) was found in
the element content of the document.
 at org.apache.xerces.framework.XMLParser.reportError(XMLParser.java:910)
 at
org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocument
Scanner.java, Compiled Code)
 at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java,
Compiled Code)
 at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:802)
 at org.apache.soap.util.xml.XercesParserLiaison.read(XercesParserLiaison.java:85)
 at org.apache.soap.rpc.Call.invoke(Call.java:76)
 at PartList.main(PartList.java:81)


I tried setting it at various points..but it didnt work..basically the charset is
2022-jp.

TIA.


Re: Solution to: Soap 2.1 + Tomcat 3.2.1 + IIS]

Posted by Sanjiva Weerawarana <sa...@watson.ibm.com>.
Hi Tim,

I just committed the fix. I also removed a debug try/catch that
was in there; can u please check and verify that this does
indeed solve the problem with the whitespace-after-colon issue?

Thanks!

Sanjiva.

----- Original Message -----
From: "Tim Almdal" <Ti...@accessbc.com>
To: <so...@xml.apache.org>
Sent: Monday, February 26, 2001 3:24 PM
Subject: Solution to: Soap 2.1 + Tomcat 3.2.1 + IIS]


> Did I blow it... The problem is not in the class
> javax.mail.internet.InternetHeaders.hdr, but in the class
> org.apache.soap.util.net.HTTPUtils, in the method post.
>
> The changes are highlighted below:
>
>   /**
>    * POST something to the given URL. The headers are put in as
>    * HTTP headers, the content length is calculated and the content
>    * byte array is sent as the POST content.
>    *
>    * @param url the url to post to
>    * @param request the message
>    * @param timeout the amount of time, in ms, to block on reading data
>    * @param httpProxyHost the HTTP proxy host or null if no proxy
>    * @param httpProxyPort the HTTP proxy port, if the proxy host is not null
>    */
>   public static TransportMessage post(URL url, TransportMessage request,
>                                       int timeout,
>                                       String httpProxyHost, int
> httpProxyPort)
>       throws IllegalArgumentException, IOException, SOAPException {
>       /* Open the connection */
>       OutputStream outStream = null;
>       InputStream inStream = null;
>       BufferedReader in = null;
>       int port;
>       Socket s;
>       try {
>           port = getPort(url);
>
>           s = buildSocket(url, port, httpProxyHost, httpProxyPort);
>
>           if (timeout > 0)  // Should be redundant but not every JVM likes
> this
>               s.setSoTimeout(timeout);
>
>           outStream = s.getOutputStream ();
>           inStream = s.getInputStream ();
>       }
>       catch (Exception e) {
>           e.printStackTrace();  // DEBUG - remove me
>           throw new IllegalArgumentException("Error opening socket: " +
>                                              e.getMessage ());
>       }
>
>       /* Construct the HTTP header. */
>       StringBuffer headerbuf = new StringBuffer();
>       headerbuf.append(Constants.HEADER_POST).append(' ')
>           .append(httpProxyHost == null ? url.getFile() : url.toString())
>           .append(" HTTP/").append(HTTP_VERSION).append("\r\n")
>           .append(Constants.HEADER_HOST).append(": ").append(url.getHost())
>           .append(':').append(port).append("\r\n")
>           .append(Constants.HEADER_CONTENT_TYPE).append(": ")
>           .append(request.getContentType()).append("\r\n")
>           .append(Constants.HEADER_CONTENT_LENGTH).append(": ")
>           .append(request.getContentLength()).append("\r\n");
>       for (Enumeration e = request.getHeaderNames(); e.hasMoreElements(); )
> {
>           Object key = e.nextElement();
>           headerbuf.append(key).append(": ")
>               .append(request.getHeader((String)key)).append("\r\n");
>       }
>       headerbuf.append("\r\n");
>
>       try {                    // DEBUG - remove me
>       /* Send the request. */
>       BufferedOutputStream bOutStream = new BufferedOutputStream(outStream);
>       bOutStream.write(
>
> headerbuf.toString().getBytes(Constants.HEADERVAL_DEFAULT_CHARSET));
>       request.writeTo(bOutStream);
>       //bOutStream.write('\r'); bOutStream.write('\n');
>       //bOutStream.write('\r'); bOutStream.write('\n');
>       bOutStream.flush();
>       outStream.flush();
>
>       BufferedInputStream bInStream = new BufferedInputStream(inStream);
>       /* Read the response status line. */
>       int statusCode = 0;
>       String statusString = null;
>       StringBuffer linebuf = new StringBuffer();
>       int b = 0;
>       while (b != '\n' && b != -1) {
>           b = bInStream.read();
>           if (b != '\n' && b != '\r' && b != -1)
>               linebuf.append((char)b);
>       }
>       String line = linebuf.toString();
>       try {
>           StringTokenizer st = new StringTokenizer(line);
>           st.nextToken(); // ignore version part
>           statusCode = Integer.parseInt (st.nextToken());
>           StringBuffer sb = new StringBuffer();
>           while (st.hasMoreTokens()) {
>               sb.append (st.nextToken());
>               if (st.hasMoreTokens()) {
>                   sb.append(" ");
>               }
>           }
>           statusString = sb.toString();
>       }
>       catch (Exception e) {
>           throw new IllegalArgumentException(
>               "Error parsing HTTP status line \"" + line + "\": " + e);
>       }
>
>       /* Read the entire response (following the status line)
>        * into a byte array. */
>       ByteArrayDataSource ds = new ByteArrayDataSource(bInStream,
>                           Constants.HEADERVAL_DEFAULT_CHARSET);
>
>       /* Extract the headers, content type and content length. */
>       byte[] bytes = ds.toByteArray();
>       Hashtable respHeaders = new Hashtable();
>       int respContentLength = -1;
>       String respContentType = null;
>       StringBuffer namebuf = new StringBuffer();
>       StringBuffer valuebuf = new StringBuffer();
>       boolean parsingName = true;
>       int offset;
>       for (offset = 0; offset < bytes.length; offset++) {
>           if (bytes[offset] == '\n') {
>               if (namebuf.length() == 0)
>                   break;
>               String name = namebuf.toString();
>
> /*  original line
>               String value = valuebuf.toString();
>
> replace using the trim function to remove any leading blanks
> */
>               String value = valuebuf.toString().trim();
>               if (name.equalsIgnoreCase(Constants.HEADER_CONTENT_LENGTH))
>                   respContentLength = Integer.parseInt(value);
>               else if (name.equalsIgnoreCase(Constants.HEADER_CONTENT_TYPE))
>                   respContentType = value;
>               else
>                   respHeaders.put(name, value);
>               namebuf = new StringBuffer();
>               valuebuf = new StringBuffer();
>               parsingName = true;
>           }
>           else if (bytes[offset] != '\r') {
>               if (parsingName) {
>                   if (bytes[offset] == ':') {
>                       parsingName = false;
> /*  original line
>                       offset++;
>
> Remove this line as it assumes a blank after the colon
> */
>                   }
>                   else
>                       namebuf.append((char)bytes[offset]);
>               }
>               else
>                   valuebuf.append((char)bytes[offset]);
>           }
>       }
>       InputStream is = ds.getInputStream();
>       is.skip(offset + 1);
>       if (respContentLength < 0)
>           respContentLength = ds.getSize() - offset - 1;
>
>       /* Construct the response object. */
>       SOAPContext ctx;
>       TransportMessage response;
>       try {
>           // Create response SOAPContext.
>           ctx = new SOAPContext();
>           // Read content.
>           response = new TransportMessage(is, respContentLength,
>                                           respContentType, ctx,
> respHeaders);
>           // Extract envelope and SOAPContext
>           response.read();
>       } catch (MessagingException me) {
>           throw new IllegalArgumentException("Error parsing response: " +
> me);
>       }
>
>       /* All done here! */
>       bOutStream.close();
>       outStream.close();
>       bInStream.close();
>       inStream.close();
>       s.close();
>       return response;
>       } catch (IOException ioe) { ioe.printStackTrace(); throw ioe; }  //
> DEBUG - remove me
>   }


Re: Solution to: Soap 2.1 + Tomcat 3.2.1 + IIS]

Posted by Sanjiva Weerawarana <sa...@watson.ibm.com>.
Hi Tim,

I just committed the fix. I also removed a debug try/catch that
was in there; can u please check and verify that this does
indeed solve the problem with the whitespace-after-colon issue?

Thanks!

Sanjiva.

----- Original Message -----
From: "Tim Almdal" <Ti...@accessbc.com>
To: <so...@xml.apache.org>
Sent: Monday, February 26, 2001 3:24 PM
Subject: Solution to: Soap 2.1 + Tomcat 3.2.1 + IIS]


> Did I blow it... The problem is not in the class
> javax.mail.internet.InternetHeaders.hdr, but in the class
> org.apache.soap.util.net.HTTPUtils, in the method post.
>
> The changes are highlighted below:
>
>   /**
>    * POST something to the given URL. The headers are put in as
>    * HTTP headers, the content length is calculated and the content
>    * byte array is sent as the POST content.
>    *
>    * @param url the url to post to
>    * @param request the message
>    * @param timeout the amount of time, in ms, to block on reading data
>    * @param httpProxyHost the HTTP proxy host or null if no proxy
>    * @param httpProxyPort the HTTP proxy port, if the proxy host is not null
>    */
>   public static TransportMessage post(URL url, TransportMessage request,
>                                       int timeout,
>                                       String httpProxyHost, int
> httpProxyPort)
>       throws IllegalArgumentException, IOException, SOAPException {
>       /* Open the connection */
>       OutputStream outStream = null;
>       InputStream inStream = null;
>       BufferedReader in = null;
>       int port;
>       Socket s;
>       try {
>           port = getPort(url);
>
>           s = buildSocket(url, port, httpProxyHost, httpProxyPort);
>
>           if (timeout > 0)  // Should be redundant but not every JVM likes
> this
>               s.setSoTimeout(timeout);
>
>           outStream = s.getOutputStream ();
>           inStream = s.getInputStream ();
>       }
>       catch (Exception e) {
>           e.printStackTrace();  // DEBUG - remove me
>           throw new IllegalArgumentException("Error opening socket: " +
>                                              e.getMessage ());
>       }
>
>       /* Construct the HTTP header. */
>       StringBuffer headerbuf = new StringBuffer();
>       headerbuf.append(Constants.HEADER_POST).append(' ')
>           .append(httpProxyHost == null ? url.getFile() : url.toString())
>           .append(" HTTP/").append(HTTP_VERSION).append("\r\n")
>           .append(Constants.HEADER_HOST).append(": ").append(url.getHost())
>           .append(':').append(port).append("\r\n")
>           .append(Constants.HEADER_CONTENT_TYPE).append(": ")
>           .append(request.getContentType()).append("\r\n")
>           .append(Constants.HEADER_CONTENT_LENGTH).append(": ")
>           .append(request.getContentLength()).append("\r\n");
>       for (Enumeration e = request.getHeaderNames(); e.hasMoreElements(); )
> {
>           Object key = e.nextElement();
>           headerbuf.append(key).append(": ")
>               .append(request.getHeader((String)key)).append("\r\n");
>       }
>       headerbuf.append("\r\n");
>
>       try {                    // DEBUG - remove me
>       /* Send the request. */
>       BufferedOutputStream bOutStream = new BufferedOutputStream(outStream);
>       bOutStream.write(
>
> headerbuf.toString().getBytes(Constants.HEADERVAL_DEFAULT_CHARSET));
>       request.writeTo(bOutStream);
>       //bOutStream.write('\r'); bOutStream.write('\n');
>       //bOutStream.write('\r'); bOutStream.write('\n');
>       bOutStream.flush();
>       outStream.flush();
>
>       BufferedInputStream bInStream = new BufferedInputStream(inStream);
>       /* Read the response status line. */
>       int statusCode = 0;
>       String statusString = null;
>       StringBuffer linebuf = new StringBuffer();
>       int b = 0;
>       while (b != '\n' && b != -1) {
>           b = bInStream.read();
>           if (b != '\n' && b != '\r' && b != -1)
>               linebuf.append((char)b);
>       }
>       String line = linebuf.toString();
>       try {
>           StringTokenizer st = new StringTokenizer(line);
>           st.nextToken(); // ignore version part
>           statusCode = Integer.parseInt (st.nextToken());
>           StringBuffer sb = new StringBuffer();
>           while (st.hasMoreTokens()) {
>               sb.append (st.nextToken());
>               if (st.hasMoreTokens()) {
>                   sb.append(" ");
>               }
>           }
>           statusString = sb.toString();
>       }
>       catch (Exception e) {
>           throw new IllegalArgumentException(
>               "Error parsing HTTP status line \"" + line + "\": " + e);
>       }
>
>       /* Read the entire response (following the status line)
>        * into a byte array. */
>       ByteArrayDataSource ds = new ByteArrayDataSource(bInStream,
>                           Constants.HEADERVAL_DEFAULT_CHARSET);
>
>       /* Extract the headers, content type and content length. */
>       byte[] bytes = ds.toByteArray();
>       Hashtable respHeaders = new Hashtable();
>       int respContentLength = -1;
>       String respContentType = null;
>       StringBuffer namebuf = new StringBuffer();
>       StringBuffer valuebuf = new StringBuffer();
>       boolean parsingName = true;
>       int offset;
>       for (offset = 0; offset < bytes.length; offset++) {
>           if (bytes[offset] == '\n') {
>               if (namebuf.length() == 0)
>                   break;
>               String name = namebuf.toString();
>
> /*  original line
>               String value = valuebuf.toString();
>
> replace using the trim function to remove any leading blanks
> */
>               String value = valuebuf.toString().trim();
>               if (name.equalsIgnoreCase(Constants.HEADER_CONTENT_LENGTH))
>                   respContentLength = Integer.parseInt(value);
>               else if (name.equalsIgnoreCase(Constants.HEADER_CONTENT_TYPE))
>                   respContentType = value;
>               else
>                   respHeaders.put(name, value);
>               namebuf = new StringBuffer();
>               valuebuf = new StringBuffer();
>               parsingName = true;
>           }
>           else if (bytes[offset] != '\r') {
>               if (parsingName) {
>                   if (bytes[offset] == ':') {
>                       parsingName = false;
> /*  original line
>                       offset++;
>
> Remove this line as it assumes a blank after the colon
> */
>                   }
>                   else
>                       namebuf.append((char)bytes[offset]);
>               }
>               else
>                   valuebuf.append((char)bytes[offset]);
>           }
>       }
>       InputStream is = ds.getInputStream();
>       is.skip(offset + 1);
>       if (respContentLength < 0)
>           respContentLength = ds.getSize() - offset - 1;
>
>       /* Construct the response object. */
>       SOAPContext ctx;
>       TransportMessage response;
>       try {
>           // Create response SOAPContext.
>           ctx = new SOAPContext();
>           // Read content.
>           response = new TransportMessage(is, respContentLength,
>                                           respContentType, ctx,
> respHeaders);
>           // Extract envelope and SOAPContext
>           response.read();
>       } catch (MessagingException me) {
>           throw new IllegalArgumentException("Error parsing response: " +
> me);
>       }
>
>       /* All done here! */
>       bOutStream.close();
>       outStream.close();
>       bInStream.close();
>       inStream.close();
>       s.close();
>       return response;
>       } catch (IOException ioe) { ioe.printStackTrace(); throw ioe; }  //
> DEBUG - remove me
>   }


Re: Solution to: Soap 2.1 + Tomcat 3.2.1 + IIS]

Posted by Sanjiva Weerawarana <sa...@watson.ibm.com>.
Hi Tim,

I also spent sometime looking at this and found this problem .. I'm
ready to commit the fix! I am glad you came to the same src; that
gives me confidence that that's in fact the problem!

The fix will be committed in a few minutes.

Bye,

Sanjiva.

----- Original Message -----
From: "Tim Almdal" <Ti...@accessbc.com>
To: <so...@xml.apache.org>
Sent: Monday, February 26, 2001 3:24 PM
Subject: Solution to: Soap 2.1 + Tomcat 3.2.1 + IIS]


> Did I blow it... The problem is not in the class
> javax.mail.internet.InternetHeaders.hdr, but in the class
> org.apache.soap.util.net.HTTPUtils, in the method post.
>
> The changes are highlighted below:
>
>   /**
>    * POST something to the given URL. The headers are put in as
>    * HTTP headers, the content length is calculated and the content
>    * byte array is sent as the POST content.
>    *
>    * @param url the url to post to
>    * @param request the message
>    * @param timeout the amount of time, in ms, to block on reading data
>    * @param httpProxyHost the HTTP proxy host or null if no proxy
>    * @param httpProxyPort the HTTP proxy port, if the proxy host is not null
>    */
>   public static TransportMessage post(URL url, TransportMessage request,
>                                       int timeout,
>                                       String httpProxyHost, int
> httpProxyPort)
>       throws IllegalArgumentException, IOException, SOAPException {
>       /* Open the connection */
>       OutputStream outStream = null;
>       InputStream inStream = null;
>       BufferedReader in = null;
>       int port;
>       Socket s;
>       try {
>           port = getPort(url);
>
>           s = buildSocket(url, port, httpProxyHost, httpProxyPort);
>
>           if (timeout > 0)  // Should be redundant but not every JVM likes
> this
>               s.setSoTimeout(timeout);
>
>           outStream = s.getOutputStream ();
>           inStream = s.getInputStream ();
>       }
>       catch (Exception e) {
>           e.printStackTrace();  // DEBUG - remove me
>           throw new IllegalArgumentException("Error opening socket: " +
>                                              e.getMessage ());
>       }
>
>       /* Construct the HTTP header. */
>       StringBuffer headerbuf = new StringBuffer();
>       headerbuf.append(Constants.HEADER_POST).append(' ')
>           .append(httpProxyHost == null ? url.getFile() : url.toString())
>           .append(" HTTP/").append(HTTP_VERSION).append("\r\n")
>           .append(Constants.HEADER_HOST).append(": ").append(url.getHost())
>           .append(':').append(port).append("\r\n")
>           .append(Constants.HEADER_CONTENT_TYPE).append(": ")
>           .append(request.getContentType()).append("\r\n")
>           .append(Constants.HEADER_CONTENT_LENGTH).append(": ")
>           .append(request.getContentLength()).append("\r\n");
>       for (Enumeration e = request.getHeaderNames(); e.hasMoreElements(); )
> {
>           Object key = e.nextElement();
>           headerbuf.append(key).append(": ")
>               .append(request.getHeader((String)key)).append("\r\n");
>       }
>       headerbuf.append("\r\n");
>
>       try {                    // DEBUG - remove me
>       /* Send the request. */
>       BufferedOutputStream bOutStream = new BufferedOutputStream(outStream);
>       bOutStream.write(
>
> headerbuf.toString().getBytes(Constants.HEADERVAL_DEFAULT_CHARSET));
>       request.writeTo(bOutStream);
>       //bOutStream.write('\r'); bOutStream.write('\n');
>       //bOutStream.write('\r'); bOutStream.write('\n');
>       bOutStream.flush();
>       outStream.flush();
>
>       BufferedInputStream bInStream = new BufferedInputStream(inStream);
>       /* Read the response status line. */
>       int statusCode = 0;
>       String statusString = null;
>       StringBuffer linebuf = new StringBuffer();
>       int b = 0;
>       while (b != '\n' && b != -1) {
>           b = bInStream.read();
>           if (b != '\n' && b != '\r' && b != -1)
>               linebuf.append((char)b);
>       }
>       String line = linebuf.toString();
>       try {
>           StringTokenizer st = new StringTokenizer(line);
>           st.nextToken(); // ignore version part
>           statusCode = Integer.parseInt (st.nextToken());
>           StringBuffer sb = new StringBuffer();
>           while (st.hasMoreTokens()) {
>               sb.append (st.nextToken());
>               if (st.hasMoreTokens()) {
>                   sb.append(" ");
>               }
>           }
>           statusString = sb.toString();
>       }
>       catch (Exception e) {
>           throw new IllegalArgumentException(
>               "Error parsing HTTP status line \"" + line + "\": " + e);
>       }
>
>       /* Read the entire response (following the status line)
>        * into a byte array. */
>       ByteArrayDataSource ds = new ByteArrayDataSource(bInStream,
>                           Constants.HEADERVAL_DEFAULT_CHARSET);
>
>       /* Extract the headers, content type and content length. */
>       byte[] bytes = ds.toByteArray();
>       Hashtable respHeaders = new Hashtable();
>       int respContentLength = -1;
>       String respContentType = null;
>       StringBuffer namebuf = new StringBuffer();
>       StringBuffer valuebuf = new StringBuffer();
>       boolean parsingName = true;
>       int offset;
>       for (offset = 0; offset < bytes.length; offset++) {
>           if (bytes[offset] == '\n') {
>               if (namebuf.length() == 0)
>                   break;
>               String name = namebuf.toString();
>
> /*  original line
>               String value = valuebuf.toString();
>
> replace using the trim function to remove any leading blanks
> */
>               String value = valuebuf.toString().trim();
>               if (name.equalsIgnoreCase(Constants.HEADER_CONTENT_LENGTH))
>                   respContentLength = Integer.parseInt(value);
>               else if (name.equalsIgnoreCase(Constants.HEADER_CONTENT_TYPE))
>                   respContentType = value;
>               else
>                   respHeaders.put(name, value);
>               namebuf = new StringBuffer();
>               valuebuf = new StringBuffer();
>               parsingName = true;
>           }
>           else if (bytes[offset] != '\r') {
>               if (parsingName) {
>                   if (bytes[offset] == ':') {
>                       parsingName = false;
> /*  original line
>                       offset++;
>
> Remove this line as it assumes a blank after the colon
> */
>                   }
>                   else
>                       namebuf.append((char)bytes[offset]);
>               }
>               else
>                   valuebuf.append((char)bytes[offset]);
>           }
>       }
>       InputStream is = ds.getInputStream();
>       is.skip(offset + 1);
>       if (respContentLength < 0)
>           respContentLength = ds.getSize() - offset - 1;
>
>       /* Construct the response object. */
>       SOAPContext ctx;
>       TransportMessage response;
>       try {
>           // Create response SOAPContext.
>           ctx = new SOAPContext();
>           // Read content.
>           response = new TransportMessage(is, respContentLength,
>                                           respContentType, ctx,
> respHeaders);
>           // Extract envelope and SOAPContext
>           response.read();
>       } catch (MessagingException me) {
>           throw new IllegalArgumentException("Error parsing response: " +
> me);
>       }
>
>       /* All done here! */
>       bOutStream.close();
>       outStream.close();
>       bInStream.close();
>       inStream.close();
>       s.close();
>       return response;
>       } catch (IOException ioe) { ioe.printStackTrace(); throw ioe; }  //
> DEBUG - remove me
>   }


Re: Solution to: Soap 2.1 + Tomcat 3.2.1 + IIS]

Posted by Sanjiva Weerawarana <sa...@watson.ibm.com>.
Hi Tim,

I just committed the fix. I also removed a debug try/catch that
was in there; can u please check and verify that this does
indeed solve the problem with the whitespace-after-colon issue?

Thanks!

Sanjiva.

----- Original Message -----
From: "Tim Almdal" <Ti...@accessbc.com>
To: <so...@xml.apache.org>
Sent: Monday, February 26, 2001 3:24 PM
Subject: Solution to: Soap 2.1 + Tomcat 3.2.1 + IIS]


> Did I blow it... The problem is not in the class
> javax.mail.internet.InternetHeaders.hdr, but in the class
> org.apache.soap.util.net.HTTPUtils, in the method post.
>
> The changes are highlighted below:
>
>   /**
>    * POST something to the given URL. The headers are put in as
>    * HTTP headers, the content length is calculated and the content
>    * byte array is sent as the POST content.
>    *
>    * @param url the url to post to
>    * @param request the message
>    * @param timeout the amount of time, in ms, to block on reading data
>    * @param httpProxyHost the HTTP proxy host or null if no proxy
>    * @param httpProxyPort the HTTP proxy port, if the proxy host is not null
>    */
>   public static TransportMessage post(URL url, TransportMessage request,
>                                       int timeout,
>                                       String httpProxyHost, int
> httpProxyPort)
>       throws IllegalArgumentException, IOException, SOAPException {
>       /* Open the connection */
>       OutputStream outStream = null;
>       InputStream inStream = null;
>       BufferedReader in = null;
>       int port;
>       Socket s;
>       try {
>           port = getPort(url);
>
>           s = buildSocket(url, port, httpProxyHost, httpProxyPort);
>
>           if (timeout > 0)  // Should be redundant but not every JVM likes
> this
>               s.setSoTimeout(timeout);
>
>           outStream = s.getOutputStream ();
>           inStream = s.getInputStream ();
>       }
>       catch (Exception e) {
>           e.printStackTrace();  // DEBUG - remove me
>           throw new IllegalArgumentException("Error opening socket: " +
>                                              e.getMessage ());
>       }
>
>       /* Construct the HTTP header. */
>       StringBuffer headerbuf = new StringBuffer();
>       headerbuf.append(Constants.HEADER_POST).append(' ')
>           .append(httpProxyHost == null ? url.getFile() : url.toString())
>           .append(" HTTP/").append(HTTP_VERSION).append("\r\n")
>           .append(Constants.HEADER_HOST).append(": ").append(url.getHost())
>           .append(':').append(port).append("\r\n")
>           .append(Constants.HEADER_CONTENT_TYPE).append(": ")
>           .append(request.getContentType()).append("\r\n")
>           .append(Constants.HEADER_CONTENT_LENGTH).append(": ")
>           .append(request.getContentLength()).append("\r\n");
>       for (Enumeration e = request.getHeaderNames(); e.hasMoreElements(); )
> {
>           Object key = e.nextElement();
>           headerbuf.append(key).append(": ")
>               .append(request.getHeader((String)key)).append("\r\n");
>       }
>       headerbuf.append("\r\n");
>
>       try {                    // DEBUG - remove me
>       /* Send the request. */
>       BufferedOutputStream bOutStream = new BufferedOutputStream(outStream);
>       bOutStream.write(
>
> headerbuf.toString().getBytes(Constants.HEADERVAL_DEFAULT_CHARSET));
>       request.writeTo(bOutStream);
>       //bOutStream.write('\r'); bOutStream.write('\n');
>       //bOutStream.write('\r'); bOutStream.write('\n');
>       bOutStream.flush();
>       outStream.flush();
>
>       BufferedInputStream bInStream = new BufferedInputStream(inStream);
>       /* Read the response status line. */
>       int statusCode = 0;
>       String statusString = null;
>       StringBuffer linebuf = new StringBuffer();
>       int b = 0;
>       while (b != '\n' && b != -1) {
>           b = bInStream.read();
>           if (b != '\n' && b != '\r' && b != -1)
>               linebuf.append((char)b);
>       }
>       String line = linebuf.toString();
>       try {
>           StringTokenizer st = new StringTokenizer(line);
>           st.nextToken(); // ignore version part
>           statusCode = Integer.parseInt (st.nextToken());
>           StringBuffer sb = new StringBuffer();
>           while (st.hasMoreTokens()) {
>               sb.append (st.nextToken());
>               if (st.hasMoreTokens()) {
>                   sb.append(" ");
>               }
>           }
>           statusString = sb.toString();
>       }
>       catch (Exception e) {
>           throw new IllegalArgumentException(
>               "Error parsing HTTP status line \"" + line + "\": " + e);
>       }
>
>       /* Read the entire response (following the status line)
>        * into a byte array. */
>       ByteArrayDataSource ds = new ByteArrayDataSource(bInStream,
>                           Constants.HEADERVAL_DEFAULT_CHARSET);
>
>       /* Extract the headers, content type and content length. */
>       byte[] bytes = ds.toByteArray();
>       Hashtable respHeaders = new Hashtable();
>       int respContentLength = -1;
>       String respContentType = null;
>       StringBuffer namebuf = new StringBuffer();
>       StringBuffer valuebuf = new StringBuffer();
>       boolean parsingName = true;
>       int offset;
>       for (offset = 0; offset < bytes.length; offset++) {
>           if (bytes[offset] == '\n') {
>               if (namebuf.length() == 0)
>                   break;
>               String name = namebuf.toString();
>
> /*  original line
>               String value = valuebuf.toString();
>
> replace using the trim function to remove any leading blanks
> */
>               String value = valuebuf.toString().trim();
>               if (name.equalsIgnoreCase(Constants.HEADER_CONTENT_LENGTH))
>                   respContentLength = Integer.parseInt(value);
>               else if (name.equalsIgnoreCase(Constants.HEADER_CONTENT_TYPE))
>                   respContentType = value;
>               else
>                   respHeaders.put(name, value);
>               namebuf = new StringBuffer();
>               valuebuf = new StringBuffer();
>               parsingName = true;
>           }
>           else if (bytes[offset] != '\r') {
>               if (parsingName) {
>                   if (bytes[offset] == ':') {
>                       parsingName = false;
> /*  original line
>                       offset++;
>
> Remove this line as it assumes a blank after the colon
> */
>                   }
>                   else
>                       namebuf.append((char)bytes[offset]);
>               }
>               else
>                   valuebuf.append((char)bytes[offset]);
>           }
>       }
>       InputStream is = ds.getInputStream();
>       is.skip(offset + 1);
>       if (respContentLength < 0)
>           respContentLength = ds.getSize() - offset - 1;
>
>       /* Construct the response object. */
>       SOAPContext ctx;
>       TransportMessage response;
>       try {
>           // Create response SOAPContext.
>           ctx = new SOAPContext();
>           // Read content.
>           response = new TransportMessage(is, respContentLength,
>                                           respContentType, ctx,
> respHeaders);
>           // Extract envelope and SOAPContext
>           response.read();
>       } catch (MessagingException me) {
>           throw new IllegalArgumentException("Error parsing response: " +
> me);
>       }
>
>       /* All done here! */
>       bOutStream.close();
>       outStream.close();
>       bInStream.close();
>       inStream.close();
>       s.close();
>       return response;
>       } catch (IOException ioe) { ioe.printStackTrace(); throw ioe; }  //
> DEBUG - remove me
>   }