Eclipse Java - Jaxb2 plugin and WSDL - java

Hi I have to generate a WSDL. I have this xsd schema
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.ima.eu/xml/cattolica"
targetNamespace="http://www.ima.eu/xml/cattolica" elementFormDefault="qualified">
<xs:element name="CreateRequestInput">
<xs:complexType>
<xs:sequence>
<xs:element name="customer" type="xs:string" minOccurs="1"/>
<xs:element name="user" type="xs:string" minOccurs="1"/>
<xs:element name="company" type="xs:string" minOccurs="1"/>
<xs:element name="insuranceNumber" type="xs:string"/>
<xs:element name="number" type="xs:string"/>
<xs:element name="creationDate" type="xs:string" minOccurs="1"/>
<xs:element name="answer" type="xs:string"/>
<xs:element name="answerType" type="xs:string"/>
<xs:element name="description" type="xs:string" minOccurs="1"/>
<xs:element name="idquintuple" type="xs:string" minOccurs="1"/>
<xs:element name="status" type="xs:string"/>
<xs:element name="priority" type="xs:string"/>
<xs:element name="idOTRS" type="xs:string" minOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="CreateRequestOutput">
<xs:complexType>
<xs:sequence>
<xs:element name="CreateRequest" type="tns:CreateRequest"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="CreateRequest">
<xs:sequence>
<xs:element name="idCRM" type="xs:string"/>
<xs:element name="status" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
Maven plugin Jaxb2 generate java objects correctly.
I did also soap config java file.
but the wsdl generated doesn't have xs:message part so with for example soap ui i cannot make request:
Why method CreateRequest is not generated in wsdl....
Thx

maybe there is a standard for naming the Responses and Requests?

Related

XSD to java beans

I am new to XSDs format. I am trying to convert one xsd to java bean using xjc.But on converting I am getting multiple beans rather than getting just one bean.How to obtain one single bean from the XSD?
Below is my xsd.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="TradeMessage" type="TradeMessageType"/>
<xs:simpleType name="empty-string">
<xs:restriction base="xs:string">
<xs:enumeration value="" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="decimal-or-empty">
<xs:union memberTypes="xs:decimal empty-string" />
</xs:simpleType>
<xs:complexType name="contractingEntityType">
<xs:sequence>
<xs:element type="tradingAccountType" name="tradingAccount"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="executingEntityType">
<xs:sequence>
<xs:element type="tradingAccountType" name="tradingAccount"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="tradeFeesType">
<xs:choice maxOccurs="unbounded" minOccurs="0">
<xs:element type="tradeFees_itemType" name="tradeFees_item"/>
</xs:choice>
</xs:complexType>
<xs:complexType name="settlementCurrencyType">
<xs:sequence>
<xs:element type="xs:string" name="iSOCode"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="tradingAccountType">
<xs:sequence>
<xs:element type="xs:string" name="uniqueID"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="currencyType">
<xs:sequence>
<xs:element type="xs:string" name="iSOCode"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="tradingInstrumentType">
<xs:sequence>
<xs:element type="xs:string" name="CUSIP"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="tradeFees_itemType">
<xs:sequence>
<xs:element type="chargeCodeType" name="chargeCode"/>
<xs:element type="xs:string" name="inConsideration"/>
<xs:element type="currencyType" name="currency"/>
<xs:element type="xs:decimal" name="currencyValue"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="IncomingTradeMessageType">
<xs:sequence>
<xs:element type="IncomingTradeType" name="IncomingTrade"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="TradeMessageType">
<xs:sequence>
<xs:element type="IncomingTradeMessageType" name="IncomingTradeMessage"/>
</xs:sequence>
<xs:attribute type="xs:string" name="schemaVersion"/>
</xs:complexType>
<xs:complexType name="chargeCodeType">
<xs:sequence>
<xs:element type="xs:string" name="name"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="theirTradingAccountType">
<xs:sequence>
<xs:element type="xs:string" name="uniqueID"/>
<xs:element type="xs:string" name="organisationUniqueID"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="tradeCurrencyType">
<xs:sequence>
<xs:element type="xs:string" name="iSOCode"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="transactionTypeType">
<xs:sequence>
<xs:element type="xs:string" name="uniqueID"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="channelType">
<xs:sequence>
<xs:element type="xs:string" name="name"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="IncomingTradeType">
<xs:sequence>
<xs:element type="xs:string" name="blockTradeReference"/>
<xs:element type="xs:string" name="sourceReference"/>
<xs:element type="xs:string" name="sourceVersion"/>
<xs:element type="xs:decimal" name="nominal"/>
<xs:element type="xs:decimal" name="price"/>
<xs:element type="xs:string" name="tradeDate"/>
<xs:element type="xs:string" name="valueDate"/>
<xs:element type="transactionTypeType" name="transactionType"/>
<xs:element type="tradingInstrumentType" name="tradingInstrument"/>
<xs:element type="tradeCurrencyType" name="tradeCurrency"/>
<xs:element type="xs:string" name="cancelled"/>
<xs:element type="xs:string" name="tradeTime"/>
<xs:element type="tradeFeesType" name="tradeFees"/>
<xs:element type="xs:decimal" name="grossConsideration"/>
<xs:element type="xs:decimal" name="netConsideration"/>
<xs:element type="xs:decimal" name="settlementConsideration"/>
<xs:element type="settlementCurrencyType" name="settlementCurrency"/>
<xs:element type="decimal-or-empty" name="settlementExRate"/>
<xs:element type="xs:string" name="settlementExRateDirection"/>
<xs:element type="theirTradingAccountType" name="theirTradingAccount"/>
<xs:element type="executingEntityType" name="executingEntity"/>
<xs:element type="contractingEntityType" name="contractingEntity"/>
<xs:element type="decimal-or-empty" name="calculatedNetPrice"/>
<xs:element type="xs:string" name="dealingCapacity"/>
<xs:element type="xs:string" name="agreedPriceIndicator"/>
<xs:element type="xs:string" name="orderReference"/>
<xs:element type="xs:string" name="lastAmendedOnBusinessDate"/>
<xs:element type="xs:string" name="creationAsatDate"/>
<xs:element type="xs:string" name="bpsBranchAccountNumber"/>
<xs:element type="xs:string" name="bpsAccountType"/>
<xs:element type="xs:string" name="shortSell"/>
<xs:element type="decimal-or-empty" name="facilitationPercentage"/>
<xs:element type="xs:string" name="isStepOut"/>
<xs:element type="xs:string" name="stepOutBrokerMPID"/>
<xs:element type="xs:string" name="bargainConditionFO"/>
<xs:element type="channelType" name="channel"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
This XSD is giving me different beans for different properties but actually I would need just one bean comprising of all the properties. As per my requirement I would receive input message (as per above xsd) and convert it directly to java bean and use this bean for further processing. If there is some other better strategy ,kindly let me know.
This is how JAXB works. A complex schema type is mapped to a Java class, and since this schema has many complex types you get several Java classes. When unmarshalling an XML document, you'll get one TradeMessageType instance.

How to specify a list of complexType in XML?

I have XML specified the following:
<xs:element name="getNewsResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="newsItem" type="tns:newsList"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="newsList">
<xs:list itemType="tns:news"/>
</xs:simpleType>
<xs:complexType name="news">
<xs:sequence>
<xs:element name="id" type="xs:string"/>
<xs:element name="date" type="xs:string"/>
<xs:element name="author" type="tns:author"/>
<xs:element name="title" type="xs:string"/>
<xs:element name="shortDescription" type="xs:string"/>
<xs:element name="content" type="xs:string"/>
</xs:sequence>
</xs:complexType>
I would like to have a list of the news in my response. However when I would like to create Java object with jaxb2 the xml returns the folllowing error when I run mvn clean compile -X:
org.xml.sax.SAXParseException: cos-st-restricts.1.1: The type 'newsList' is atomic, so its {base type definition}, 'tns:news', must be an atomic simple type definition or a built-in primitive datatype.
How I should change my XML to be able to compile?
In addition to using the built-in list types, you can create new list types by derivation from existing atomic types. You cannot create list types from existing list types, nor from complex types.
https://www.w3.org/TR/xmlschema-0/#ListDt
This is from one of my working XSD, a user with multiple addresses:
<xs:complexType name="user">
<xs:sequence>
<xs:element name="addresses" type="tns:addressData" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
Note that addressData is a complexType.
I guess this is what you need:
<xs:element name="getNewsResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="newsItems" type="tns:news" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="news">
<xs:sequence>
<xs:element name="id" type="xs:string"/>
<xs:element name="date" type="xs:string"/>
<xs:element name="author" type="tns:author"/>
<xs:element name="title" type="xs:string"/>
<xs:element name="shortDescription" type="xs:string"/>
<xs:element name="content" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://pro.com/balcao/xdto"
xmlns:tns="http://pro.com/balcao/xdto"
elementFormDefault="qualified">
<xs:element name="salvarCliente" >
<xs:complexType>
<xs:sequence>
<xs:element name="nome" type="xs:string" />
<xs:element name="telefone" type="xs:string" />
<xs:element name="provincia" type="xs:string" />
<xs:element name="municipio" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="listarClientes">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="clientes" type="tns:cliente" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="cliente">
<xs:sequence>
<xs:element name="nome" type="xs:string" />
<xs:element name="telefone" type="xs:string" />
<xs:element name="provincia" type="xs:string" />
<xs:element name="municipio" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>

Java XML Schema Validation elementFormDefault="qualified"

I have a XSD:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified"
elementFormDefault="qualified">
<xs:element name="Structure">
<xs:annotation>
<xs:documentation>Comment describing your root element</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" ref="Tag1"/>
<xs:element maxOccurs="unbounded" minOccurs="0" ref="Tag2"/>
<xs:element minOccurs="0" ref="Properties"/>
<xs:element minOccurs="0" ref="Tag3"/>
</xs:sequence>
<xs:attribute name="url"/>
</xs:complexType>
</xs:element>
<xs:element name="Tag1">
<xs:complexType>
<xs:attribute name="attr"/>
<xs:attribute name="attr2"/>
</xs:complexType>
</xs:element>
<xs:element name="Tag2">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element minOccurs="0" ref="Object"/>
<xs:element maxOccurs="unbounded" minOccurs="0" ref="Tag2"/>
</xs:sequence>
<xs:attribute name="filter"/>
</xs:complexType>
</xs:element>
<xs:element name="Object">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="tag35">
<xs:complexType>
<xs:sequence minOccurs="0">
<xs:element maxOccurs="unbounded" minOccurs="0" ref="Tag3"/>
</xs:sequence>
<xs:attribute name="attr4"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="attr48"/>
</xs:complexType>
</xs:element>
<xs:element name="element52">
<xs:annotation>
<xs:documentation>Text54</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" ref="el58"/>
</xs:sequence>
<xs:attribute name="vector"/>
</xs:complexType>
</xs:element>
<xs:element name="el66" type="el66Type"/>
<xs:element name="el58">
<xs:complexType mixed="true">
<xs:attribute name="ID" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name="Tag3">
<xs:complexType>
<xs:sequence maxOccurs="unbounded" minOccurs="0">
<xs:element minOccurs="0" name="MetaProperty">
<xs:complexType>
<xs:sequence minOccurs="0">
<xs:any/>
</xs:sequence>
<xs:attribute name="name"/>
<xs:attribute name="value"/>
</xs:complexType>
</xs:element>
<xs:element minOccurs="0" ref="Property"/>
</xs:sequence>
<xs:attribute name="ID"/>
<xs:attribute name="language" use="optional"/>
</xs:complexType>
</xs:element>
<xs:element name="Property">
<xs:complexType>
<xs:sequence minOccurs="0">
<xs:any minOccurs="0" processContents="skip"/>
</xs:sequence>
<xs:attribute name="name"/>
<xs:attribute name="type"/>
</xs:complexType>
</xs:element>
<xs:element name="Properties">
<xs:complexType>
<xs:sequence maxOccurs="unbounded" minOccurs="0">
<xs:element minOccurs="0" ref="Property"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType mixed="true" name="el66Type">
<xs:attribute name="ID" type="xs:string"/>
</xs:complexType>
</xs:schema>
And an xml:
<Structure url="/Test/url">
<Tag1/>
<Tag2>
<Object>
<tag35/>
</Object>
</Tag2>
<Properties>
<Property name="bla" type="value1"/>
<Property name="bla2" type="value2"/>
</Properties>
</Structure>
I am doing a validation, and I am getting the following error:
org.xml.sax.SAXParseException; cvc-complex-type.2.4.a: Invalid content was found starting with element 'Tag2'. One of '{Tag1, Tag2, Tag3}' is expected.
I checked in previous questions and always the solution is related with elementFormDefault="qualified" but now it is not the case so, could it be possible that there is a bug there? Any clue, will be grateful.
Your XML is valid against your XSD as posted in your question.
The error message in your question would not be returned. It must have been from different XML or XSD documents.
As Michael Kay states in the comments:
elementFormDefault only affects local elements declarations.
elementFormDefault only comes into play when the XSD has a targetNamespace.
For more details about elementFormDefault see this answer.

Spring - Xsd file with constructor

I have an entity class auto-generated from xsd file;
the problem is that it hasn't any constructor and I must add it manual.
How can I specify a constructor?
Here my xsd file:
entities.xsd
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://capgemini.it/soap/entity/generated"
targetNamespace="http://capgemini.it/soap/entity/generated" elementFormDefault="qualified">
<xs:element name="getEntityRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="getEntityResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="entity" type="tns:entity"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="entity">
<xs:sequence>
<xs:element name="firstName" type="xs:string"/>
<xs:element name="lastName" type="xs:string"/>
<xs:element name="cf" type="xs:string"/>
<xs:element name="role" type="xs:string"/>
<xs:element name="valid" type="xs:boolean"/>
<xs:element name="isIta" type="xs:boolean"/>
<xs:element name="sesso" type="xs:boolean"/>
<xs:element name="nationalNumber" type="xs:string"/>
<xs:element name="crs" type="xs:string"/>
<xs:element name="lvlId" type="xs:int"/>
<xs:element name="qual" type="xs:string"/>
</xs:sequence>
</xs:complexType>
Thanks for any suggestion :)

How to return and array in a soap service?

and i want to return and array of buyers this is my xsd file, there is also the definition of buyer
in the xsd file:
<xs:element name="getBuyerResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="buyer" type="tns:buyer" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="deleteBuyerRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="id" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="deleteBuyerResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="response" type="xs:boolean" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="buyer">
<xs:sequence>
<xs:element name="id" type="xs:int" />
<xs:element name="name" type="xs:string" />
<xs:element name="lastname" type="xs:string" />
</xs:sequence>
</xs:complexType>
i dont know how to write the request and response for all the buyers in the application.
I am using spring boot,
java 7,
maven,
posgress,
Thanks
You can use the maxOccurs attribute. For example, to return any amount of buyer elements in your getBuyerResponse:
<xs:element name="getBuyerResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="buyer" type="tns:buyer" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
Or to return a maximum of 8 buyer elements:
<xs:element name="getBuyerResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="buyer" type="tns:buyer" maxOccurs="8"/>
</xs:sequence>
</xs:complexType>
</xs:element>
Note that maxOccurs defaults to 1 if you do not specify it.

Categories