1 25 package org.objectweb.wssample.servlets.wsclient; 26 27 import java.io.IOException ; 28 import java.io.PrintWriter ; 29 30 import javax.naming.Context ; 31 import javax.naming.InitialContext ; 32 import javax.naming.NamingException ; 33 import javax.servlet.ServletConfig ; 34 import javax.servlet.ServletException ; 35 import javax.servlet.http.HttpServlet ; 36 import javax.servlet.http.HttpServletRequest ; 37 import javax.servlet.http.HttpServletResponse ; 38 import javax.xml.rpc.ServiceException ; 39 import javax.xml.rpc.Stub ; 40 41 import org.objectweb.wssample.gen.jaxrpc.JaxRpcEndpointInterface; 42 import org.objectweb.wssample.gen.jaxrpc.JaxRpcEndpointInterfaceService; 43 44 47 public class JOnASJaxRpcClientServlet extends HttpServlet { 48 49 54 public void init(ServletConfig config) throws ServletException { 55 super.init(config); 56 } 57 58 61 public void destroy() { 62 63 } 64 65 75 protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException , 76 IOException { 77 response.setContentType("text/html"); 78 PrintWriter out = response.getWriter(); 79 80 out.println("<html>"); 81 out.println("<head>"); 82 out.println("<title>JOnAS JaxRpc WebService Test Page</title>"); 83 out.println("</head>"); 84 out.println("<body>"); 85 86 try { 87 88 Context ctx = new InitialContext (); 91 JaxRpcEndpointInterfaceService service = (JaxRpcEndpointInterfaceService) ctx 92 .lookup("java:comp/env/service/jaxrpc"); 93 95 JaxRpcEndpointInterface port = service.getJaxRpcEndpoint1(); 98 100 String hello = port.sayHello(request.getParameter("name")); 102 int cotes = port.getCotes(); 103 104 out.println("Working with URL : <i>" + ((Stub ) port)._getProperty(Stub.ENDPOINT_ADDRESS_PROPERTY) 106 + "</i><br/>"); 107 out.println("<b>result of sayHello(name) method :</b><i>" + hello + "</i><br/>"); 108 out.println("<b>result of getCotes() method :</b><i>" + cotes + "</i><br/>"); 109 110 } catch (ServiceException se) { 111 out.println("Something goes wrong when calling the WebService"); 112 se.printStackTrace(out); 113 } catch (NamingException ne) { 114 out.println("Exception while retrieving InitialContext"); 115 ne.printStackTrace(out); 116 } 117 118 out.println("</body>"); 119 out.println("</html>"); 120 121 out.close(); 122 } 123 124 133 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException , IOException { 134 processRequest(request, response); 135 } 136 137 146 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException , 147 IOException { 148 processRequest(request, response); 149 } 150 151 154 public String getServletInfo() { 155 return "Short description"; 156 } 157 158 } | Popular Tags |