XSD validation error - xml namespace issues - soap

I'm running a simple web service and I have a problem constructing and validating a response. This issue relates to namespaces.
In my WSDL I have:
<wsdl:definitions targetNamespace="http://me.com/mystuff">
<wsdl:types><xs:schema targetNamespace="http://me.com/mystuf">
....
<xs:complexType name="MyResponse">
<xs:all>
<xs:element name="Value" type="xs:boolean"/>
<xs:element name="ResponseString" type="xs:string"/>
</xs:all>
</wsdl:types>
//MyResponse is bound as a response for a soap operation
</wsdl:definitions>
I first tried to construct the response as:
String NAMESPACE_URI="http://me.com/mystuff";
Namespace namespace = Namespace.getNamespace("xyz", NAMESPACE_URI);
Element response = new Element(txType + "Response", namespace);
Element value = new Element("Value");
value.setText("true");
response.addContent(value);
Element responseString = new Element("ResponseString");
response.addContent(responseString);
responseString.setText("");
But I'd get:
org.xml.sax.SAXException: Exception in startElement: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.
org.jdom.JDOMException: Exception in startElement: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.
So I added namespace declarations to the child elements in the response:
Element value = new Element("Value", namespace);
Element responseString = new Element("ResponseString", namespace);
But then I get:
ERROR PayloadValidatingInterceptor:238 - XML validation error on response: cvc-complex-type.2.4.a: Invalid content was found starting with element 'xyz:Value'. One of '{Value, ResponseString}' is expected.
Any ideas on how to resolve this?

If you control the schema, add elementFormDefault="qualified" to the xs:schema element in your schema; that should make the namespace-qualified versions of Value and ResponseString you are now generating be valid.
If you don't control the schema, then the Value and ResponseString elements will need not to be namespace-qualified, which looks like what your original attempt was doing; I can't see what was going wrong there. If you can figure out which statement in particular was raising that error, it would help.

Related

Shibboleth: SAML Assertion Attributes with different datatypes

Returned SAML assertion for all the attributes default to
xsi:type="xsd:string"
In Assertion response, it showing like below
<saml2:Attribute
FriendlyName="givenName"
Name="givenName"
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">
<saml2:AttributeValue
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="xsd:string">testshibboleth
</saml2:AttributeValue>
</saml2:Attribute>
Now, I want to change xsi:type from string to Boolean or Integer or Duration like different data types.
Is there any possibility to do that?
I followed a few articles and they are telling to update metadata
https://wiki.shibboleth.net/confluence/display/IDP30/MetadataDrivenConfiguration
I tried updating metadata to accept boolean at least but not able to return those in assertion and not sure how to use that at attribute-filter.

Getting the error "Number of packages exceeds maximum" from FedEX API

I am getting "FedEx Ship Error: (8522) Number of packages exceeds maximum" error. I am trying to send a multiple-package shipment request to fedEX, but it is getting failed in first package request only.
For sending multiple shipment request to FedEX, we have to send separate request for each package, the master tracking information will be returned in reply from the first package requested. That master tracking information is then inserted into the requests for each additional package requested for that multiple-package shipment.
The example below is first package request.
Below is the XML request Body I am sending to FedEX API "https://wsbeta.fedex.com:443/xml"
The code is just preparing the data structure, converting it into XML and hitting the fedEX API with XML request.
my $http_request = HTTP::Request->new('POST', $config->{'URL'});
$http_request->content_type('application/x-www-form-urlencoded');
$http_request->content(Encode::encode_utf8($xml_request_body));
my $http_response;
eval {
$http_response = $ua->request($http_request);
};
return errorShipResponse($p) if (!defined $http_response || !$http_response->is_success);
my $response;
eval {
$response = XML::Simple::XMLin(
$http_response->content,
ForceArray => 1,
NSExpand => 1
);
};
$xml_request_body
<?xml version="1.0" encoding="UTF-8"?>
<ProcessShipmentRequest xmlns="http://fedex.com/ws/ship/v12">
<WebAuthenticationDetail>
<UserCredential>
<Key>aaaaaaaaaaa</Key>
<Password>aaaaaaaaaaaaaaaa</Password>
</UserCredential>
</WebAuthenticationDetail>
<ClientDetail>
<AccountNumber>111111111</AccountNumber>
<MeterNumber>111111111111</MeterNumber>
</ClientDetail>
<Version>
<ServiceId>ship</ServiceId>
<Major>12</Major>
<Intermediate>0</Intermediate>
<Minor>0</Minor>
</Version>
<RequestedShipment>
<ShipTimestamp>2016-09-06T06:42:41-04:00</ShipTimestamp>
<DropoffType>REGULAR_PICKUP</DropoffType>
<ServiceType>SMART_POST</ServiceType>
<PackagingType>YOUR_PACKAGING</PackagingType>
<TotalWeight>
<Units>LB</Units>
<Value>15.00</Value>
</TotalWeight>
<Shipper>
<AccountNumber>111111111111</AccountNumber>
<Tins>
<TinType>BUSINESS_STATE</TinType>
<Number444444444444</Number>
</Tins>
<Contact>
<CompanyName>aaaaaaaaaaaa</CompanyName>
<PhoneNumber>11111111</PhoneNumber>
</Contact>
<Address>
ADDRESS HERE
</Address>
</Shipper>
<Recipient>
<Contact>
<PersonName>mukta jain</PersonName>
<PhoneNumber>1234567899</PhoneNumber>
</Contact>
<Address>
<StreetLines>lwehcfkwdjh</StreetLines>
<City>NY</City>
<StateOrProvinceCode>NY</StateOrProvinceCode>
<PostalCode>12345</PostalCode>
<CountryCode>US</CountryCode>
<Residential>true</Residential>
</Address>
</Recipient>
<ShippingChargesPayment>
<PaymentType>SENDER</PaymentType>
<Payor>
<ResponsibleParty>
<AccountNumber>444444444</AccountNumber>
<Tins>
<TinType>BUSINESS_STATE</TinType>
<Number>4444444444</Number>
</Tins>
<Contact>
<CompanyName>aaaaaaaaa</CompanyName>
<PhoneNumber>111111111</PhoneNumber>
</Contact>
<Address>
<ADDRESS HERE>
</Address>
</ResponsibleParty>
</Payor>
</ShippingChargesPayment>
<SmartPostDetail>
<Indicia>PARCEL_SELECT</Indicia>
<AncillaryEndorsement>ADDRESS_CORRECTION</AncillaryEndorsement>
<SpecialServices>USPS_DELIVERY_CONFIRMATION</SpecialServices>
<HubId>1234</HubId>
<CustomerManifestId>123456</CustomerManifestId>
</SmartPostDetail>
<LabelSpecification>
<LabelFormatType>COMMON2D</LabelFormatType>
<ImageType>EPL2</ImageType>
<LabelStockType>STOCK_4X6</LabelStockType>
</LabelSpecification>
<RateRequestTypes>LIST</RateRequestTypes>
<PackageCount>3</PackageCount>
<RequestedPackageLineItems>
<SequenceNumber>1</SequenceNumber>
<GroupPackageCount>1</GroupPackageCount>
<Weight>
<Units>LB</Units>
<Value>5</Value>
</Weight>
<Dimensions>
<Length>7</Length>
<Width>7</Width>
<Height>7</Height>
<Units>IN</Units>
</Dimensions>
<CustomerReferences>
<CustomerReferenceType>INVOICE_NUMBER</CustomerReferenceType>
<Value>E2315141</Value>
</CustomerReferences>
<CustomerReferences>
<CustomerReferenceType>CUSTOMER_REFERENCE</CustomerReferenceType>
<Value>E2315141</Value>
</CustomerReferences>
</RequestedPackageLineItems>
</RequestedShipment>
</ProcessShipmentRequest>
You give us almost nothing to work with, so it's hard to be any help at all. But there's one thing that seems strange in your request body. Assuming that you're showing us a dump of a Perl data structure, it seems weird that all of your scalar values are implemented as anonymous arrays. For example, the line defining the package count is:
'PackageCount' => [ 3],
Where I'd expect to see:
'PackageCount' => 3,
It's possible that you have access to some documentation that tells you to do it this way, but it seems strange to me.
It would also explain the error message as the array reference would be interpreted as an integer which would almost certainly be far greater than any number expected by the API!
Update: When I wrote this answer, the question included what looked like a large Perl data structure which exhibited the weirdness that I discuss above. Now that has been changed to an XML document which seems to have the correct values. I have no idea where the original data structure came from or how it was used. And, in the absence of any feedback from the original poster, I have no idea how useful this answer is.

SmartGWT not able to parse data in the DataSource.transformResponse() method

I need some help please...
I am working with a GWT enabled web application. I am using the gwt-2.3.0 SDK.
I have a method that extends the DataSource class and uses the transformResponse method:
public class DeathRecordXmlDS extends DataSource {
protected void transformResponse(DSResponse response, DSRequest request, Object data){
super.transformResponse(response, request, data);
}
}
As I understand, the transformResponse() method should get control and at this point, I will have access to the data that is being provided to the Client side of my application. I am trying to work with the Object data parameter (the third parameter) that is passed in.
I am expecting an XML formatted string to be passed in. The XML will contain data (a count field) that I need to access and use.
I don't seem to be getting an XML string. Here's what I know...
I do see the XML data being passed to my webapp (the client). I can see this because I inspect the webpage that I am working with and I see the Response data. Here's an example of something that I expect to receive:
XML data from Query:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Collection numRecords="0">
<DeathRecords/>
</Collection>
The above XML is valid (I checked it in a Validator). This is a case where there was no data (No Death Records) being returned to my application. The numRecords XML attribute is set to "0". Of course, If I do have records returned the numRecords will contain the number of records and I'll get that same number of DeathRecord nodes.
I am not getting the above data (or, I don't know how to work with it) in the transformResponse() method.
Here's what I've done to try to figure this out...
The Object data parameter... it is a JavaScriptObject. I know this because I did a .getClass().getName() on it:
DeathRecordXmlDS::transformResponse() data.getClass().getName(): com.google.gwt.core.client.JavaScriptObject$
Then, to try to work with it, I converted it to a String:
com.google.gwt.core.client.JavaScriptObject dataJS = (com.google.gwt.core.client.JavaScriptObject)data;
System.out.println("DeathRecordXmlDS::transformResponse() data as a JavaScriptObject: "+dataJS.toString());
The contents of 'data' formatted as a String look like:
DeathRecordXmlDS::transformResponse() data as a JavaScriptObject: [XMLDoc <Collection>]
So, it looks like I have something that has to do with my 'Collection' node, but not a String of XML data that I can parse and get to my numRecords attribute.
What do I need to do to gain access to the XML in the transformResponse() method?
Thanks!
I think your data object is already translated to a javascript collection.
Maybe you could use the utility class XMLTools to retrieve your numRecords information:
Integer numRecords = Integer.parseInt(XMLTools.selectString(data, "Collection/#numRecords"));
After working on this for an additional period of time I was able to read the XML data that I am working with. I used the following piece of code:
try{
JsArray<JavaScriptObject> nodes = ((JavaScriptObject) XMLTools.selectNodes(data, "/Collection/#numRecords")).cast();
for (int i = 0; i < nodes.length(); i++) {
com.google.gwt.dom.client.Element element = (com.google.gwt.dom.client.Element) nodes.get(i);
numRecords = element.getNodeValue();
}
} catch(Exception e){
// If Parsing fails, capture the exception
System.out.println("DeathRecordXmlDS::transformResponse() Not able to parse the XML");
}
I think the first step to solving this was understanding that the parameter 'data' of type Object was really a JavaScriptObject. I learned this after looking at the .getClass() and .getName(). This helped me understand what I was working with:
System.out.println("DeathRecordXmlDS::transformResponse() data.getClass().getName(): "+data.getClass().getName());
Once I knew it was a JavaScriptObject, I was able to do a little more focused of a Google search for what I was trying to accomplish. I was a little surprised that the XMLTools.selectNodes() function worked the way it did, but the end result is that I was able to read the numRecords attribute.
Thanks for the suggestion!

What is an InstallationID in Quickbooks QBMSXML

I have a qbmsxml that I'm sending that continues to get a response error 2000.
<qbmsxml>
<signonmsgsrq>
<signondesktoprq>
<clientdatetime>2014-04-03T09:37:23</clientdatetime>
<applicationlogin>my.application.login.id</applicationlogin>
<connectionticket>SDK-MY-Connection-Ticket</connectionticket>
<language>English</language>
<appid>9999999999</appid>
<appver>1.0</appver>
</signondesktoprq>
</signonmsgsrq>
<qbmsxmlmsgsrq>
<customercreditcardauthrq>
<transrequestid>140403937231</transrequestid>
<creditcardnumber>4111111111111111</creditcardnumber>
<expirationmonth>12</expirationmonth>
<expirationyear>2017</expirationyear>
<isecommerce>true</isecommerce>
<amount>0.01</amount>
<nameoncard>John Doe</nameoncard>
<creditcardaddress>1234 Main Street</creditcardaddress>
<creditcardpostalcode>12345</creditcardpostalcode>
</customercreditcardauthrq>
</qbmsxmlmsgsrq>
</qbmsxml>
As I've been reviewing the information on creating a request, I found an 'InstallationID' tag referenced. It goes in the element like so:
<signonmsgsrq>
<signondesktoprq>
<clientdatetime>2014-04-03T09:37:23</clientdatetime>
<applicationlogin>my.application.login.id</applicationlogin>
<connectionticket>SDK-MY-Connection-Ticket</connectionticket>
<installationid>IDTYPE</installationid>
<language>English</language>
<appid>9999999999</appid>
<appver>1.0</appver>
</signondesktoprq>
</signonmsgsrq>
My question is: What is the IDTYPE for InstallationID? Where can I get it? What options can I set it to?
I think the problem is not related to your InstallationID field at all. I think the problem is that your XML isn't conforming to what Intuit expects.
Specifically, everything in your XML request is lowercase, when Intuit expects it to be camel case. You're also missing a qbmsxml version header, and a xml version header.
Here's an example of a correctly formed request:
<?xml version="1.0" encoding="utf-8"?>
<?qbmsxml version="3.0"?>
<QBMSXML>
<SignonMsgsRq>
<SignonTicketRq>
<ClientDateTime>2009-10-09T13:14:16</ClientDateTime>
<SessionTicket>xxxxxxxxxxxxky4yL6eBtCULX1zgQ:106892184</SessionTicket>
</SignonTicketRq>
</SignonMsgsRq>
<QBMSXMLMsgsRq>
<CustomerCreditCardChargeRq>
<TransRequestID>35f9cf7cb20994e8a32e6b3e91e8e602</TransRequestID>
<CreditCardNumber>xxxxxxxxxxxx5100</CreditCardNumber>
<ExpirationMonth>10</ExpirationMonth>
<ExpirationYear>2009</ExpirationYear>
<Amount>295.00</Amount>
<NameOnCard>Keith Palmer</NameOnCard>
<CreditCardAddress>56 Cowles Road</CreditCardAddress>
<CreditCardPostalCode>06279</CreditCardPostalCode>
</CustomerCreditCardChargeRq>
</QBMSXMLMsgsRq>
</QBMSXML>
Where are you getting your syntax from? It seems very wrong... here are some good examples:
http://wiki.consolibyte.com/wiki/doku.php/quickbooks_qbms_integration

Returning XML object through jax-rs

I have a JAX-RS web service which looks like so:
#Path("/status")
#Produces("application/xml")
#GET
public PrecisionStatus getPrecisionValue(){
PrecisionStatus status = ...
return status;
}
Initially, the result was:
<PrecisionStatus sensorID="TemperatureSensor5"><condition>OK</condition><fieldValue>60.0</fieldValue></PrecisionStatus>
It looks fine, but I want to declare the xsd file which describes this document. By using JAXB marshalling features, I was able to produce (in logger/console) the desired output:
<PrecisionStatus sensorID="TemperatureSensor5" xsi:noNamespaceSchemaLocation="http://mysite.com/myapp/xsd0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<condition>OK</condition>
<fieldValue>60.0</fieldValue>
</PrecisionStatus>
(this is confirmed by unmarshalling the object).
However, if i return this object return status;, the browser receives the former xml document, namely the one without the reference to xsd.
I am pretty sure that the object has the right form, but somewhat the reference to xsd is stripped in the final result. Any clue?
You could create a JAX-RS MessageBodyWriter to have access to the Marshaller in order to set the JAXB_NO_NAMESPACE_SCHEMA_LOCATION property. For a complete example see:
Formatted XML output in CXF?