當前位置: 首頁>>代碼示例>>Java>>正文


Java SOAPHeader類代碼示例

本文整理匯總了Java中javax.xml.soap.SOAPHeader的典型用法代碼示例。如果您正苦於以下問題:Java SOAPHeader類的具體用法?Java SOAPHeader怎麽用?Java SOAPHeader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SOAPHeader類屬於javax.xml.soap包,在下文中一共展示了SOAPHeader類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: handleMessage

import javax.xml.soap.SOAPHeader; //導入依賴的package包/類
@Override
public boolean handleMessage(SOAPMessageContext context) {
	Boolean request = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
	if (!request) {
		try {
			SOAPMessage msg = context.getMessage();
			SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
			SOAPHeader header = env.getHeader();
			if (header == null) {
				header = env.addHeader();
				return false;
			}
			Node node = (Node) header.getElementsByTagName("token").item(0);
			String token = node.getChildNodes().item(0).getNodeValue();
			if (token != null && token.equals("Kalango Lab")) {
				System.out.println("Token válido");
				return true;
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
	return true;
}
 
開發者ID:kalangolab,項目名稱:programacaoweb,代碼行數:27,代碼來源:UsuarioHandlerMessage.java

示例2: handleRequest

import javax.xml.soap.SOAPHeader; //導入依賴的package包/類
/**
 * Adds an "Access" element to the SOAP header
 */
public boolean handleRequest(MessageContext msgct) {
	if (msgct instanceof SOAPMessageContext) {
		SOAPMessageContext smsgct = (SOAPMessageContext) msgct;
		try {
			SOAPMessage msg = smsgct.getMessage();
			SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
			SOAPHeader header = msg.getSOAPHeader();

			if (header == null)
				header = envelope.addHeader(); // add an header if non exists

			SOAPHeaderElement accessElement = header.addHeaderElement(envelope.createName("Access", "ns0", JPLAG_TYPES_NS));
			SOAPElement usernameelem = accessElement.addChildElement("username");
			usernameelem.addTextNode(username);
			SOAPElement passwordelem = accessElement.addChildElement("password");
			passwordelem.addTextNode(password);
			SOAPElement compatelem = accessElement.addChildElement("compatLevel");
			compatelem.addTextNode(compatibilityLevel + "");
		} catch (SOAPException x) {
			System.out.println("Unable to create access SOAP header!");
			x.printStackTrace();
		}
	}
	return true;
}
 
開發者ID:jplag,項目名稱:jplag,代碼行數:29,代碼來源:JPlagClientAccessHandler.java

示例3: createSimpleSOAPPart

import javax.xml.soap.SOAPHeader; //導入依賴的package包/類
private void createSimpleSOAPPart(SOAPMessage message) throws SOAPException {
    SOAPPart sPart = message.getSOAPPart();
    SOAPEnvelope env = sPart.getEnvelope();
    SOAPBody body = env.getBody();
    SOAPHeader header = env.getHeader();
    header.addHeaderElement(env.createName("Header1",
                                           "pref",
                                           "http://test.apach.org/test"))
            .addTextNode("This is header1");

    Name ns = env.createName("echo", "swa2", "http://fakeNamespace2.org");
    final SOAPBodyElement bodyElement = body.addBodyElement(ns);
    Name ns2 = env.createName("something");
    final SOAPElement ele1 = bodyElement.addChildElement(ns2);
    ele1.addTextNode("This is some text");

    Name ns3 = env.createName("ping", "swa3", "http://fakeNamespace3.org");
    final SOAPBodyElement bodyElement2 = body.addBodyElement(ns3);
    Name ns4 = env.createName("another");
    final SOAPElement ele2 = bodyElement2.addChildElement(ns4);
    ele2.addTextNode("This is another text");
}
 
開發者ID:wso2,項目名稱:wso2-axis2,代碼行數:23,代碼來源:IntegrationTest.java

示例4: parseApiVersion_ctmg_1_8

import javax.xml.soap.SOAPHeader; //導入依賴的package包/類
@Test
public void parseApiVersion_ctmg_1_8() throws Exception {
    // given
    SOAPPart part = mock(SOAPPart.class);
    SOAPEnvelope envelope = mock(SOAPEnvelope.class);
    SOAPHeader soapHeader = mock(SOAPHeader.class);
    List<Node> version = new ArrayList<Node>();
    Node node = mock(Node.class);
    doReturn("testVersion").when(node).getValue();
    version.add(node);
    Iterator<?> it = version.iterator();
    doReturn(it).when(soapHeader).extractHeaderElements(
            eq("ctmg.service.version"));
    doReturn(soapHeader).when(envelope).getHeader();
    doReturn(envelope).when(part).getEnvelope();
    doReturn(part).when(message).getSOAPPart();
    // when
    String result = SoapRequestParser.parseApiVersion(context);

    // then
    assertEquals("testVersion", result);
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:23,代碼來源:SoapRequestParserTest.java

示例5: serializeClient

import javax.xml.soap.SOAPHeader; //導入依賴的package包/類
private void serializeClient(final SOAPHeader header, final AbstractMessage message, final SOAPEnvelope envelope) throws SOAPException {
    LOGGER.debug("Generate \"Client\" element.");
    ObjectType clientObjectType = MessageHelper.getObjectType(message.getConsumer());
    SOAPElement clientHeader = header.addChildElement(Constants.NS_XRD_ELEM_CLIENT, Constants.NS_XRD_PREFIX);
    clientHeader.addAttribute(envelope.createQName(Constants.NS_ID_ATTR_OBJECT_TYPE, Constants.NS_ID_PREFIX), clientObjectType.toString());
    SOAPElement xRoadInstance = clientHeader.addChildElement(Constants.NS_ID_ELEM_XROAD_INSTANCE, Constants.NS_ID_PREFIX);
    xRoadInstance.addTextNode(message.getConsumer().getXRoadInstance());
    SOAPElement memberClass = clientHeader.addChildElement(Constants.NS_ID_ELEM_MEMBER_CLASS, Constants.NS_ID_PREFIX);
    memberClass.addTextNode(message.getConsumer().getMemberClass());
    SOAPElement memberCode = clientHeader.addChildElement(Constants.NS_ID_ELEM_MEMBER_CODE, Constants.NS_ID_PREFIX);
    memberCode.addTextNode(message.getConsumer().getMemberCode());
    if (clientObjectType == ObjectType.SUBSYSTEM) {
        SOAPElement subsystem = clientHeader.addChildElement(Constants.NS_ID_ELEM_SUBSYSTEM_CODE, Constants.NS_ID_PREFIX);
        subsystem.addTextNode(message.getConsumer().getSubsystemCode());
    }
    LOGGER.debug("\"Client\" element was succesfully generated.");
}
 
開發者ID:vrk-kpa,項目名稱:xrd4j,代碼行數:18,代碼來源:AbstractHeaderSerializer.java

示例6: parseXteeHeader

import javax.xml.soap.SOAPHeader; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private XTeeHeader parseXteeHeader(SOAPMessage paringMessage) throws SOAPException {
  XTeeHeader pais = new XTeeHeader();
  if (paringMessage.getSOAPHeader() == null) {
    return pais;
  }

  SOAPHeader header = paringMessage.getSOAPHeader();
  for (Iterator<Node> headerElemendid = header.getChildElements(); headerElemendid.hasNext();) {
    Node headerElement = headerElemendid.next();
    if (!SOAPUtil.isTextNode(headerElement) && headerElement.getFirstChild() != null) {
      String localName = headerElement.getLocalName();
      String value = headerElement.getFirstChild().getNodeValue();
      pais.addElement(new QName(headerElement.getNamespaceURI(), localName), value);
    }
  }
  return pais;
}
 
開發者ID:nortal,項目名稱:j-road,代碼行數:19,代碼來源:AbstractXTeeBaseEndpoint.java

示例7: addSoapHeader

import javax.xml.soap.SOAPHeader; //導入依賴的package包/類
protected void addSoapHeader(SOAPMessage soapMessage) throws SOAPException, NoSuchAlgorithmException {
	onvifDevice.createNonce();
	String encrypedPassword = onvifDevice.getEncryptedPassword();
	if (encrypedPassword != null && onvifDevice.getUsername() != null) {

		SOAPPart sp = soapMessage.getSOAPPart();
		SOAPEnvelope se = sp.getEnvelope();
		SOAPHeader header = soapMessage.getSOAPHeader();
		se.addNamespaceDeclaration("wsse",
				"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
		se.addNamespaceDeclaration("wsu",
				"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");

		SOAPElement securityElem = header.addChildElement("Security", "wsse");
		// securityElem.setAttribute("SOAP-ENV:mustUnderstand", "1");

		SOAPElement usernameTokenElem = securityElem.addChildElement("UsernameToken", "wsse");

		SOAPElement usernameElem = usernameTokenElem.addChildElement("Username", "wsse");
		usernameElem.setTextContent(onvifDevice.getUsername());

		SOAPElement passwordElem = usernameTokenElem.addChildElement("Password", "wsse");
		passwordElem.setAttribute("Type",
				"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest");
		passwordElem.setTextContent(encrypedPassword);

		SOAPElement nonceElem = usernameTokenElem.addChildElement("Nonce", "wsse");
		nonceElem.setAttribute("EncodingType",
				"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary");
		nonceElem.setTextContent(onvifDevice.getEncryptedNonce());

		SOAPElement createdElem = usernameTokenElem.addChildElement("Created", "wsu");
		createdElem.setTextContent(onvifDevice.getLastUTCTime());
	}
}
 
開發者ID:D2Edev,項目名稱:onvifjava,代碼行數:36,代碼來源:SoapClient.java

示例8: writeTo

import javax.xml.soap.SOAPHeader; //導入依賴的package包/類
public void writeTo(SOAPMessage saaj) throws SOAPException {
    try {
        // TODO what about in-scope namespaces
        // Not very efficient consider implementing a stream buffer
        // processor that produces a DOM node from the buffer.
        TransformerFactory tf = XmlUtil.newTransformerFactory();
        Transformer t = tf.newTransformer();
        XMLStreamBufferSource source = new XMLStreamBufferSource(_mark);
        DOMResult result = new DOMResult();
        t.transform(source, result);
        Node d = result.getNode();
        if(d.getNodeType() == Node.DOCUMENT_NODE)
            d = d.getFirstChild();
        SOAPHeader header = saaj.getSOAPHeader();
        if(header == null)
            header = saaj.getSOAPPart().getEnvelope().addHeader();
        Node node = header.getOwnerDocument().importNode(d, true);
        header.appendChild(node);
    } catch (Exception e) {
        throw new SOAPException(e);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:23,代碼來源:StreamHeader.java

示例9: initHeaderUnderstanding

import javax.xml.soap.SOAPHeader; //導入依賴的package包/類
/** Set the initial understood/not understood state of the headers in this
 * object
 */
private void initHeaderUnderstanding() {
    SOAPHeader soapHeader = ensureSOAPHeader();
    if (soapHeader == null) {
        return;
    }

    Iterator allHeaders = soapHeader.examineAllHeaderElements();
    while(allHeaders.hasNext()) {
        SOAPHeaderElement nextHdrElem = (SOAPHeaderElement) allHeaders.next();
        if (nextHdrElem == null) {
            continue;
        }
        if (nextHdrElem.getMustUnderstand()) {
            notUnderstood(nextHdrElem.getElementQName());
        }
        //only headers explicitly marked as understood should be
        //in the understoodHeaders set, so don't add anything to
        //that set at the beginning
    }

}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,代碼來源:SAAJMessageHeaders.java

示例10: writeTo

import javax.xml.soap.SOAPHeader; //導入依賴的package包/類
public void writeTo(SOAPMessage saaj) throws SOAPException {
        try {
            // TODO what about in-scope namespaces
            // Not very efficient consider implementing a stream buffer
            // processor that produces a DOM node from the buffer.
            Transformer t = XmlUtil.newTransformer();
            SOAPHeader header = saaj.getSOAPHeader();
            if (header == null)
                header = saaj.getSOAPPart().getEnvelope().addHeader();
// TODO workaround for oracle xdk bug 16555545, when this bug is fixed the line below can be
// uncommented and all lines below, except the catch block, can be removed.
//            t.transform(epr.asSource(localName), new DOMResult(header));
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            XMLStreamWriter w = XMLOutputFactory.newFactory().createXMLStreamWriter(baos);
            epr.writeTo(localName, w);
            w.flush();
            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance();
            fac.setNamespaceAware(true);
            Node eprNode = fac.newDocumentBuilder().parse(bais).getDocumentElement();
            Node eprNodeToAdd = header.getOwnerDocument().importNode(eprNode, true);
            header.appendChild(eprNodeToAdd);
        } catch (Exception e) {
            throw new SOAPException(e);
        }
    }
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:27,代碼來源:EPRHeader.java

示例11: writeTo

import javax.xml.soap.SOAPHeader; //導入依賴的package包/類
@Override
public void writeTo(SOAPMessage saaj) throws SOAPException {
    //TODO: SAAJ returns null instead of throwing SOAPException,
    // when there is no SOAPHeader in the message,
    // which leads to NPE.
    try {
        SOAPHeader header = saaj.getSOAPHeader();
        if (header == null) {
            header = saaj.getSOAPPart().getEnvelope().addHeader();
        }
        Element node = (Element)infoset.writeTo(header);
        node.setAttributeNS(AddressingVersion.W3C.nsUri,AddressingVersion.W3C.getPrefix()+":"+IS_REFERENCE_PARAMETER,TRUE_VALUE);
    } catch (XMLStreamBufferException e) {
        throw new SOAPException(e);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:17,代碼來源:OutboundReferenceParameterHeader.java

示例12: deserializeConsumer

import javax.xml.soap.SOAPHeader; //導入依賴的package包/類
/**
 * Deserializes the client element of the SOAP header to a ConsumerMember
 * object.
 *
 * @param header SOAP header to be deserialized
 * @return ConsumerMember object
 * @throws XRd4JException if there's a XRd4J error
 * @throws XRd4JMissingMemberException if ConsumerMember is missing
 */
protected final ConsumerMember deserializeConsumer(final SOAPHeader header)
        throws XRd4JException, XRd4JMissingMemberException {
    LOGGER.debug("Deserialize \"{}\".", Constants.NS_XRD_ELEM_CLIENT);
    // Client headers
    Map<String, String> client;
    // Client object type
    ObjectType clientObjectType;

    NodeList list = header.getElementsByTagNameNS(Constants.NS_XRD_URL, Constants.NS_XRD_ELEM_CLIENT);
    if (list.getLength() == 1) {
        clientObjectType = this.deserializeObjectType((Node) list.item(0));
        client = SOAPHelper.nodesToMap(list.item(0).getChildNodes());
        LOGGER.trace(ELEMENT_FOUND_LOG_PATTERN, Constants.NS_XRD_ELEM_CLIENT);
        return this.getConsumerMember(client, clientObjectType);
    }
    LOGGER.warn("\"{}\" element missing from SOAP header.", Constants.NS_XRD_ELEM_CLIENT);
    throw new XRd4JMissingMemberException("Client element is missing from SOAP header.");
}
 
開發者ID:vrk-kpa,項目名稱:xrd4j,代碼行數:28,代碼來源:AbstractHeaderDeserializer.java

示例13: deserializeProducer

import javax.xml.soap.SOAPHeader; //導入依賴的package包/類
/**
 * Deserializes the service element of the SOAP header to a ProducerMember
 * object.
 *
 * @param header SOAP header to be deserialized
 * @return ProducerMember object
 * @throws XRd4JException if there's a XRd4J error
 * @throws XRd4JMissingMemberException if ProducerMember is missing
 */
protected final ProducerMember deserializeProducer(final SOAPHeader header)
        throws XRd4JException, XRd4JMissingMemberException {
    LOGGER.debug(DESERIALIZE_LOG_PATTERN, Constants.NS_XRD_ELEM_SERVICE);
    // Service headers
    Map<String, String> service;
    // Service object type
    ObjectType serviceObjectType;

    NodeList list = header.getElementsByTagNameNS(Constants.NS_XRD_URL, Constants.NS_XRD_ELEM_SERVICE);
    if (list.getLength() == 1) {
        serviceObjectType = this.deserializeObjectType((Node) list.item(0));
        service = SOAPHelper.nodesToMap(list.item(0).getChildNodes());
        LOGGER.trace(ELEMENT_FOUND_LOG_PATTERN, Constants.NS_XRD_ELEM_SERVICE);
        return this.getProducerMember(service, serviceObjectType);
    }
    LOGGER.warn("\"{}\" element missing from SOAP header.", Constants.NS_XRD_ELEM_SERVICE);
    throw new XRd4JMissingMemberException("Service element is missing from SOAP header.");
}
 
開發者ID:vrk-kpa,項目名稱:xrd4j,代碼行數:28,代碼來源:AbstractHeaderDeserializer.java

示例14: serializeService

import javax.xml.soap.SOAPHeader; //導入依賴的package包/類
private void serializeService(final SOAPHeader header, final AbstractMessage message, final SOAPEnvelope envelope) throws SOAPException {
    LOGGER.debug("Generate \"Service\" element.");
    ObjectType serviceObjectType = MessageHelper.getObjectType(message.getProducer());
    SOAPElement serviceHeader = header.addChildElement(Constants.NS_XRD_ELEM_SERVICE, Constants.NS_XRD_PREFIX);
    serviceHeader.addAttribute(envelope.createQName(Constants.NS_ID_ATTR_OBJECT_TYPE, Constants.NS_ID_PREFIX), serviceObjectType.toString());
    SOAPElement xRoadInstance = serviceHeader.addChildElement(Constants.NS_ID_ELEM_XROAD_INSTANCE, Constants.NS_ID_PREFIX);
    xRoadInstance.addTextNode(message.getProducer().getXRoadInstance());
    if (serviceObjectType == ObjectType.SERVICE) {
        SOAPElement memberClass = serviceHeader.addChildElement(Constants.NS_ID_ELEM_MEMBER_CLASS, Constants.NS_ID_PREFIX);
        memberClass.addTextNode(message.getProducer().getMemberClass());
        SOAPElement memberCode = serviceHeader.addChildElement(Constants.NS_ID_ELEM_MEMBER_CODE, Constants.NS_ID_PREFIX);
        memberCode.addTextNode(message.getProducer().getMemberCode());
    }
    if (message.getProducer().getSubsystemCode() != null && !message.getProducer().getSubsystemCode().isEmpty()) {
        SOAPElement subsystem = serviceHeader.addChildElement(Constants.NS_ID_ELEM_SUBSYSTEM_CODE, Constants.NS_ID_PREFIX);
        subsystem.addTextNode(message.getProducer().getSubsystemCode());
    }
    SOAPElement serviceCode = serviceHeader.addChildElement(Constants.NS_ID_ELEM_SERVICE_CODE, Constants.NS_ID_PREFIX);
    serviceCode.addTextNode(message.getProducer().getServiceCode());
    if (message.getProducer().getServiceVersion() != null && !message.getProducer().getServiceVersion().isEmpty()) {
        SOAPElement serviceVersion = serviceHeader.addChildElement(Constants.NS_ID_ELEM_SERVICE_VERSION, Constants.NS_ID_PREFIX);
        serviceVersion.addTextNode(message.getProducer().getServiceVersion());
    }
    LOGGER.debug("\"Service\" element was succesfully generated.");
}
 
開發者ID:vrk-kpa,項目名稱:xrd4j,代碼行數:26,代碼來源:AbstractHeaderSerializer.java

示例15: writeTo

import javax.xml.soap.SOAPHeader; //導入依賴的package包/類
public void writeTo(SOAPMessage saaj) throws SOAPException {
    try {
        // TODO what about in-scope namespaces
        // Not very efficient consider implementing a stream buffer
        // processor that produces a DOM node from the buffer.
        TransformerFactory tf = XmlUtil.newTransformerFactory(true);
        Transformer t = tf.newTransformer();
        XMLStreamBufferSource source = new XMLStreamBufferSource(_mark);
        DOMResult result = new DOMResult();
        t.transform(source, result);
        Node d = result.getNode();
        if(d.getNodeType() == Node.DOCUMENT_NODE)
            d = d.getFirstChild();
        SOAPHeader header = saaj.getSOAPHeader();
        if(header == null)
            header = saaj.getSOAPPart().getEnvelope().addHeader();
        Node node = header.getOwnerDocument().importNode(d, true);
        header.appendChild(node);
    } catch (Exception e) {
        throw new SOAPException(e);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:StreamHeader.java


注:本文中的javax.xml.soap.SOAPHeader類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。