Resolve collision in class names when converting from WSDL to Java - data-binding

I am converting WSDL to Java with CXF. When -autoNameResolution key is enabled CXF generates many files with the same content. Is there any way to avoid it?
To avoid nested static classes I've enabled <jaxb:globalBindings localScoping="toplevel">. As you can see in the WSDL element "Apple" is referenced three times. Unfortunately I cannot change WSDL. CXF creates
Apple.java, Apple2.java, Apple3.java accordingly or crashes when -autoNameResolution flag is not set.
<xs:element name="Forest">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="99" minOccurs="0" name="Apple">
<xs:complexType>
<xs:sequence>
<xs:element name="Size" type="xsd:string" />
<xs:element name="Color" type="xsd:string" />
<xs:element name="Taste" type="xsd:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element minOccurs="0" name="TreeOne">
<xs:complexType>
<xs:sequence>
<xs:element name="Branch1" type="xsd:string">
</xs:element>
<xs:element maxOccurs="99" minOccurs="0" name="Apple">
<xs:complexType>
<xs:sequence>
<xs:element name="Size" type="xsd:string" />
<xs:element name="Color" type="xsd:string" />
<xs:element name="Taste" type="xsd:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element minOccurs="0" name="TreeTwo">
<xs:complexType>
<xs:sequence>
<xs:element name="BranchTwo" type="xsd:string">
</xs:element>
<xs:element maxOccurs="99" minOccurs="0" name="Apple">
<xs:complexType>
<xs:sequence>
<xs:element name="Size" type="xsd:string" />
<xs:element name="Color" type="xsd:string" />
<xs:element name="Taste" type="xsd:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
Is there any way to teach wsdl2java not to create Apple2.java and Apple3.java and refer to Apple.java in all three cases? With bindings I could change the name to something else like Apple2->Peach, Apple3->Watermelon but this is not that What I am looking for. It might be obvious to see that all three apples have same set of fields, and are actually the same?
Is there any way to solve that? May be some refactoring plugin that refactors code generated by cxf?

You can force JAXB/XJC to reuse existing classes using the jaxb:class/#ref customization. Something along the lines:
<jaxb:class ref="com.acme.foo.Apple"/>
Where com.acme.foo.Apple is the FQCN of one of the generated Apple classes.
Bind this to the other two xs:complexTypes and JAXB will reuse the existing class instead of generating the same thing again.
I don't have much experience with customizing WSDLs so unfortunatelly I can't point you to the exact syntax of the binding in this case.

Related

Breaking out of loop in DFDL

I am trying to convert a FLAT file to XML using DFDL. It has following format:
Each element is 5 byte.All are in same line but i am separating them to avoid confusion. I will address element by first letter in them.
0AAAA
81AAA
eeeee
qqqqq
82BBB
rrrrr
sssss
9QQQQ
Now 0 and 9 are grandparents we don't have to worry about them. 8 is parent and second byte of 81AAA(that is 1) will determine the format of its children. There can be many 8 and many children of a 8 parent(but all of them will have same format).
I tried one schema but once it go into children(eeeee) its not coming out of it and every record is being printed in children format only.
Below is a schema that I think describes your data, tested on Daffodil 2.2.0:
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/">
<xs:include schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd" />
<xs:annotation>
<xs:appinfo source="http://www.ogf.org/dfdl/">
<dfdl:format ref="GeneralFormat" />
</xs:appinfo>
</xs:annotation>
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element name="GrandParent" maxOccurs="unbounded">
<xs:complexType>
<xs:choice dfdl:initiatedContent="yes">
<xs:element name="Zero" dfdl:initiator="0">
<xs:complexType>
<xs:sequence>
<xs:element name="Value" type="xs:string" dfdl:length="4" dfdl:lengthKind="explicit" />
<xs:element ref="Eight" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Nine" dfdl:initiator="9">
<xs:complexType>
<xs:sequence>
<xs:element name="Value" type="xs:string" dfdl:length="4" dfdl:lengthKind="explicit" />
<xs:element ref="Eight" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Eight" dfdl:initiator="8">
<xs:complexType>
<xs:sequence>
<xs:element name="ChildrenFormat" type="xs:string" dfdl:length="1" dfdl:lengthKind="explicit" />
<xs:element name="Value" type="xs:string" dfdl:length="3" dfdl:lengthKind="explicit" />
<xs:choice dfdl:choiceDispatchKey="{ ./ChildrenFormat }">
<xs:element ref="One" maxOccurs="unbounded" dfdl:choiceBranchKey="1" />
<xs:element ref="Two" maxOccurs="unbounded" dfdl:choiceBranchKey="2" />
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="One" type="xs:string" dfdl:length="5" dfdl:lengthKind="explicit">
<xs:annotation>
<xs:appinfo source="http://www.ogf.org/dfdl/">
<dfdl:discriminator test="{ fn:not(fn:starts-with(., '8') or fn:starts-with(., '9')) }" />
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="Two" type="xs:string" dfdl:length="5" dfdl:lengthKind="explicit">
<xs:annotation>
<xs:appinfo source="http://www.ogf.org/dfdl/">
<dfdl:discriminator test="{ fn:not(fn:starts-with(., '8') or fn:starts-with(., '9')) }" />
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:schema>
A description of how this works:
The Root of the data is an unbounded number of GrandParent elements
Each GrandParent element contains either a Zero or a Nine, based on the initiator. The initiator consumes the first of the 5 bytes of the grandparent data
The Zero/Nine elements contain a Value which consumes the remaining 4 bytes of the gradparent data
Following the Value is zero or more Eight elements
Each Eight element has an initiator of "8", consuming the first of 5 bytes
Each Eight element has a ChildrenFormat, consuming the second of 5 bytes
Each Eight element has a Value, consuming the last 3 of 5 bytes
Each Eight element has an unbounded number of either all One or all Two elements
A choiceDispatchKey/Branch is used to determine whether to parse all One or all Two elements, dispatching off of the ChildrenFormat element
Each One or Two element consumes 5 bytes
In order to determine when the unbounded number of One or Two elements ends, a discriminator is placed on the One/Two elements. This discriminator fails when the data parsed as a One/Two does not start with an '8' or a '9'.
Also, all fields are treated as strings for simplicity
With this, your example data parses to an infoset like so:
<Root>
<GrandParent>
<Zero>
<Value>AAAA</Value>
<Eight>
<ChildrenFormat>1</ChildrenFormat>
<Value>AAA</Value>
<One>eeeee</One>
<One>qqqqq</One>
</Eight>
<Eight>
<ChildrenFormat>2</ChildrenFormat>
<Value>BBB</Value>
<Two>rrrrr</Two>
<Two>sssss</Two>
</Eight>
</Zero>
</GrandParent>
<GrandParent>
<Nine>
<Value>QQQQ</Value>
</Nine>
</GrandParent>
</Root>

How do I access a distinguished field in a BizTalk multipart message

I have a multipart message with this schema (edited for brevity):
<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://MyCompany/Schemas/Canonical/Property/1.0" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://MyCompany/Schemas/Canonical/Property/1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Property">
<xs:annotation>
<xs:appinfo>
<b:properties>
<b:property distinguished="true" xpath="/*[local-name()='Property' and namespace-uri()='http://MyCompany/Schemas/Canonical/Property/1.0']/*[local-name()='UPRN' and namespace-uri()='']" />
</b:properties>
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="Addresses">
<xs:complexType />
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="UPRN" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Given that the message name in an Orchestration is MyMessage, how would I access the value of the distinguished field 'UPRN' in a BizTalk Expression Editor.
When I try dot notation all I get from IntilliSense is MyMessage.Property
It's supposed to be:
MessageName.PartName.RootNode.ElememtName[...].FieldName

Oozie global configurations

Based on oozie doc I understand that I can use the global element to avoid repeating, let's say, the job-tracker specification, for every action. Although, given the following simple workflow:
<workflow-app name="Test Hello World" xmlns="uri:oozie:workflow:0.4">
<global>
<job-tracker>${jobTracker}</job-tracker>
<name-node>${nameNode}</name-node>
</global>
<start to="import"/>
<action name="import">
<shell xmlns="uri:oozie:shell-action:0.1">
<exec>hw.sh</exec>
<file>hw.sh#hw.sh</file>
</shell>
<ok to="end"/>
<error to="kill"/>
</action>
<kill name="kill">
<message>Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
</kill>
<end name="end"/>
</workflow-app>
when running oozie validate on it I get:
Error: Invalid app definition, org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 19; cvc-complex-type.2.4.a: Invalid content was found starting with element 'exec'. One of '{"uri:oozie:shell-action:0.1":job-tracker}' is expected.
So basically, it still expects a job-tracker element in the action.
If you have any idea on this behavior, your answers will be much appreciated.
Thank you.
Here is the schema of oozie shell action version 0.1. You will notice that job-tracker and name-node tags require the minimum occurrence of 1 time. Same applies for the exec tag as well.
Source: Shell XML-Schema
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:shell="uri:oozie:shell-action:0.1" elementFormDefault="qualified"
targetNamespace="uri:oozie:shell-action:0.1">
<xs:element name="shell" type="shell:ACTION"/>
<xs:complexType name="ACTION">
<xs:sequence>
<xs:element name="job-tracker" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="name-node" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="prepare" type="shell:PREPARE" minOccurs="0" maxOccurs="1"/>
<xs:element name="job-xml" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="configuration" type="shell:CONFIGURATION" minOccurs="0" maxOccurs="1"/>
<xs:element name="exec" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="argument" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="env-var" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="file" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="archive" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="capture-output" type="shell:FLAG" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="FLAG"/>
<xs:complexType name="CONFIGURATION">
<xs:sequence>
<xs:element name="property" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="name" minOccurs="1" maxOccurs="1" type="xs:string"/>
<xs:element name="value" minOccurs="1" maxOccurs="1" type="xs:string"/>
<xs:element name="description" minOccurs="0" maxOccurs="1" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="PREPARE">
<xs:sequence>
<xs:element name="delete" type="shell:DELETE" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="mkdir" type="shell:MKDIR" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="DELETE">
<xs:attribute name="path" type="xs:string" use="required"/>
</xs:complexType>
<xs:complexType name="MKDIR">
<xs:attribute name="path" type="xs:string" use="required"/>
</xs:complexType>
</xs:schema>

Issue consuming Webservice that has restricted complex type through .net

Issue description :
We are trying to consume a service that is exposed by TIBCO in SOAP format, we are facing issues during transforming a restricted complex type object it into .net object. We are able to receive the SOAP packet, but its failing to deserialize it into the valid c# object. However the object was instantiated but without any value (values were null). The response status is success, but the translation of the object is failing. Below is the WSDL snippet for the reference. Apart from building a custom deserialzer is there any other better approach for this problem :
<xs:complexType name="GetIndividualByCIMIdResponseType">
<xs:annotation>
<xs:documentation xml:lang="en">
This response
</xs:documentation>
</xs:annotation>
<xs:complexContent>
<xs:extension base="cst:SimpleResponse">
<xs:sequence>
<xs:element name="Individual" type="ns0:IndividualRestrictedType" minOccurs="0"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="IndividualRestrictedType">
<xs:complexContent>
<xs:restriction base="ns0:IndividualType">
<xs:sequence>
<xs:element name="DoNotMerge" type="ns0:DoNotMergeType" minOccurs="0"/>
<xs:element name="PartyIdentifier" type="ns0:CIMIdentifierType" minOccurs="0"/>
<xs:element name="EmailAccountList" type="ns0:EmailAccountListType" minOccurs="0"/>
<xs:element name="TelephoneServiceList" type="ns0:TelephoneServiceListType" minOccurs="0"/>
<xs:element name="AddressList" type="ns0:AddressListType" minOccurs="0"/>
<xs:element name="DateOfBirth" type="ns0:DateOfBirthType" minOccurs="0"/>
<xs:element name="FamilyName" type="ns0:FamiltyNameType" minOccurs="0"/>
<xs:element name="FirstName" type="ns0:FirstNameType" minOccurs="0"/>
<xs:element name="Initials" type="ns0:InitialsType" minOccurs="0"/>
<xs:element name="MiddleNames" type="ns0:MiddleNamesType" minOccurs="0"/>
<xs:element name="PreferredName" type="ns0:PreferredNameType" minOccurs="0"/>
<xs:el`enter code here`ement name="Sex" type="ns0:SexType" minOccurs="0"/>
<xs:element name="Title" type="ns0:TitleType" minOccurs="0"/>
<xs:element name="YearOfBirth" type="ns0:YearOfBirthType" minOccurs="0"/>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>

ASP.net parsing Diffgrams in XML to use in DataList

I have a method:
public static DataSet getTable()
{
DataSet DS = new DataSet("My Set");
DS.ReadXml(getCategories());
return DS;
}
My getCategories() returns a stream containing my XML.
But when I run this, I get this error:
The supplied xml instance is a schema or contains an inline schema. This class cannot infer a schema for a schema.
So I'm not sure what to do.
My goal is to use the call to getTable() to populate a DataList.
I've tried using the DataTable and I get a different, but similar error.
Any help would be great.
Thanks.
Here is my XML file. Might help. Thanks.
<?xml version="1.0" encoding="utf-8"?>
<WSPackage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<ResponseInteger>0</ResponseInteger>
<ResponseBoolean>false</ResponseBoolean>
<ResponseDataset>
<xs:schema id="CategoryDS" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="CategoryDS" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Category">
<xs:complexType>
<xs:sequence>
<xs:element name="PartCategories" type="xs:string" minOccurs="0" />
<xs:element name="CategoryDescriptions" type="xs:string" minOccurs="0" />
<xs:element name="CategoryImageURLs" type="xs:string" minOccurs="0" />
<xs:element name="CategoryModelFlags" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<CategoryDS xmlns="">
<Category diffgr:id="Category1" msdata:rowOrder="0" diffgr:hasChanges="inserted">
<PartCategories>TESTCAT</PartCategories>
<CategoryDescriptions>TESTING API</CategoryDescriptions>
<CategoryImageURLs />
<CategoryModelFlags />
</Category>
</CategoryDS>
</diffgr:diffgram>
</ResponseDataset>
<ErrorMessage />
<UserMessage />
</WSPackage>
It is related to the fact that you have the following xml in there.. If you take that out it should work. it is not going to create a schema for something that already exists.
<xs:element name="Category">
<xs:complexType>
<xs:sequence>
<xs:element name="PartCategories" type="xs:string" minOccurs="0" />
<xs:element name="CategoryDescriptions" type="xs:string" minOccurs="0" />
<xs:element name="CategoryImageURLs" type="xs:string" minOccurs="0" />
<xs:element name="CategoryModelFlags" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
t

Resources