How to read second (n-th) child of details in FaultException? CreateMessageFault().GetDetail only returns first child - soap

Here is my SOAP response
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>[MessageId=1000012650] The requested record was not found : The requested record was not found</faultstring>
<detail>
<ErrorCode>100.101017</ErrorCode>
<ProposedSolution>Proposed Solution</ProposedSolution>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>
When getting FaultExeption I can read <ErrorCode> which is first child:
catch (FaultException ex)
{
var errorCode = ex.CreateMessageFault().GetDetail<XmlElement>().OuterXml;
}
My question is how to read second (or third ..) child? In my case ProposedSolution

Related

Soap Response parsing using cypress

<soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<soap:Body>
<m:GetPriceRespon`enter code here`se xmlns:m="https://www.w3schools.com/prices">
<m:Price>1.90</m:Price>
</m:GetPriceResponse>
</soap:Body>
</soap:Envelope>
I want to read "Price" from above XML , how to read this price using cypress and store it to a variable ? could any one help me with the sample cypress code ?
You can use a DOMParser to make a queryable document,
it('parses XML price', () => {
const xmlStr = `<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope/" soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<soap:Body>
<m:GetPriceResponse xmlns:m="https://www.w3schools.com/prices">
<m:Price>1.90</m:Price>
</m:GetPriceResponse>
</soap:Body>
</soap:Envelope>`
const parser = new DOMParser();
const doc = parser.parseFromString(xmlStr, "application/xml");
const price = +doc.querySelector("Price").textContent // numeric value of text content
cy.wrap(price)
.as('price') // save for later
.should('eq', 1.90) // verify the value
});
You can do something like this:
const xml = `<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope/" soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
<soap:Body>
<m:GetPriceResponse xmlns:m="https://www.w3schools.com/prices">
<m:Price>1.90</m:Price>
</m:GetPriceResponse>
</soap:Body>
</soap:Envelope>`
cy.wrap(Cypress.$(xml))
.then((xml) => xml.filter('soap:Body').find('m:Price').text())
.as('price')
cy.get('#price').then((price) => {
//Access price here
})

MarkAsJunk operation Error Code 9020. Getting "An internal server error occurred. The operation failed."

I am trying to use the MarkAsJunk operation using only SOAP requests with Office.context.mailbox.makeEwsRequestAsync. For this purpose I also use the easyEWS module which is a wrapper over OfficeJS. The code I'm using to send the SOAP looks like this:
this.markAsJunk = function (itemId) {
var soap = '<m:MarkAsJunk IsJunk="true" MoveItem="true"' +
'
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">' +
' <ItemIds>' +
' <t:ItemId Id="' + itemId + '"/>' +
' </ItemIds>' +
'</m:MarkAsJunk>';
soap = getSoapHeader(soap);
asyncEws(soap, function (data) { });
};
The SOAP which I'm sending looks like this:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
<RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />
</soap:Header>
<soap:Body>
<m:MarkAsJunk IsJunk="true" MoveItem="true"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<ItemIds>
<t:ItemId Id="AAMkADg2OGZmNDkzLWVjNDYtNGI2MC1iMGI3LWE3YmEzMDk5MThiNABGAAAAAAC3FQIsRYg6SZwlyqfCFdA0BwBTNDtA08+GRo/QPlH0XaGpAAAAAAEMAABTNDtA08+GRo/QPlH0XaGpAADEMDCVAAA="/>
</ItemIds>
</m:MarkAsJunk>
</soap:Body>
</soap:Envelope>
ItemIds is present in namespace xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages", so you need to use "m:ItemIds".
Please refer the tutorial here for the SOAP request format.

Server was unable to process request.,Object reference not set to an instance of an object. SOAP API

want to push data through soap API, code provided in API documentation is given below. i am getting error. error i am getting. let me know where i am wrong, thanks in advance.
url
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<PushData xmlns="RBSS">
<RBSS>
<Lead_Response_DateTime>20-05-2016 10:25:16</Lead_Response_DateTime>
<Lead_Push_DateTime>20-05-2016 10:25:16</Lead_Push_DateTime>
<Lead_Recd_DataTime>20-05-2016 10:25:16</Lead_Recd_DataTime>
<FirstName>test</FirstName>
<Phone1>9876543215</Phone1>
<Phone2>9876543215</Phone2>
<Email>amrit#gmail.com</Email>
<DOB>20-05-2016</DOB>
<Age>26</Age>
<Child_DOB>20-05-2002</Child_DOB>
<Child_Age>4</Child_Age>
<Pincode>400052</Pincode>
<City_Name>Mumbai</City_Name>
<Address>2, Akshardham…..</Address>
<Annual_Income>1000000</Annual_Income>
<Annual_Income_Slab>10</Annual_Income_Slab>
<SMS_Keyword>0</SMS_Keyword>
<Short_Code></Short_Code>
<Circle_Operator></Circle_Operator>
<Sum_Assured></Sum_Assured>
<Premium_Pitched></Premium_Pitched>
<Company_Name>WRS</Company_Name>
<Website_Name>Bima Deals.com</Website_Name>
<UTN_Source>FaceBook</UTN_Source>
<Lead_Source></Lead_Source>
<Type_Of_Lead></Type_Of_Lead>
<Verification_Type></Verification_Type>
<Product_Name></Product_Name>
<Product_Category></Product_Category>
<No_of_Companies></No_of_Companies>
<Names_of_Companied></Names_of_Companied>
<SMS_Message_Sent></SMS_Message_Sent>
<Customer__Remarks></Customer__Remarks>
<FLAG></FLAG>
<Lead_Type>INCOMING_WEB</Lead_Type>
<Channel_Type>INTERNET</Channel_Type>
<Mode_Type>PREFIXED_APPOINTMENT</Mode_Type>
<Source_Type>BIMADEALS</Source_Type>
<Campaign_Type>APR_16</Campaign_Type>
<Opportunity_Id>123456</Opportunity_Id>
<PROSPECT_ID></PROSPECT_ID>
<Title>MR</Title>
<UID></UID>
<LastName>Lastname</LastName>
<Gender>Male</Gender>
<MaritalStatus></MaritalStatus>
<MobileNo>9865856325</MobileNo>
<AgeAtRetirement></AgeAtRetirement>
<VendorCSE_Name></VendorCSE_Name>
<TermOfPlan></TermOfPlan>
<Smoker_NonSmoker></Smoker_NonSmoker>
<VendorCode></VendorCode>
<MeetingDate></MeetingDate>
<MeetingTime></MeetingTime>
<City_ID>67</City_ID>
<ID>123</ID>
<CallcenterID></CallcenterID>
<ADDLInfo1></ADDLInfo1>
<ADDLInfo2></ADDLInfo2>
</RBSS>
</PushData>
</soap:Body>
</soap:Envelope>

Schema validation error when using Restriction in EWS FindItem request

I'm trying to find items in inbox with ItemClass = IPM.Note
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:wsi="http://ws-i.org/schemas/conformanceClaim/">
<soap:Header>
<t:RequestServerVersion Version="Exchange2010_SP2"></t:RequestServerVersion>
</soap:Header>
<soap:Body>
<FindItem Traversal="Shallow" xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
<ItemShape>
<t:BaseShape xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">IdOnly</t:BaseShape>
<t:AdditionalProperties xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<t:FieldURI FieldURI="item:ItemClass"></t:FieldURI>
</t:AdditionalProperties>
</ItemShape>
<IndexedPageItemView MaxEntriesReturned="50" Offset="0" BasePoint="Beginning"></IndexedPageItemView>
<Restriction>
<IsEqualTo>
<FieldURI FieldURI="item:ItemClass"></FieldURI>
<FieldURIOrConstant>
<Constant Value="IPM.Note"></Constant>
</FieldURIOrConstant>
</IsEqualTo>
</Restriction>
<ParentFolderIds>
<t:DistinguishedFolderId Id="inbox" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"></t:DistinguishedFolderId>
</ParentFolderIds>
</FindItem>
</soap:Body>
</soap:Envelope>
Resulting in this SchemaValidationError
a:ErrorSchemaValidation: The request failed schema validation: The element 'Restriction' in namespace 'http://schemas.microsoft.com/exchange/services/2006/messages' has invalid child element 'IsEqualTo' in namespace 'http://schemas.microsoft.com/exchange/services/2006/messages'. List of possible elements expected: 'SearchExpression' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types'. [undefined] Error: a:ErrorSchemaValidation: The request failed schema validation: The element 'Restriction' in namespace 'http://schemas.microsoft.com/exchange/services/2006/messages' has invalid child element 'IsEqualTo' in namespace 'http://schemas.microsoft.com/exchange/services/2006/messages'. List of possible elements expected: 'SearchExpression' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types'.
To my understaning, SearchExpression is an abstract type that can be replaced with IsEqualTo, among other types.
What am I missing here?
Some of these elements are in the 'types' namespace so they need the t: prefix
<Restriction>
<t:IsEqualTo>
<t:FieldURI FieldURI="item:ItemClass"></t:FieldURI>
<t:FieldURIOrConstant>
<t:Constant Value="IPM.Note"></t:Constant>
</t:FieldURIOrConstant>
</t:IsEqualTo>
</Restriction>

Change HTTP response code in CXF SOAP Fault

I have this error
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Message part {http://soap.ws.server.wst.fit.cvut.cz/}createOrders was not recognized. (Does it exist in service WSDL?)</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
which is completely fine. But the problem is that CXF is returning Internal Server Error (HTTP 500). I would expect it to return 400 Bad Request because a wrong request is causing this. How can I change that?
DETAILS
The wrong request which produces the error above - there should be <soap:createOrder/> instead of <soap:createOrders/>.
POST http://localhost:8080/wst-server-1.0.0/services/soap/order
POST data:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://soap.ws.server.wst.fit.cvut.cz/">
<soapenv:Header/>
<soapenv:Body>
<soap:createOrders/>
</soapenv:Body>
</soapenv:Envelope>
[no cookies]
Request Headers:
Content-Length: 238
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
I know maybe this is too late for the answer but another way to handle HTTP status code is using CXF interceptors.
you can add an interceptor in your server CXF configure
public class ServiceConfigurer implements CxfConfigurer {
#Override
public void configureServer(Server server) {
server.getEndpoint().getOutFaultInterceptors().add(new ChangingStatusCodeInterceptor();
}
}
and in your interceptor, you can change this
public class SaveInfluxDataInterceptor extends WSS4JOutInterceptor {
#Override
public void handleMessage(SoapMessage soapMessage) {
((Fault)exchange.get(Exception.class)).setStatusCode(202); // this is because of soap12OutFaultInterceptor look to this fault
// or you can use this
// exchange.getOutFaultMessage().put(Message.RESPONSE_CODE, 202);
}
}
I used Camel with CXF. maybe this solution should change in yours.