从soap标头中删除mustUnderstand属性

发布于 2024-12-05 05:58:27 字数 158 浏览 0 评论 0 原文

如何从轴客户端中的soap标头中删除mustunderstand属性。即使我没有特别设置它,当我设置soap标头信息mustundertand时,actor属性会自动添加到soap消息中。有人知道如何删除它们吗? 我正在使用 Axis2 1.4 版本的 wsdl2java 来创建我的 ws 客户端。

How to remove mustunderstand attribute from soap header in axis client.even i dont set it especially, when i set soap header info mustundertand and actor attributes are automatically added to soap message.Does anybody know how to remove them ?
I am using Axis2 1.4 version's wsdl2java to create my ws client.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

瘫痪情歌 2024-12-12 05:58:27

这些解决方案都不适合我,因为:

查看“将 ws-security 添加到 wsdl2java 生成的类的答案”帮助我编写了一个适合我的解决方案:

void addSecurityHeader(Stub stub, final String username, final String password) {
  QName headerName = new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security");  // Or any other namespace that fits in your case
  AtomicReference<SOAPHeaderElement> header 
    = new AtomicReference<SOAPHeaderElement>
        (new SOAPHeaderElement(headerName) {                       
           {  
             SOAPElement utElem = addChildElement("UsernameToken");
             utElem.addChildElement("Username").setValue(username);
             utElem.addChildElement("Password").setValue(password);
           }
           @Override
           public void setAttribute(String namespace, String localName, String value) {
             if (!Constants.ATTR_MUST_UNDERSTAND.equals(localName)) {  // Or any other attribute name you'd want to avoid
               super.setAttribute(namespace, localName, value);
             }
           }
        });
  SOAPHeaderElement soapHeaderElement = header.get();
  soapHeaderElement.setActor(null);      // No intermediate actors are involved.
  stub.setHeader(soapHeaderElement);  // Finally, attach the header to the stub
}

None of those solutions worked for me, as:

Looking at the answer to "Adding ws-security to wsdl2java generated classes" helped me to write a solution that worked for me:

void addSecurityHeader(Stub stub, final String username, final String password) {
  QName headerName = new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security");  // Or any other namespace that fits in your case
  AtomicReference<SOAPHeaderElement> header 
    = new AtomicReference<SOAPHeaderElement>
        (new SOAPHeaderElement(headerName) {                       
           {  
             SOAPElement utElem = addChildElement("UsernameToken");
             utElem.addChildElement("Username").setValue(username);
             utElem.addChildElement("Password").setValue(password);
           }
           @Override
           public void setAttribute(String namespace, String localName, String value) {
             if (!Constants.ATTR_MUST_UNDERSTAND.equals(localName)) {  // Or any other attribute name you'd want to avoid
               super.setAttribute(namespace, localName, value);
             }
           }
        });
  SOAPHeaderElement soapHeaderElement = header.get();
  soapHeaderElement.setActor(null);      // No intermediate actors are involved.
  stub.setHeader(soapHeaderElement);  // Finally, attach the header to the stub
}
十秒萌定你 2024-12-12 05:58:27

如果您想禁用 AXIS 客户端中必须了解的检查,您必须
将以下行添加到您的代码中:

_call.setProperty(Call.CHECK_MUST_UNDERSTAND, new Boolean(false));

则永远不会调用 AXIS 客户端的 MustUnderstandChecker

If you want to disable the must understand check in the AXIS client you have
to add the following line to your code:

_call.setProperty(Call.CHECK_MUST_UNDERSTAND, new Boolean(false));

then the MustUnderstandChecker of the AXIS Client is never invoked.

‘画卷フ 2024-12-12 05:58:27

就我而言,它可以手动从 SOAPHeader 中删除该属性

SOAPHeader header = env.getHeader();
OMChildrenQNameIterator childrenWithName = (OMChildrenQNameIterator) header.getChildrenWithName(omElementauthentication.getQName());
    while (childrenWithName.hasNext()) {
        org.apache.axiom.om.OMElement omElement = (org.apache.axiom.om.OMElement) childrenWithName.next();
        QName mustAnderstandQName = omElement.resolveQName("soapenv:mustUnderstand");
        if (mustAnderstandQName == null) {
            continue;
        }
        OMAttribute mustAnderstandAttribute = omElement.getAttribute(mustAnderstandQName);
            if (mustAnderstandAttribute == null) {
                continue;
            }
        omElement.removeAttribute(mustAnderstandAttribute);
    }

In my case it worked manually remove the attribute from the SOAPHeader

SOAPHeader header = env.getHeader();
OMChildrenQNameIterator childrenWithName = (OMChildrenQNameIterator) header.getChildrenWithName(omElementauthentication.getQName());
    while (childrenWithName.hasNext()) {
        org.apache.axiom.om.OMElement omElement = (org.apache.axiom.om.OMElement) childrenWithName.next();
        QName mustAnderstandQName = omElement.resolveQName("soapenv:mustUnderstand");
        if (mustAnderstandQName == null) {
            continue;
        }
        OMAttribute mustAnderstandAttribute = omElement.getAttribute(mustAnderstandQName);
            if (mustAnderstandAttribute == null) {
                continue;
            }
        omElement.removeAttribute(mustAnderstandAttribute);
    }
一绘本一梦想 2024-12-12 05:58:27

我最近遇到了类似的情况,通过谷歌搜索,我设法找到了以下解决方案。

使用 Axis2 后,您可能会生成一个 MyWSStub 文件,其中包含对您的服务的调用。
创建一个扩展存根的包装类(最好不要触及自动生成的存根文件),例如 MyWSStubWrapper:

public class MyWSStubWrapper extends MyWSStub {

/**
 * @throws AxisFault
 */
public MyWSStubWrapper() throws AxisFault {
}

/**
 * @param configurationContext
 * @throws AxisFault
 */
public MyWSStubWrapper(ConfigurationContext configurationContext) throws AxisFault {
    super(configurationContext);
}

/**
 * @param targetEndpoint
 * @throws AxisFault
 */
public MyWSStubWrapper(String targetEndpoint) throws AxisFault {
    super(targetEndpoint);
}

/**
 * @param configurationContext
 * @param targetEndpoint
 * @throws AxisFault
 */
public MyWSStubWrapper(ConfigurationContext configurationContext, String targetEndpoint) throws AxisFault {
    super(configurationContext, targetEndpoint);
}

/**
 * @param configurationContext
 * @param targetEndpoint
 * @param useSeparateListener
 * @throws AxisFault
 */
public MyWSStubWrapper(ConfigurationContext configurationContext, String targetEndpoint, boolean useSeparateListener) throws AxisFault {
    super(configurationContext, targetEndpoint, useSeparateListener);
}

@Override
protected void addHeader(OMElement omElementToadd, SOAPEnvelope envelop, boolean mustUnderstand) {
    SOAPHeaderBlock soapHeaderBlock = envelop.getHeader().addHeaderBlock(omElementToadd.getLocalName(), omElementToadd.getNamespace());
    OMNode omNode = null;

    // add child elements
    for (Iterator iter = omElementToadd.getChildren(); iter.hasNext();) {
        omNode = (OMNode) iter.next();
        iter.remove();
        soapHeaderBlock.addChild(omNode);
    }

    OMAttribute omatribute = null;
    // add attributes
    for (Iterator iter = omElementToadd.getAllAttributes(); iter.hasNext();) {
        omatribute = (OMAttribute) iter.next();
        soapHeaderBlock.addAttribute(omatribute);
    }
}

}

请记住,如果您愿意,上面的代码将从标头中完全删除soapenv:mustUnderstand="0|1"添加您需要调用soapHeaderBlock.setMustUnderstand(true|false);在你的代码中的某个地方。

I was recently struggling with similar situation and by doing some google-ing I managed to find the following solution.

Having used Axis2 you would've probably generated a MyWSStub file that contains the calls to your service.
Create an wrapper class (better not touch the auto-generated stub files) that extends your stub e.g. MyWSStubWrapper:

public class MyWSStubWrapper extends MyWSStub {

/**
 * @throws AxisFault
 */
public MyWSStubWrapper() throws AxisFault {
}

/**
 * @param configurationContext
 * @throws AxisFault
 */
public MyWSStubWrapper(ConfigurationContext configurationContext) throws AxisFault {
    super(configurationContext);
}

/**
 * @param targetEndpoint
 * @throws AxisFault
 */
public MyWSStubWrapper(String targetEndpoint) throws AxisFault {
    super(targetEndpoint);
}

/**
 * @param configurationContext
 * @param targetEndpoint
 * @throws AxisFault
 */
public MyWSStubWrapper(ConfigurationContext configurationContext, String targetEndpoint) throws AxisFault {
    super(configurationContext, targetEndpoint);
}

/**
 * @param configurationContext
 * @param targetEndpoint
 * @param useSeparateListener
 * @throws AxisFault
 */
public MyWSStubWrapper(ConfigurationContext configurationContext, String targetEndpoint, boolean useSeparateListener) throws AxisFault {
    super(configurationContext, targetEndpoint, useSeparateListener);
}

@Override
protected void addHeader(OMElement omElementToadd, SOAPEnvelope envelop, boolean mustUnderstand) {
    SOAPHeaderBlock soapHeaderBlock = envelop.getHeader().addHeaderBlock(omElementToadd.getLocalName(), omElementToadd.getNamespace());
    OMNode omNode = null;

    // add child elements
    for (Iterator iter = omElementToadd.getChildren(); iter.hasNext();) {
        omNode = (OMNode) iter.next();
        iter.remove();
        soapHeaderBlock.addChild(omNode);
    }

    OMAttribute omatribute = null;
    // add attributes
    for (Iterator iter = omElementToadd.getAllAttributes(); iter.hasNext();) {
        omatribute = (OMAttribute) iter.next();
        soapHeaderBlock.addAttribute(omatribute);
    }
}

}

Bear in mind that the above code will completely remove the soapenv:mustUnderstand="0|1" from your headers if you wish to added you need to call soapHeaderBlock.setMustUnderstand(true|false); somewhere in your code.

清秋悲枫 2024-12-12 05:58:27

1) 您是否使用 Axis SOAPHeaderElement,如果使用,是否将 MustUnderstand setter 设置为 false?

2) 由于您使用 wsdl2java 生成客户端,因此 WSDL(或更准确地说,模式)很可能在 SOAP 绑定中引用的元素上包含 MustUnderstand 属性。所以当wsdlToJava生成客户端代码时,这些属性自然会被添加。有关说明,请参阅此处必须理解属性。
如果修改 WSDL 是不可能的,并且您必须从标头中删除此属性,那么我想您可以尝试使用处理程序来完成此操作

3) 不建议,但如果您确实必须删除此属性,那么我想您可以添加更改标头的客户端处理程序: http://ws.apache.org/axis/java/apiDocs/org/apache/axis/handlers/package-summary.html

1) Are you using the Axis SOAPHeaderElement and if so, are you setting the mustUnderstand setter to false?

2) Since you're generating your client with wsdl2java, it's quite possible that the WSDL (or more accurately, the schema) contains the mustUnderstand attribute on an element referenced in your SOAP binding. So when wsdlToJava generates the client code, those attributes will naturally be added. See here for a description of the mustUnderstand attribute.
If modifying the WSDL is out of the question, and you must remove this attribute from the header, then I suppose you can try to do it with a handler

3) Not advisable, but if you really MUST remove this attribute then I suppose you can add a client side handler that alters the header: http://ws.apache.org/axis/java/apiDocs/org/apache/axis/handlers/package-summary.html

街道布景 2024-12-12 05:58:27

我使用带有 ws security 的 axis 1.4 客户端

正如 Reinhard 所说,在我的情况下,
这有效

MyService service = new MyServiceLocator(); 
MyServicePortType port = service.getMyServiceHttpsSoap11Endpoint();

((Stub) port)._setProperty(Call.CHECK_MUST_UNDERSTAND, Boolean.FALSE);

i am using axis 1.4 client with ws security

in my case as Reinhard said
this worked

MyService service = new MyServiceLocator(); 
MyServicePortType port = service.getMyServiceHttpsSoap11Endpoint();

((Stub) port)._setProperty(Call.CHECK_MUST_UNDERSTAND, Boolean.FALSE);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文