Spring ws client parse emtpy tag as space - spring

In my application i requesting soap ws and recieve request with some empty tags.
<tag></tag>
Those tags parsing in " " (space) in java.
Is this normal behavior? Can i make ws client parse empty tags as empty string?

Related

How to prevent of converting header name into lower case - Spring boot?

I am developing a java based web application in spring-boot where I am sending http-header from server to client end.
Server-side I have used Spring-boot in form of REST API, whereas at client end we have simple plain HTML5/Angular framework.
My query is, while I am sending any header from server then at client end I always get it into lowercase vs actual.
For example, I am setting header something like,
header.add("KK-ACTUAL-VALUE", "sfsfjDFFDHTsdfJKKA");
At client end, it gives,
kk-actual-value : "sfsfjDFFDHTsdfJKKA"; (Header name converts into lower case!)
Now, the question is, how to prevent it ?
I want to have the same header name what is actually passed by Server/API.
Looks like tomcat container turns the headers to lowercase. Since spring boot uses an embedded tomcat is been affected by it. More info here: https://github.com/mitre/HTTP-Proxy-Servlet/issues/65
As the Http standard specifies:
Each header field consists of a case-insensitive field name followed
by a colon (":") ...
https://www.rfc-editor.org/rfc/rfc7230#section-3.2
To make the header case-sensitive you can set it to the MultiValueMap, and then pass it as a parameter to the HttpHeaders constructor.
The code snippet can be something like this:
MultiValueMap <String, String> headers = new LinkedMultiValueMap<>();
headers.add("KK-ACTUAL-VALUE", "sfsfjDFFDHTsdfJKKA");
HttpHeaders responseHeaders = new HttpHeaders(headers);

Reach Web Api Action with ampersand in query string

how can I reach my Web Api Actions with ampersand in the query string?
This works:
http://localhost:12345/api/MyController/MyAction?user=test&pw=abc123
This does not:
http://localhost:12345/api/MyController/MyAction?user=test&pw=abc123
Error Message is:
{
"message": "No HTTP resource was found that matches the request URI 'http://localhost:12345/api/MyController/MyAction?user=test&pw=abc123'.",
"messageDetail": "No action was found on the controller 'MyController' that matches the request."
}
I thought Web API would automatically decode the query string parameters but apperently it does not...
When you use & in the query string, you are actually escaping that ampersand so that it gets read as part of that parameter. So the Web API method is actually only receiving one parameter, "user" that has "test&pw=abc123" in it.

How to send Rest GET request that contains "#" value in url parameters?

I'm implementing a spring rest webservice. And when i'm sending a GET request to server using following url, it works fine. But when I'm sending a password with # character, server takes only the characters before the #. How can I send parameter value that contains # character?
authentication/authenticate?type=username&username=someuser&password=pass#2033

How to send message hl7 to Mirth HTTP connector using POST

I have a mirth instance (version 3.0.1) sending out using a POST method to a web api restfull service.
[POST("MessagesHl7/OML_O21")] public HttpResponseMessage
PostOmlo21([FromBody] sting receivedmessage) {..}
The problem is that the message hl7 that is sent to the service
in a outbound message is cut in the first characters. For example, in the message:
MSH|^~\&|CPSI^1.3.6.1.4.1.27248.1.17^ ISO|CGH|...
in the receivedmessage variable the text MSH|^~\ is received only.
How can I do in order that the message is not cut?
In the http channel, the configuration is:POST, not query parameters,
in
headers content-type application/x-www-form-urlencoded,
Content-Type value application/xml,
and the value that send is =${message.encodedData}.
Change your action method to not use binding and just read the request body as string.
[POST("MessagesHl7/OML_O21")]
public Task<HttpResponseMessage> PostOmlo21()
{
string receivedMessage = await Request.Content.ReadAsStringAsync();
}
I would suggest to use Base64 encoding for the HL7 piped message since
there are many special characters within the message which can be interpreted
in the wrong way during parsing. Especially during the parsing of xml.
Of course you have to decode the HL7 message on Server side.
But i think Mirth gives you all functionallity to do that.
I don't know which class to use in C#/ASP in Java appropriate classes and frameworks for
encoding an decoding Base64 exist. I believe the same is true for C# and ASP.

Ajax response having special characters

I am using AJAX for validation. I am using servlet in server side.I am writing in the response as follows
response.setContentType("text/xml");
response.setCharacterEncoding("UTF-8");
response.setHeader("Cache-Control", "no-cache");
response.getWriter().write("123");
The response XMl is coming as invalid if i have any special charcters like ©
,® and soon in IE.
Please let me know how to get the response xml as valid by having the above special characters in it.
Download Apache Commons StringEscapeUtils. It has a function for escaping things like ©

Resources