[英]Problem with passing SOAP headers using Apache CXF client
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
: http://myserver3333.com:8080/ws/services
: http://myserver3333.com:8080/ws/services
/ws/services和您查找Web服务的方式部署是通过SOAP标头进行的。
So, for example, if you try to hit the service vis SOAP UI, 因此,例如,如果您尝试通过SOAP UI访问服务,
http://myserver3333.com:8080/ws/services
http://myserver3333.com:8080/ws/services
: http://myserver3333.com:8080/ws/services
: http://myserver3333.com:8080/ws/services
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获得两点后,我在这里:
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 this one. 我的假设是,这个错误是一样的这一个。 But I am not using ?wsdl.
但是我没有使用?wsdl。 So, any suggestions?
那么,有什么建议吗?
2 comments: 2条评论:
1) You aren't picking up CXF. 1)您没有接CXF。 Check your classpath to make sure CXF is there and not the Sun/Oracle implementation.
检查您的类路径以确保存在CXF,而不是Sun / Oracle实现。 com.sun.xml.ws.wsdl.parser.InaccessibleWSDLException shows you are picking up the Sun implementation.
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,而不是端点本身。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.