| Author |
HELP: JSP calling Web Services
|
Andy Tealle
Greenhorn
Joined: Nov 10, 2004
Posts: 1
|
|
Hi, I'm new to webservices. I'm currently running Apache Tomcat 4.1 with Axis on FreeBSD to deploy my web services. Right now I'm using *.jws files to deploy and have successfully generated stubs for my code. I have also created a client to call my webservice. All this works fine when invoking the web service client from command line, however, the problem comes when i try to call the client file from jsp. I get the following error when doing this: org.apache.jasper.JasperException: javax/xml/rpc/Service at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:254) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter . . . etc... javax.servlet.ServletException: javax/xml/rpc/Service at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:536) at org.apache.jsp.test_main1_jsp._jspService(test_main1_jsp.java:102) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256) at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) . . . etc... =========================================================================== Here is my client code which i'm trying to invoke: import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.apache.axis.encoding.XMLType; import org.apache.axis.utils.Options; import javax.xml.rpc.ParameterMode; public class AuthenticateClient1 { public String authenticateClient(String username, String passwd, String db_name) throws Exception { String host = "http://localhost:"; String servicepath = "/axis/Jws_Interface/Authenticate.jws"; //Options options = new Options(args); int port = 8180; String endpoint = host + port + servicepath; String method = "authenticating"; //args = options.getRemainingArgs(); String op1 = username; String op2 = passwd; String op3 = db_name; String ret = null; Service service = new Service(); Call call = (Call) service.createCall(); call.setTargetEndpointAddress(new java.net.URL (endpoint)); call.setOperationName(method); if (op1 != null && op2 != null && op3 != null) { call.addParameter("op1", XMLType.XSD_STRING, ParameterMode.IN); call.addParameter("op2", XMLType.XSD_STRING, ParameterMode.IN); call.addParameter("op3", XMLType.XSD_STRING, ParameterMode.IN); call.setReturnType(XMLType.XSD_STRING); ret = (String) call.invoke(new Object [] {op1,op2,op3}); } return ret; } public static void main(String args[]) throws Exception { AuthenticateClient1 auth = new AuthenticateClient1(); String result = auth.authenticateClient(args[0], args[1], args[2]); System.out.println(result); } } =========================================================================== Here's my jsp code which i'm invoking from: <%@ page contentType="text/html;charset=windows-1252"%> <%@ page import="AuthenticateClient1"%> <%@ page import="org.w3c.dom.*" %> <%@ page import="org.w3c.dom.Text" %> <%@ page import="org.apache.axis.client.*"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title> Web Service JSP Client - Scriptlet </title> </head> <body> <% String parm1 = request.getParameter("parm1"); String result = ""; if (parm1 == null) parm1 = " "; %> <br> <form action="test_main2.jsp" method=get> <table border="0"> <tr> <td> Greeting:</b> </td> <td> <input type="text" name="parm1" size="14" value="<%=parm1 %>"> </td> <td> <input type="Submit" value="Submit"/> </td> </tr> </table> </form> <p> <br> <% try{ AuthenticateClient1 auth = new AuthenticateClient1(); result = auth.authenticateClient(parm1, parm1, parm1); } catch (Exception e) { result = "Web service unreachable tonight :-("; } %> The response returned is: <%=result %> </body> </html> =========================================================================== any help will be greatly appreciated
|
 |
Cesar Olavo
Greenhorn
Joined: Nov 19, 2004
Posts: 17
|
|
Hi, I'm having the same problem. I have a jsp calling a bean that in turn calls a web service, but all I got is this (useless) stack trace (please convince me otherwise!). I soon realised that the exception is thrown when the bean is called (precisely, in this line: <jsp:useBean id="jp" class="jpath.JPathBeanWS" scope="session" /> ) What's more weird is that I made two other versions of this same program and both worked: first i replaced the jsp client for a comand line one and everything was fine; then i put the "service" into the bean and had no problem at all too. So I ruled out most common mistakes.I also replaced the jsp:usebean for a scriptlet calling the bean so I could catch a more precise exception (in the code below), but to no avail. So, please, what i'm overlooking? Cesar Here's the jsp: <HTML> <HEAD><TITLE>Java Package</TITLE></HEAD> <BODY> <%-- <jsp:useBean id="jp" class="jpath.JPathBeanWS" scope="session" /> <jsp:setProperty name="jp" property="classe" /> --%> <% try{ jpath.JPathBeanWS jp = new jpath.JPathBeanWS(); jp.setClasse("java.lang.String"); String respP = jp.getPack(); String respC = jp.getClasse(); if (respC != null) out.println("<H3> " + respP + "</H3>" ); }catch(Exception e){ out.println("QUALQUER COISA"+e); if(e instanceof javax.servlet.ServletException) { Throwable et; et = ((javax.servlet.ServletException)e).getRootCause(); if(et!=null&&et instanceof Exception) { out.println("QUALQUER COISA"+(Exception)et); } } } %> <H2> Enter the full name of the class </H2> <H3> (e.g. java.lang.String) </H3> <BR> <FORM METHOD=POST> <INPUT TYPE="TEXT" NAME="classe" > <INPUT TYPE="SUBMIT"> </FORM> <BR> <% String respP = jp.getPack(); String respC = jp.getClasse(); if (respC != null) out.println("<H3> " + respP + "</H3>" ); %> </BODY> </HTML> And here's the bean: package jpath; import jpath.local.*; import org.apache.axis.AxisFault; import org.apache.axis.client.Call; import org.apache.axis.client.Service; import javax.xml.namespace.QName; public class JPathBeanWS { public JPathBeanWS(){ } private String classe; private String pack; public void setClasse(String _classe){ classe = _classe; } public String getClasse() {return classe;} public String getPack () { if (classe != null) pack = this.javaPath( classe ); else pack = ""; return pack; } private String javaPath(String className) { String s = "test"; try { JPathService service = new JPathServiceLocator(); JPath port = service.getJPath(); s = (port.javaPath(className)); } catch(AxisFault af) { System.err.println("An Axis Fault occurred: " + af);} catch(Exception e) { System.err.println("Exception caught: " + e);} return s; } }
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 11862
|
|
I don't think you are seeing the true cause of the exception. Try to catch it earlier and do exception.printStackTrace( System.err ); Bill
|
Java Resources at www.wbrogden.com
|
 |
 |
|
|
subject: HELP: JSP calling Web Services
|
|
|