I have at my hands a SOAP API that has plenty of functionality, but from which I only need two methods: adding user to a database and deleting user from a database.
Currently I am locked to Perl as the language for this task.
Because deleting a user takes in as the only parameter the "id" of the user (not "userId" as in username), I need to define it myself rather than relying on MySQL's auto_increment.
Relevant parts from the WSDL:
<xs:element name="saveLocalUserEx">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="user" nillable="true" type="ns2:LocalUser"/>
<xs:element minOccurs="0" name="requestingUser" nillable="true" type="xs:string"/></xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="LocalUser">
<xs:sequence>
<xs:element minOccurs="0" name="dbData" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="description" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="displayName" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="domainName" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="enabled" type="xs:boolean"/>
<xs:element minOccurs="0" name="firstName" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="id" nillable="true" type="xs:long"/>
<xs:element minOccurs="0" name="lastName" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="loginId" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="loginPasswordHash" nillable="true" type="xs:string"/><xs:element minOccurs="0" name="loginPasswordHashType" type="xs:int"/>
<xs:element minOccurs="0" name="preOrSelfProvisioned" type="xs:boolean"/>
<xs:element minOccurs="0" name="DEFAULT_PASSWORD_HASH_TYPE" type="xs:int"/>
<xs:element minOccurs="0" name="PKCS5_REVERSIBLE_HASH_TYPE" type="xs:int"/>
<xs:element minOccurs="0" name="SHA1_NON_REVERSIBLE_HASH_TYPE" type="xs:int"/>
<xs:element minOccurs="0" name="STR_DEFAULT_ADMIN_NAME" nillable="true" type="xs:string"/><xs:element minOccurs="0" name="STR_DEFAULT_DOMAIN" nillable="true" type="xs:string"/><xs:element minOccurs="0" name="STR_DEFAULT_SPONSOR_NAME" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
Here are (relevant parts) of the code I first wrote.
my $soap = SOAP::Lite
->uri($uri)
->proxy($proxy);
sub SOAP::Transport::HTTP::Client::get_basic_credentials {
return 'abc' => 'abc';
}
my $test_id = 1515;
# Preparing data for API query for saving the new user.
my $data = SOAP::Data->name("LocalUser" =>
\SOAP::Data->value(
SOAP::Data->name("loginId" => $new_username),
SOAP::Data->name("enabled" => true),
SOAP::Data->name("domainName" => $domainname),
SOAP::Data->name("loginPasswordHash" => $hash),
SOAP::Data->name("id" => $test_id),
SOAP::Data->name("description" => 'Guest User Account generated on: ' . localtime()),
SOAP::Data->name("displayName" => 'Guest')
)
);
my $som = $soap->saveLocalUserEx($data);
print Dumper $som->result();
It almost does the job. In the matter of fact; API accepts this query, result is success and a new user is generated. The problem is, that id field in the database is still MySQL auto_incremented, and not 1515 I tried to give it this time. Then I started thinking that maybe I need to type the parameter explicitly to long, because wsdl states the type for id is xs:long.
I've tried modifying my code with:
SOAP::Data->type('xs:long')->name("id" => $test),
and
SOAP::Data->type('long')->name("id" => $test),
But these didn't help. API query succeeds, but id is not made to 1515.
Do you guys have any idea how to make this work? Thanks!
Related
I have this xml part of Data:
<xs:element name="DESCR">
<xs:complexType>
<xs:sequence>
<xs:element name="ADDITIONAL">
<xs:complexType>
<xs:sequence>
<xs:element name="DESCR_CODE">
<xs:complexType>
<xs:attribute name="CODE" type="xs:unsignedInt" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>]
I am interested in mapping this xml to json as:
"DESCR": {
"ADDITIONAL": {
"DESCR_CODE": "{{DESCR.ADDITIONAL.DESCR_CODE.CODE}}"
}
}
but I don't get the value of attribute CODE.
How could the value of an XML attribute be mapped to JSON?
I have xsd like this -
<xs:complexType name="ChoiceListItem">
<xs:sequence>
<xs:element name="childChoices" maxOccurs="unbounded" minOccurs="0" nillable="true" type="tns:ChoiceListItem"/>
<xs:element name="name" nillable="true" type="xsd:string"/>
<xs:element name="stringValue" nillable="true" type="xsd:string"/>
<xs:element name="integerValue" nillable="true" type="xsd:int"/>
</xs:sequence>
</xs:complexType>
Here you can see that my childChoices type is ChoiceListItem under which it is defined. Here is my Java class -
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "ChoiceListItem", propOrder = {
"childChoices",
"name",
"stringValue",
"integerValue"
})
public class ChoiceListItem {
#XmlElement(nillable = true)
protected List<ChoiceListItem> childChoices;
#XmlElement(required = true, nillable = true)
protected String name;
#XmlElement(required = true, nillable = true)
protected String stringValue;
#XmlElement(required = true, type = Integer.class, nillable = true)
protected Integer integerValue;
When I run it in SOAPUI it did not display the childChoices value but displays the other three items. Here is my output response -
<ns3:getChoiceListItemsResponse xmlns:ns3="http://getservice.service">
<getChoiceListItemsReturn>
<items>
<ChoiceListItem>
<name>AD SERVICE</name>
<stringValue>AD SERVICE</stringValue>
<integerValue xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</ChoiceListItem>
I guess xsd is not defined properly..Can somebody please help me in defining correct xsd in which sequence element type refer to same Complex type?
I have solved it by making changes into my xsd
<xs:complexType name="ChoiceListItem">
<xs:sequence>
<xs:element name="childChoices" nillable="true" type="tns:ChoiceListItemArray"/>
<xs:element name="name" nillable="true" type="xsd:string"/>
<xs:element name="stringValue" nillable="true" type="xsd:string"/>
<xs:element name="integerValue" nillable="true" type="xsd:int"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ChoiceListItemArray">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="ChoiceListItem" nillable="true" type="tns:ChoiceListItem"/>
</xs:sequence>
</xs:complexType>
I have a XML data source like below:
<xs:element name="block" type="xs:string" minOccurs="0" />
<xs:element name="lot" type="xs:string" minOccurs="0" />
<xs:element name="wafer" type="xs:string" minOccurs="0" />
Now I want to create a formula which need all block+lot as a string with each record as a single line.
so suppose the data is
<xs:element name="block" type="xs:string" minOccurs="0" >A1</block>
<xs:element name="lot" type="xs:string" minOccurs="0" >B1</lot>
<xs:element name="wafer" type="xs:string" minOccurs="0" >C1</wafer>
<xs:element name="block" type="xs:string" minOccurs="0" >A2</block>
<xs:element name="lot" type="xs:string" minOccurs="0" >B2</lot>
<xs:element name="wafer" type="xs:string" minOccurs="0" >C2</wafer>
then the result string is A1B1/nA2B2
How to do it?I tried to use variable and while do loop, but how to let the variable point to next record? Thx.
We just started developing our own sabre app and we are trying to create a session to proceed with other services.
But an exception returned :
com.sabre.universalservices.base.exception.ApplicationException: errors.general.USG_COULD_NOT_COMPLETE_REQUEST
This is the code used :
<SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' xmlns:eb='http://www.ebxml.org/namespaces/messageHeader' xmlns:xlink='http://www.w3.org/1999/xlink' xmlns:xsd='http://www.w3.org/1999/XMLSchema'>
<SOAP-ENV:Header>
<eb:MessageHeader SOAP-ENV:mustUnderstand='1' eb:version='1.0'>
<eb:ConversationId>*myConversationId*</eb:ConversationId>
<eb:From>
<eb:PartyId type='urn:x12.org:IO5:01'>999999</eb:PartyId>
</eb:From>
<eb:To>
<eb:PartyId type='urn:x12.org:IO5:01'>123123</eb:PartyId>
</eb:To>
<eb:CPAId>IPCC</eb:CPAId>
<eb:Service eb:type='OTA'>SessionCreateRQ</eb:Service>
<eb:Action>SessionCreateRQ</eb:Action>
<eb:MessageData>
<eb:MessageId>1000</eb:MessageId>
<eb:Timestamp>2016-04-06T01:14:12Z</eb:Timestamp>
<eb:TimeToLive>2016-04-06T02:14:12Z</eb:TimeToLive>
</eb:MessageData>
</eb:MessageHeader>
<wsse:Security xmlns:wsse='http://schemas.xmlsoap.org/ws/2002/12/secext' xmlns:wsu='http://schemas.xmlsoap.org/ws/2002/12/utility'>
<wsse:UsernameToken>
<wsse:Username>*Username*</wsse:Username>
<wsse:Password>*Password*</wsse:Password>
<Organization>IPCC;</Organization>
<Domain>DEFAULT</Domain>
</wsse:UsernameToken>
</wsse:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<eb:Manifest SOAP-ENV:mustUnderstand='1' eb:version='1.0'>
<eb:Reference xmlns:xlink='http://www.w3.org/1999/xlink' xlink:href='cid:rootelement' xlink:type='simple'/>
</eb:Manifest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
And here is the returned response :
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<DataSet xmlns="http://tempuri.org/">
<xs:schema xmlns:mstns="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:app1="http://www.ebxml.org/namespaces/messageHeader" xmlns:app2="http://schemas.xmlsoap.org/ws/2002/12/secext" id="Envelope" targetNamespace="http://schemas.xmlsoap.org/soap/envelope/" attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:import namespace="http://www.ebxml.org/namespaces/messageHeader"/>
<xs:import namespace="http://schemas.xmlsoap.org/ws/2002/12/secext"/>
<xs:attribute name="mustUnderstand" msdata:Prefix="soap-env" type="xs:string"/>
<xs:element name="Envelope" msdata:IsDataSet="true" msdata:Locale="en-US" msdata:Prefix="soap-env">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="app1:PartyId"/>
<xs:element name="Header" msdata:Prefix="soap-env">
<xs:complexType>
<xs:sequence>
<xs:element ref="app2:Security" minOccurs="0"/>
<xs:element ref="app1:MessageHeader"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Body" msdata:Prefix="soap-env">
<xs:complexType>
<xs:sequence>
<xs:element name="Fault" msdata:Prefix="soap-env" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="faultcode" form="unqualified" type="xs:string" minOccurs="0"/>
<xs:element name="faultstring" form="unqualified" type="xs:string" minOccurs="0"/>
<xs:element name="detail" form="unqualified">
<xs:complexType>
<xs:sequence>
<xs:element name="StackTrace" form="unqualified" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<xs:schema xmlns:mstns="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://schemas.xmlsoap.org/ws/2002/12/secext" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:app2="http://schemas.xmlsoap.org/ws/2002/12/secext" xmlns:app1="http://www.ebxml.org/namespaces/messageHeader" targetNamespace="http://schemas.xmlsoap.org/ws/2002/12/secext" attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:import namespace="http://www.ebxml.org/namespaces/messageHeader"/>
<xs:import namespace="http://schemas.xmlsoap.org/soap/envelope/"/>
<xs:element name="Security" msdata:Prefix="wsse" type="xs:string"/>
</xs:schema>
<xs:schema xmlns:mstns="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://www.ebxml.org/namespaces/messageHeader" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:app1="http://www.ebxml.org/namespaces/messageHeader" xmlns:app2="http://schemas.xmlsoap.org/ws/2002/12/secext" targetNamespace="http://www.ebxml.org/namespaces/messageHeader" attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:import namespace="http://schemas.xmlsoap.org/soap/envelope/"/>
<xs:import namespace="http://schemas.xmlsoap.org/ws/2002/12/secext"/>
<xs:element name="PartyId" msdata:Prefix="eb" nillable="true">
<xs:complexType>
<xs:simpleContent msdata:Prefix="eb" msdata:ColumnName="PartyId_Text" msdata:Ordinal="1">
<xs:extension base="xs:string">
<xs:attribute name="type" msdata:Prefix="eb" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="MessageHeader" msdata:Prefix="eb">
<xs:complexType>
<xs:sequence>
<xs:element name="CPAId" msdata:Prefix="eb" type="xs:string" minOccurs="0" msdata:Ordinal="1"/>
<xs:element name="ConversationId" msdata:Prefix="eb" type="xs:string" minOccurs="0" msdata:Ordinal="2"/>
<xs:element name="Action" msdata:Prefix="eb" type="xs:string" minOccurs="0" msdata:Ordinal="3"/>
<xs:element name="From" msdata:Prefix="eb" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element ref="PartyId" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="To" msdata:Prefix="eb" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element ref="PartyId" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Service" msdata:Prefix="eb" nillable="true" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent msdata:Prefix="eb" msdata:ColumnName="Service_Text" msdata:Ordinal="1">
<xs:extension base="xs:string">
<xs:attribute name="type" msdata:Prefix="eb" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="MessageData" msdata:Prefix="eb" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="MessageId" msdata:Prefix="eb" type="xs:string" minOccurs="0"/>
<xs:element name="Timestamp" msdata:Prefix="eb" type="xs:string" minOccurs="0"/>
<xs:element name="RefToMessageId" msdata:Prefix="eb" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="version" msdata:Prefix="eb" type="xs:string"/>
<xs:attribute ref="mstns:mustUnderstand"/>
</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">
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Header diffgr:id="Header1" msdata:rowOrder="0" diffgr:hasChanges="inserted" msdata:hiddenHeader_Id="0">
<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext"/>
<eb:MessageHeader xmlns:eb="http://www.ebxml.org/namespaces/messageHeader" diffgr:id="MessageHeader1" msdata:rowOrder="0" diffgr:hasChanges="inserted" msdata:hiddenMessageHeader_Id="0" eb:version="1.0" soap-env:mustUnderstand="1" msdata:hiddenHeader_Id="0">
<eb:CPAId>IPCC</eb:CPAId>
<eb:ConversationId>www.tiitco.com10:16</eb:ConversationId>
<eb:Action>ErrorRS</eb:Action>
<eb:From diffgr:id="From1" msdata:rowOrder="0" diffgr:hasChanges="inserted" msdata:hiddenFrom_Id="0" msdata:hiddenMessageHeader_Id="0">
<eb:PartyId diffgr:id="PartyId1" msdata:rowOrder="0" diffgr:hasChanges="inserted" eb:type="URI" msdata:hiddenFrom_Id="0">123123</eb:PartyId>
</eb:From>
<eb:To diffgr:id="To1" msdata:rowOrder="0" diffgr:hasChanges="inserted" msdata:hiddenTo_Id="0" msdata:hiddenMessageHeader_Id="0">
<eb:PartyId diffgr:id="PartyId2" msdata:rowOrder="1" diffgr:hasChanges="inserted" eb:type="URI" msdata:hiddenTo_Id="0">999999</eb:PartyId>
</eb:To>
<eb:Service diffgr:id="Service1" msdata:rowOrder="0" diffgr:hasChanges="inserted" eb:type="OTA" msdata:hiddenMessageHeader_Id="0">SessionCreateRQ</eb:Service>
<eb:MessageData diffgr:id="MessageData1" msdata:rowOrder="0" diffgr:hasChanges="inserted" msdata:hiddenMessageHeader_Id="0">
<eb:MessageId>b00c9239-c921-4983-a8ed-831732f54b84#176</eb:MessageId>
<eb:Timestamp>2016-04-06T07:19:41</eb:Timestamp>
<eb:RefToMessageId>1000</eb:RefToMessageId>
</eb:MessageData>
</eb:MessageHeader>
</soap-env:Header>
<soap-env:Body diffgr:id="Body1" msdata:rowOrder="0" diffgr:hasChanges="inserted" msdata:hiddenBody_Id="0">
<soap-env:Fault diffgr:id="Fault1" msdata:rowOrder="0" diffgr:hasChanges="inserted" msdata:hiddenFault_Id="0" msdata:hiddenBody_Id="0">
<faultcode xmlns="">soap-env:Server.SystemFailure</faultcode>
<faultstring xmlns="">SOAPException: Could not complete the request</faultstring>
<detail xmlns="" diffgr:id="detail1" msdata:rowOrder="0" diffgr:hasChanges="inserted" msdata:hiddenFault_Id="0">
<StackTrace>
com.sabre.universalservices.base.exception.ApplicationException: errors.general.USG_COULD_NOT_COMPLETE_REQUEST
</StackTrace>
</detail>
</soap-env:Fault>
</soap-env:Body>
</soap-env:Envelope>
</diffgr:diffgram>
</DataSet>
Does anyone have an idea on what could be the problem?
The returned response looks more like a schema declaration in an xsd file.
Is that what you are getting back?
Anyway, the error USG_COULD_NOT_COMPLETE_REQUEST is included on the error codes list:
https://developer.sabre.com/docs/read/soap_basics/status_codes_and_errors
What is the endpoint you are trying to hit?
Customer Acceptance Testing/CERT?
https://developer.sabre.com/docs/read/soap_basics/environments
Are you using a SOAP client tool? Any language?
More info will help.
This seems like an authentication error of some sorts. Here is some working XML for creating a session, compare. Like fcarreno said you are likely missing the PseudoCityCode node.
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<MessageHeader xmlns="http://www.ebxml.org/namespaces/messageHeader">
<From>
<PartyId type="urn:x12.org:IO5:01">*or</PartyId>
</From>
<To>
<PartyId type="urn:x12.org:IO5:01">Sabre</PartyId>
</To>
<CPAId>X2TH</CPAId>
<ConversationId>1473816876</ConversationId>
<Service type="sabreXML">SessionCreateRQ</Service>
<Action>SessionCreateRQ</Action>
<MessageData>
<MessageId>1473816876</MessageId>
<Timestamp>2016-09-14T01:34:36</Timestamp>
<TimeToLive>2016-09-14T02:34:36</TimeToLive>
</MessageData>
</MessageHeader>
<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext" xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/12/utility">
<wsse:UsernameToken>
<wsse:Username>*user</wsse:Username>
<wsse:Password>*pass</wsse:Password>
<Organization>*ipcc</Organization>
<Domain>DEFAULT</Domain>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<SessionCreateRQ xmlns="http://www.opentravel.org/OTA/2002/11">
<POS>
<Source PseudoCityCode="*ipcc" />
</POS>
</SessionCreateRQ>
</soapenv:Body>
</soapenv:Envelope>
following xsd (partial):
<xs:complexType name="Fruit">
<xs:sequence>
<xs:element name="type" type="FruitType"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="FruitType">
<xs:restriction base="xs:string">
<xs:enumeration value="ABC">
</xs:enumeration>
<xs:enumeration value="DEF">
</xs:enumeration>
<xs:enumeration value="GHI">
</xs:enumeration>
<xs:enumeration value="JKL">
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
Generating code with xjc will generate the following java code (FruitType is an Enum):
#XmlElement(required = true)
#XmlSchemaType(name = "string")
protected FruitType fruit;
When generating a SOAP WebService with JAX-WS the following element will be generated:
<xs:element name="type" type="xs:string"/>
Which ist obviously wrong. I'd expect this to be
<xs:element name="type" type="FruitType"/>
If I delete this line by hand
#XmlSchemaType(name = "string")
in my Java Code everything in the wsdl is fine :
<xs:element name="type" type="tns:FruitType"/>
So the question is: How can I tell JAXB not to generate the #XmlSchemaType?
Instead of referencing FruitType with type
<xs:complexType name="Fruit">
<xs:sequence>
<xs:element name="type" type="FruitType"/>
</xs:sequence>
</xs:complexType>
the trick ist to have a simpleType inline:
<xs:complexType name="Fruit">
<xs:sequence>
<xs:element name="type">
<xs:simpleType>
<xs:restriction base="FruitType"/>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
this will generate the correct java file and WSDL:
<xs:element name="type" type="tns:FruitType"/>