jax-ws:服务器端不支持的Media Exception内容类型

时间:2017-01-31 06:41:09

标签: java web-services jax-ws

我的soap客户端正在成功请求并从soap服务器获得200 OK。但是,由于缺少内容类型标头,应用程序出错。我试图在处理程序中添加内容类型标头但是甚至没有调用(使用调试器,我可以看到该方法永远不会被入站消息命中,但对于出站它被命中)

这是处理程序代码:

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;

        }

以下是我如何附上我的处理程序

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);

这是我回来成功通话的日志。注意响应标头上的空内容类型,这会导致此错误。

---[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]

修改

通过更多调试,我能够通过intellij调试控制台手动更改内容类型以包含“text / xml”,并且所有内容都按预期运行

我将下面的contentType更改为“text / xml”,其中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);
        }

0 个答案:

没有答案
相关问题