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


Java SOAPEnvelope類代碼示例

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


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

示例1: createXPath

import javax.xml.soap.SOAPEnvelope; //導入依賴的package包/類
/**
 * Constructs XPath query over the SOAP message
 * 
 * @param query XPath query
 * @param response SOAP message
 * @return XPath query
 * @throws SOAPException in case of SOAP issue
 * @throws JaxenException XPath problem
 */
public final XPath createXPath(final String query, final SOAPMessage response) throws SOAPException, JaxenException {

  /* Uses DOM to XPath mapping */
  final XPath xpath = new DOMXPath(query);

  /* Define a namespaces used in response */
  final SimpleNamespaceContext nsContext = new SimpleNamespaceContext();
  final SOAPPart sp = response.getSOAPPart();
  final SOAPEnvelope env = sp.getEnvelope();
  final SOAPBody bdy = env.getBody();

  /* Add namespaces from SOAP envelope */
  addNamespaces(nsContext, env);

  /* Add namespaces of top body element */
  final Iterator<?> bodyElements = bdy.getChildElements();
  while (bodyElements.hasNext()) {
    SOAPElement element = (SOAPElement) bodyElements.next();
    addNamespaces(nsContext, element);
  }
  xpath.setNamespaceContext(nsContext);
  return xpath;
}
 
開發者ID:inbravo,項目名稱:scribe,代碼行數:33,代碼來源:SOAPExecutor.java

示例2: createMessage

import javax.xml.soap.SOAPEnvelope; //導入依賴的package包/類
private SOAPMessage createMessage(MessageFactory mf) throws SOAPException, IOException {
    SOAPMessage msg = mf.createMessage();
    SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
    Name name = envelope.createName("hello", "ex", "http://example.com");
    envelope.getBody().addChildElement(name).addTextNode("THERE!");

    String s = "<root><hello>THERE!</hello></root>";

    AttachmentPart ap = msg.createAttachmentPart(
            new StreamSource(new ByteArrayInputStream(s.getBytes())),
            "text/xml"
    );
    msg.addAttachmentPart(ap);
    msg.saveChanges();

    return msg;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:XmlTest.java

示例3: handleMessage

import javax.xml.soap.SOAPEnvelope; //導入依賴的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

示例4: createSOAPRequestMessage

import javax.xml.soap.SOAPEnvelope; //導入依賴的package包/類
/**
 * createSOAPRequestMessage - create a SOAP message from an object
 *
 * @param webServiceKey
 *            key to locate the web service
 * @param request
 *            - request body content
 * @param action
 *            - SOAP Action string
 * @return SOAPMessage
 * @throws SOAPException
 *             - if there was an error creating the SOAP Connection
 * @throws JAXBException
 *             - if there was an error marshalling the SOAP Message
 */
private SOAPMessage createSOAPRequestMessage(String webServiceKey, Object request, String action) throws SOAPException, JAXBException {
    WebService service = getWebService(webServiceKey);

    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage message = factory.createMessage();
    SOAPPart soapPart = message.getSOAPPart();

    // SOAP Envelope
    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("example", service.getNamespaceURI());

    if (action != null) {
        MimeHeaders headers = message.getMimeHeaders();
        headers.addHeader("SOAPAction", service.getNamespaceURI() + "VerifyEmail");
    }

    // SOAP Body
    SOAPBody body = message.getSOAPBody();

    marshallObject(webServiceKey, request, body);

    message.saveChanges();
    return message;
}
 
開發者ID:AgileTestingFramework,項目名稱:atf-toolbox-java,代碼行數:40,代碼來源:WebServiceAutomationManager.java

示例5: handleRequest

import javax.xml.soap.SOAPEnvelope; //導入依賴的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

示例6: createSimpleSOAPPart

import javax.xml.soap.SOAPEnvelope; //導入依賴的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

示例7: parseApiVersion_ctmg_1_8

import javax.xml.soap.SOAPEnvelope; //導入依賴的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

示例8: serializeClient

import javax.xml.soap.SOAPEnvelope; //導入依賴的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

示例9: addSoapHeader

import javax.xml.soap.SOAPEnvelope; //導入依賴的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

示例10: serializeResponse

import javax.xml.soap.SOAPEnvelope; //導入依賴的package包/類
@Override
/**
 * Serializes the response data.
 *
 * @param response ServiceResponse holding the application specific
 * response object
 * @param soapResponse SOAPMessage's response object where the response
 * element is added
 * @param envelope SOAPMessage's SOAPEnvelope object
 */
public void serializeResponse(ServiceResponse response, SOAPElement soapResponse, SOAPEnvelope envelope) throws SOAPException {
    // Add "data" element
    SOAPElement data = soapResponse.addChildElement(envelope.createName("data"));
    // Put response data inside the "data" element
    data.addTextNode((String) response.getResponseData());
}
 
開發者ID:vrk-kpa,項目名稱:xrd4j,代碼行數:17,代碼來源:ExampleAdapter.java

示例11: processRequestNode

import javax.xml.soap.SOAPEnvelope; //導入依賴的package包/類
private void processRequestNode(final SOAPBodyElement body, final ServiceResponse response,
                                final SOAPMessage soapRequest, final SOAPEnvelope envelope) throws SOAPException {
    boolean requestFound = false;
    NodeList list = soapRequest.getSOAPBody().getElementsByTagNameNS("*", response.getProducer().getServiceCode());
    if (list.getLength() == 1) {
        // Copy request from soapRequest
        requestFound = copyRequestNode((Node) list.item(0), body, response);
    }
    // It was not possible to copy the request element, so we must create it
    if (!requestFound) {
        SOAPElement temp = body.addChildElement(envelope.createName("request"));
        if (response.isAddNamespaceToRequest()) {
            LOGGER.debug("Add provider namespace to request element.");
            SOAPHelper.addNamespace(temp, response);
        }
    }
}
 
開發者ID:vrk-kpa,項目名稱:xrd4j,代碼行數:18,代碼來源:AbstractServiceResponseSerializer.java

示例12: serializeService

import javax.xml.soap.SOAPEnvelope; //導入依賴的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

示例13: getEnvelope

import javax.xml.soap.SOAPEnvelope; //導入依賴的package包/類
@Override
public SOAPEnvelope getEnvelope() throws SOAPException {

    // If there is no SOAP envelope already created, then create
    // one from a source if one exists. If there is a newer source
    // then use that source.

    if (sourceWasSet)
          sourceWasSet = false;

    lookForEnvelope();
    if (envelope != null) {
        if (source != null) { // there's a newer source, use it
            document.removeChild(envelope);
            envelope = createEnvelopeFromSource();
        }
    } else if (source != null) {
        envelope = createEnvelopeFromSource();
    } else {
        envelope = createEmptyEnvelope(null);
        document.insertBefore(((EnvelopeImpl) envelope).getDomElement(), null);
    }
    return envelope;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:SOAPPartImpl.java

示例14: writeTerminalResponse

import javax.xml.soap.SOAPEnvelope; //導入依賴的package包/類
/**
 * Gets the terminal response.
 * 
 * @param message
 * @throws SOAPException
 */
private void writeTerminalResponse(SOAPMessage message) throws SOAPException {
    SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
    Name terminalResponseName = envelope.createName("EditTerminalResponse", PREFIX, NAMESPACE_URI);
    SOAPBodyElement terminalResponseElement = (SOAPBodyElement) message.getSOAPBody().getChildElements(terminalResponseName).next();

    NodeList list = terminalResponseElement.getChildNodes();
    Node n = null;
    for (int i = 0; i < list.getLength(); i++) {
        n = list.item(i);
        if ("status".equalsIgnoreCase(n.getLocalName()))
            break;
    }

    logger.info("status of device = " + n.getNodeValue());

}
 
開發者ID:booleguo,項目名稱:sam-elle,代碼行數:23,代碼來源:EditTerminalClient.java

示例15: createTerminalRequest

import javax.xml.soap.SOAPEnvelope; //導入依賴的package包/類
/**
 * This method creates a Terminal Request and sends back the SOAPMessage.
 * MSISDN value is passed into this method
 * 
 * @param msisdn
 * @return
 * @throws SOAPException
 */
private SOAPMessage createTerminalRequest(String msisdn) throws SOAPException {
    SOAPMessage message = messageFactory.createMessage();
    message.getMimeHeaders().addHeader("SOAPAction", "http://api.jasperwireless.com/ws/service/terminal/GetTerminalsByMsisdn");
    SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
    Name terminalRequestName = envelope.createName("GetTerminalsByMsisdnRequest", PREFIX, NAMESPACE_URI);
    SOAPBodyElement terminalRequestElement = message.getSOAPBody().addBodyElement(terminalRequestName);
    Name msgId = envelope.createName("messageId", PREFIX, NAMESPACE_URI);
    SOAPElement msgElement = terminalRequestElement.addChildElement(msgId);
    msgElement.setValue("TCE-100-ABC-34084");
    Name version = envelope.createName("version", PREFIX, NAMESPACE_URI);
    SOAPElement versionElement = terminalRequestElement.addChildElement(version);
    versionElement.setValue("1.0");
    Name license = envelope.createName("licenseKey", PREFIX, NAMESPACE_URI);
    SOAPElement licenseElement = terminalRequestElement.addChildElement(license);
    licenseElement.setValue(apiKey);
    Name msisdns = envelope.createName("msisdns", PREFIX, NAMESPACE_URI);
    SOAPElement msisdnsElement = terminalRequestElement.addChildElement(msisdns);
    Name msisdnName = envelope.createName("msisdn", PREFIX, NAMESPACE_URI);
    SOAPElement msisdnElement = msisdnsElement.addChildElement(msisdnName);
    msisdnElement.setValue(msisdn);
    return message;
}
 
開發者ID:booleguo,項目名稱:sam-elle,代碼行數:31,代碼來源:GetTerminalsByMsisdnClient.java


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