java 使用 Apache CXF 客户端传递 SOAP 标头的问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7410275/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Problem with passing SOAP headers using Apache CXF client
提问by zengr
I am trying to implement a simple client for a webservice, the only problem I am facing with the webservice is, it has a generic endpoint: http://myserver3333.com:8080/ws/services
and the way you lookup for web services deployed is via SOAP header.
我正在尝试为 web 服务实现一个简单的客户端,我面临的 web 服务的唯一问题是,它有一个通用端点:http://myserver3333.com:8080/ws/services
并且您查找部署的 web 服务的方式是通过 SOAP 标头。
So, for example, if you try to hit the service vis SOAP UI,
因此,例如,如果您尝试通过 SOAP UI 访问服务,
- the endpoint I specify is:
http://myserver3333.com:8080/ws/services
- In the SOAP headers I specific the following:
SERVICE-NAME = MyAwesomeService
OPERATION-NAME = makeMeMoreAwesome
- 我指定的端点是:
http://myserver3333.com:8080/ws/services
- 在 SOAP 标头中,我指定了以下内容:
SERVICE-NAME = MyAwesomeService
OPERATION-NAME = makeMeMoreAwesome
So, how can I do the same thing using apache cxf client?
那么,如何使用 apache cxf 客户端做同样的事情呢?
My current code:
我目前的代码:
URL wsdlLocation = new URL("http://myserver3333.com:8080/ws/service");
MyAwesomeService service = new MyAwesomeService(wsdlLocation);
MyAwesomeServicePort port = service.getMyAwesomeServiceSOAPPort();
List<Header> headers = new ArrayList<Header>();
Header operationNameHeader = new Header(new QName("OPERATION-NAME"), "makeMeMoreAwesome",
new JAXBDataBinding(String.class));
Header serviceNameHeader = new Header(new QName("SERVICE-NAME"), "MyAwesomeService",
new JAXBDataBinding(String.class));
headers.add(operationNameHeader);
headers.add(serviceNameHeader);
BindingProvider bindingProvider = (BindingProvider)port;
bindingProvider.getRequestContext().put(Header.HEADER_LIST, headers);
MakeMeMoreAwesomeRequest request = new MakeMeMoreAwesomeRequest();
MakeMeMoreAwesomeResponse response = port.makeMeMoreAwesome(request);
System.out.println(response.getAck());
But when I run this, I get this error:
但是当我运行这个时,我收到这个错误:
Exception in thread "main" com.sun.xml.ws.wsdl.parser.InaccessibleWSDLException: 2 counts of InaccessibleWSDLException.
java.io.IOException: Server returned HTTP response code: 500 for URL: http://myserver3333.com:8080/ws/services
java.io.IOException: Server returned HTTP response code: 500 for URL: http://myserver3333.com:8080/ws/services?wsdl
Which is correct because there is no WSDL at that location, it need to follow the soap header to get the service.
这是正确的,因为在那个位置没有 WSDL,它需要遵循soap 头来获取服务。
Update:
更新:
After two points from @Daniel Kulp I am here:
在@Daniel Kulp 提出两点之后,我来了:
- I added a new line:
bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://myserver3333.com:8080/ws/services");
- 我添加了一个新行:
bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://myserver3333.com:8080/ws/services");
And now I get this error:
现在我收到这个错误:
org.apache.cxf.binding.soap.SoapFault: "http://www.myserver.com/ws/services", the namespace on the "errorMessage" element, is not a valid SOAP version.
at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.readVersion(ReadHeadersInterceptor.java:115)
at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:141)
at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:60)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:771)
My assumption is, this error is same as thisone. But I am not using ?wsdl. So, any suggestions?
我的假设是,这个错误是一样的这一个。但我没有使用 ?wsdl。那么,有什么建议吗?
采纳答案by Daniel Kulp
2 comments:
2 条评论:
1) You aren't picking up CXF. Check your classpath to make sure CXF is there and not the Sun/Oracle implementation. com.sun.xml.ws.wsdl.parser.InaccessibleWSDLException shows you are picking up the Sun implementation.
1) 你没有拿起 CXF。检查您的类路径以确保存在 CXF 而不是 Sun/Oracle 实现。com.sun.xml.ws.wsdl.parser.InaccessibleWSDLException 表明您正在选择 Sun 实现。
2) The URL passed into MyAwesomeService(wsdlLocation) MUST be a URL to the WSDL, not the endpoint itself.
2) 传入 MyAwesomeService(wsdlLocation) 的 URL 必须是 WSDL 的 URL,而不是端点本身。