Reputation: 1741
I've to manage many webservices and have to put my aplication in the middle of them and clients: clients will call me, I'll call the servers and manage the responses to send them to clients.
Both request and response have an 'envelope's defined: different but almost the same.
Lets say:
<req xmlns="namespaceReq">
<req-data>..different info 1..</req-data>
<info>...Info object...</info>
</req>
and
<resp xmlns="namespaceResp">
<resp-data>..different info 2...<resp-data>
<info>...Info object...</info>
</resp>
So I want to share common classes between request and response -aka the info object-; I've done a java package for the request (with the namespace of the request in its package-name and Req and Req-data classes), another one for the response (with the namespace of the response in its package-name, and also, Resp and Resp-data classes) and have done another package to hold the common part (the Info class) and there's my problem...
How should I manage the namespaces so that I could share the common Info object to both request and response?
If I put request's namespace in the package-info.java it works for the request but not for the response, if I put response it doesn't work for request...
Upvotes: 0
Views: 841
Reputation: 3424
The common objects package should define its own XML namespace ... I have done the kind of configuration that you're trying to do, but I generated the objects from XSD files ... Example:
XSD Commons:
<xs:schema
targetNamespace="http://xyz/commons"
xmlns:tns="http://xyz/commons"
elementFormDefault="qualified"
version="1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="InfoType">
<xs:sequence>
<xs:element name="Address" type="xs:string" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:schema>
XSD Requests:
<xs:schema
targetNamespace="http://xyz/requests"
xmlns:tns="http://xyz/requests"
xmlns:commons="http://xyz/commons"
elementFormDefault="qualified"
version="1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
<xs:import namespace="http://xyz/commons" schemaLocation="commons.xsd" />
<xs:element name="Request" type="tns:RequestType" />
<xs:complexType name="RequestType">
<xs:sequence>
<xs:element name="info" type="commons:InfoType" />
</xs:sequence>
</xs:complexType>
</xs:schema>
Upvotes: 1