my soap client is making successful request and getting 200 OK from soap server. However, the application is erroring due to missing content-type header. I tried to add content-type header in handler but that is not even invoked (using debugger, I can see that method is never hit for inbound message but for outbound it is hit)
Here is the handler code:
public class ClientHandler implements SOAPHandler<SOAPMessageContext> {
public boolean handleMessage(SOAPMessageContext context) {
if ((Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)) {
System.out.println(" here: in outbound call");
}
if (!(Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)) {
Map<String, List<String>> headers = (Map<String, List<String>>)context.get(MessageContext.HTTP_RESPONSE_HEADERS);
List<String> value = new ArrayList<String>();
value.add("text/xml");
if (headers != null) {
headers.put("content-type", value);
} else {
Map<String, List<String>> brandNewHeaders = new HashMap<String, List<String>>();
brandNewHeaders.put("content-type", value);
context.put(MessageContext.HTTP_RESPONSE_HEADERS, brandNewHeaders);
}
}
return true;
}
Here is how I attach my handler
WSGService service = new WSGService();
appPort = service.getWSGHttpPort();
final Binding binding = ((BindingProvider) provisionPort).getBinding();
BindingProvider bp = (BindingProvider)provisionPort;
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, provisionurl);
List<Handler> handlerList = new ArrayList<>();
handlerList.add(new ClientHandler());
binding.setHandlerChain(handlerList);
Here is the log I get back for a successful call. NOTE empty content-type on response header, which is causing this error.
---[HTTP request - https://foobar/url]---
Accept: [text/xml, multipart/related]
Content-Type: [text/xml; charset=utf-8]
SOAPAction: ["/FOOBARWSG"]
User-Agent: [JAX-WS RI 2.2.4-b01]
<?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body>**BODY**</S:Body></S:Envelope>--------------------
---[HTTP response - https://foobar/url - 200]---
null: [HTTP/1.0 200 OK]
Access-Control-Allow-Headers: [Content-Type, Accept, Accept-Encoding, Content-Encoding, X-Client-UID, Authorization, X-Associated-Id]
Access-Control-Allow-Methods: [GET, POST, PUT, DELETE]
Access-Control-Allow-Origin: [*]
Access-Control-Expose-Headers: [WWW-Authenticate]
Connection: [close]
Content-Length: [2915]
content-type: []
Date: [Tue, 31 Jan 2017 06:24:05 GMT]
Server: [JBOSS Application Server]
X-WsgSource: [DUMMY,15,2017-01-31 06:24:05]
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns></SOAP-ENV:Body></SOAP-ENV:Envelope>--------------------
22:24:07,605 ERROR ErrorPageFilter:180 - Forwarding to error page from request [/dummy/customerType/null] due to exception [Unsupported Content-Type: Supported ones are: [text/xml]]
com.sun.xml.internal.ws.server.UnsupportedMediaException: Unsupported Content-Type: Supported ones are: [text/xml]
EDIT:
with more debugging, I was able to manually change content-type to include "text/xml" in response through intellij debug console and everything behaved as expected
I changed contentType below to "text/xml" which had empty value in it in the HttpTrasportPipe.class
this.checkStatusCode(responseStream, con);
Packet reply = request.createClientResponse((Message)null);
reply.wasTransportSecure = con.isSecure();
if(responseStream != null) {
String contentType = con.getContentType();
if(contentType != null && contentType.contains("text/html") && this.binding instanceof SOAPBinding) {
throw new ClientTransportException(ClientMessages.localizableHTTP_STATUS_CODE(Integer.valueOf(con.statusCode), con.statusMessage));
}
this.codec.decode(responseStream, contentType, reply);
}