XJC -jaxb2-maven-plugin-Generated Getter Setter methods does not follow Java conventions - xjc

I am working on jaxb2-maven-plugin, I am generating Java POJOs from XSD.
I have an XSD like this
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="employee">
<xs:complexType>
<xs:sequence>
<xs:element name="projects">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="project">
<xs:complexType>
<xs:sequence>
<xs:element name="product" type="xs:string" />
<xs:element name="id" type="xs:unsignedByte" />
<xs:element name="**PRIce**" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
When I generate the POJOs using the above it generated the getters/setters for field PRIce like this.
public class Project {
#XmlElement(name = "PRIce", required = true)
protected String prIce;
public String getPRIce() {
return prIce;
}
public void setPRIce(String value) {
this.prIce = value;
}
}
But we need the output like this.
public class Project {
#XmlElement(name = "PRIce", required = true)
protected String prIce;
public String getPrIce() {
return prIce;
}
public void setPrIce(String value) {
this.prIce = value;
}
}

Related

XJC - Add Lombok Annotation on top of every Generated XSD class and remove Setters Getters

I am working on jaxb2-maven-plugin, I am generating Java POJOs from XSD.
I need to add #Data annotation on top of the class without setters getters.
The output file should look like this.
#Data
public class Employee {
#JsonProperty("name")
private Name name;
#JsonProperty("joindate")
private String joindate;
#JsonProperty("payload")
private String payload;
}
My XSD is like this
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="employee">
<xs:complexType>
<xs:sequence>
<xs:element name="name">
<xs:complexType>
<xs:sequence>
<xs:element name="lastname" type="xs:string" />
<xs:element name="firstname" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="hiredate" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
I need to add annotation on Name.java as well. I have around 100 XSDs. I need to do this for all XSDs

What is the meaning of '/' in following TIBCO expression

I have following code in Tibco business works module
$ES_GetInfo/root/pfx4:GetInformationAndPropertyDetailsResponse/pfx4:LicenseInfo/pfx4:CoreEnt/pfx4:Ent
[pfx4:Ent/pfx4:EntOfferingCode = $Read_DB_Data/group/ROW/EOC]
/pfx4:EntState = "Disabled"
I can understand it is comparing "EntOfferingCode" with "EOC", but could not get the expression "/pfx4:EntState = 'Disabled'"?
As per the TIBCO, the whole expression returns a boolean value.
What is the meaning of "/pfx4:entState='Disabled'". Is logical or conditional or something else?
The whole expression is logical condition. The '/' is just xml schema elements separator in XPath (XML Path Language) syntax. You can start learning tibco xpath from here https://docs.tibco.com/pub/activematrix_businessworks/6.3.0/doc/html/GUID-D319018B-AA74-428D-A034-E477778AD2B6.html
The expression first filtering all the "Ent" nodes that have EntOfferingCode = $Read_DB_Data/group/ROW/EOC
then check if exists EntState = "Disabled" in filtered result
the expression can be replaced by
not (empty($Start/pfx:GetInformationAndPropertyDetailsResponse/pfx:LicenseInfo/pfx:CoreEnt/pfx:Ent[ pfx:EntOfferingCode= "EOC" and pfx:EntState = "Disabled"]))
For example
if the schema is like
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.tibco.com/schemas/TestProcess/Schema/Schema.xsd"
targetNamespace="http://www.tibco.com/schemas/TestProcess/Schema/Schema.xsd"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:element name="GetInformationAndPropertyDetailsResponse">
<xs:complexType>
<xs:sequence>
<xs:element ref="LicenseInfo" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="LicenseInfo">
<xs:complexType>
<xs:sequence>
<xs:element ref="CoreEnt" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="CoreEnt">
<xs:complexType>
<xs:sequence>
<xs:element ref="Ent" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Ent">
<xs:complexType>
<xs:sequence>
<xs:element name="EntOfferingCode" type="xs:string"/>
<xs:element name="EntState" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Expression return true for:
<?xml version = "1.0" encoding = "UTF-8"?>
<GetInformationAndPropertyDetailsResponse xmlns = "http://www.tibco.com/schemas/TestProcess/Schema/Schema.xsd">
<LicenseInfo>
<CoreEnt>
<Ent>
<EntOfferingCode>EOC</EntOfferingCode>
<EntState>Disabled</EntState>
</Ent>
</CoreEnt>
</LicenseInfo>
</GetInformationAndPropertyDetailsResponse>
Expression return false for:
<?xml version = "1.0" encoding = "UTF-8"?>
<GetInformationAndPropertyDetailsResponse xmlns = "http://www.tibco.com/schemas/TestProcess/Schema/Schema.xsd">
<LicenseInfo>
<CoreEnt>
<Ent>
<EntOfferingCode>EOC</EntOfferingCode>
<EntState>Enabled</EntState>
</Ent>
<Ent>
<EntOfferingCode>EOC1</EntOfferingCode>
<EntState>Disabled</EntState>
</Ent>
</CoreEnt>
</LicenseInfo>
</GetInformationAndPropertyDetailsResponse>
if you just use
$ES_GetInfo/root/pfx4:GetInformationAndPropertyDetailsResponse/pfx4:LicenseInfo/pfx4:CoreEnt/pfx4:Ent/pfx4:EntState = "Disabled"
it will return true for both examples
If your question is what does the xslt expression mean, it is basically checking the following:
For all LicenseInfo/CoreEnt/Ent,
where Ent/EntOfferingCode = EOC value from the DB
check if the corresponding Enstate is Disabled or not
if Disabled, output true, else output false.

Spring WS is not generating wsdl operations for all the public methods in the Endpoint class

I have a Spring endpoint class with two public methods. But when Spring is auto-generating the wsdl it doesn't include the second public method. Could you pleas let me know what is wrong and what needs to be done. I am using Spring 4.3 and below are the classes.
Configuration class
#EnableWs
#Configuration
public class SoapServiceConfig extends WsConfigurerAdapter {
#Bean
public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean(servlet, "/ws/*");
}
#Bean(name = "policies")
public DefaultWsdl11Definition policyserviceWsdl11Definition(#Autowired #Qualifier("swissSchema") XsdSchema swissSchema) {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setPortTypeName("PoliciesPort");
wsdl11Definition.setLocationUri("/ws");
wsdl11Definition.setTargetNamespace("http://www.testcomp.com/iaworkflow/soapservice");
wsdl11Definition.setSchema(swissSchema);
return wsdl11Definition;
}
#Bean(name = "bankservice")
public DefaultWsdl11Definition bankServiceWsdlDefinition(#Autowired #Qualifier("bankSchema")XsdSchema bankSchema) {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setPortTypeName("BankAPIPort");
wsdl11Definition.setLocationUri("/ws/bankapi");
wsdl11Definition.setTargetNamespace("http://www.testcomp.com/consumer/bankservice/soapservice");
wsdl11Definition.setSchema(bankSchema);
return wsdl11Definition;
}
#Bean
#Qualifier("bankSchema")
public XsdSchema bankSchema() {
return new SimpleXsdSchema(new ClassPathResource("bankservice.xsd"));
}
#Bean
#Qualifier("swissSchema")
public XsdSchema swissSchema() {
return new SimpleXsdSchema(new ClassPathResource("policylookup.xsd"));
}
}
Endpoint
#Endpoint
public class BankingServiceEndpoint {
private static final String NAMESPACE_URI = "http://www.testcomp.com/consumer/bankservice/soapservice";
#PayloadRoot(namespace = NAMESPACE_URI, localPart = "BankInfoSearchRequest")
#ResponsePayload
public BankInfoSearchResponse getBankInfo(#RequestPayload BankInfoSearchRequest request) {
BankInfoSearchResponse response = createDummyResponse(request.getPolicyNumber(),request.getLimit());
return response;
}
#PayloadRoot(namespace = NAMESPACE_URI, localPart = "BankVerificationRequest")
#ResponsePayload
public BankVerificationResponse verifyBankInformation(#RequestPayload BankVerificationRequest request) {
return BankVerificationResponse.builder().build();
}
}
Generated WSDL
<?xml version="1.0" encoding="UTF-8" standalone="no"?><wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:sch="http://www.testcomp.com/consumer/bankservice/soapservice" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.testcomp.com/consumer/bankservice/soapservice" targetNamespace="http://www.testcomp.com/consumer/bankservice/soapservice">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://www.testcomp.com/consumer/bankservice/soapservice" version="1.0">
<xs:element name="BankInfoSearchRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="policyNumber" type="xs:string"/>
<xs:element name="limit" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="BankInfoSearchResponse">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="1" name="policyNumber" nillable="false" type="xs:string"/>
<xs:element name="bankdatas" type="tns:BankDatas"/>
<xs:element maxOccurs="1" name="error" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="BankDatas">
<xs:sequence>
<xs:element maxOccurs="unbounded" name="bankinfo" type="tns:BankInfo"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="BankInfo">
<xs:sequence>
<xs:element name="AccountNumber" type="xs:string"/>
<xs:element name="RoutingNumber" type="xs:string"/>
<xs:element name="BankName" type="xs:string"/>
<xs:element name="VerificationDescription" type="xs:string"/>
<xs:element name="VerificationCode" type="xs:string"/>
<xs:element name="Verified" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="BankVerificationRequest">
<xs:sequence>
<xs:element maxOccurs="1" name="PolicyOwnerInformation" type="tns:PolicyOwnerInformation"/>
<xs:element maxOccurs="1" name="BankInfo" type="tns:BankInfo"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="PolicyOwnerInformation">
<xs:sequence>
<xs:element name="FirstName" type="xs:string"/>
<xs:element name="MiddleName" type="xs:string"/>
<xs:element name="LastName" type="xs:string"/>
<xs:element name="SSN" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="BankVerificationResponse">
<xs:sequence>
<xs:element maxOccurs="1" name="PolicyOwnerInformation" type="tns:PolicyOwnerInformation"/>
<xs:element maxOccurs="1" name="Bankinfo" type="tns:BankInfo"/>
<xs:element name="BankVerificationTransactionId" type="xs:string"/>
<xs:element name="ItemReferenceId" type="xs:string"/>
<xs:element name="SubmittedBy" type="xs:string"/>
<xs:element name="VerificationResponse" type="xs:string"/>
<xs:element name="VerificationStatus" type="xs:string"/>
<xs:element name="BankVerificationTransactionType" type="xs:string"/>
<xs:element name="Created" type="xs:string"/>
<xs:element name="Success" type="xs:string"/>
<xs:element name="Error" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="BankInfoSearchResponse">
<wsdl:part element="tns:BankInfoSearchResponse" name="BankInfoSearchResponse">
</wsdl:part>
</wsdl:message>
<wsdl:message name="BankInfoSearchRequest">
<wsdl:part element="tns:BankInfoSearchRequest" name="BankInfoSearchRequest">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="BankAPIPort">
<wsdl:operation name="BankInfoSearch">
<wsdl:input message="tns:BankInfoSearchRequest" name="BankInfoSearchRequest">
</wsdl:input>
<wsdl:output message="tns:BankInfoSearchResponse" name="BankInfoSearchResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BankAPIPortSoap11" type="tns:BankAPIPort">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="BankInfoSearch">
<soap:operation soapAction=""/>
<wsdl:input name="BankInfoSearchRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="BankInfoSearchResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="BankAPIPortService">
<wsdl:port binding="tns:BankAPIPortSoap11" name="BankAPIPortSoap11">
<soap:address location="http://localhost:9080/workflowintg/ws/bankapi"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
I figured out the issue. There was a problem in the XSD. I declared the root element as xs:complexType instead of xs:element.

MappingJackson2XmlHttpMessageConverter creates extra/duplicate xml elements during marshalling

i am using xjc to create jaxb binding classes from an xsd... and using MappingJackson2XmlHttpMessageConverter to convert the objects to xml.. but what i am seeing is, when i have a list in the binding file, the converter creates a duplicate xml element..
XSD:
<xs:complexType name="orderSubmitType">
<xs:all>
<xs:element name="orderId" type="xs:string" />
<xs:element name="giftCards" type="giftCards"/>
</xs:all>
</xs:complexType>
<xs:complexType name="giftCards">
<xs:sequence>
<xs:element name="giftCard" type="giftCard" minOccurs="0" maxOccurs="10"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="giftCard">
<xs:all>
<xs:element name="cardNumber" type="xs:string" />
<xs:element name="pinNumber" type="xs:string" />
</xs:all>
</xs:complexType>
JAVA:
public class TestRestTemplateConfiguration {
public static RestTemplate getTestClientRestTemplate() {
if (INSTANCE == null) {
RestTemplate restTemplate = new RestTemplate();
restTemplate.setErrorHandler(new TestClientResponseErrorHandler());
ClientHttpRequestInterceptor loggingInterceptor = new TestClientLoggingInterceptor();
restTemplate.setInterceptors(Collections.singletonList(loggingInterceptor));
restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory()));
MappingJackson2HttpMessageConverter jacksonConverter = new MappingJackson2HttpMessageConverter();
MappingJackson2XmlHttpMessageConverter jacksonXmlConverter = new MappingJackson2XmlHttpMessageConverter();
restTemplate.setMessageConverters(Arrays.asList(jacksonConverter,jacksonXmlConverter));
INSTANCE = restTemplate;
}
return INSTANCE;
}
}
final xml that is created is ..
<?xml version="1.0" encoding="UTF-8"?>
<OrderSubmitType>
<orderId>111111</orderId>
<giftCards>
<giftCard>
<giftCard>
<cardNumber>123456790</cardNumber>
<pinNumber>1111</pinNumber>
</giftCard>
</giftCard>
</giftCards>
</OrderSubmitType>
as you can see... there is a extra
<giftcard></giftcard> elements...
can anyone tell me what is the mistake that i am doing...
thanks...

Parse Exception

I have the same element id in two different complex types of an xml, I am getting the below exception if i try to parse using maven Jaxb plugin ,Is there a way to parse without renaming using the elements with the help of bindings , As i have the attribute id atleast 30 times in the schema.Thanks in advance
com.sun.istack.SAXParseException2: Property "Id" is already defined. Use <jaxb:property> to resolve this conflict.
<xs:element name="aliases" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="alias" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element ref="tran" minOccurs="0"/>
<xs:element name="id">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="old_value" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="end" type="xs:string"/>
<xs:attribute name="start" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="tin_affiliation">
<xs:complexType>
<xs:sequence>
<xs:element ref="tran" minOccurs="0"/>
<xs:element name="id">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="old_value" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="end" type="xs:string"/>
<xs:attribute name="start" type="xs:string"/>
</xs:complexType>
</xs:element>
An alternative solution to using a binding file is to declare the ID Type separately. Since it looks identical in both elements, and since the conflict in this case is due to a duplicate type declaration.
The Schema would then look like the following.
Note: It's tested and working, but had to comment <xs:element ref="tran" minOccurs="0"/> since I don't have the definition.
Schema
<xs:element name="aliases">
<xs:complexType>
<xs:sequence>
<xs:element name="alias" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<!--<xs:element ref="tran" minOccurs="0"/> -->
<xs:element name="id" type="idType" />
</xs:sequence>
<xs:attribute name="end" type="xs:string"/>
<xs:attribute name="start" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="tin_affiliation">
<xs:complexType>
<xs:sequence>
<!-- <xs:element ref="tran" minOccurs="0"/> -->
<xs:element name="id" type="idType" />
</xs:sequence>
<xs:attribute name="end" type="xs:string"/>
<xs:attribute name="start" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:complexType name="idType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="old_value" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Generated Java Class: IdType
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "idType", propOrder = {
"value"
})
public class IdType {
#XmlValue
protected String value;
#XmlAttribute(name = "old_value")
protected String oldValue;
/**
* Gets the value of the value property.
*
* #return
* possible object is
* {#link String }
*
*/
public String getValue() {
return value;
}
/**
* Sets the value of the value property.
*
* #param value
* allowed object is
* {#link String }
*
*/
public void setValue(String value) {
this.value = value;
}
/**
* Gets the value of the oldValue property.
*
* #return
* possible object is
* {#link String }
*
*/
public String getOldValue() {
return oldValue;
}
/**
* Sets the value of the oldValue property.
*
* #param value
* allowed object is
* {#link String }
*
*/
public void setOldValue(String value) {
this.oldValue = value;
}
}
Generated Java Class: TinAffiliation
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "", propOrder = {
"id"
})
#XmlRootElement(name = "tin_affiliation")
public class TinAffiliation {
#XmlElement(required = true)
protected IdType id;
#XmlAttribute(name = "end")
protected String end;
#XmlAttribute(name = "start")
protected String start;
/**
* Gets the value of the id property.
*
* #return
* possible object is
* {#link IdType }
*
*/
public IdType getId() {
return id;
}
/**
* Sets the value of the id property.
*
* #param value
* allowed object is
* {#link IdType }
*
*/
public void setId(IdType value) {
this.id = value;
}
/**
* Gets the value of the end property.
*
* #return
* possible object is
* {#link String }
*
*/
public String getEnd() {
return end;
}
/**
* Sets the value of the end property.
*
* #param value
* allowed object is
* {#link String }
*
*/
public void setEnd(String value) {
this.end = value;
}
/**
* Gets the value of the start property.
*
* #return
* possible object is
* {#link String }
*
*/
public String getStart() {
return start;
}
/**
* Sets the value of the start property.
*
* #param value
* allowed object is
* {#link String }
*
*/
public void setStart(String value) {
this.start = value;
}
}
There can be multiple XML attibutes/elements with same name in your XML element without any issues. The exception you are seeing is when this would result in a generated class having two properties with the same name. This can occur in the following situations.
A complex type contains an attribute and element with the same name.
A complex type contains an attribute/element with the same name as an attribute/element as a complex type that it extends.
I Could able to achieve this using the plugins org.codehaus.mojo: jaxb2-maven-plugin: 2.3 and org.jvnet.jaxb2_commons:jaxb2-basics-annotate:0.6.4 and with the below binding configuration notably multiple="true
<jxb:bindings node=".//xs:attribute[#name='abc]"
multiple="true">
<jxb:property name="abc_attribute" />
</jxb:bindings>
</jxb:bindings>

Resources