问题描述
我尝试在java 7中使用客户端访问Web服务。我得到它:
I try to client to web service in java 7. I get it:
警告:表示消息寻址属性的必需标头不存在,问题标题: {}行动
com.sun.xml.internal.ws.addressing.model.MissingAddressingHeaderException:缺少WS-Addressing标题:{}行动
WARNING: A required header representing a Message Addressing Property is not present, Problem header:{http://www.w3.org/2005/08/addressing}Actioncom.sun.xml.internal.ws.addressing.model.MissingAddressingHeaderException: Missing WS-Addressing header: "{http://www.w3.org/2005/08/addressing}Action"
如何解决此错误?
非常感谢。
- Web服务安全性类似于SOAPUI中的以下部分 -
--web service security looks like following parts in SOAPUI--
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-1">
<wsse:Username>gelistirici</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">gelistirme12</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">NT357!!_</wsse:Nonce>
<wsu:Created>2016-05-07T11:57:03.821Z</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
- 网络服务界面 -
--Web Service Interface--
@WebMethod(action = "getRequestDetail")
@WebResult(name = "requestDetail", targetNamespace = "")
@RequestWrapper(localName = "getRequestDetail", targetNamespace = "http://xmlns.oracle.com/scheduler", className = "tr.com.service.soap.client.oracle.ess.beans.GetRequestDetail")
@ResponseWrapper(localName = "getRequestDetailResponse", targetNamespace = "http://xmlns.oracle.com/scheduler", className = "tr.com.service.soap.client.oracle.ess.beans.GetRequestDetailResponse")
public RequestDetail getRequestDetail(
@WebParam(name = "requestId", targetNamespace = "http://xmlns.oracle.com/scheduler")
long requestId)
throws NotFoundException_Exception, RuntimeServiceException_Exception;
- 网络服务客户端的java代码 -
--java code for web service client--
ESSWebService_Service service = new ESSWebService_Service();
ESSWebService port = service.getSchedulerServiceImplPort();
BindingProvider provider = BindingProvider.class.cast(port);
provider.getRequestContext().put("UsernameToken", "UsernameToken-1");
provider.getRequestContext().put("Username", "gelistirici");
provider.getRequestContext().put("Password", "gelistirme12");
provider.getRequestContext().put("Nonce", "NT357!!_");
provider.getRequestContext().put("Created", "2016-05-07T11:57:03.821Z");
RequestDetail requestDetail = port.getRequestDetail(37);
推荐答案
我收到此错误:代表一个必需的标题消息寻址属性不存在。在这种情况下要做的事情:将上面的部分添加到实现< SOAPHandler< SOAPMessageContext>
I get this error: "A required header representing a Message Addressing Property is not present" . Things to do in this case: add above part to class that implement <SOAPHandler<SOAPMessageContext>
@Override
public Set<QName> getHeaders() {
Set<QName> set = new HashSet<QName>();
set.add(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing", "Action"));
return set;
}
和(如果你已经写过)删除标题元素(Action,ReplyTo,To ,MessageID)
and (if you have written) delete header elements(Action, ReplyTo, To, MessageID)
SOAPHeaderElement actionElement = header.addHeaderElement(new QName("http://www.w3.org/2005/08/addressing", "Action"));
actionElement.setMustUnderstand(true);
String action = (String) messageContext.get("javax.xml.ws.soap.http.soapaction.uri");
actionElement.addTextNode(action);
SOAPHeaderElement replyToElement = header.addHeaderElement(new QName("http://www.w3.org/2005/08/addressing", "ReplyTo"));
SOAPElement addressElement = replyToElement.addChildElement(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing","Address"));
addressElement.addTextNode("http://www.w3.org/2005/08/addressing/anonymous");
SOAPHeaderElement toElement = header.addHeaderElement(new QName("http://www.w3.org/2005/08/addressing", "To"));
toElement.setMustUnderstand(true);
String endpoint = (String) messageContext.get("javax.xml.ws.service.endpoint.address");
toElement.addTextNode(endpoint);
SOAPHeaderElement messageIdElement = header.addHeaderElement(new QName("http://www.w3.org/2005/08/addressing", "MessageID"));
messageIdElement.addTextNode("uuid:" +UUID.randomUUID().toString());
这篇关于Java-Missing WS-Addressing标题:“{http://www.w3.org/2005/08/addressing} Action”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!