[
https://issues.apache.org/jira/browse/CXF-5064?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13678376#comment-13678376
]
Thomas McLean commented on CXF-5064:
------------------------------------
Sure,
Given a POJO intended as a header in a SOAP message...
========================================================================
package com.feith.soapheadertest;
public class HeaderObj
{
String field1 = null;
String field2 = null;
public HeaderObj(){}
public HeaderObj( String value )
{
if( value != null && !value.trim().isEmpty() )
{
String fields[] = value.split( "-" );
if( fields.length == 2 )
{
field1 = fields[0];
field2 = fields[1];
}
}
}
public String getField1() { return field1; }
public void setField1(String field1) { this.field1 = field1; }
public String getField2() { return field2; }
public void setField2(String field2) { this.field2 = field2; }
@Override
public String toString()
{
return field1 + "-" + field2;
}
}
========================================================================
...an XmlAdapter to serialize that object into a string...
========================================================================
package com.feith.soapheadertest;
import javax.xml.bind.annotation.adapters.XmlAdapter;
public class HeaderObjTypeAdapter extends XmlAdapter<String, HeaderObj>
{
@Override
public String marshal( HeaderObj v ) throws Exception
{
if( v == null )
return null;
return v.toString();
}
@Override
public HeaderObj unmarshal( String v ) throws Exception
{
return new HeaderObj( v );
}
}
========================================================================
...and the following SEI...
========================================================================
package com.feith.soapheadertest;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebParam.Mode;
import javax.jws.WebService;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
@WebService( targetNamespace="http://www.feith.com/services/cxfSOAPHeaderTest" )
public interface SOAPHeaderTest
{
@WebMethod( operationName="test" )
public void test(
@WebParam( header=true, mode=Mode.IN, name="SESSIONID" )
@XmlJavaTypeAdapter( HeaderObjTypeAdapter.class )
HeaderObj headerObj
);
}
========================================================================
The resulting WSDL is the following...
========================================================================
<?xml version='1.0' encoding='UTF-8'?><wsdl:definitions
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://www.feith.com/services/cxfSOAPHeaderTest"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="CXFSOAPHeaderTest"
targetNamespace="http://www.feith.com/services/cxfSOAPHeaderTest">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.feith.com/services/cxfSOAPHeaderTest"
attributeFormDefault="unqualified" elementFormDefault="unqualified"
targetNamespace="http://www.feith.com/services/cxfSOAPHeaderTest">
<xs:element name="test" type="tns:test"/>
<xs:element name="testResponse" type="tns:testResponse"/>
<xs:complexType name="test">
<xs:sequence/>
</xs:complexType>
<xs:complexType name="headerObj">
<xs:sequence>
<xs:element minOccurs="0" name="field1" type="xs:string"/>
<xs:element minOccurs="0" name="field2" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="testResponse">
<xs:sequence/>
</xs:complexType>
<xs:element name="SESSIONID" nillable="true" type="tns:headerObj"/>
</xs:schema>
</wsdl:types>
<wsdl:message name="testResponse">
<wsdl:part element="tns:testResponse" name="result">
</wsdl:part>
</wsdl:message>
<wsdl:message name="test">
<wsdl:part element="tns:test" name="parameters">
</wsdl:part>
<wsdl:part element="tns:SESSIONID" name="SESSIONID">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="SOAPHeaderTest">
<wsdl:operation name="test">
<wsdl:input message="tns:test" name="test">
</wsdl:input>
<wsdl:output message="tns:testResponse" name="testResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="CXFSOAPHeaderTestSoapBinding" type="tns:SOAPHeaderTest">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="test">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="test">
<soap:header message="tns:test" part="SESSIONID" use="literal">
</soap:header>
<soap:body parts="parameters" use="literal"/>
</wsdl:input>
<wsdl:output name="testResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="CXFSOAPHeaderTest">
<wsdl:port binding="tns:CXFSOAPHeaderTestSoapBinding"
name="SOAPHeaderTestImplPort">
<soap:address location="http://localhost:8080/CXFTest/cxftest"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
========================================================================
Notice that SESSIONID defined as
========================================================================
<xs:complexType name="headerObj">
<xs:sequence>
<xs:element minOccurs="0" name="field1" type="xs:string"/>
<xs:element minOccurs="0" name="field2" type="xs:string"/>
</xs:sequence>
</xs:complexType>
.........
<xs:element name="SESSIONID" nillable="true" type="tns:headerObj"/>
========================================================================
With the given XML adapter I would expect it to be defined as
========================================================================
<xs:element name="SESSIONID" nillable="true" type="xs:string"/>
========================================================================
> XmlJavaTypeAdapter ignored on SOAP Headers
> ------------------------------------------
>
> Key: CXF-5064
> URL: https://issues.apache.org/jira/browse/CXF-5064
> Project: CXF
> Issue Type: Bug
> Components: JAXB Databinding
> Affects Versions: 2.7.5
> Environment: Windows 7, JDK 1.6.0_35 (x64)
> Reporter: Thomas McLean
>
> Supplying an XmlJavaTypeAdapter annotation that should marshal a simple POJO
> with two string fields into a single String element produces a complex
> element that would be the correct representation without the type adapter.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira