get the exact XML, which is send to Soap Service - spring-boot

from our application we are calling a soap service like below
res = (CreateResponse) JAXBIntrospector.getValue(getWebServiceTemplate()
.marshalSendAndReceive(soapUrl, req, new headers(msgHeader)));
now i want to see the actual request xml which is send to the SOAP url.
soapUrl - target soap url
req - it is an object of a class CreateRequest
msgHeader - it is an object MsgHeader
Because, currently we are getting an error
ns0:MsgErrorCd Description="REQUEST STRUCTURE INVALID"
So the team , which maintains the SOAP service, need the input XML,
Could you pls help me..

in the application.properties file, added the below lines, now the request xml is getting printed in the console.
logging.level.org.springframework.ws.server.MessageTracing.sent=DEBUG
logging.level.org.springframework.ws.client.MessageTracing.received=TRACE
logging.level.org.springframework.ws.server.MessageTracing.received=TRACE

Related

Spring RestTemplate Response string is shorter than expected

I am trying to get an access token via RestTemplate.postForEntity().
myRestTemplate.postForEntity(authBaseUrl, request, Object.class);
I have a specific class for it, but let's use now a simple Object as type. It contains an access_token field.
It works, because I can get response, but the length if the access tokens (which is a string)
is 1196 character long. And I can get the same length in Postman too.
But if I use the intelliJ built-in REST client, the length is 1199.
Only the token from the intelliJ rest client works (So the longer).
Because I always get a new access token, it is impossible to get the same token twice.
How can I debug it?
What could be the problem?
Is the code that generates the response available to you? if so in your response add a header content-length so you can see what the server sent and what you received. Also, debug the server side and see what is being generated. In addition take another 3d party Http client and test it with this client see if you see a difference. The Http clients that you can try are Apache Http client, OK Http client, or my favorite - a very simplistic client written by me as part of my own Open Source MgntUtils library. Here is the Javadoc for my http client Here is a link to a similar question where you can get the references for any of above mentioned Http clients: How to check the status of POST endpoint/url in java

Get Response payload through Datapower gateway script for invalid XML

I'm using IBM API connect & IBM DataPower 2018.
I have a SOAP web service, and I need to do some customized logging for it by capturing the request\response payload.
When the service returns a valid XML, or even SOAP exception, I could easily handle such cases, and save the request\response payload in separate DB schema for operational purposes.
I updated the response payload by returning non XML response from the backend, like "ABCDEFGHI....".
when I call this service through datapower, it returns clear response.
<errorResponse>
<httpCode>400</httpCode>
<httpMessage>Bad Request</httpMessage>
<moreInformation>Invalid XML payload received.</moreInformation>
</errorResponse>
But I am unable to capture the message.body payload which is in my case "ABCDEFGHI..", the apim.getvariable('message.body') returns nothing.
My question:
How to capture the invalid response payload (none well XML) for SOAP service by using Gateway script?
You can't... as the the message will be rejected prior to processing since DataPower will set the message type to SOAP it will reject anything not being SOAP.
You would need to pass it through a "chaining" API (or service on the DataPower instance) which could capture the response payload.

Rest End point not showing any json data when using POSTMAN application

I am trying to implement sample spring boot project and trying to retrieve result using POSTMAN application. But when using POSTMAN , I am not able to see that response for a GET request. But I can see by using browser properly. POSTMAN returning "Expected ':' instead of 't'" as result. But I can see result properly by using browser.
And my controller code is like the following,
#GetMapping("/check")
public List<Users> check() {
return (List<Users>) userObj.findAll();
}
Can anyone help me to find out why I am not able to see result using POSTMAN application please?
You are saying to postman (for that matter any client) that your api is producing json and instead you are returning just a string.
Check your header you will have a field called
Content-Type → application/json;charset=UTF-8
All you need to do is ensure you are sending valid json or remove that header entry so clients do not try to read it as json.
Or just to check you are getting right data by changing format from json to text in postman
You server application needs to understand the incoming request type. can you define the Content-Type=application/json and give a try.

ASP.NET MVC 4 Web Api: POST with unknown or not specified Content-Type

My web api returns the error code 500, if a client POST's some data and not specifying the content-type.
The Error-Message
No MediaTypeFormatter is available to read an object of type
'Document' from content with media type ''undefined''.
show that the server can't find a formatter.
But in this case: "no content-typ or unknown content-type set by the client", the client is responsible for the error - not the server.
Instead of an error code 500, the web api should return somthing like 4XX.
My question is: How can I configure the web api that it will return a status code 400.
An other exapmle is: While content negotiation: If The client sends that he accept XML, but the server cant send XML but JSON, the server sends JSON anyway. In this case the web api should return the status code: 406 Not Acceptable.

How does WCF wrap xml body messages?

I'm running into a problem getting my WCF service to work with other clients.
The ServiceContract looks like this:
[ServiceContract]
public interface IMyService
{
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare,
ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml,
UriTemplate = "/calculation/{accountNumber}")]
string RunCalculations(string returnInformation, string accountNumber);
}
I wrote a simple client to make sure that everything was working, and when I pass in the xml I want, everything works swimmingly.
The problem is that the service exists to expose an interface our product to a third party vendor, who's developing a web interface in php. When he tries to issue the request, he gets a 400 Bad Request error, which, looking through the trace, is caused when WCF tries to parse his xml.
The error message I get is:
Unable to deserialize XML body with root name 'BusinessTaxReturn' and root namespace '' (for operation 'RunCalculations' and contract ('IMyService', 'http://tempuri.org/')) using DataContractSerializer.
Ensure that the type corresponding to the XML is added to the known types collection of the service.
I assume that WCF is wrapping the message that my client sends, and then attempting to unwrap it when the service recieves the message. This leaves me with two questions:
What does WCF wrap XML messages with?
What is the best way to resolve this problem? Should I just have the client wrap their message, or should I really be trying to use a DataContract?
To figure this out, use a HTTP Debugging Proxy like Fiddler to spy on the messages your WCF client sends to the WCF server, and compare these to the messages sent by the PHP app.

Resources