Java – Jax WS changes the content type to content type because the server is super sensitive

I have to connect to a poorly executed server that can only understand content type (capital-t), not content type How do I get my jax-ws client to send content type?

I tried:

Map<String,List<String>> headers = (Map<String,List<String>>)
((BindingProvider)port).getRequestContext().get(MessageContext.HTTP_Request_HEADERS);

But the title is empty What on earth did I do wrong?

Solution

I dig more into this question. Sadly, I'm afraid the answer is: you can't Let me share my findings

First, you will https://jax-ws.dev.java.net/guide/HTTP_headers.html The code found in does not access the HTTP header of future HTTP requests (which has not been created at this time). It allows you to set other HTTP headers to make the request (which will be added to the HTTP request)

So don't expect the following code not to return null if you don't put anything (in fact, you'll only get where you put it):

((BindingProvider)port).getRequestContext().get(MessageContext.HTTP_Request_HEADERS);

Then I did some tests based on the code provided in the same link:

AddNumbersImplService service = new AddNumbersImplService();
AddNumbersImpl port = service.getAddNumbersImplPort();

((BindingProvider)port).getRequestContext().put(MessageContext.HTTP_Request_HEADERS,Collections.singletonMap("X-Client-Version",Collections.singletonList("1.0-RC")));

port.addNumbers(3,5);

This is what I see in the HTTP request when I run the client code:

POST /q2372336/addnumbers HTTP/1.1
Content-type: text/xml;charset="utf-8"
X-client-version: 1.0-RC
Soapaction: ""
Accept: text/xml,multipart/related,text/html,image/gif,image/jpeg,*; q=.2,*/*; q=.2
User-Agent: JAX-WS RI 2.1.6 in JDK 6
Host: localhost:8080
Connection: keep-alive
Content-Length: 249

You notice the difference: only the first character of the x-client-version header file is retained above, and the rest is reduced!

In fact, if you examine the class c.s.x.w.t. used to represent HTTP request (and response) headers Headers, it will be "normalized (string)" when added:

/* Normalize the key by converting to following form.
 * First char upper case,rest lower case.
 * key is presumed to be ASCII 
 */
 private String normalize (String key) {
     ...
 }

So, although c.s.x.w.t h. C. httptransportpipe class (I understand that this is where the HTTP request is created, and this is where the previously added header will be added to the HTTP request header). In fact, "content type" is added as the keyword in the "c.s.x.w.t.headers" instance. Due to the implementation details mentioned above, the key will be modified

I may be wrong, but I can't see what can be changed without patching the code Strangely, I don't think this "normalized" thing is in line with the RFC (I didn't check which RFCs said about the title) I was surprised Actually, you should be raise an issue

So I see three options here (because waiting for repair may not be an option):

>Patch the code yourself and rebuild the jax-ws RI (with all the drawbacks of this approach). > Try another Jax - WS implementation for your client, such as CFX. > Let the request modify the title immediately through some custom agent

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>