Reputation: 480
I have one protocole (onvif) who is using a mix between .xsd definition for his service in SOAP and a dynamic class definition (XML) for the internal event system.
The system work as follow :
The .wsdl definition files are present on this site
When I do request to a device (via the WS-BaseNotification system) I receive the events descriptions like below :
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope"
xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:c14n="http://www.w3.org/2001/10/xml-exc-c14n#"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:wsa5="http://www.w3.org/2005/08/addressing"
xmlns:wsrfbf="http://docs.oasis-open.org/wsrf/bf-2"
xmlns:wstop="http://docs.oasis-open.org/wsn/t-1"
xmlns:tt="http://www.onvif.org/ver10/schema"
xmlns:wsrfr="http://docs.oasis-open.org/wsrf/r-2"
xmlns:tev1="http://www.onvif.org/ver10/events/wsdl/NotificationProducerBinding"
xmlns:tev2="http://www.onvif.org/ver10/events/wsdl/EventBinding"
xmlns:tev3="http://www.onvif.org/ver10/events/wsdl/SubscriptionManagerBinding"
xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2"
xmlns:tev4="http://www.onvif.org/ver10/events/wsdl/PullPointSubscriptionBinding"
xmlns:tev="http://www.onvif.org/ver10/events/wsdl"
xmlns:tns1="http://www.onvif.org/ver10/topics"
xmlns:tnsaxis="http://www.axis.com/2009/event/topics"
xmlns:ter="http://www.onvif.org/ver10/error"
xmlns:pt="http://www.onvif.org/ver10/pacs"
xmlns:tdc="http://www.onvif.org/ver10/doorcontrol/wsdl"
xmlns:tac="http://www.onvif.org/ver10/accesscontrol/wsdl">
<SOAP-ENV:Header>
<wsa5:RelatesTo>urn:uuid:885a71ab-e227-40c9-8471-7b92616cd959</wsa5:RelatesTo>
<wsa5:To SOAP-ENV:mustUnderstand="true">http://www.w3.org/2005/08/addressing/anonymous</wsa5:To>
<wsa5:Action SOAP-ENV:mustUnderstand="true">http://www.onvif.org/ver10/events/wsdl/EventPortType/GetEventPropertiesResponse</wsa5:Action>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<tev:GetEventPropertiesResponse>
<tev:TopicNamespaceLocation>http://www.onvif.org/onvif/ver10/topics/topicns.xml</tev:TopicNamespaceLocation>
<wsnt:FixedTopicSet>false</wsnt:FixedTopicSet>
<wstop:TopicSet>
<tns1:AccessPoint>
<State>
<Enabled wstop:topic="true">
<tt:MessageDescription IsProperty="true">
<tt:Source>
<tt:SimpleItemDescription Name="Device Source" Type="xsd:string"></tt:SimpleItemDescription>
<tt:SimpleItemDescription Name="AccessPointToken" Type="pt:ReferenceToken"></tt:SimpleItemDescription>
</tt:Source>
<tt:Data>
<tt:SimpleItemDescription Name="State" Type="xsd:boolean"></tt:SimpleItemDescription>
</tt:Data>
</tt:MessageDescription>
</Enabled>
</State>
</tns1:AccessPoint>
</wstop:TopicSet>
<wsnt:TopicExpressionDialect>http://www.onvif.org/ver10/tev/topicExpression/ConcreteSet</wsnt:TopicExpressionDialect>
<wsnt:TopicExpressionDialect>http://docs.oasis-open.org/wsn/t-1/TopicExpression/Concrete</wsnt:TopicExpressionDialect>
<tev:MessageContentFilterDialect>http://www.onvif.org/ver10/tev/messageContentFilter/ItemFilter</tev:MessageContentFilterDialect>
<tev:MessageContentSchemaLocation>http://www.onvif.org/ver10/schema/onvif.xsd</tev:MessageContentSchemaLocation>
</tev:GetEventPropertiesResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
My objectif is to create .java class to each event (there is a lots of event), I can obviously hardcoded each event, or code myself a parser, but I am pretty sure there is a automated way to generated them from the XML.
My tries has always failed with JAXB, because the namespace where not resolved. And I have no idea if jaxb can mix the .wsdl/.xsd definition and xml to generate the .java
Thanks
Note this problem is related to this other thread but focus only on the generation of .java from the XML.
Upvotes: 0
Views: 644
Reputation: 2422
My objectif is to create .java class to each event (there is a lots of event)
You need to get hold of the XML Schema description for each event, and then generate the java classes using JAXB. That might require you to fetch the WSDL for each event type and extract the XSD definitions from it. I expect that step could be scripted if you have many event types to process.
I am pretty sure there is a automated way to generated them from the XML.
In general, it is dangerous to assume that. A single XML document is just one example of a valid document. The real event type definition might contain optional elements that are not present in your examples. The only safe way to do this (unless you are 100% sure that the events contain no optional elements) is to obtain the WSDL/XSD for each event type.
My tries has always failed with JAXB, because the namespace where not resolved.
XML namespaces are not difficult to understand, so this should be easy to fix. Feel free to ask specific questions about the errors if you really cannot understand them.
I have no idea if jaxb can mix the .wsdl/.xsd definition and xml to generate the .java
Basic JAXB works with XSDs, not WSDL. However, there are many tools which can generate Java bindings from a WSDL definition. They all use JAXB under the covers for the generation of the Java classes from the XSD part. You should explore those options before looking for hand-coded solutions.
Upvotes: 1