Soap JAX-WS:尝试添加安全头时获取DomeException-HIERARCHY\u REQUEST\u错误
当我试图在发出请求之前向SOAP信封添加安全头时,我遇到了以下异常 尝试检索消息时引发异常(因此context.getMessage()引发异常) 当我使用SoapUI时,一切都按计划进行。我使用JAXB2在客户端和web服务端进行编组 我已经没有主意了…任何帮助都将不胜感激 谢谢 另外,当我在web服务端进行安全检查时,仍然会抛出(并捕获)异常,但是请求通过了,并且收到的响应没有任何问题 这是我的密码:Soap JAX-WS:尝试添加安全头时获取DomeException-HIERARCHY\u REQUEST\u错误,soap,weblogic,jax-ws,Soap,Weblogic,Jax Ws,当我试图在发出请求之前向SOAP信封添加安全头时,我遇到了以下异常 尝试检索消息时引发异常(因此context.getMessage()引发异常) 当我使用SoapUI时,一切都按计划进行。我使用JAXB2在客户端和web服务端进行编组 我已经没有主意了…任何帮助都将不胜感激 谢谢 另外,当我在web服务端进行安全检查时,仍然会抛出(并捕获)异常,但是请求通过了,并且收到的响应没有任何问题 这是我的密码: public class SoapSecurityHandler implements
public class SoapSecurityHandler implements SOAPHandler {
private static Logger logger = Logger.getLogger(SoapSecurityHandler.class);
private final String clntUserName = "my_username";
private final String clntPassword = "my_password";
public boolean handleMessage(SOAPMessageContext context) {
logger.info("Enter handleMessage()");
Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outboundProperty.booleanValue()) {
try {
logger.info("Getting the message");
SOAPMessage message = context.getMessage();
logger.info("Getting the soappart");
SOAPPart soapPart = message.getSOAPPart();
logger.info("Getting the envelope");
SOAPEnvelope envelope = soapPart.getEnvelope();
logger.info("Getting the factory");
SOAPFactory factory = SOAPFactory.newInstance();
logger.info("Got the factory");
QName name = new QName(
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
"Security", "wsse");
SOAPElement securityHeader = factory.createElement(name);
SOAPElement usernameTokenElement = securityHeader.addChildElement("UsernameToken");
SOAPElement usernameElement = usernameTokenElement.addChildElement("Username");
usernameElement.addTextNode(clntUserName);
SOAPElement pwdElement = usernameTokenElement.addChildElement("Password");
pwdElement.addTextNode(clntPassword);
logger.info("Added the username and password to the usernameToken element");
SOAPHeader header = envelope.addHeader();
logger.info("Added the header to the envelope");
header.addChildElement(securityHeader);
logger.info("Added the security header to the header");
} catch (Exception e) {
logger.error("Exception in handler: " + e);
e.printStackTrace();
}
} else {
logger.info("This is an inbound message");
}
logger.info("Exit handleMessage()");
return true;
}
public boolean handleFault(SOAPMessageContext context) {
return false;
}
public void close(MessageContext context) {
//
}
public Set getHeaders() {
return new HashSet();
}
}
好的,经过多次尝试和错误后,我在pom.xml中添加了以下内容来解决这个问题:
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-jaxws</artifactId>
<version>1.5.4</version>
</dependency>
org.apache.axis2
axis2 jaxws
1.5.4
Weblogic使用的是自己的impl jar,它们总是过时的
以下是我的pom.xml文件中的所有axis2声明:
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2</artifactId>
<version>1.5.4</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-kernel</artifactId>
<version>1.5.4</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-local</artifactId>
<version>1.5.4</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-http</artifactId>
<version>1.5.4</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-jaxws</artifactId>
<version>1.5.4</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-api</artifactId>
<version>1.2.10</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-impl</artifactId>
<version>1.2.10</version>
</dependency>
org.apache.axis2
axis2
1.5.4
org.apache.axis2
axis2内核
1.5.4
org.apache.axis2
axis2本地传输
1.5.4
org.apache.axis2
axis2传输http
1.5.4
org.apache.axis2
axis2 jaxws
1.5.4
org.apache.ws.commons.axiom
axiom api
1.2.10
org.apache.ws.commons.axiom
简化公理
1.2.10
从我的类路径中删除axis2-jaxws-1.6.2.jar文件后,我收到了相同的错误
实际上,axis2-jaxws-1.6.2.jar导致了另一个错误,因此我无法将其放回原处并寻找另一个解决方案。最后,我还通过从类路径中删除axis2-saaj-1.6.2.jar来修复这个错误
删除axis2-saaj-1.6.2.jar禁止使用org.apache.axis2.saaj.SoapPartImpl而不是com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPPart1_1mpl作为抽象类javax.xml.soap.SoapPart的扩展
这就解决了我的问题。顺便说一句,这是我发现的帖子,它和我做的事情一样,但没有任何问题。也许这是与weblogic的jar冲突?我以前对“jar优先级”有问题。对不起,忘了包含链接:很抱歉恢复一篇旧文章,但是您是否有可能仍然可以访问新的stacktrace,以便我可以看到需要替换哪些确切的Impl类?我没有将“axiom dom”列为依赖项。需要吗
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2</artifactId>
<version>1.5.4</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-kernel</artifactId>
<version>1.5.4</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-local</artifactId>
<version>1.5.4</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-http</artifactId>
<version>1.5.4</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-jaxws</artifactId>
<version>1.5.4</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-api</artifactId>
<version>1.2.10</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-impl</artifactId>
<version>1.2.10</version>
</dependency>