Creating SOAP Error responses - exception

I am creating a Web Service that internal client at my company will be calling. The service methods look like the following:
CreateProposalResponse ProposalSOAService::CreateProposal( CreateProposalRequest )
For the CreateProposalResponse message I need to add business Error Messages into the response. I've been reading a lot about putting errors into the SOAP Headers, but for business errors I don't feel that this is the appropriate place to put them because you this should be system/transport/validation kinds of errors not business Errors. Below is my response XML for the CreateProposal() SOA call. Can someone advice me on how to add Error messages to this response? I am having a hard time envisioning this and how the calling clients would determine the difference from a normal response and a business error/exception.
My CreateProposalResponse Message looks like the following:
<?xml version="1.0" encoding="UTF-8" ?>
<CreateProposalResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.xxx.com/aces/proposal src/Proposal_v1.0.xsd"
xmlns="http://xmlns.raytheon.com/aces/proposal">
<userId>022483</userId>
<Proposal>
<proposalTitle>SBT Prop</proposalTitle>
<proposalDescription>Proposal is for SBT</proposalDescription>
<businessSegmentCode>SAS</businessSegmentCode>
<proposalType>Test</proposalType>
<proposalExternalRefID>SBT38829</proposalExternalRefID>
<proposalStartDate>2009-01-01</proposalStartDate>
<proposalEndDate>2025-01-01</proposalEndDate>
</Proposal>
<sourceSystemID>SBT</sourceSystemID>
<targetSystemID>ACES</targetSystemID>
</CreateProposalResponse>

I agree with Aasmund Eldhuset unless these errors are an indication that the operation has failed. In that case, you should use a SOAP Fault.

How about simply having an <errors> array element as an optional element in your message, and populate it with one or more <error> elements describing the error(s)? Then, you could specify that a response message will either contain a populated <errors> element (along with other metadata elements that might be desirable even in the face of an error; perhaps <sourceSystemID> and <targetSystemID> are such elements?) but no <Proposal>, or it will not contain a <Proposal> but no <errors> (or the element will be empty).
(By the way, I agree that business errors should be indicated in the message body, not as SOAP errors.)

Related

Mule ESB - Catch Exception Strategy block and Payload

Mule documentation states that catch-exception-strategy is similar to java catch block. But unfortunately, the payload is consumed (message is consumed); from the catch block the payload is lost (unlike a java method where you can access the method input parameters from a catch/finally block).
The problem with this design is that at any instance, (from the catch strategy flow) it is impossible to know the error and last known enriched payload which was used (which caused the error?). This complicates auditing of data which caused the error.
Suppose if there is a flow with 10 message processors, it becomes tedious to identify the message processor which threw error.
I can see 2 workarounds regarding the payload:
1) After the inbound endpoint, push the payload to a flow variable before every message processor (again another disadvantage is what happens to the Inbound properties and attachments?)
2) Use Rollback exception strategy with zero attempts (the transaction will be rolled back), and original input message may be available. (drawback: it is difficult to introspect on why the error happend and on which message processor - example: I may have 5 or 6 DB processors)
The reason why this becomes important is supporting an ESB application in production becomes easier.
For example, from the catch-block if we are able to pipe the payload and exception details (linked to a single UID), then you can run a log monitor tool, push it to a real time dashboard for monitoring purpose/raise Alerts. The same approach can be uniformly applied to all the applications/flows and java components, etc.
MMC is weak in this area - for example, if you want to supress Alerts from a batch job after 5 occurrences, MMC cannot do it.
My questions are:
1) Is there any reason on why the payload is made unavailable?
Possible workaround is to push (last known data) to another variable as part of message called originalPayload or originalInboundProperties?
2) Any other straight forward way of piping the exception and payload to an appender (instead of workarounds)?
Ananth Krishnan (WHISHWORKS.com)

JAX-WS adds namespace in Signature of token

I am accessing a third party web service using JAX-WS generated client (Java) code.
A call to a service that initiates a client session returns a Token in the response which, a.o., contains a Signature. The Token is required in subsequent calls to other services for authentication purposes.
I learned from using SoapUI that the WS/Endpoint requires the Token to be used as-is... meaning everything works fine when I literally copy the Token (which is one big line) from the initial response to whatever request I like to make next.
Now I am doing the same in my JAX-WS client. I retrieved a Token (I copied it from the response which I captured with Fiddler) and I tested it succesfully in a subsequent call using SoapUI.
However, when performing a subsequent call to a service using the JAX-WS client, the Signature part in the Token is changed. It should look like:
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">...</Signature>
But (when capturing the request with Fiddler) it now looks like:
<Signature:Signature xmlns:Signature="http://www.w3.org/2000/09/xmldsig#" xmlns="http://www.w3.org/2000/09/xmldsig#">...</Signature:Signature>
Apparently this is not acceptable according to the WS/Endpoint so now I'd like to know:
Why is the Token marshalled back this way?
More importantly, how can I prevent my client from doing that?
Thanks in advance!
Have you tested it? It should work nevertheless. The original signature used the defautl namespace (...xmldigsig) the JAXB version uses the same namespace but explicit says that the Signature element belongs to that namespae (Signature:Signature). The effect is the same, both xml express that Signature is in the http://www.w3.org/2000/09/xmldsig# namespace
You can customize the jaxby output with #XMLSchema on the package info, #XMLType on the class or inside the element.
http://blog.bdoughan.com/2010/08/jaxb-namespaces.html
By the help of #Zielu I was able to solve this by altering package-info.java (in the package of the generated files) like so:
#javax.xml.bind.annotation.XmlSchema(
namespace = "http://namespaceofthirdparty-asingeneratedversionof package-info.java"
, xmlns = {
#javax.xml.bind.annotation.XmlNs(namespaceURI = "http://www.w3.org/2000/09/xmldsig#", prefix = "")
}
, elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) package com.where.generated.files.are;

Custom page or action on "XML Parsing Error"

Question
Is there any possibility to tell browser via HTTP header or html code what to do when XML Parsing Error occurs? Like maybe X-OnXmlParsingError, <meta name="onXmlParsingError" href="http://example.com"/> etc.
Additional info
Some more info: I generate XHTML code send to browser with application/xhtml+xml header. So, when something is wrong with my xhtml code, the browser instead of my beautiful webpage shows XML Parsing Error - and that is expected behavior. But I want to change it, and tell every browser what to do, when this error occurs. For example redirect to custom page that is well-malformed-for-sure with some friendly message.
I know I can parse the output code on server side, but I don't want this. It's highly inefficient and probability of unwell malformed code is... almost 0, but still.
Browsers
Opera
hides the problem:
(...) we've decided to stop throwing draconian XML parsing failed error messages, and instead, attempt to reparse the document automatically as HTML. Instead of showing an error message in the browser, it's now dumped to the console, so as a developer, you can still find XML parsing error warnings in Opera Dragonfly and the Error Console if you want to.
Firefox
generates
<parserror>(...)</parseerror>
instead of normal html, so it's easy to detect the error by document.documentElement === 'html'.
Server-side workaround
Besides the question requirements, the fastest (2500 checks in 1 sec, T4200 # 2.00Ghz) PHP validator I found is:
<?php
// returns 1 on success and 0 on failure
xml_parse(xml_parser_create(), $stringWithHtmlCode) == 1
I strongly recommend to read the comments under the accepted answer.
Why not retrieve the XHTML via an XMLHttpRequest (or early IE fallback), and check your ability to request xmlhttp.resposeXML. If doing so throws an exception or returns null, redirect to your error page. Otherwise, rewrite the document using window.onload = function() { document.write(xmlhttp.responseText); };

invalid xml request for calculator service

I'm completely new to axis2c and I've just downloaded and unpacked
axis2c 1.6 for Windows (binary release).
I've followed the installation instructions and have successfully
started axis2_http_server.
Trying to access the Calculator service's WSDL works fine but any call to
the service's add method returns "invalid XML in request" as well as the
same text is shown in the console window where axis2_http_server is
running.
I've also tried soapUI. The request shown is:
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:typ="http://ws.apache.org/axis2/services/Calculator/types">
<soapenv:Header/>
<soapenv:Body>
<typ:add>
<param_1>1.0</param_1>
<param_2>1.0</param_2>
</typ:add>
The response is
<soapenv:Fault>
<faultcode>soapenv:Sender</faultcode>
<faultstring>Invalid XML format in request</faultstring>
</soapenv:Fault>
The problem is issued in in calc.c (function axis2_calc_add()), where
seq_node = axiom_node_get_first_child(complex_node, env);
returns NULL.
Calculator service example has multiple issues that prevents it to work.
Firstly, implementation of add operation is invalid, it expects request like that (here is only contents of soap body):
<typ:add>
<complex_node>
<seq_node>
<param_1>1</param_1>
<param_2>2</param_2>
</seq_node>
</complex_node>
</typ:add>
Looks like someone committed that code by mistake.
Secondly, code that is implemented in Calculator service does not allow to have whitespaces between request elements. It takes any first node hoping it is an element, but fails, because takes text node between elements.
To start that example without modification of the service:
use one of sub, div, mul operations.
remove all whitespaces in request element like that:
<typ:sub><param_1>3</param_1><param_2>2</param_2></typ:sub>
Then you will be able to call the service.
If you want to see fully working Calculator service, you can compile Axis2/C from axis2-unofficial project (or install it from binary archive).
Or, you can apply that changes to the original source code and recompile it.

What is the best way to make a configurable text elements for HTML5 App

I am doing a HTML5 app. Everything works well. The client suddenly requested that he needs to change error messages and text labels as he wish after completing the code, but without touching the HTML5. So I got two solutions in to my mind.
1 Use javascript variables
// Error Messages
var msg_authentication_failed = "The username or password is invalid. Please try again";
and use this variable as I wanted.
2 Use XML file (Or JSON)
<?xml version="1.0" encoding="ISO-8859-1"?>
<ErrorMessages>
<AuthenticationFail>The username or password is invalid. Please try again</AuthenticationFail>
</ErrorMessages>
Load XML file and set values using it's tag names.
However I feel that the 2nd solution is easy to maintain by the client but performance wise it's not good.
Is there any other possible way to get done this kind of requirement? Appreciate your suggestions.
I'm running a jQuery Mobile project which supports around 6 languages (from Europe) and what I did was simply maintaining the labels in a JSON string.
using the event pagebeforeshow I update the labels when showing form element's labels. If it is an error message, I wrote a custom function that can access the string based on the labelID.
More than XML, JSON is extremely easy to handle. I would suggest you to go ahead with it.