At 11:27 AM 10/3/2001 +0800, Ong Boon Pang wrote:
>Hi,
>...
>I have always tried to keep the browser programming in Javascript/JScript
>as simple as possible with only FORM POST/GET...
>...
> >Like passing parameters from a browser to a servlet/jsp etc.
>I read the links...All I have found close is Tom Myers's:
>http://marc.theaimsgroup.com/?l=soap-user&m=99183274828678&w=2

Well, if anybody wants it, here's the PassAlong.jsp I did then
just to play with the idea, 64 lines of which a third is comment,
basically derived by looking at what SOAP 2.0 did with calls.
And GetAddress.htm is not tested with Netscape, but the idea
will certainly work with Netscape; I simply build the envelope
in Javascript, pass to the JSP, and package it there. No big deal,
but it might save you an hour or two if you really need to do
that kind of thing. (Note that I'm not very careful about charset;
it is specified, but not consistently. :-) )
Feedback appreciated, of course.

Tom Myers
<%@ page  errorPage="error.jsp" import="java.net.*,java.io.*"
 %><% // Tom Myers, [EMAIL PROTECTED] June 2001; feedback appreciated.
/* the idea is to receive router,host, and envelope as strings, then package as
POST /soap/servlet/rpcrouter HTTP/1.0
Host: localhost:8080
Content-Type: text/xml; charset=utf-8
Content-Length: 490
SOAPAction: ""

<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"; 
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"; 
xmlns:xsd="http://www.w3.org/1999/XMLSchema";>
<SOAP-ENV:Body>
<ns1:getAddressFromName xmlns:ns1="urn:AddressFetcher" 
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/";>
<nameToLookup xsi:type="xsd:string">John B. Good</nameToLookup>
</ns1:getAddressFromName>
</SOAP-ENV:Body> 
</SOAP-ENV:Envelope>

and pass the response back to the user.
*/
  String urlString=request.getParameter("router");
  int x=0;
  String payload=request.getParameter("envelope");
  URL url=new URL(urlString);
  int timeout=20000;
  int port= url.getPort(); if(port<0)port=80;
  Socket s = new Socket(url.getHost(),port);
  s.setSoTimeout(timeout);
  OutputStream outStream = s.getOutputStream ();
  InputStream inStream = s.getInputStream ();

  StringBuffer headerbuf = new StringBuffer();
  headerbuf.append("POST ")
              .append(url.getFile()).append(" HTTP/1.0\r\n")
          .append("Host: ")
             .append(url.getHost()).append(':').append(port).append("\r\n")
          .append("Content-Type: text/xml; charset=iso-8859-1\r\n")
          .append("Content-Length: ")
             .append(payload.length()).append("\r\n")
          .append("SOAPAction: \"\"\r\n")
          .append("\r\n");
                                     /* Send headerbuf and payload. */
      BufferedOutputStream bOutStream = new BufferedOutputStream(outStream);
      bOutStream.write(headerbuf.toString().getBytes("iso-8859-1"));
      bOutStream.write(payload.getBytes("iso-8859-1"));
      bOutStream.flush(); outStream.flush();

      BufferedInputStream bInStream = new BufferedInputStream(inStream);
      InputStreamReader reader=new InputStreamReader(bInStream,"iso-8859-1");
      
      StringWriter sw=new java.io.StringWriter();
      for(int ch=reader.read();ch>=0;ch=reader.read())sw.write((char)ch);
      String resString=sw.toString();
      int endHeaderPos=resString.indexOf("\r\n\r\n");
      if(endHeaderPos>=0)resString=resString.substring(endHeaderPos+4);

      bOutStream.close(); outStream.close();
      bInStream.close();  inStream.close();
      s.close();

      response.setContentType("text/xml; charset=utf-8");
      response.setContentLength(resString.length());
      out.write(resString);
 %>
Title: GetAddress.htm
name:

Reply via email to