WSDL enumeration restriction with key/value pairs - soap

I'm working on a SOAP webservice which features many inputfields using enumeration restrictions.
These enumerations are much like an HTML select/option setup; I expect a certain value to be returned but the label of that value should be exposed using the WSDL as well.
An example: the client wishes to add an insurance policy regarding his/her house and thus needs to specify the type of building involved.
<xsd:restriction base="xsd:string">
<xsd:enumeration value="00001" />
<xsd:enumeration value="00002" />
<xsd:enumeration value="00003" />
</xsd:restriction>
However, the client does not yet understand what these values 1, 2 and 3 are. So, something like this:
<xsd:restriction base="xsd:string">
<xsd:enumeration value="00001" label="Brick and mortar" />
<xsd:enumeration value="00002" label="Straw" />
<xsd:enumeration value="00003" label="Aircastle" />
</xsd:restriction>
would be great for the client to be used to display these labels to the consumer.
Is there any standard WSDL annotation/syntax for this construction?

Is there any standard WSDL annotation/syntax for this construction?
I'm afraid not. The XML Schema enumeration is used to constrain a value to be within a specified set of possible values. When your client sends you the request, the element with the restriction type will only be allowed to have (in your case) a value of 00001, 00002 or 00003 or it won't be valid.
The restriction only specifies the values, you can't add labels. You could at best add an <annotation> but that would be just documentation. In the client UI, it would be the responsibility of each client to say that 00001 is actually "Brick and mortar" and that 00002 is "Straw" etc.
If you don't want to do that, and instead want to also return labels, then you need a slightly more complex object, maybe something like this:
<option>
<key>00001</key>
<label>Brick and mortar</label>
</option>
You provide a label and you restrict the key with a schema like:
<xsd:simpleType name="ValuesType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="00001" />
<xsd:enumeration value="00002" />
<xsd:enumeration value="00003" />
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="OptionType">
<xsd:sequence>
<xsd:element name="key" type="ValuesType" />
<xsd:element name="label" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
You can return a list of options to the clients and they can present it in the interface with key as value and label as the text of options in <select> inputs, while on the request you will get back the selected value (i.e. the selected key).

Related

wsimport pass no value to an enumerated parameter

I have a SOAP URL with one of the input parameters of enumerated type as below. With SOAPUI I'm just able to remove the ? mark and able to execute the request successfully. <urn:Comm_Source></urn:Comm_Source>
I created client code using wsimport and it creates the input method parameter as CommSourceType object. If I pass null for this value the web service fails.
<xsd:element maxOccurs="1" minOccurs="0" name="Comm_Source" nillable="false" type="s0:Comm_SourceType"/>
There is a lack of information for the complete answer (eg the whole wsdl/xsd or what means: If I pass null for this value the web service fails.).
In general:
null is not the same as an empty string.
<urn:Comm_Source></urn:Comm_Source> - is an empty string
<urn:Comm_Source xsi:nil="true" /> - is a null value (xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance")
the specified element <xsd:element maxOccurs="1" minOccurs="0" name="Comm_Source" nillable="false" type="s0:Comm_SourceType" /> does not support null because there is nillable="false".
The element can either be omitted or an empty string can be written in it.

WSDL contract list occuring with numbers

When I define the fields of a contract in XSD I define a list field with maxOccurs= and minOccurs>0.
Can i declare the XSD in such a way that when the request is received the fields with occurs have occurance number?
e.g.
I hope i make my self clear.
<xsd:complexType name="FieldNameType">
<xsd:sequence>
<xsd:element name="FieldName" type="FieldNameType" minOccurs="1" maxOccurs="8"/>
</xsd:sequence>
</xsd:complexType>
and when the request is send i get something like:
<FieldName_1></FieldName_1>
<FieldName_2></FieldName_2>
<FieldName_3></FieldName_3>
Thanks in advance!
I found a work-around! As i saw i can iterate through the same nodes in an XSLT file.

Creating a comment that gets displayed in generated request? WSDL SOAP xml

Im in the process of writing a wsdl file for an existing system. I'd like to add comments to generated requests.
For instance this:
<xsd:simpleType name="coffeetype">
<xsd:restriction base="xsd:integer">
<!--0=likescoffee,1=doesnotlikecoffe-->
<xsd:enumeration value="0" />
<xsd:enumeration value="1" />
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="CoffeeRequestInput" nillable="false" type="tns:coffeetype" />
Should look like this in the generated request: (eg. when loading the WSDL in SoapUI)
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdl="https://example.com/some.wsdl">
<soapenv:Header/>
<soapenv:Body>
<!--0=likescoffee,1=doesnotlikecoffe-->
<wsdl:CoffeeRequestInput>0</wsdl:CoffeeRequestInput>
</soapenv:Body>
</soapenv:Envelope>
I was able to see these comments when opening the WSDL but not when generating a request from that WSDL.
Already looked into annotations but I wasn't able to use them to create the result I wanted. (Probably an error on my side)
In short you cannot create documentation in requests as you would like to. However you can generate documentation from your WSDL that can be be very useful. By using the "xsd:documentation" tag you can add documentation directly to the elements.
For example
<xsd:simpleType name="coffeetype">
<xsd:restriction base="xsd:integer">
<xsd:enumeration value="0" />
<xsd:enumeration value="1" />
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="CoffeeRequestInput" nillable="false" type="tns:coffeetype">
<xsd:annotation>
<xsd:documentation>
This object is the CoffeeRequestInput object is an Enumeration which can be used to determine is the user sending the request likes coffee or not.
Valid values for the enumeration is as follows:
0 = like coffee
1 = does not like coffee (probably a user not a programmer making a request).
Some other things that you need to document goes here.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
You can then use software such as Altova StyleForce, LiquidXML and OxyGen to generate PDF, Word documents or HTML pages which shows the SOAP services and operations with all your comments included.
If you feel up to it you can write your own XLST to transform your WSDL and XSD's into a neat HTML page which documents you interfaces as well. The best part about this is that when you update the WSDL with new operations and so on that the documentation is updated as well.

How to extract JAX-WS #RequestWrapper attribute (or full bean)

Is it possible to extract an attribute (as in XML attribute value) from a RequestWrapper object?
In my implementation, I'd like to use the value of the attribute, but can't reference it with #WebParam, as that is only for elements (I believe)
#SOAPBinding is defined "Document/Literal/Wrapped"
WSDL (relevant sections, target attribute at **):
<s:element name="GetStatus">
<s:complexType>
<s:element minOccurs="0" maxOccurs="1" name="Entity" type="s0:Entity"/>
**<s:attribute name="Handle" type="s:string"/>
</s:complexType>
</s:element>
<s:element name="GetStatusResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="StatusCode" type="s0:StatusCode"/>
<s:element minOccurs="0" maxOccurs="1" name="Server" type="s0:Server"/>
</s:sequence>
</s:complexType>
</s:element>
<message name="GetStatusIn">
<part name="parameters" element="s0:GetStatus"/>
</message>
<message name="GetStatusOut">
<part name="parameters" element="s0:GetStatusResponse"/>
</message>
<portType name="Service">
<operation name="GetStatus">
<input message="s0:GetStatusIn"/>
<output message="s0:GetStatusOut"/>
</operation>
</portType>
SEI abstract method (able to specify XML elements with WebParam):
#WebMethod(operationName="GetStatus")
#RequestWrapper(localName=“GetStatus",className="com.example.GetStatus")
#ResponseWrapper(localName=“GetStatusResponse",className="com.example.GetStatusResponse")
public void getStatus(
#WebParam(name="Entity”)Entity entity,
#WebParam(name="StatusCode",mode=WebParam.Mode.OUT)Holder<StatusCode> statusCode,
#WebParam(name="Server", mode=WebParam.Mode.OUT)Holder<Server> server
);
Implementation:
#Override
public void getStatus(
Entity entity,
Holder<StatusCode> statusCode,
Holder<Server> server
) { ... }
It’s obvious how I can read the value of the #RequestWrapper bean Status (Entity via #WebParam), but is there any way to access the value (Handle) within Status. WebParam, as far as I understand, does not support attributes, only elements.
An alternate way to ask/seek solution might be asking how to access the full bean being referenced by RequestWrapper, in this case GetStatus.
I know if I transition to Document/Literal/Bare I can simply have the parameters and return value reflect the bean, but I'd prefer to solve this using wrapped as all information points to this being the most widely preferred binding.
Self-answered for posterity.
No. To qualify as wrapped style, only elements must be present.
Was reviewing the JAX-WS specification overnight
2.3.1.2 Wrapper Style
A WSDL operation qualifies for wrapper style mapping only if the following criteria are met:
(i) The operation’s input and output messages (if present) each contain only a single part
(ii) The input message part refers to a global element declaration whose localname is equal to the operation name
(iii) The output message (if present) part refers to a global element declaration
(iv) The elements referred to by the input and output message (if present) parts (henceforth referred to as
wrapper elements) are both complex types defined using the xsd:sequence compositor
(v) The wrapper elements only contain child elements, they MUST not contain other structures such
as wildcards (element or attribute), xsd:choice, substitution groups (element references are not
permitted) or attributes; furthermore, they MUST not be nillable.
Non-elements can be present too, as long as they are contained inside an javax.xml.ws.Holder object.

hyperjaxb3 xsd:string length in JPA entity

I use Hyperjaxb3 to generate JPA entities from XSD schema. I have a xsd:string type that I want to use for description text (text area in the UI):
<xsd:complexType name="Description">
<xsd:simpleContent>
<xsd:extension base="**xsd:string**">
<xsd:attribute name="abc" type="xsd:NCName" use="optional" />
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
Hyperjaxb3 generates class (entity) Description with attribute value, annotated like this:
#Basic
#Column(name = "VALUE_", **length = 255**)
public String getValue() {
return value;
}
The questions I have:
I saw that if I put xsd:maxLength restriction on xsd:simpleType, JPA #Column.length has the value of maxLength. How can I set xsd:rescriction on xsd:simpleContent that is xsd:extension of xsd:string? Do I have to define a complexType with xsd:resctriction that I will extend? And if yes, will Hyperjaxb generate #Column.length by my restriction. I tried following:
<xsd:simpleType name="DescriptionParent">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="4096" />
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="Description">
<xsd:simpleContent>
<xsd:extension base="DescriptionParent">
<xsd:attribute name="abc" type="xsd:NCName" use="optional" />
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
But the JPA column length is still 255.
Is it also possible to set in my JAXB customization (*.xjb file) the lenght of the column for given type (somehow let hyperjaxb know that this is the orm I want to use for my specific type)? Or is it totally out of the way and xsd:maxLength should be used (above) I managed to set it globally for Hyperjaxb customization:
Thanks for your help.
Second question: yes, you can configure global type mappings for simple types.
See Per-type customization for single properties.
First question: it seems to be a bug/missing feature, please file an issue here.