• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java SOAPHeaderBlock类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.axiom.soap.SOAPHeaderBlock的典型用法代码示例。如果您正苦于以下问题:Java SOAPHeaderBlock类的具体用法?Java SOAPHeaderBlock怎么用?Java SOAPHeaderBlock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SOAPHeaderBlock类属于org.apache.axiom.soap包,在下文中一共展示了SOAPHeaderBlock类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: doProcessing

import org.apache.axiom.soap.SOAPHeaderBlock; //导入依赖的package包/类
@Test
public void doProcessing() throws Exception {
    // Creating SOAP envelope
    SOAPEnvelope env = SOAPEnv.createEnvelope(SOAPEnv.SOAPVersion.SOAP_12);
    // Adding header
    SOAPHeaderBlock headerBlock = Messaging.createElement(env);

    MessageContext mc = new MessageContext();

    try {
        mc.setEnvelope(env);
    } catch (AxisFault axisFault) {
        fail(axisFault.getMessage());
    }

    assertFalse(headerBlock.isProcessed());

    try {
        Handler.InvocationResponse invokeResp = handler.invoke(mc);
        assertEquals(Handler.InvocationResponse.CONTINUE, invokeResp);
    } catch (Exception e) {
        fail(e.getMessage());
    }

    assertTrue(headerBlock.isProcessed());
}
 
开发者ID:holodeck-b2b,项目名称:Holodeck-B2B,代码行数:27,代码来源:ReportHeaderProcessedTest.java


示例2: removeSOAPHeader

import org.apache.axiom.soap.SOAPHeaderBlock; //导入依赖的package包/类
private void removeSOAPHeader(MessageDataSource messageDataSource) throws SOAPException {

        SOAPEnvelope soapEnvelope = (SOAPEnvelope) messageDataSource.getDataObject();
        SOAPHeader soapHeader = soapEnvelope.getHeader();
        if (soapHeader != null) {
            for (Iterator iter = soapHeader.examineAllHeaderBlocks(); iter.hasNext(); ) {
                Object o = iter.next();
                if (o instanceof SOAPHeaderBlock) {
                    SOAPHeaderBlock headerBlk = (SOAPHeaderBlock) o;
                    if (name.equals(headerBlk.getLocalName())) {
                        headerBlk.detach();
                    }
                } else if (o instanceof OMElement) {
                    OMElement headerElem = (OMElement) o;
                    if (name.equals(headerElem.getLocalName())) {
                        headerElem.detach();
                    }
                }
            }
        }
    }
 
开发者ID:wso2-attic,项目名称:carbon-gateway-framework,代码行数:22,代码来源:HeaderMediator.java


示例3: getElements

import org.apache.axiom.soap.SOAPHeaderBlock; //导入依赖的package包/类
/**
 * Gets an {@link Iterator} for all <code>eb:SignalMessage</code> elements from the given ebMS 3 Messaging header in
 * the SOAP message that represent <i>Error Signals</i>.
 *
 * @param   messaging  The SOAP Header block that contains the ebMS header,i.e. the <code>eb:Messaging</code> element
 * @return             An {@link Iterator} for all {@link OMElement}s representing a <code>eb:SignalMessage</code>
 *                     element that contains an Error Signal, i.e. has one or more <code>eb:Error</code> child
 *                     elements
 */
public static Iterator<OMElement> getElements(final SOAPHeaderBlock messaging) {
    // Check all SignalMessage elements in the header
    final Iterator<OMElement> signals = SignalMessageElement.getElements(messaging);

    final ArrayList<OMElement>  errors = new ArrayList<>();
    while(signals.hasNext()) {
        final OMElement signal  = (OMElement) signals.next();
        // If this SignalMessage element has at least one Error child,
        //   it is an Error signal and should be returned
        if (signal.getFirstChildWithName(Q_ELEMENT_NAME) != null)
            errors.add(signal);
    }

    return errors.iterator();
}
 
开发者ID:holodeck-b2b,项目名称:Holodeck-B2B,代码行数:25,代码来源:ErrorSignalElement.java


示例4: getElements

import org.apache.axiom.soap.SOAPHeaderBlock; //导入依赖的package包/类
/**
 * Gets an {@link Iterator} for all <code>eb:SignalMessage</code> elements from the given ebMS 3 Messaging header in
 * the SOAP message that represent <i>Receipt Signal</i> message units.
 *
 * @param messaging   The SOAP Header block that contains the ebMS header,i.e. the <code>eb:Messaging</code> element
 * @return      An {@link Iterator} for all {@link OMElement}s representing a <code>eb:SignalMessage</code> element
 *              that contains an Receipt Signal, i.e. has one or more <code>eb:Receipt</code> child elements
 */
public static Iterator<OMElement> getElements(final SOAPHeaderBlock messaging) {
    // Check all SignalMessage elements in the header
    final Iterator<?> signals = SignalMessageElement.getElements(messaging);

    final ArrayList<OMElement>  receipts = new ArrayList<>();
    while(signals.hasNext()) {
        final OMElement signal  = (OMElement) signals.next();
        // If this SignalMessage element has a Receipt child,
        //   it is an Receipt signal and should be returned
        if (signal.getFirstChildWithName(Q_ELEMENT_NAME) != null)
            receipts.add(signal);
    }

    return receipts.iterator();
}
 
开发者ID:holodeck-b2b,项目名称:Holodeck-B2B,代码行数:24,代码来源:ReceiptElement.java


示例5: doProcessing

import org.apache.axiom.soap.SOAPHeaderBlock; //导入依赖的package包/类
@Override
protected InvocationResponse doProcessing(final MessageContext mc) throws Exception {
    // First get the ebMS header block, that is the eb:Messaging element
    final SOAPHeaderBlock messaging = Messaging.getElement(mc.getEnvelope());

    if (messaging != null) {
        // Check if the message was received through I-Cloud, i.e. if eb:Messaging header was targeted to
        // nextMSH SOAP role/actor
        final boolean isMultiHop = MultiHopConstants.NEXT_MSH_TARGET.equalsIgnoreCase(messaging.getRole());

        if (isMultiHop) {
            log.debug("Message received through I-Cloud, update message units");
            StorageManager updateManager = HolodeckB2BCore.getStorageManager();
            for (final IMessageUnitEntity mu : MessageContextUtils.getReceivedMessageUnits(mc))
                updateManager.setMultiHop(mu, isMultiHop);
        }
    }

    return InvocationResponse.CONTINUE;
}
 
开发者ID:holodeck-b2b,项目名称:Holodeck-B2B,代码行数:21,代码来源:CheckFromICloud.java


示例6: testSendingMustUnderstandWithNextRole

import org.apache.axiom.soap.SOAPHeaderBlock; //导入依赖的package包/类
public void testSendingMustUnderstandWithNextRole() throws Exception {
    ServiceClient serviceClient = getClient(Echo.SERVICE_NAME, Echo.ECHO_OM_ELEMENT_OP_NAME);
    
    SOAPFactory fac = OMAbstractFactory.getSOAP12Factory();
    OMNamespace headerNs = fac.createOMNamespace("http://dummyHeader", "dh");
    SOAPHeaderBlock h1 = fac.createSOAPHeaderBlock("DummyHeader", headerNs);
    h1.setMustUnderstand(true);
    h1.addChild(fac.createOMText("Dummy String"));
    h1.setRole(SOAP12Constants.SOAP_ROLE_NEXT);
    
    serviceClient.addHeader(h1);
    
    OMElement payload = TestingUtils.createDummyOMElement();

    serviceClient.getOptions().setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
    
    try {
    	serviceClient.sendReceive(payload);
    } catch (AxisFault fault) {
        // This should be a MustUnderstand fault
        assertEquals(fault.getFaultCode(), SOAP12Constants.QNAME_MU_FAULTCODE);
        return;
    }
    fail("MU header was processed");
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:26,代码来源:SoapProcessingModelTest.java


示例7: processFaultsInfoIfPresent

import org.apache.axiom.soap.SOAPHeaderBlock; //导入依赖的package包/类
private void processFaultsInfoIfPresent() {
    OMElement detailElement = AddressingFaultsHelper
            .getDetailElementForAddressingFault(messageContext, addressingNamespaceObject);
    if (detailElement != null) {
        //The difference between SOAP 1.1 and SOAP 1.2 fault messages is explained in the WS-Addressing Specs.
        if (isFinalAddressingNamespace && messageContext.isSOAP11()) {
            // Add detail as a wsa:FaultDetail header
            if (!isAddressingHeaderAlreadyAvailable(Final.FAULT_HEADER_DETAIL, false)) {
                SOAPHeaderBlock faultDetail = header.addHeaderBlock(
                        Final.FAULT_HEADER_DETAIL, addressingNamespaceObject);
                faultDetail.addChild(ElementHelper.importOMElement(detailElement, factory));
            }
        } else if (!messageContext.isSOAP11()) {
            // Add detail to the Fault in the SOAP Body
            SOAPFault fault = envelope.getBody().getFault();
            if (fault != null && fault.getDetail() != null) {
                fault.getDetail().addDetailEntry(
                        ElementHelper.importOMElement(detailElement, factory));
            }
        }
    }
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:23,代码来源:AddressingOutHandler.java


示例8: createSOAPHeaderBlock

import org.apache.axiom.soap.SOAPHeaderBlock; //导入依赖的package包/类
private OMElement createSOAPHeaderBlock(String value, String headerName, ArrayList attributes) {
    if (LoggingControl.debugLoggingAllowed && log.isTraceEnabled()) {
        log.trace("createSOAPHeaderBlock: value=" + value + " headerName=" + headerName);
    }
    if (value != null && value.length()!=0) {
        SOAPHeaderBlock soapHeaderBlock =
                header.addHeaderBlock(headerName, addressingNamespaceObject);
        soapHeaderBlock.addChild(factory.createOMText(value));
        if (attributes != null && !attributes.isEmpty()) {
            Iterator attrIterator = attributes.iterator();
            while (attrIterator.hasNext()) {
                AttributeHelper
                        .importOMAttribute((OMAttribute)attrIterator.next(), soapHeaderBlock);
            }
        }
        addRoleToHeader(soapHeaderBlock);
        return soapHeaderBlock;
    }
    return null;
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:21,代码来源:AddressingOutHandler.java


示例9: processMustUnderstandProperty

import org.apache.axiom.soap.SOAPHeaderBlock; //导入依赖的package包/类
/**
 * Sets a mustUnderstand attribute on all headers that are found with the appropriate
 * addressing namespace.
 */
private void processMustUnderstandProperty() {
    if (addMustUnderstandAttribute) {
        List headers = header.getHeaderBlocksWithNSURI(addressingNamespace);

        for (int i = 0, size = headers.size(); i < size; i++) {
            SOAPHeaderBlock soapHeaderBlock = (SOAPHeaderBlock)headers.get(i);
            soapHeaderBlock.setMustUnderstand(true);
            if (LoggingControl.debugLoggingAllowed && log.isTraceEnabled()) {
                log.trace(
                        "processMustUnderstandProperty: Setting mustUnderstand=true on: " +
                                soapHeaderBlock.getLocalName());
            }
        }
    }
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:20,代码来源:AddressingOutHandler.java


示例10: testAxis2DisableAddressingForOutMessagesTrue

import org.apache.axiom.soap.SOAPHeaderBlock; //导入依赖的package包/类
public void testAxis2DisableAddressingForOutMessagesTrue() throws Exception {
    File configFile = new File(System.getProperty("basedir",".") +
            "/test-resources/axis2-disableAddressingForOutMessagesTrue.xml");
    ConfigurationContext cfgCtx = ConfigurationContextFactory
    .createConfigurationContextFromFileSystem("target/test-classes",
            configFile.getAbsolutePath());
    
    msgCtxt = cfgCtx.createMessageContext();
    
    // Need to add a SOAP Header to stop this error from XMLComparator:
    // "There is no Header element under Envelope"
    SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
    SOAPHeaderBlock soapHeaderBlock = envelope.getHeader().addHeaderBlock(
            "testHeader", new OMNamespaceImpl("http://test.com", "test"));
    msgCtxt.setEnvelope(envelope);
    
    outHandler.invoke(msgCtxt);

    XMLUnit.setIgnoreWhitespace(true);
    assertXMLEqual(msgCtxt.getEnvelope().toString(), TestUtil
            .getOMBuilder("addressingDisabledTest.xml")
            .getDocumentElement().toString());   
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:24,代码来源:AddressingOutHandlerTest.java


示例11: setUnprocessedHeaders

import org.apache.axiom.soap.SOAPHeaderBlock; //导入依赖的package包/类
private void setUnprocessedHeaders(MessageContext messageContext, RolePlayer rolePlayer) {
    SOAPEnvelope envelope = messageContext.getEnvelope();
    Iterator headerBlocks = envelope.getHeader().getHeadersToProcess(rolePlayer);
    List<QName> unprocessedHeaders = new ArrayList<QName>();
    while (headerBlocks.hasNext()) {
        SOAPHeaderBlock headerBlock = (SOAPHeaderBlock) headerBlocks.next();
        QName headerName = headerBlock.getQName();
        // if this header block has been processed or mustUnderstand isn't
        // turned on then its cool
        if (headerBlock.isProcessed() || !headerBlock.getMustUnderstand()) {
            continue;
        } else {
            unprocessedHeaders.add(headerName);
        }
    }
    if(unprocessedHeaders !=null && unprocessedHeaders.size()>0){
        messageContext.setProperty(Constants.UNPROCESSED_HEADER_QNAMES, unprocessedHeaders);           
    }       
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:20,代码来源:RoleBasedMustUndertandTests.java


示例12: addChildElement

import org.apache.axiom.soap.SOAPHeaderBlock; //导入依赖的package包/类
public SOAPElement addChildElement(String localName, String prefix, String uri)
        throws SOAPException {
    OMNamespace ns = new NamespaceImpl(uri, prefix);
    SOAPHeaderBlock headerBlock = null;
    if (this.element.getOMFactory() instanceof SOAP11Factory) {
        headerBlock = new SOAP11HeaderBlockImpl(localName, ns, omSOAPHeader,
                                                (SOAPFactory)this.element.getOMFactory());
    } else {
        headerBlock = new SOAP12HeaderBlockImpl(localName, ns, omSOAPHeader,
                                                (SOAPFactory)this.element.getOMFactory());
    }
    SOAPHeaderElementImpl soapHeaderElement = new SOAPHeaderElementImpl(headerBlock);
    element.setUserData(SAAJ_NODE, this, null);
    soapHeaderElement.element.setUserData(SAAJ_NODE, soapHeaderElement, null);
    soapHeaderElement.setParentElement(this);
    return soapHeaderElement;
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:18,代码来源:SOAPHeaderImpl.java


示例13: appendElement

import org.apache.axiom.soap.SOAPHeaderBlock; //导入依赖的package包/类
@Override
protected Element appendElement(ElementImpl child) throws SOAPException {     
    OMNamespace ns = new NamespaceImpl(child.getNamespaceURI(),
                                       child.getPrefix());
    SOAPHeaderBlock headerBlock = null;
    if (this.element.getOMFactory() instanceof SOAP11Factory) {
        headerBlock = new SOAP11HeaderBlockImpl(child.getLocalName(), ns,
                                                omSOAPHeader,
                                                (SOAPFactory)this.element.getOMFactory());
    } else {
        headerBlock = new SOAP12HeaderBlockImpl(child.getLocalName(), ns,
                                                omSOAPHeader,
                                                (SOAPFactory)this.element.getOMFactory());

    }
 
    element.setUserData(SAAJ_NODE, this, null);
    
    SOAPHeaderElementImpl soapHeaderElement = new SOAPHeaderElementImpl(headerBlock);
    copyContents(soapHeaderElement, child);
    soapHeaderElement.element.setUserData(SAAJ_NODE, soapHeaderElement, null);
    soapHeaderElement.setParentElement(this);
    return soapHeaderElement;
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:25,代码来源:SOAPHeaderImpl.java


示例14: addHeaderElement

import org.apache.axiom.soap.SOAPHeaderBlock; //导入依赖的package包/类
/**
 * Creates a new <CODE>SOAPHeaderElement</CODE> object initialized with the specified name and
 * adds it to this <CODE>SOAPHeader</CODE> object.
 *
 * @param name a <CODE>Name</CODE> object with the name of the new <CODE>SOAPHeaderElement</CODE>
 *             object
 * @return the new <CODE>SOAPHeaderElement</CODE> object that was inserted into this
 *         <CODE>SOAPHeader</CODE> object
 * @throws SOAPException if a SOAP error occurs
 */
public SOAPHeaderElement addHeaderElement(Name name) throws SOAPException {
    
    if (name.getURI() == null
            || name.getURI().trim().length() == 0) {
        throw new SOAPException("SOAP1.1 and SOAP1.2 requires all HeaderElements to have " +
                "a namespace.");
    }
    String prefix = name.getPrefix() == null ? "" : name.getPrefix();
    OMNamespace ns = new NamespaceImpl(name.getURI(), prefix);

    SOAPHeaderBlock headerBlock = null;
    if (this.element.getOMFactory() instanceof SOAP11Factory) {
        headerBlock = new SOAP11HeaderBlockImpl(name.getLocalName(), ns, omSOAPHeader,
                                                (SOAPFactory)this.element.getOMFactory());
    } else {
        headerBlock = new SOAP12HeaderBlockImpl(name.getLocalName(), ns, omSOAPHeader,
                                                (SOAPFactory)this.element.getOMFactory());
    }

    SOAPHeaderElementImpl soapHeaderElement = new SOAPHeaderElementImpl(headerBlock);
    element.setUserData(SAAJ_NODE, this, null);
    soapHeaderElement.element.setUserData(SAAJ_NODE, soapHeaderElement, null);
    soapHeaderElement.setParentElement(this);
    return soapHeaderElement;
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:36,代码来源:SOAPHeaderImpl.java


示例15: getChildren

import org.apache.axiom.soap.SOAPHeaderBlock; //导入依赖的package包/类
private Iterator getChildren(Iterator childIter) {
    Collection childElements = new ArrayList();
    while (childIter.hasNext()) {
        org.w3c.dom.Node domNode = (org.w3c.dom.Node)childIter.next();
        Node saajNode = toSAAJNode(domNode);
        if (saajNode instanceof javax.xml.soap.Text) {
            childElements.add(saajNode);
        } else if (!(saajNode instanceof SOAPHeaderElement)) {
            // silently replace node, as per saaj 1.2 spec
            SOAPHeaderElement headerEle = new SOAPHeaderElementImpl((SOAPHeaderBlock)domNode);
            ((NodeImpl)domNode).setUserData(SAAJ_NODE, headerEle, null);
            childElements.add(headerEle);
        } else {
            childElements.add(saajNode);
        }
    }
    return childElements.iterator();
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:19,代码来源:SOAPHeaderImpl.java


示例16: invoke

import org.apache.axiom.soap.SOAPHeaderBlock; //导入依赖的package包/类
public InvocationResponse invoke(MessageContext msgContext) throws AxisFault {
    if (msgContext == null) {
        return InvocationResponse.CONTINUE;
    } 
            
    SOAPEnvelope envelope = msgContext.getEnvelope();
    if (envelope.getHeader() == null) {
        return InvocationResponse.CONTINUE;          
    }
    
    // Passing in null will get headers targeted for NEXT and ULTIMATE RECEIVER
    Iterator headerBlocks = envelope.getHeader().getHeadersToProcess(null);
    while (headerBlocks.hasNext()) {
        SOAPHeaderBlock headerBlock = (SOAPHeaderBlock) headerBlocks.next();
        headerBlock.setProcessed();            
    }
    return InvocationResponse.CONTINUE;        
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:19,代码来源:UnderstandAllHeadersHandler.java


示例17: invoke

import org.apache.axiom.soap.SOAPHeaderBlock; //导入依赖的package包/类
/**
 * 
 * Process the security block from the message context header.
 */
public final InvocationResponse invoke(final MessageContext msgContext) throws AxisFault {

  /* Get header */
  final SOAPHeader header = msgContext.getEnvelope().getHeader();

  if (header != null) {
    final Iterator<?> blocks = header.examineAllHeaderBlocks();

    while (blocks.hasNext()) {

      /* Get header block */
      final SOAPHeaderBlock block = (SOAPHeaderBlock) blocks.next();

      if (block != null) {

        /* Check for security header block */
        if (block.getLocalName().equalsIgnoreCase("Security") || block.getLocalName().equalsIgnoreCase("Action")
            || block.getLocalName().equalsIgnoreCase("To")) {

          logger.debug("----Inside invoke; found '" + block.getLocalName() + "' header. Marking it processed");

          /* Mark it processed to avoid exception at client side */
          block.setProcessed();
        }
      }
    }
  }

  return InvocationResponse.CONTINUE;
}
 
开发者ID:inbravo,项目名称:scribe,代码行数:35,代码来源:MSSOAPMustUnderstandHandler.java


示例18: setClientSessionID

import org.apache.axiom.soap.SOAPHeaderBlock; //导入依赖的package包/类
public void setClientSessionID(String id) {

        SOAPFactory soapFactory = OMAbstractFactory.getSOAP12Factory();

        OMNamespace synNamespace = soapFactory.
                createOMNamespace("http://ws.apache.org/namespaces/synapse", "syn");
        SOAPHeaderBlock header = soapFactory.createSOAPHeaderBlock("ClientID", synNamespace);
        header.setText(id);

        client.addHeader(header);
    }
 
开发者ID:wso2,项目名称:product-ei,代码行数:12,代码来源:ServiceInvoker.java


示例19: getHeadersLogMessage

import org.apache.axiom.soap.SOAPHeaderBlock; //导入依赖的package包/类
private String getHeadersLogMessage(CarbonMessage carbonMessage, Reader reader) throws Exception {
    StringBuffer sb = new StringBuffer();
    MessageDataSource messageDataSource = carbonMessage.getMessageDataSource();
    if (messageDataSource == null) {
        messageDataSource = reader.makeMessageReadable(carbonMessage);
    }
    if (messageDataSource.getDataObject() != null && messageDataSource.getDataObject() instanceof OMElement) {
        OMElement omElement = (OMElement) messageDataSource.getDataObject();
        if (omElement instanceof SOAPEnvelope) {
            try {
                SOAPHeader header = (SOAPHeader) ((SOAPEnvelope) omElement).getHeader();
                if (header != null) {
                    for (Iterator iter = header.examineAllHeaderBlocks(); iter.hasNext(); ) {
                        Object o = iter.next();
                        if (o instanceof SOAPHeaderBlock) {
                            SOAPHeaderBlock headerBlk = (SOAPHeaderBlock) o;
                            sb.append(separator).append(headerBlk.getLocalName()).
                                    append(" : ").append(headerBlk.getText());
                        } else if (o instanceof OMElement) {
                            OMElement headerElem = (OMElement) o;
                            sb.append(separator).append(headerElem.getLocalName()).
                                    append(" : ").append(headerElem.getText());
                        }
                    }
                }

            } catch (Exception e) {
                log.error("Exception occurred while processing SOAPHeader", e);
                return null;
            }

        }
    }
    setCustomProperties(sb, carbonMessage, reader);
    return trimLeadingSeparator(sb);
}
 
开发者ID:wso2-attic,项目名称:carbon-gateway-framework,代码行数:37,代码来源:LogMediator.java


示例20: getSignatureReferences

import org.apache.axiom.soap.SOAPHeaderBlock; //导入依赖的package包/类
/**
 * Gets all <code>ds:Reference</code> descendant elements from the signature in the default WS-Security header.
 * <p>In an ebMS there may only be one <code>ds:Signature</code> element, so we can take the<code>
 * ds:SignedInfo</code> of the first one to get access to the <code>ds:Reference</code> elements.
 *
 * @param mc    The {@link MessageContext} of the message to get the reference from
 * @return      The {@link Collection} of <code>ds:Reference</code> elements contained in the signature,<br>
 *              <code>null</code> or an empty collection if there is no signature in the default security header.
 */
public static Collection<OMElement> getSignatureReferences(final MessageContext mc) {
   // Get all WS-Security headers
    final ArrayList<SOAPHeaderBlock> secHeaders = mc.getEnvelope().getHeader()
                                                    .getHeaderBlocksWithNSURI(SecurityConstants.WSS_NAMESPACE_URI);
    if (secHeaders == null || secHeaders.isEmpty())
        return null; // No security headers in message

    // There can be more than one security header, get the default header
    SOAPHeaderBlock defHeader = null;
    for(final SOAPHeaderBlock h : secHeaders) {
        if (h.getRole() == null)
            defHeader = h;
    }
    if (defHeader == null)
        return null; // No default security header

    // Get the ds:SignedInfo descendant in the default header.
    final Iterator<OMElement> signatureElems = defHeader.getChildrenWithName(
                                                      new QName(SecurityConstants.DSIG_NAMESPACE_URI, "Signature"));
    if (signatureElems == null || !signatureElems.hasNext())
        return null; // No Signature in default header

    // The ds:SignedInfo element is the first child of ds:Signature
    final OMElement signedInfoElement = signatureElems.next().getFirstElement();
    // Collect all ds:Reference contained in it
    Collection<OMElement> references = null;
    if (signedInfoElement != null) {
        references = new ArrayList<>();
        for (final Iterator<OMElement> it =
                signedInfoElement.getChildrenWithName(new QName(SecurityConstants.DSIG_NAMESPACE_URI, "Reference"))
            ; it.hasNext() ;)
            references.add(it.next());

    }

    return references;
}
 
开发者ID:holodeck-b2b,项目名称:Holodeck-B2B,代码行数:47,代码来源:SecurityUtils.java



注:本文中的org.apache.axiom.soap.SOAPHeaderBlock类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CheckpointListener类代码示例发布时间:2022-05-23
下一篇:
Java Serializer类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap