<%-- strona testowa dla soapreverse.jsp --%>
<%@page import="java.net.*,javax.xml.parsers.*"%>
<%@page import="java.util.*,java.text.*,com.psol.resourceful.*,org.apache.soap.*,org.apache.soap.rpc.*,org.apache.soap.encoding.*,org.apache.soap.util.xml.*,org.apache.soap.encoding.soapenc.*"%>
<%@page import="org.apache.soap.transport.http.*,org.apache.soap.transport.*"%>
<%@page import="org.w3c.dom.*"%>
<%!
private Response rpcCall(URL rpcRouter,
                         String methodName,
                         Vector params)
   throws SOAPException, ParserConfigurationException
{
   DocumentBuilderFactory factory =
       DocumentBuilderFactory.newInstance();
   factory.setNamespaceAware(true);
   DocumentBuilder builder = factory.newDocumentBuilder();
   Document doc = builder.newDocument();
   Element el1 = doc.createElementNS("http://schemas.xmlsoap.org/soap/envelope/","Header");
   Element el2 = doc.createElementNS("http://myown","Own");
   el2.setAttribute("SOAP-ENV:mustUnderstand",
                      "1");
   el1.appendChild(el2);
   el2 = doc.createElementNS("http://myown","Own2");
   el2.setAttribute("SOAP-ENV:mustUnderstand",
                      "1");
   el1.appendChild(el2);
   BeanSerializer serializer = new BeanSerializer();
   Call call = new Call();
   call.setTargetObjectURI("http://www.psol.com/2001/reverse");
   call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
   call.setMethodName(methodName);
   // call.setHeader(Header.unmarshall(el1,call.getSOAPContext()));
   SOAPHTTPConnection transport = new SOAPHTTPConnection();
   transport.setUserName("jetty");
   transport.setPassword("unleashed");
   call.setSOAPTransport(transport);
   if(params != null)
      call.setParams(params);
   return call.invoke(rpcRouter,
                      "http://www.psol.com/2001/soapaction");
}
%>
<html>
<head>
   <title>Mini SOAP client</title>
</head>
<body>
<h1>Mini SOAP client</h1>
<form action="<%= request.getRequestURI() %>" method="post">
<table>
   <tr><td>SOAP server:</td>
      <td><input type="text" name="rpcrouter" size="50"
         value="http://localhost:5401/resourceful/soapreverse.jsp"></td></tr>
   <tr><td>String:</td><td><input type="text" name="string"></td></tr>
</table>
<input type="submit" value="Reverse">
</form>
<%
String stString = request.getParameter("string"),
       stRPCRouter = request.getParameter("rpcrouter");
URL rpcRouter = null;
if(stRPCRouter != null && stRPCRouter.trim().length() != 0 &&
   stString != null && stString.trim().length() != 0)
{
   rpcRouter = new URL(stRPCRouter);
   Response resp = null;
   Vector params = new Vector();
   params.addElement(new Parameter("string",String.class,stString,null));
   resp = rpcCall(rpcRouter,"reverse",params);
   if(!resp.generatedFault())
   {
%>
<p>Reverse is <b><%= (String)resp.getReturnValue().getValue() %></b></p>
<%
   }
   else
   {
      Fault fault = resp.getFault();
%>
<p>Error: <%= fault.getFaultCode() %><br>
<%= fault.getFaultString() %></p>
<%
   }
%>
<%
}
%>
</body>
</html>
