users@glassfish.java.net

Accessing Web Service from JSP fails

From: <glassfish_at_javadesktop.org>
Date: Tue, 18 Aug 2009 07:34:57 PDT

Hi everyone,

I am trying to run in GlassFishv3 (glassfish-v3-ea-b44) an example from the "Java Web Services - Up and Running" book and it does not work. Here is the structure of the example. I have two applications deployed as war, one containing just the Web Service and the second one containing the html and jsp files for displaying and accessing the web service.

The class for the Web Service is shown below:

[code]
package ch06.tc;

import javax.jws.WebService;
import javax.jws.WebMethod;

@WebService
public class TempConvert {
        @WebMethod
        public float c2f(float t) { return 32.0f + (t * 9.0f / 5.0f); }
        @WebMethod
        public float f2c(float t) { return (5.0f / 9.0f) * (t - 32.0f); }
} [/code]

The deployed file for the above class is tc.war. GlassFish automatically generates the wsdl for the service:

[code]
<!--
 Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2-hudson-351-.
-->

<!--
 Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2-hudson-351-.
-->

<definitions targetNamespace="http://tc.ch06/" name="TempConvertService">

<types>

<xsd:schema>
<xsd:import namespace="http://tc.ch06/" schemaLocation="http://localhost:8080/tc/TempConvertService?xsd=1"/>
</xsd:schema>
</types>

<message name="c2f">
<part name="parameters" element="tns:c2f"/>
</message>

<message name="c2fResponse">
<part name="parameters" element="tns:c2fResponse"/>
</message>

<message name="f2c">
<part name="parameters" element="tns:f2c"/>
</message>

<message name="f2cResponse">
<part name="parameters" element="tns:f2cResponse"/>
</message>

<portType name="TempConvert">

<operation name="c2f">
<input wsam:Action="http://tc.ch06/TempConvert/c2fRequest" message="tns:c2f"/>
<output wsam:Action="http://tc.ch06/TempConvert/c2fResponse" message="tns:c2fResponse"/>
</operation>

<operation name="f2c">
<input wsam:Action="http://tc.ch06/TempConvert/f2cRequest" message="tns:f2c"/>
<output wsam:Action="http://tc.ch06/TempConvert/f2cResponse" message="tns:f2cResponse"/>
</operation>
</portType>

<binding name="TempConvertPortBinding" type="tns:TempConvert">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>

<operation name="c2f">
<soap:operation soapAction=""/>

<input>
<soap:body use="literal"/>
</input>

<output>
<soap:body use="literal"/>
</output>
</operation>

<operation name="f2c">
<soap:operation soapAction=""/>

<input>
<soap:body use="literal"/>
</input>

<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>

<service name="TempConvertService">

<port name="TempConvertPort" binding="tns:TempConvertPortBinding">
<soap:address location="http://localhost:8080/tc/TempConvertService"/>
</port>
</service>
</definitions>
[/code]
, which I will use with the wsimport command to generate client side artifacts that I will use from the jsp. Below is the main jsp file:

[code]
<%@ page errorPage = 'error.jsp' %>
<%@ page import = "client.TempConvert" %>
<%@ page import = "client.TempConvertService" %>
<html><body>
<%! private float _f2c, _c2f, temp; %>
<%
   String temp_str = request.getParameter("temperature");
   if (temp_str != null) temp = Float.parseFloat(temp_str.trim());

   TempConvertService service = new TempConvertService();
   TempConvert port = service.getTempConvertPort();
   _f2c = port.f2C(temp);
   _c2f = port.c2F(temp);
%>
<p><%= this.temp %>F = <%= this._f2c %>C</p>
<p><%= this.temp %>C = <%= this._c2f %>F</p>
<a href = 'index.html'>Try another</a>
</body></html>
[/code]
where the value of the temperature comes from a form inside an html file. After I deploy the second file, called tcJSP.war, and run the html file that calls the main jsp file, I get the following error:

[code]
com.sun.xml.ws.client.ClientTransportException: HTTP transport error: java.lang.UnsupportedOperationException: Method not implemented.

com.sun.xml.ws.transport.http.client.HttpClientTransport.getOutput(HttpClientTransport.java:132)
com.sun.xml.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:153)
com.sun.xml.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:93)
com.sun.xml.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:117) com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:629)
com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:588)
com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:573)
com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:470)
com.sun.xml.ws.client.Stub.process(Stub.java:235)
com.sun.xml.ws.client.sei.SEIStub.doProcess(SEIStub.java:147)
com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:109)
com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:89)
com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:130) $Proxy136.f2C(Unknown Source) org.apache.jsp.temp_005fconvert_jsp._jspService(temp_005fconvert_jsp.java from :59)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:109)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:403)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:366)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:461)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:302)
 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:187)
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:656)
com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:351)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:249)
com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:143)
 com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:726)
com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:615)
com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:895)
com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:162)
com.sun.enterprise.v3.services.impl.GlassfishProtocolChain.executeProtocolFilter(GlassfishProtocolChain.java:71)
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:103)
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:89)
com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:67)
com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
java.util.concurrent.FutureTask.run(FutureTask.java:138)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
java.lang.Thread.run(Thread.java:619)
[/code]
The interesting part is that if I deploy the second war (tcJSP.war) in Tomcat and leave only the first one (tc.war) in GlassFish, everything works out great.

Any ideas what the problem might be?

Thanks,
Mihai
[Message sent by forum member 'mihaifonoage' (mihaifonoage)]

http://forums.java.net/jive/thread.jspa?messageID=360976