I Cannot generate wsdl JAVA with wsimport for GetHotelMediaRQ. Could you please tell me how to resolve the problem?
wsimport -target 2.1 -keep -d /Users/jinli/Tmp/ws/classes -s . -p org.jellylab.soap.sacs.proto 'http://webservices.sabre.com/wsdl/sabreXML1.0.00/VCMP/GetHotelMediaRQ_v2.0.0.wsdl'
parsing WSDL...
[ERROR] 'HotelMediaInfos' is already defined
line 51 of http://webservices.sabre.com/wsdl/sabreXML1.0.00/VCMP/GetHotelMediaRS_v2.0.0.xsd
[ERROR] (related to above error) the first definition appears here
line 390 of http://webservices.sabre.com/wsdl/sabreXML1.0.00/VCMP/HotelMediaCommons_v2.0.0.xsd
Exception in thread "main" com.sun.tools.internal.ws.wscompile.AbortException
at com.sun.tools.internal.ws.processor.modeler.wsdl.JAXBModelBuilder.bind(JAXBModelBuilder.java:129)
at com.sun.tools.internal.ws.processor.modeler.wsdl.WSDLModeler.buildJAXBModel(WSDLModeler.java:2283)
at com.sun.tools.internal.ws.processor.modeler.wsdl.WSDLModeler.internalBuildModel(WSDLModeler.java:183)
at com.sun.tools.internal.ws.processor.modeler.wsdl.WSDLModeler.buildModel(WSDLModeler.java:126)
at com.sun.tools.internal.ws.wscompile.WsimportTool.buildWsdlModel(WsimportTool.java:429)
at com.sun.tools.internal.ws.wscompile.WsimportTool.run(WsimportTool.java:190)
at com.sun.tools.internal.ws.wscompile.WsimportTool.run(WsimportTool.java:168)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.sun.tools.internal.ws.Invoker.invoke(Invoker.java:159)
at com.sun.tools.internal.ws.WsImport.main(WsImport.java:42)
The error is correct, this was defined 2 times. You need to download the WSDL and all the associated schemas.
The GetHotelMediaRS_v2.0.0.xsd looks like below xsd:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:stlp="http://services.sabre.com/STL_Payload/v02_02" xmlns="http://services.sabre.com/hotel/media/v2" targetNamespace="http://services.sabre.com/hotel/media/v2" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:import namespace="http://services.sabre.com/STL_Payload/v02_02" schemaLocation="built-ins/STL2_Payload_v02_02.xsd" />
<xs:include schemaLocation="HotelMediaCommons_v2.0.0.xsd" />
<xs:element name="GetHotelMediaRS">
<xs:annotation>
<xs:documentation xml:lang="en">
Hotel Media Response Message provides hotel media content available for the specified hotel property code.
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:complexContent>
<xs:extension base="stlp:STL_Response_Payload">
<xs:sequence>
<xs:element name="HotelMediaInfos" type="HotelMediaInfos">
<xs:annotation>
<xs:documentation xml:lang="en">
Contains information about one or more hotel codes and corresponding available media types.
This depends on the hotel codes provided in the request.
</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
<xs:complexType name="HotelMediaInfos">
<xs:annotation>
<xs:documentation xml:lang="en">
Contains information about one or more hotel codes and corresponding available media types.
This depends on the hotel codes provided in the request.
</xs:documentation>
</xs:annotation>
<xs:sequence minOccurs="0" maxOccurs="50">
<xs:element name="HotelMediaInfo" type="HotelMediaInfo">
<xs:annotation>
<xs:documentation xml:lang="en">
Contains infroamtion about various media types available for a particular hotel code.
This depends on the hotel code provided in the request.
</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
You should simply remove the complexType definition HotelMediaInfos, and you would end up with something like the bellow xsd:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:stlp="http://services.sabre.com/STL_Payload/v02_02" xmlns="http://services.sabre.com/hotel/media/v2" targetNamespace="http://services.sabre.com/hotel/media/v2" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:import namespace="http://services.sabre.com/STL_Payload/v02_02" schemaLocation="built-ins/STL2_Payload_v02_02.xsd" />
<xs:include schemaLocation="HotelMediaCommons_v2.0.0.xsd" />
<xs:element name="GetHotelMediaRS">
<xs:annotation>
<xs:documentation xml:lang="en">
Hotel Media Response Message provides hotel media content available for the specified hotel property code.
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:complexContent>
<xs:extension base="stlp:STL_Response_Payload">
<xs:sequence>
<xs:element name="HotelMediaInfos" type="HotelMediaInfos">
<xs:annotation>
<xs:documentation xml:lang="en">
Contains information about one or more hotel codes and corresponding available media types.
This depends on the hotel codes provided in the request.
</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:schema>
You can even replace the content above in the GetHotelMediaRS_v2.0.0.xsd, and you should be able to compile.
Personal recommendation, in the future, try to do these things yourself. It will help you learn and avoid depending on Sabre or the community.
Related
I want to XML payloads like:
<ResponseDto>
<ResponseHeader>
<success>true</success>
</ResponseHeader>
<ResponseBody>
<ObjectA>
</ObjectA>
</ResponseBody>
</ResponseDto>
and another payload like:
<ResponseDto>
<ResponseHeader>
<success>true</success>
</ResponseHeader>
<ResponseBody>
<ObjectB>
</ObjectB>
</ResponseBody>
</ResponseDto>
so I want to make a class for ResponseDto which contains ResponseHeader Object and a generic Java Object in which I can place different types of objects, so I tried multiple types of Objects in a single class with #XMLElement(name = "ResponseBody") but it did not allow me to have same names of XMLElements
What can I do in this scenario?
Thanks in advance.
Most of enterprise applications use JAXB. You could get many tutorials some are below.
http://www.mkyong.com/java/jaxb-hello-world-example/
https://examples.javacodegeeks.com/core-java/xml/bind/jaxb-marshal-example/
https://www.javacodegeeks.com/2014/12/jaxb-tutorial-xml-binding.html
Step 1: First you would require to make xsd file. There are many online sites where xsd can be generated. Use http://xmlgrid.net/xml2xsd.html for now. XSD should look like this.
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="ResponseDto">
<xs:complexType>
<xs:sequence>
<xs:element name="ResponseHeader">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="success"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ResponseBody">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="ObjectA" minOccurs="0"/>
<xs:element type="xs:string" name="ObjectB" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Refer my below post for reference.
read and get xml values in java
I am having some trouble with the way JAXB currently generates java objects from .xsd files. Below I have a code snippet from a .xsd file I am using. The intent of this code is that it will have a list of LogicalDevices which are objects that contain various information.
<xs:element name="LogicalDeviceList">
<xs:annotation>
<xs:documentation>List of all LogicalDevices currently added for the application</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="LogicalDevice" minOccurs="0" maxOccurs="unbounded">
<xs:annotation>
<xs:documentation>An added logical device</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:attribute name="DeviceDefinitionId" use="required">
<xs:annotation>
<xs:documentation>The DeviceDefinitionId of the Logical device</xs:documentation>
.......... Other LogicalDevice Information
Currently the JAXB parser creates an object where the LogicalDeviceList isn't a list of LogicalDevices, and the LogicDevice returns a list of DeviceDefinitionIds.
As the XML I am receiving and unmarshaling cannot change in anyway, is there a way to fix this problem? Is it as simple as changing the .xsd file to read as such
UPDATE: The modification below does not work. 5-24-2013
<xs:element name="LogicalDeviceList" minOccurs="0" maxOccurs="unbounded">
<xs:annotation>
<xs:documentation>List of all LogicalDevices currently added for the application</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="LogicalDevice">
<xs:annotation>
<xs:documentation>An added logical device</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:attribute name="DeviceDefinitionId" use="required">
<xs:annotation>
<xs:documentation>The DeviceDefinitionId of the Logical device</xs:documentation>
If so, why does the C# .xsd parser generate objects and list from the original xsd as intended and JAXB does not.
For the XML schema fragment:
<xs:element name="LogicalDeviceList">
<xs:annotation>
<xs:documentation>List of all LogicalDevices currently added for the application</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="LogicalDevice" minOccurs="0" maxOccurs="unbounded">
<xs:annotation>
<xs:documentation>An added logical device</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:attribute name="DeviceDefinitionId" use="required">
<xs:annotation>
<xs:documentation>The DeviceDefinitionId of the Logical device</xs:documentation>
...
You are going to get a class structure like the following where the LogicalDeviceList class has a collection of LogicalDevice instances.
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "", propOrder = {
"logicalDevice"
})
public static class LogicalDeviceList {
#XmlElement(name = "LogicalDevice")
protected List<LogicalDeviceList.LogicalDevice> logicalDevice;
JAXB may not exactly match what is generated by C#, but it is a perfectly acceptable representation of the XML schema.
I am trying to generate JAXB model from the following xsd
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://abc.com/mmm/trt" attributeFormDefault="unqualified"
elementFormDefault="qualified">
<xs:annotation>
<xs:documentation>Schema for Cache Refresh Event.
</xs:documentation>
</xs:annotation>
<xs:simpleType name="cacheCode">
<xs:restriction base="xs:string">
<xs:enumeration value="BUSINESS_RULE" />
<xs:enumeration value="USER" />
</xs:restriction>
</xs:simpleType>
<xs:element name="cacheRefreshEvent">
<xs:complexType>
<xs:sequence>
<xs:element name="cacheCode" type="cacheCode" minOccurs="1"
maxOccurs="1" />
<xs:element name="entityRefId" type="xs:string" minOccurs="0"
maxOccurs="20" />
<xs:element name="cacheRefreshDate" type="xs:dateTime"
minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
But, it is giving me the following error, which i got in Eclipse console
parsing a schema...
[ERROR] src-resolve.4.1: Error resolving component 'cacheCode'. It was detected that 'cacheCode' has no namespace, but components with no target namespace are not referenceable from schema document 'file:/F:/Sprint6/cache/src/main/resources/CacheRefreshEvent.xsd'. If 'cacheCode' is intended to have a namespace, perhaps a prefix needs to be provided. If it is intended that 'cacheCode' has no namespace, then an 'import' without a "namespace" attribute should be added to 'file:/F:/Sprint6/cache/src/main/resources/CacheRefreshEvent.xsd'.
line 18 of file:/F:/Sprint6/cache/src/main/resources/CacheRefreshEvent.xsd
Failed to parse a schema.
Please help.
Remove this extra namespace attribute targetNamespace="http://www.hcentive.com/mea/trr"
OR add this xmlns="http://www.hcentive.com/mea/trr"
Both solutions will work :)
For you reference targetnamespace-and-xmlns
In front of me there is a problem - a complete schema parse (with include, import, redefine). The problem, is not even parsing scheme, it's to resolve types from this schema.
To explain the problem, here is an example:
schema.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:myprefix="http://myhost.ru/service/" xmlns:anprefix="http://anotherhost.ru/pub-service/" targetNamespace="http://myhost.ru/service/">
<xs:import namespace="http://anotherhost.ru/pub-service/" schemaLocation="anotherhost_schema.xsd"/>
<xs:complexType>
<xs:sequence>
<xs:element name="ServiceCode" type="anprefix:ServiceCodeType">
<xs:annotation>
<xs:documentation>Service code</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="MessageClass" type="myprefix:MessageClassType"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="MessageClassType">
<xs:restriction base="xs:string">
<xs:enumeration value="REQUEST">
<xs:annotation>
<xs:documentation>Request from client
</xs:documentation>
</xs:annotation>
</xs:enumeration>
<xs:enumeration value="RESPONSE">
<xs:annotation>
<xs:documentation>Response to client</xs:documentation>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
</xs:schema>
anotherhost_schema.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:anprefix="http://anotherhost.ru/pub-service/" targetNamespace="http://anotherhost.ru/pub-service/">
<xs:simpleType name="ServiceCodeType">
<restriction base="xs:string">
</restriction>
</xs:simpleType>
</xs:schema>
Example is not very difficult, the real problem is much bigger. My problem is to parse schema and create it's internal representation (that form generator and request handler will use), for example, as follows:
{
"ServiceCode": {"string", String.class, "Service code"},
"MessageClass": {"string", {"REQUEST":"Request from client","RESPONSE":"Response to client"}, ""}
}
Inner representation can be various, but simple for use in Java. Is there such a library? I know, that there is a library, called JAXB, created specially for XML-parsing, but I don't understand how to bind it to my problem.
I have a xsd that contains something like:
<xs:complexType>
<xs:sequence minOccurs="0">
<xs:element ref="HereIsTheProblem"/>
<xs:element ref="blaBla"/>
</xs:sequence>
<xs:attribute name="something" type="xs:string" use="required">
<xs:annotation/>
</xs:attribute>
<xs:attribute name="somethingElse" type="xs:string">
<xs:annotation/>
</xs:attribute>
<xs:attribute name="HereIsTheProblem" type="xs:string">
<xs:annotation/>
</xs:attribute>
</xs:complexType>
now when i try to parse the schema using jaxb to generate java classes it fails:
[ERROR] Element "{http://something.somemorething.com/etc/}HereIsTheProblem" shows up in more than one properties.
how to resolve this without making any modification in the schema?
PS:my jaxb version is 2.1.13
You need to use a binding file indicating jaxB how it should handle this name collision. For example, put something like this in a file named something like bindings.xjb:
<jaxb:bindings version="2.1" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:com.fnf="http://www.fnf.com/xes">
<jaxb:bindings schemaLocation="your schema location here" node="/xs:schema">
<jaxb:bindings node="//XPath selector">
<jaxb:property name="HereIsTheProblem2" />
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
Can't provide you a complete solution without a complete schema
Also we can modify the XSD as below.
<xs:complexType>
<xs:sequence minOccurs="0">
<xs:element ref="HereIsTheProblem"/>
<xs:element ref="blaBla"/>
</xs:sequence>
<xs:attribute name="something" type="xs:string" use="required">
<xs:annotation/>
</xs:attribute>
<xs:attribute name="somethingElse" type="xs:string">
<xs:annotation/>
</xs:attribute>
<xs:attribute name="HereIsTheProblem" type="xs:string">
<xs:annotation>
<xs:appinfo>
<jaxb:property name="HereIsTheProblemAttr"/>
</xs:appinfo>
</xs:annotation>
</xs:attribute>
</xs:complexType>
The main issue is inside the pojo class, if we have the element and the attribute with the same name, it will try to create variables with the same name which is not allowed in simple java principles. So we can define the variable name to be different from one another like above.