Hi all.I'm newbie to web service and Axis; i have a problem.... i have written
a very simple Web Service; it's code is:
import java.io.Serializable;
import org.w3c.dom.Document;
public class PersonHandler implements Serializable {
/**
* Web service esposto. Invocato esso accetta un document e lo restituisce
in uscita.
* @param doc Document -il document .
* @return Document -il document.
*/
public Document getUserProfile(Document doc) {
return doc;
}
}
Well, i use Axis1.2RC2, JBuilder 2005, Windows XP Home Ed SP2, JBoss 3.2.6; i
want ot create a web service not style RPC but Message.... JBuilder creates
this files:
WSDL:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://websrvc.prototype.eng.it"
xmlns:apachesoap="http://xml.apache.org/xml-soap"
xmlns:impl="http://websrvc.prototype.eng.it"
xmlns:intf="http://websrvc.prototype.eng.it"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.2beta3
Built on Aug 01, 2004 (05:59:22 PDT)-->
<wsdl:message name="getUserProfileResponse">
<wsdl:part name="getUserProfileReturn" type="apachesoap:Document"/>
</wsdl:message>
<wsdl:message name="getUserProfileRequest">
<wsdl:part name="doc" type="apachesoap:Document"/>
</wsdl:message>
<wsdl:portType name="PersonHandler">
<wsdl:operation name="getUserProfile" parameterOrder="doc">
<wsdl:input message="impl:getUserProfileRequest"
name="getUserProfileRequest"/>
<wsdl:output message="impl:getUserProfileResponse"
name="getUserProfileResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="PersonHandlerSoapBinding" type="impl:PersonHandler">
<wsdlsoap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getUserProfile">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getUserProfileRequest">
<wsdlsoap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded"/>
</wsdl:input>
<wsdl:output name="getUserProfileResponse">
<wsdlsoap:body
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="PersonHandlerService">
<wsdl:port binding="impl:PersonHandlerSoapBinding" name="PersonHandler">
<wsdlsoap:address
location="http://localhost:8080/webService/services/PersonHandler"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
WSDD
<?xml version="1.0" encoding="UTF-8"?>
<deployment name="defaultClientConfig"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"
xmlns:handler="http://xml.apache.org/axis/wsdd/providers/handler"
xmlns="http://xml.apache.org/axis/wsdd/">
<globalConfiguration name="GlobalConfiguration1" type=""
regenerateElement="false">
<requestFlow name="RequestFlow1" type="" regenerateElement="false">
<handler name="Handler1"
type="java:org.apache.axis.handlers.JWSHandler"
regenerateElement="false">
<parameter name="scope" value="session"
regenerateElement="false"/>
</handler>
<handler name="Handler2"
type="java:org.apache.axis.handlers.JWSHandler"
regenerateElement="false">
<parameter name="scope" value="request"
regenerateElement="false"/>
<parameter name="extension" value=".jwr"
regenerateElement="false"/>
</handler>
</requestFlow>
</globalConfiguration>
<handler name="URLMapper"
type="java:org.apache.axis.handlers.http.URLMapper"
regenerateElement="false"/>
<handler name="LocalResponder"
type="java:org.apache.axis.transport.local.LocalResponder"
regenerateElement="false"/>
<handler name="Authenticate"
type="java:org.apache.axis.handlers.SimpleAuthenticationHandler"
regenerateElement="false"/>
<transport name="http" type="" regenerateElement="false">
<requestFlow name="RequestFlow1" type="" regenerateElement="false">
<handler name="Handler1" type="URLMapper"
regenerateElement="false"/>
<handler name="Handler2"
type="java:org.apache.axis.handlers.http.HTTPAuthHandler"
regenerateElement="false"/>
</requestFlow>
</transport>
<transport name="local" type="" regenerateElement="false">
<responseFlow name="ResponseFlow1" type="" regenerateElement="false">
<handler name="Handler1" type="LocalResponder"
regenerateElement="false"/>
</responseFlow>
</transport>
<service name="AdminService" type="" regenerateElement="false"
provider="java:MSG" validate="false">
<parameter name="allowedMethods" value="AdminService"
regenerateElement="false"/>
<parameter name="enableRemoteAdmin" value="false"
regenerateElement="false"/>
<parameter name="className" value="org.apache.axis.utils.Admin"
regenerateElement="false"/>
<namespace>http://xml.apache.org/axis/wsdd/</namespace>
</service>
<service name="Version" type="" regenerateElement="false"
provider="java:RPC" validate="false">
<parameter name="allowedMethods" value="getVersion"
regenerateElement="false"/>
<parameter name="className" value="org.apache.axis.Version"
regenerateElement="false"/>
</service>
<service name="PersonHandler" type="" regenerateElement="false"
provider="java:MSG" style="document" use="encoded" validate="false">
<parameter name="scope" value="Request" regenerateElement="false"/>
<parameter name="className"
value="it.eng.prototype.websrvc.PersonHandler"
regenerateElement="false"/>
<parameter name="allowedMethods" value="*" regenerateElement="false"/>
<namespace>http://websrvc.prototype.eng.it</namespace>
</service>
</deployment>
I have written a simple class that creates the document; its code is:
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
public class Parser {
/**
* Mi genero il document da passare al web service.
* @param queryString String -come deve essere il documento
* @return Document -il documento creato
* @exception FactoryConfigurationError -se ci sono problemi nella
creazione della Factory
* @exception ParserConfigurationException -se ci sono problemi nel
parserizzare il documento
*/
public Document generateDocument(String queryString) throws
FactoryConfigurationError, ParserConfigurationException {
DocumentBuilder builder =
DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.newDocument();
Element root = doc.createElement("queries");
root.setAttribute("tipoServizio", "testPMM");
doc.appendChild( root );
Element tag = doc.createElement( "query" );
root.appendChild( tag );
tag.appendChild( doc.createTextNode( queryString ) );
return doc;
}
}
Then i have created a simple client:
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.message.SOAPBodyElement;
import org.apache.axis.utils.XMLUtils;
import org.apache.axis.MessageContext;
import org.apache.axis.Message;
import javax.xml.rpc.ServiceException;
import java.util.Vector;
import org.w3c.dom.Document;
import java.io.Reader;
import java.io.StringReader;
import javax.xml.namespace.QName;
import org.apache.log4j.Logger;
import java.net.URL;
import java.net.MalformedURLException;
public class SimpleAxisClient {
/**
* Il logger
*/
private static final Logger LOG = Logger.getLogger(SimpleAxisClient.class.
getName());
/**
* Preparo il l'oggetto Call da utilizzare
* @param endpoint String -l'endpoint da utilizzare
* @param operation String -l'operazione da invocare
* @return Call -il Call generato.
* @throws ServiceException -Se ci sono problemi col servizio
*/
private Call getCall(String endpoint, String operation) throws
ServiceException {
if (LOG.isDebugEnabled()) {
LOG.debug("Creating call.....");
}
Call result = (Call)(new Service()).createCall();
try {
result.setTargetEndpointAddress(new URL(endpoint));
} catch (MalformedURLException ex) {
LOG.error( ex );
}
//result.setOperation( new QName( endpoint, operation ), operation );
if (LOG.isDebugEnabled()) {
LOG.debug("Done!!");
}
return result;
}
/**
* Invoco il web service passandogli il Document generato
* @param doc Document -il Document generato.
* @param endpoint String -l'endpoint del servizio.
* @param operation String -l'operazione da invocare.
* @return Document -il document in uscita al webService
* @throws Exception
*/
public Document passDocument(Document doc, String endpoint,
String operation) throws Exception {
Call call = getCall(endpoint, operation);
Vector result = (Vector) call.invoke
(new SOAPBodyElement[] {new SOAPBodyElement(doc.
getDocumentElement())});
SOAPBodyElement sbe = (SOAPBodyElement) result.get(0);
MessageContext mc = call.getMessageContext();
Message m = mc.getRequestMessage();
Document docreq = m.getSOAPEnvelope().getAsDocument();
if( LOG.isDebugEnabled() ){
LOG.debug("Body trasmesso: " +
XMLUtils.DocumentToString(docreq));
}
return docreq;
}
}
Well when i try this client (i have created 2 web app one that contains the web
service and one that contains the client), i have this error(i have printed the
full stacktrace):
09:43:10,275 INFO [EjbModule] Deploying UserBean
09:43:10,865 INFO [EJBDeployer] Deployed:
file:/C:/jboss-3.2.6/server/default/deploy/WebSrvcTest.jar
09:43:11,256 INFO [TomcatDeployer] deploy, ctxPath=/prototipo,
warUrl=file:/C:/jboss-3.2.6/server/default/tmp/deploy/tmp55055ClientModule.war/
09:43:12,488 INFO [TomcatDeployer] deploy, ctxPath=/bpws4j,
warUrl=file:/C:/jboss-3.2.6/server/default/tmp/deploy/tmp55056bpws4j.war/
09:43:13,369 INFO [TomcatDeployer] deploy, ctxPath=/jmx-console,
warUrl=file:/C:/jboss-3.2.6/server/default/deploy/jmx-console.war/
09:43:13,720 INFO [TomcatDeployer] deploy, ctxPath=/web-console,
warUrl=file:/C:/jboss-3.2.6/server/default/deploy/management/web-console.war/
09:43:15,212 INFO [TomcatDeployer] deploy, ctxPath=/webService,
warUrl=file:/C:/jboss-3.2.6/server/default/tmp/deploy/tmp55057webService.war/
09:43:18,867 INFO [Http11Protocol] Starting Coyote HTTP/1.1 on
http-0.0.0.0-8080
09:43:19,258 INFO [ChannelSocket] JK2: ajp13 listening on /0.0.0.0:8009
09:43:19,268 INFO [JkMain] Jk running ID=0 time=0/101 config=null
09:43:19,368 INFO [Server] JBoss (MX MicroKernel) [3.2.6 (build:
CVSTag=JBoss_3_2_6 date=200410140106)] Started in 29s:783ms
09:43:42,691 INFO [STDOUT] java.lang.IllegalArgumentException: localPart
cannot be null
09:43:42,691 INFO [STDOUT] at
javax.xml.namespace.QName.<init>(QName.java:106)
09:43:42,691 INFO [STDOUT] at
javax.xml.namespace.QName.<init>(QName.java:81)
09:43:42,691 INFO [STDOUT] at
org.apache.axis.message.PrefixedQName.<init>(PrefixedQName.java:30)
09:43:42,701 INFO [STDOUT] at
org.apache.axis.message.MessageElement.copyNode(MessageElement.java:2045)
09:43:42,701 INFO [STDOUT] at
org.apache.axis.message.MessageElement.copyNode(MessageElement.java:1997)
09:43:42,771 INFO [STDOUT] at
org.apache.axis.message.MessageElement.<init>(MessageElement.java:197)
09:43:42,771 INFO [STDOUT] at
org.apache.axis.message.SOAPBodyElement.<init>(SOAPBodyElement.java:70)
09:43:42,771 INFO [STDOUT] at
it.eng.prototype.websrvc.client.SimpleAxisClient.passDocument(SimpleAxisClient.java:85)
09:43:42,771 INFO [STDOUT] at
it.eng.prototype.servlet.Dispatcher.doPost(Dispatcher.java:48)
09:43:42,781 INFO [STDOUT] at
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
09:43:42,781 INFO [STDOUT] at
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
09:43:42,791 INFO [STDOUT] at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
09:43:42,791 INFO [STDOUT] at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
09:43:42,791 INFO [STDOUT] at
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)
09:43:42,791 INFO [STDOUT] at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
09:43:42,801 INFO [STDOUT] at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
09:43:42,801 INFO [STDOUT] at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
09:43:42,801 INFO [STDOUT] at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
09:43:42,801 INFO [STDOUT] at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
09:43:42,811 INFO [STDOUT] at
org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
09:43:42,811 INFO [STDOUT] at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
09:43:42,811 INFO [STDOUT] at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
09:43:42,821 INFO [STDOUT] at
org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:66)
09:43:42,821 INFO [STDOUT] at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
09:43:42,821 INFO [STDOUT] at
org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:158)
09:43:42,831 INFO [STDOUT] at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
09:43:42,831 INFO [STDOUT] at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
09:43:42,831 INFO [STDOUT] at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
09:43:42,831 INFO [STDOUT] at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
09:43:42,841 INFO [STDOUT] at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
09:43:42,841 INFO [STDOUT] at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
09:43:42,841 INFO [STDOUT] at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
09:43:42,851 INFO [STDOUT] at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
09:43:42,851 INFO [STDOUT] at
org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
09:43:42,851 INFO [STDOUT] at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
09:43:42,851 INFO [STDOUT] at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
09:43:42,851 INFO [STDOUT] at
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
09:43:42,891 INFO [STDOUT] at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
09:43:42,891 INFO [STDOUT] at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
09:43:42,891 INFO [STDOUT] at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
09:43:42,902 INFO [STDOUT] at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
09:43:42,902 INFO [STDOUT] at java.lang.Thread.run(Thread.java:534)
09:43:43,422 ERROR [Dispatcher] java.lang.IllegalArgumentException: localPart
cannot be null
Can anybody help me??? Thanks
____________________________________________________________
6X velocizzare la tua navigazione a 56k? 6X Web Accelerator di Libero!
Scaricalo su INTERNET GRATIS 6X http://www.libero.it