Hello,
I'm trying to implement a contract-first web service with embedded xfire.
That's what I do:
1. Generate java classes from a wsdl (Listing 1)
2. Embed xfire in my application using a helper class (Listing 2)
3. Invoke the generated pojo with a SOAP message that complies to the
original WSDL. (Listing 3)
This basically works, but the called pojo method does not get the url from
the SOAP request.
The result does not comply with my original WSDL file and therefore can't be
understood by the caller.
4. Obtain the wsdl using xfire (Listing 4)
The WSDL xfire issues is different from the original one.
It adds a request element to the request and an out element to the response.
This does not conform to the original WSDL file.
I tried to add the original WSDL by calling _service.setWSDLWriter(new
ResourceWSDL("filedir.wsdl"));
This caused xfire to return the corrent wsdl, but the internal processing
still uses with the request and out elements.
Have I done anything wrong or is it not possible to follow contract-first
with xfire?
Any help would be very much appreciated.
Listing 1: Source WSDL
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:filedir="http://www.demo.org/test/filedir/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="filedir"
targetNamespace="http://www.demo.org/test/filedir/">
<wsdl:types>
<xsd:schema targetNamespace="http://www.demo.org/test/filedir/">
<xsd:element name="listFiles">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="url"
type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="listFilesResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="url"
type="xsd:string" />
<xsd:element name="files"
type="filedir:file" maxOccurs="unbounded"
minOccurs="0"></xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="file">
<xsd:sequence>
<xsd:element name="name"
type="xsd:string"></xsd:element>
<xsd:element name="size"
type="xsd:int"></xsd:element>
<xsd:element name="creation"
type="xsd:dateTime"></xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
<wsdl:message name="listFiles">
<wsdl:part element="filedir:listFiles" name="parameters"/>
</wsdl:message>
<wsdl:message name="listFilesResponse">
<wsdl:part element="filedir:listFilesResponse" name="parameters"/>
</wsdl:message>
<wsdl:portType name="filedir">
<wsdl:operation name="listFiles">
<wsdl:input message="filedir:listFiles"/>
<wsdl:output message="filedir:listFilesResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="filedirSOAP" type="filedir:filedir">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="listFiles">
<soap:operation soapAction="http://www.demo.org/test/filedir/listFiles"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="filedir">
<wsdl:port binding="filedir:filedirSOAP" name="filedirPort">
<soap:address location="http://www.demo.org/test/filedir"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Listing 2: Helper class for embedding xfire
public class SOAPHelper
{
private XFire _xfire;
private Service _service;
private String _serviceName;
private ServiceFactory _factory;
public SOAPHelper()
{
_xfire = new DefaultXFire();
_factory = new ObjectServiceFactory(_xfire.getTransportManager(),new
AegisBindingProvider());
}
public void registerService(Object pojo, String serviceName) throws
Exception
{
_serviceName=serviceName;
_service = _factory.create(pojo.getClass(),_serviceName,null,null);
_service.setInvoker(new BeanInvoker(pojo));
_xfire.getServiceRegistry().register(_service);
}
public ByteArrayOutputStream invoke(InputStream in) throws Exception
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
MapSession session = new MapSession();
MessageContext context = new MessageContext();
context.setSession(session);
context.setXFire(_xfire);
context.setProperty(Channel.BACKCHANNEL_URI, out);
if (_service != null)
{
context.setService(_xfire.getServiceRegistry().getService(_serviceName));
}
XMLStreamReader streamReader = STAXUtils.createXMLStreamReader(in,
"UTF-8", null);
InMessage msg = new InMessage(streamReader);
Transport t =
_xfire.getTransportManager().getTransport(LocalTransport.BINDING_ID);
Channel c = t.createChannel();
c.receive(context, msg);
return out;
}
public Document getWsdl() throws Exception
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
_xfire.generateWSDL(_serviceName, out);
return stringToDocument(out.toString());
}
public String getWsdlAsText() throws Exception
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
_xfire.generateWSDL(_serviceName, out);
return out.toString();
}
private org.w3c.dom.Document stringToDocument(String text) throws
Exception
{
org.w3c.dom.Document ret;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
ret = builder.parse(new InputSource(new StringReader(text)));
return ret;
}
}
Listing 3: Application
// Initialization
FileProvider _provider = new FileProvider(); // That's the generated pojo
SOAPHelper helper = new SOAPHelper();
helper.registerService(_provider,"filedir");
InputStream istream = ... // Stream contains the incoming SOAP message
ByteArrayOutputStream ostream;
// Invoke method
ostream =helper.invoke(istream);
String response = ostream.toString();
System.out.println(response);
// Obtain wsdl
System.out.println(helper.getWsdlAsText());
Listing 3: SOAP message
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:prov="http://provider.file.components.test.demo.org"
xmlns:fil="http://filedir.test.demo.org">
<soapenv:Header/>
<soapenv:Body>
<prov:listFiles>
<fil:url>ftp://demo/grants</fil:url>
</prov:listFiles>
</soapenv:Body>
</soapenv:Envelope>
Listing 4: xfire Generated WSDL
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:ns1="http://filedir.test.demo.org"
xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"
xmlns:soapenc11="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soapenc12="http://www.w3.org/2003/05/soap-encoding"
xmlns:tns="http://provider.file.components.test.demo.org"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://provider.file.components.test.demo.org">
<wsdl:types>
<xsd:schema targetNamespace="http://filedir.epobus.epo.org"
elementFormDefault="qualified" attributeFormDefault="qualified">
<xsd:complexType name="ListFiles">
<xsd:sequence>
<xsd:element name="url" type="xsd:string" minOccurs="0"
nillable="true" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ListFilesResponse">
<xsd:sequence>
<xsd:element name="files" type="ns1:ArrayOfFile" minOccurs="0"
nillable="true" />
<xsd:element name="url" type="xsd:string" minOccurs="0"
nillable="true" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="ArrayOfFile">
<xsd:sequence>
<xsd:element name="File" type="ns1:File" nillable="true"
minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="File">
<xsd:sequence>
<xsd:element name="creation" type="xsd:dateTime" minOccurs="0"
nillable="true" />
<xsd:element name="name" type="xsd:string" minOccurs="0"
nillable="true" />
<xsd:element name="size" type="xsd:int" minOccurs="0" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
<xsd:schema
targetNamespace="http://provider.file.components.epobus.epo.org"
elementFormDefault="qualified" attributeFormDefault="qualified">
<xsd:element name="listFiles">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="request" type="ns1:ListFiles" nillable="true"
minOccurs="1" maxOccurs="1" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="listFilesResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="out" type="ns1:ListFilesResponse"
nillable="true" minOccurs="1" maxOccurs="1" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="listFilesResponse">
<wsdl:part element="tns:listFilesResponse" name="parameters" />
</wsdl:message>
<wsdl:message name="listFilesRequest">
<wsdl:part element="tns:listFiles" name="parameters" />
</wsdl:message>
<wsdl:portType name="filedirPortType">
<wsdl:operation name="listFiles">
<wsdl:input message="tns:listFilesRequest" name="listFilesRequest" />
<wsdl:output message="tns:listFilesResponse" name="listFilesResponse"
/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="filedirHttpBinding" type="tns:filedirPortType">
<wsdlsoap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="listFiles">
<wsdlsoap:operation soapAction="" />
<wsdl:input name="listFilesRequest">
<wsdlsoap:body use="literal" />
</wsdl:input>
<wsdl:output name="listFilesResponse">
<wsdlsoap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="filedir">
<wsdl:port binding="tns:filedirHttpBinding" name="filedirHttpPort">
<wsdlsoap:address location="http://localhost/services/filedir" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
--
View this message in context:
http://www.nabble.com/Contract-first-with-embedded-xfire-does-not-work-tf3845516.html#a10890475
Sent from the XFire - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email