Search
Calendar
June 2017
S M T W T F S
« Sep    
 123
45678910
11121314151617
18192021222324
252627282930  
Your widget title
Archives

Posts Tagged ‘WSDL’

PostHeaderIcon Why “contract first” approach won’t work with CXF or SpringWS for Axis-generated WSDLs

Case

My previous subject was the following: considering a WSDL that was generated by Axis 2, develop a webservice with CXF and/or SpringWS in “contract first” (ie the contract seen as an API is given, Java code comes afterwards) approach.

It cannot work easyly, unless you are ready to spend time, money and energy in creating adapters and adding layers in your application architecture.

CXF

With CXF, the first step is to generate Java code with the wsdl2java embeded in Maven CXF plugin. The output is explicit:

Failed to execute goal org.apache.cxf:cxf-codegen-plugin:2.6.1:#wsdl2java on project PocEjb3: Rpc/encoded wsdls are not supported with #CXF

(cf my tweet)

RPC vs Encoded

Actually, the SOAP envelope has two ways to transport the message: RPC and Document. More detail is available here: Which style of WSDL should I use?
Axis 2 generates RPC/encoded webservice ; this method is deprecated, CXF does not support it.

Spring WS

I then tried to use Spring WS. I thought “Spring WS is only contract-first, it should work”. The first pitfall I fell on was that SpringWS bases on XSD files, not on actual WSDL. For instance, if you follow SpringWS tutorial, you will find such a block:

    <sws:dynamic-wsdl id="holiday" portTypeName="HumanResource" locationUri="/holidayService/"
targetNamespace="http://mycompany.com/hr/definitions">
<sws:xsd location="/WEB-INF/hr.xsd"/>
</sws:dynamic-wsdl>

To workaround, you can specify use tag, such as:

<sws:static-wsdl id="precomputed-holiday" location="/WEB-INF/precomputed-holiday.wsdl"/>

Anyway, the next issue appears: SpringWS expects to deal with document webservices, ie blocks like:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://mycompany.com/hr/schemas">
    <soapenv:Header/>
    <soapenv:Body>
        <sch:HolidayRequest>
        <!--You may enter the following 2 items in any order-->
            <sch:Holiday>
            <sch:StartDate>?</sch:StartDate>
            <sch:EndDate>?</sch:EndDate>
            </sch:Holiday>
        <sch:Employee>
            <sch:Number>?</sch:Number>
            <sch:FirstName>?</sch:FirstName>
            <sch:LastName>?</sch:LastName>
        </sch:Employee>
    </sch:HolidayRequest>
</soapenv:Body>
</soapenv:Envelope>>

whereas Axis-generated WSDL look like:

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:int="http://interfaces.api.lalou.jonathan">
    <soapenv:Header/>
    <soapenv:Body>
        <int:sayHello soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
    </soapenv:Body>
</soapenv:Envelope>

In other words, I have just fallen on the exact same issue as with CXF: SpringWS cannot support RPC/encoded WSDLs.