Web Services & Java Server Pages
by John M. Kanalakis Jr.

Example 1:
(a)

<%@ 
page isThreadSafe="true" import="java.net.*,java.util.*,org.apache.soap.*,org.apache.soap.rpc.*;" 
%>

(b)
<%!
//SOAP specific variable declarations
URL m_urlEndpoint = null;
String m_stringMethodsURI = null;

Call m_callRemoteMethod = null;
Vector m_vectorParameters = null;
Response m_responseReturn = null;
Fault m_faultReturn = null;
%>


Example 2:
(a) 
<%
  URL m_urlEndpoint = new URL("http://aspx.securewebs.com/prasadv/BreakingNewsService.asmx");
  String m_stringMethodsURI = new String( "BreakingNewsService" );
%>

(b)
<%
m_callRemoteMethod = new Call();
m_callRemoteMethod.setTargetObjectURI( stringMethodsURI );
m_callRemoteMethod.setMethodName( "GetCNNNews");
m_callRemoteMethod.setEncodingStyleURI( Constants.NS_URI_SOAP_ENC );
%>

Example 3:
<%
    	vectorParameters = new Vector();
    	vectorParameters.addElement( new Parameter( "symbol", String.class, "ORCL", null ) );
call.setParams( vectorParameters );
%>


Example 4:

<%
     try
     {
          Response soapresponse = call.invoke( m_urlEndpoint, "" );  
          if( !soapresponse.generatedFault() )
          {
               Parameter result = soapresponse.getReturnValue();
               out.println( result.getValue() );
          }
          else
          {
               Fault fault = soapresponse.getFault(); //error occurred
               out.println(fault.getFaultCode() + ":"+ fault.getFaultString() );
          }
     }
     catch( SOAPException exceptionSoap ) 
     {
          out.println( exceptionSoap.getFaultCode() + ":" + exceptionSoap.getMessage() );
     }
%> 

Listing One
<html>

<head>
<title>Web Services Portal</title>
</head>

<body>
<form>
<div align="left">
  <table border="0" cellpadding="0" cellspacing="0" width="800">
    <tr>
        <h2>JSP / Web Services Portal</h2>
    </tr>
    <tr>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>
        <div align="left">
          <table border="0" cellpadding="0" cellspacing="0" width="800">
            <tr>
              <td width="200" valign="top">
                <div align="left">
                  <table border="1" cellpadding="0" 
                                           cellspacing="0" width="100%">
                    <tr>
                      <td width="100%">STOCKS
                        <div align="left">
                          <table border="0" cellpadding="0" 
                                            cellspacing="0" width="100%">
                            <tr>
                              <td width="50%" height="21">Apple</td>
                              <td width="50%" height="21">$$AAPL$$</td>
                            </tr>
                            <tr>
                              <td width="50%" height="21">AOL</td>
                              <td width="50%" height="21">$$AOL$$</td>
                            </tr>
                            <tr>
                              <td width="50%" height="19">Cisco</td>
                              <td width="50%" height="19">$$CSCO$$</td>
                            </tr>
                            <tr>
                              <td width="50%" height="21">Citigroup</td>
                              <td width="50%" height="21">$$C$$</td>
                            </tr>
                            <tr>
                              <td width="50%" height="21">Netscape</td>
                              <td width="50%" height="21">$$NSCP$$</td>
                            </tr>
                            <tr>
                              <td width="50%" height="21">Oracle</td>
                              <td width="50%" height="21">$$ORCL$$</td>
                            </tr>
                            <tr>
                              <td width="50%" height="21">Sony</td>
                              <td width="50%" height="21">$$SONY$$</td>
                            </tr>
                          </table>
                        </div>
                        <p align="center">Symbol <input type="text" 
                                                          name="T3" size="6">
                        <input type="button" value="Get Quote" name="B2"></p>
                        <p align="center">$$QUOTE$$</p>
                        <p align="center">&nbsp;</p>
                      </td>
                    </tr>
                    <tr>
                      <td width="100%">$$WEATHER$$
                        <p align="center">ZIP 
                              <input type="text" name="T2" size="5">
                              <input type="button" 
                                           value="Get Weather" name="B3"></p>
                        <p align="center">&nbsp;</p>
                      </td>
                    </tr>
                    <tr>
                      <td width="100%">$$TRAFFIC$$
                        <p align="center">ZIP 
                              <input type="text" name="T4" size="5">
                              <input type="button" 
                                           value="Get Traffic" name="B4"></p>
                        <p>&nbsp;</p>
                      </td>
                    </tr>
                  </table>
                </div>
              </td>
              <td width="600" valign="top">

                <div align="left">
                  <table border="1" cellpadding="0" 
                                    cellspacing="0" width="100%">
                    <tr>
                      <td width="100%">
                        <p align="center">&nbsp;</p>
                        <p align="center">Key Words <input type="text" name="T1" size="25">
                        <input type="button" value="Search" name="B1"><br>
                        <input type="radio" value="V1" checked name="R1">Google&nbsp;&nbsp;
                        <input type="radio" name="R1" value="V2">Lycos&nbsp;&nbsp;
                        <input type="radio" name="R1" value="V3">Alta Vista</p>
                        <p>$$SEARCH_RESULTS$$</p>
                      </td>
                    </tr>
                  </table>
                </div>
              </td>
            </tr>
          </table>
        </div>
      </td>
    </tr>
  </table>
</div>
</form>
</body>

</html>

Listing Two
<SOAP-ENV:Envelope xmlns:SOAP-ENV=("http://services.xmethods.net:80/soap">
<SOAP-ENV:Body>
<ns1:getQuote xmlns:ns1="urn:xmethods-delayed-quotes">
<symbol xsi:type="xsd:string">ORCL</symbol>
</ns1:getQuote>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>




1


