How to test a soap endpoint that returns soapfaultclientexception - citrus-framework

I have a soap endpoint that returns fault message when passing some parameters. I need to validate the fault string and pass the test when fault string is returned.
runner.soap(action -> action
.client(testClient)
.receive()
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.validate("/t:soap:Fault/t:faultcode", "test"));
This above code gives me a soapfaultclientexception. I couldn't pass this test. Any idea.

Please use fault strategy=propagate on the soap client configuration. By default it uses throwException strategy. This is why you get the exception.
With propagate you should be able to verify the fault in a receive action.
Please refer to the documentation for the details.

Related

define a response for a REST Api on a validation endpoint

I struggle to find the good way to respect the REST principle for an http endpoint:
I should define an endpoint who will check that a complex form object fill a few conditions and return the list of the unfilled conditions. (no change in the database will be produce by the endpoint ). Basically it's a validator
POST .../myComplexForm/validate-myvalidationCase
Request: myComplexForm{field1: int, field2:int ....}
Response : ??????
What is the proper way to define this response-bject respecting REST ?
The endpoint can find in the object more than one error and should return all of them, not just one ( It's not a validation field by field. More a "you are not allowed to have more than XXX if it's Sunday and you are YYYY)
What should the endpoint return?
a list of error?
Throw an http exception containing the list of error?
A response object with a
field by error? then what will be the http code?
Thanks !
If the purpose of the endpoint is to receive any object, and return whether the object was valid or not, then in my opinion sending an invalid object is not really an error.
An error should tell a client, 'you should stop doing that', or 'you should change something about your request and try again', but in this case the explicit purpose is to also report invalid sates.
So if the object was invalid, I would still probably return a 200 OK. I don't really have an opinion on what format your result should be, as it depends on what the goal is of this feature. You should return what the client needs.

Intercept/Callback for QuickFIX message

I am using a FIX protocol to communicate with one of our counterparties. I have used Camel with Spring to build my communication routes.
I have a requirement where in my counterparty is expecting an ACK for every request it sends to me.
For example:
TradeCaptureRequestAck in response to TradeCaptureRequest
AllocationReportAck in response to AllocationReport
Confirmation_Ack in response to Confirmation
They are expecting a response irrespective of what happens at our end (even if something fails or exception occurs).
One way I know we can intercept the incoming message via MessageFactory. We can create a custom messagefactory and inject it in while creating QuickFixJComponent bean.
Problem with this approach is at factory level I will just be able to get the message type like TradeCaptureReport, AllocationReport etc. but not the content because factory only creates (and returns) the appropriate Message object. Actual work of populating this message object with incoming message data happens in Session class I guess (not sure about this).
Can someone please tell me if there is a way I can get or intercept the request message as soon as it reaches the route so that I can send the appropriate ACK to counterparty?

How to get ResponseEntity body in spring-integration

I am using xml based configuration - http outbound gateway to trii=gger a rest service, the response is ResponseEntity and I dont know that service details. The output I receive should be put in a JMS Queue.
How can I update the below to extract only the body of response entity and pass to output-channel? If there is a transformer, please give example. Is it possible using config?
<int:chain input-channel="gsInChannel" output-channel="dest-channel">
<int-http:outbound-gateway
url="https://ia-zatie.str13.tst.belst.nu/ia-zaatie/rest/signal/v2"
http-method="POST"
header-mapper="headerMapper"
request-factory="sslFactory"
>
</int-http:outbound-gateway>
</int:chain>
dest-channel is jms:outbound-channel-adapter
boot version 1.4.3 and integration version 4.3.6
Error: org.springframework.messaging.MessageHandlingException: error
occurred in message handler
[org.springframework.integration.jms.JmsSendingMessageHandler#0];
nested exception is
org.springframework.jms.support.converter.MessageConversionException:
Cannot convert object of type
[org.springframework.http.ResponseEntity] to JMS message. Supported
message payloads are: String, byte array, Map, Serializable
object.
I was using HTTP POST method and so not expecting, a response. SoO has not included expected-response-type, which returns the body
<int-http:outbound-gateway
url="https://ia-zatie.str13.tst.belst.nu/ia-zaatie/rest/signal/v2"
http-method="POST"
header-mapper="headerMapper"
request-factory="sslFactory"
expected-response-type="java.lang.String">

Proper way to convey error messages during calls to a REST service?

I'm writing a REST based web service, and I'm trying to figure out the best way to handle error conditions.
Currently the service is returning HTTP Errors, such as Bad Request, but how can I return extra information to give developers using the web service an idea what they're doing wrong?
For example: creating a user with a null username returns an error of Bad Request. How can I add that the error was caused by a null username parameter?
According to the HTTP spec, the text that comes after the three digit response code, the "Reason-Phrase", can only be replaced with a logical equivalent. So you can't respond with 400 null user and expect anything useful to happen. Indeed, The client is not required to examine or display the Reason- Phrase.
In general, the HTTP response entity (typically the page that accompanies the response) should contain information useful to the client to guide them forward, even when the response is an error. On the web, most such errors are HTML, and are devoid of machine readable information, but most browsers do show the error to the user (and SO's error page is pretty good!).
So for a primarily machine readable resource you have two options:
Pass a human readable message anyway. Return 400 Bad Request with a HTML response, which the client may opt to show to the user. It's dead easy but it's a bit like throwing an unchecked exception, it passes all the hard work to the client, or indeed the end user.
Allow clients to recover. Return 400 Bad Request with a machine readable response which is part of your API, so clients can recover from known error conditions. This is harder, like throwing a checked exception, it becomes part of the API, and it allows clients to recover gracefully if they want to.
You could even make the server support both scenarios by defining a media type for the machie readable error recovery document, and allow clients to "accept" them: Accept: application/atom+xml, application/my.proprietary.errors+json
Clients that forget the mandatory field can opt in to getting machine readable errors or human readable errors by choosing to Accepting the error media type.
It's stated in the HTTP spec that most error codes should return some basic text that gives a clarification of why the error is being returned. The basic Java Servlet Spec defines the HttpServletResponse.sendError(int Code, String message) for this purpose.
String desc = "my Description";
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(desc).type("text/plain").build());

BizTalk 2006 SOAP Adapter - Messaging only Web Service Call

In BizTalk 2006, I am trying to set up a messaging-only scenario whereby the recieved message (a string) is passed to a web service method that takes a single string parameter. In other words, the whole body of the BizTalk message should be passed as the parameter to the web service call.
The service method looks like this:
[WebMethod]
public void LogAuditEvent(string auditEventMessage)
I have set up the assembly with the proxy class in the SOAP adapter configuration as required, but I can't figure out how to get the message body to be passed as the parameter. Without doing anything special, I get the following error message:
Failed to serialize the message part
"auditEventMessage" into the type
"String" using namespace "".
I think this means that the adapter cannot find a message part named after the parameter. So, my question is what do I need to do to get my message set up correctly? I was thinking that maybe I needed to add an outbound map, but was not sure what to use as the source schema and how to generate a proper schema for the web service request message.
Does anyone have any pointers on this seemingly simple task?
Thanks.
TDL,
I would take a look at the links below for some tips on how to do this. SOAP adapter can be problematic I would recommend WCF if your using R2. And if not look at the WSE adapters as well.
http://blogs.digitaldeposit.net/saravana/post/2007/01/31/Calling-Web-Service-from-BizTalk-2006-in-a-Messaging-only-Scenario-(aka-Content-based-Routing).aspx
-and-
http://www.pluralsight.com/community/blogs/aaron/archive/2005/10/07/15386.aspx
-and-
http://social.technet.microsoft.com/Forums/en-US/biztalkgeneral/thread/92f2cad3-39b9-47d0-9e6f-011ccd2f9e10/
-Bryan