webservices arguments instead of parameters - java

I'm doing Java-first development on a service and the WSDL file being generated (I'm using Tomcat v6.0 as my container with the CXF Servlet) is using arg0, arg1 etc. as the parameter names for my service methods rather than using the actual parameter name specified in my Java code. Is this a known shortcoming or am I doing something wrong? The WSDL isn't very self-documenting with parameter names like this!
Here's an example wsdl snippet:
<xs:complexType name="insertVendor">
<xs:sequence>
<xs:element minOccurs="0" name="arg0" type="xs:string"/>
<xs:element minOccurs="0" name="arg1" type="xs:string"/>
<xs:element minOccurs="0" name="arg2" type="xs:string"/>
<xs:element minOccurs="0" name="arg3" type="xs:string"/>
<xs:element minOccurs="0" name="arg4" type="xs:string"/>
<xs:element minOccurs="0" name="arg5" type="xs:string"/>
<xs:element minOccurs="0" name="arg6" type="xs:string"/>
<xs:element minOccurs="0" name="arg7" type="xs:string"/>
<xs:element minOccurs="0" name="arg8" type="xs:string"/>
<xs:element minOccurs="0" name="arg9" type="xs:string"/>
<xs:element minOccurs="0" name="arg10" type="xs:string"/>
<xs:element minOccurs="0" name="arg11" type="xs:string"/>
</xs:sequence>
Thanks,
mallesh

You can create request class and pass it in service method
Class Requestclass(){
// all the arguments you want, create POJO class
}
pass this class in your method,
insertVendor(RequestClass req){}

Here is the answer
Official answer: The JAX-WS spec (specifically section 3.6.1) mandates that it be generated this way. To customize the name, you have to use an #WebParam(name = "blah") annotation to specify better names. (You can use #WebResult for the return value, but you'll only see the results if you look at the XML.)

Related

Java class to XSD

Could someone please tell me what XSD matches this Java class?
public class MyClass {
private List<String> list1;
private List<String> list2;
private XMLGregorianCalendar date;
// getters and setters
}
I've tried the following, but I'm receiving an One of :attribute, :attributeGroup, :anyAttribute is expected error:
<xs:element name="myClass">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="list1" type="xs:string"/>
</xs:sequence>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="list2" type="xs:string"/>
</xs:sequence>
<xs:element name="date" nillable="true" type="xs:dateTime"/>
</xs:complexType>
</xs:element>
So it seems I'm not using the <xs:sequence> tag correctly. Could someone please shed some light? (I'm far from being an expert in XML-related stuff)...
I'm using Spring Boot 1.4.4.RELEASE version with Java 7.
The xs:sequence within a xs:complexType defines a specific order in which an elements children must occur. To create a list of elements you simply use the minOccurs and maxOccurs directly on the xs:element tag you want repeated, as follows:
<xs:element name="myClass">
<xs:complexType>
<xs:sequence>
<xs:element name="list1" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="list2" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="date" nillable="true" type="xs:dateTime"/>
</xs:sequence>
</xs:complexType>
</xs:element>
This should create the class you expect and require XML such as the following (order of tags matter):
<myClass>
<list1>a</list1>
<list1>b</list1>
<list2>y</list2>
<list2>z</list2>
<date>2019-06-26T00:00:00.0000000Z</date>
</myClass>
Placing minOccurs and maxOccurs on the xs:sequence tag requires the entire sequence of elements to be repeated.

WSImport bindings for two WSDLs with the same namespace

I am writing a client that leverages two separate WSDLs from a third party. These two WSDLs have the exact same namespaces. So, I created binding files to put the objects generated from the two WSDLs into separate packages to avoid conflicts. However, there are a few common elements between these two WSDLs that share the exact same definition. Having these objects be generated into separate packages is not desirable since I'd like to share them. I have been unable to find any way to do this using binding files. The closest I got was to pull those shared elements out of the WSDLs and put them in a new XSD, change the targetNamespace of this XSD, and then target that namespace in the binding file to put it into a different package. The issue with this approach is that now the namespace of the generated common objects is different, so it doesn't serialize properly when calling the actual service.
The shared elements in question look like this:
<xs:complexType name="OperationResult">
<xs:sequence>
<xs:element name="MessageID" nillable="true" type="xs:string"/>
<xs:element name="Results" nillable="true" type="tns:ArrayOfCommandResult"/>
</xs:sequence>
</xs:complexType>
<xs:element name="OperationResult" nillable="true" type="tns:OperationResult"/>
<xs:complexType name="ArrayOfCommandResult">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="CommandResult" nillable="true" type="tns:CommandResult"/>
</xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfCommandResult" nillable="true" type="tns:ArrayOfCommandResult"/>
<xs:complexType name="CommandResult">
<xs:sequence>
<xs:element minOccurs="0" name="EntityID" type="xs:int"/>
<xs:element name="EntityType" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="ExchangeID" nillable="true" type="xs:string"/>
<xs:element name="Code" nillable="true" type="xs:string"/>
<xs:element name="Reason" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="Description" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="CommandResult" nillable="true" type="tns:CommandResult"/>
and they are just defined inside of the
<xs:schema elementFormDefault="qualified" targetNamespace="http://schemas.mypartnercompany.com/stuff/2013/06"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
Is there anything that I can do to get these common objects to generate to a separate package so I can share them between the two services, without having to change the namespace myself?

Don't display the element in xml if its id attribute is null

I have a xsd where there are 2 complextype elements under <Customer> complextype. One is <NormalCustomer> and <PrivilegedCustomer>. In my xml, I want either Normal or Privileged customer to be present under <Customer> tag based on the id attribute of Normal/Privileged customers.
below is my xsd
<xs:choice>
<xs:element name="normalCustomer" type="tns:normalCustomer" minOccurs="0" nillable="true"/>
<xs:element name="privilegedcustomer" type="tns:privilegedcustomer" minOccurs="0" nillable="true"/>
</xs:choice>
Complextype NormalCustomer
<xs:complexType name="normalCustomer">
<xs:sequence>
<xs:element name="id" type="xs:long"/>
<xs:element name="customerName" type="xs:string" minOccurs="1"/>
<xs:element name="customerType" type="xs:string" minOccurs="1"/>
</xs:sequence>
</xs:complexType>
Complextype PrivilegedCustomer
<xs:complexType name="privilegedCustomer">
<xs:sequence>
<xs:element name="id" type="xs:long"/>
<xs:element name="customerName" type="xs:string" minOccurs="1"/>
<xs:element name="customerType" type="xs:string" minOccurs="1"/>
</xs:sequence>
</xs:complexType>
Note: Am using JAXB for processing
Please suggest me how can I modify the tag to achieve my requirement.
Remove minOccurs="0" nillable="true" from both elements. The <xs:choice> enforces that exactly one of the elements are present. If none present are allowed, add minOccurs="0" to <xs:choice>.

Jaxb generate one get method for all elements

Part of my xsd file looks like this:
<xs:complexType name="group">
<xs:sequence maxOccurs="unbounded" minOccurs="1">
<xs:element name="title" type="xs:string"/>
<xs:element name="description" type="xs:string"/>
<xs:element name="module" type="module" nillable="true" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
When I generate my classes using Jaxb in Eclipse. The "Group" class generates a method called:
public List<JAXBElement<?>> getTitleAndDescriptionAndModule();
How do I change the xsd so that I get getter for each of the elements?

ct-props-correct error when parsing schema

I'm using the JAXB xjc tool to generate some Java interface files from xsds. I'm running into a problem where I'm getting a tonne of errors of the form:
org.xml.sax.SAXParseException: ct-props-correct.4: Error for type 'COCT_MT110200CA.PayeeRole'. Duplicate attribute uses with the same name and target namespace are specified. Name of duplicate attribute use is 'nullFlavor'.
The relevant parts of the schema are as follows:
<xs:complexType name="COCT_MT110200CA.Holder">
<xs:sequence>
<xs:group ref="InfrastructureRootElements"/>
<xs:element name="payeeRole" type="COCT_MT110200CA.PayeeRole" minOccurs="1" maxOccurs="1">
</xs:element>
</xs:sequence>
<xs:attributeGroup ref="InfrastructureRootAttributes"/>
<xs:attribute name="nullFlavor" type="NullFlavor" use="optional"/>
<xs:attribute name="typeCode" type="ParticipationType" use="optional" fixed="HLD"/>
</xs:complexType>
Where COCT_MT110200CA.PayeeRole is defined as:
<xs:complexType name="COCT_MT110200CA.PayeeRole">
<xs:sequence>
<xs:group ref="InfrastructureRootElements"/>
<xs:element name="id" type="II" minOccurs="0" maxOccurs="unbounded">
</xs:element>
<xs:choice>
<xs:element name="payeePerson" type="COCT_MT110200CA.PayeePerson" nillable="true"
minOccurs="0"
maxOccurs="1">
</xs:element>
<xs:element name="payeeOrganization" type="COCT_MT110200CA.PayeeOrganization"
nillable="true"
minOccurs="0"
maxOccurs="1">
</xs:element>
</xs:choice>
</xs:sequence>
<xs:attributeGroup ref="InfrastructureRootAttributes"/>
<xs:attribute name="nullFlavor" type="NullFlavor" use="optional"/>
<xs:attribute name="classCode" type="RoleClass" use="optional" fixed="PAYEE"/>
</xs:complexType>
Any thoughts? I don't see anything wrong with this myself...
Oooh, I think I figured this out, there was a pesky attributeGroup (InfrastructureRootAttributes) there, and in that attributeGroup was the nullFlavor duplicate...

Categories