当前位置: 首页>>代码示例>>Java>>正文


Java SOAPBody.addNamespaceDeclaration方法代码示例

本文整理汇总了Java中javax.xml.soap.SOAPBody.addNamespaceDeclaration方法的典型用法代码示例。如果您正苦于以下问题:Java SOAPBody.addNamespaceDeclaration方法的具体用法?Java SOAPBody.addNamespaceDeclaration怎么用?Java SOAPBody.addNamespaceDeclaration使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.xml.soap.SOAPBody的用法示例。


在下文中一共展示了SOAPBody.addNamespaceDeclaration方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSOAPMessage

import javax.xml.soap.SOAPBody; //导入方法依赖的package包/类
/**
 * Example of soap messaging in RestAssured.
 * @throws Exception
 */
@Test
public void testSOAPMessage() throws Exception {
    /*
    Construct SOAP Request Message instead of hardcoding as a string which is error prone:
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
        <SOAP-ENV:Header/>
        <SOAP-ENV:Body xmlns:ns2="http://namespace2.com">
            <n2:GetVendor>
                <n2:id>1290</n2:id>
            </n2:GetVendor>
        </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
     */
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    SOAPEnvelope envelope = soapPart.getEnvelope();
    SOAPBody soapBody = envelope.getBody();

    // Add namespace declarations
    soapBody.addNamespaceDeclaration("ns2", "http://namespace2.com");

    SOAPElement vendorElement = soapBody.addChildElement("Vendor", "ns2");
    vendorElement.addChildElement("id", "ns2").addTextNode("1290");
    soapMessage.saveChanges();

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    soapMessage.writeTo(out);
    String soapMessageInText = new String(out.toByteArray());

    /* Response stub returned from WireMock
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
        <SOAP-ENV:Header/>
        <SOAP-ENV:Body xmlns:ns2="http://namespace2.com">
            <ns2:Vendor>
                <ns2:id>1290</ns2:id>
                <ns2:name>John Smith</ns2:name>
                <ns2:phone>650-222-3333</ns2:phone>
            </ns2:Vendor>
        </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
     */

    //@formatter:off
    response = given().
            config(RestAssuredConfig.newConfig().
                    xmlConfig(XmlConfig.xmlConfig().
                            namespaceAware(true).
                            declareNamespace("ns2", "http://namespace2.com"))).
            spec(requestSpec).
            header("SOAPAction", "http://localhost/getVendor").
            contentType("application/soap+xml; charset=UTF-8;").
            body(soapMessageInText).
    when().
            post("/v1/vendors").
    then().assertThat().
            contentType(ContentType.XML).
            statusCode(200).
            extract().response();
    //@formatter:on

    // One way to assert
    String responseString = response.asString();
    String vendorName = new XmlPath(responseString).getString("Envelope.Body.Vendor.name");
    assertThat(vendorName, is("John Smith"));

    // Another way to assert
    vendorName = XmlPath.with(responseString).get("Envelope.Body.Vendor.name");
    assertThat(vendorName, is("John Smith"));
}
 
开发者ID:eing,项目名称:restassured_cli,代码行数:75,代码来源:SampleComponentTest.java

示例2: testAddChildElement

import javax.xml.soap.SOAPBody; //导入方法依赖的package包/类
@Validated @Test
public void testAddChildElement() throws Exception {
    String s = "MyName1";
    String p = "MyPrefix1";
    String u = "myURI";
    SOAPBody body = MessageFactory.newInstance().createMessage().getSOAPBody();
    SOAPElement myse = body.addNamespaceDeclaration(p, u);
    SOAPElement se = body.addChildElement(s, p);
    if (se == null) {
        fail("SOAPElement was null");
    } else {
        Iterator i = body.getChildElements();
        int count = getIteratorCount(i);
        i = body.getChildElements();
        if (count != 1) {
            fail("Wrong iterator count returned of " + count + ", expected 1");
        } else {
            SOAPElement se2 = (SOAPElement)i.next();
            if (!se.equals(se2)) {
                fail("Elements not equal");
            }
        }
        String name = se.getElementName().getLocalName();
        Name n = se.getElementName();
        String prefix = se.getElementName().getPrefix();
        if (!name.equals(s) || !prefix.equals(p)) {
            fail("addChildElement() did not return correct local name and prefix");
        }
    }
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:31,代码来源:SOAPElementTest.java

示例3: testRemoveNamespaceDeclaration

import javax.xml.soap.SOAPBody; //导入方法依赖的package包/类
@Validated @Test
public void testRemoveNamespaceDeclaration() throws Exception {
    String prefix = "myPrefix";
    String uri = "myURI";
    SOAPMessage msg = MessageFactory.newInstance().createMessage();
    SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
    SOAPBody body = envelope.getBody();
    body.addNamespaceDeclaration(prefix, uri);
    boolean b = body.removeNamespaceDeclaration(prefix);
    assertTrue("removeNamespaceDeclaration() did not return true", b);
    b = body.removeNamespaceDeclaration(prefix);
    assertFalse("removeNamespaceDeclaration() did not return false", b);
    assertNull(body.getNamespaceURI(prefix));
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:15,代码来源:SOAPElementTest.java

示例4: launchMobyAsyncService

import javax.xml.soap.SOAPBody; //导入方法依赖的package包/类
/**
 * This method is used to launch an asynchronous MOBY job.
 *
 * @param endpoint
 *            The endpoint of the service.
 * @param msName
 *            The MOBY service name.
 * @param mobyXML
 *            The MOBY payload to be sent to the service.
 * @return The EndpointReference object which helds the details of the MOBY
 *         asynchronous job.
 * @throws MobyException
 */
private static EndpointReference launchMobyAsyncService(String endpoint,
		String msName, String mobyXML) throws MobyException {
	try {
		Service service = Service.create(new QName(
				MobyService.BIOMOBY_SERVICE_URI, msName + "Service"));
		QName mQName = new QName(MobyService.BIOMOBY_SERVICE_URI, msName
				+ "Port");

		service.addPort(mQName, SOAPBinding.SOAP11HTTP_BINDING, endpoint);
		Dispatch<SOAPMessage> dispatch = service.createDispatch(mQName,
				SOAPMessage.class, Service.Mode.MESSAGE);
		Map<String, Object> rc = dispatch.getRequestContext();
		rc.put(BindingProvider.SOAPACTION_USE_PROPERTY, new Boolean(true));
		rc.put(BindingProvider.SOAPACTION_URI_PROPERTY,
				MobyService.BIOMOBY_SERVICE_URI + "#" + msName + "_submit");

		MessageFactory mf = MessageFactory.newInstance();
		SOAPMessage request = mf.createMessage();
		SOAPPart part = request.getSOAPPart();

		String mobyPrefix = "mobyws";
		String xsiPrefix = "xsi";

		// Obtain the SOAPEnvelope and header and body elements.
		SOAPEnvelope env = part.getEnvelope();
		SOAPBody body = env.getBody();

		// Now the SOAP body
		body.addNamespaceDeclaration(mobyPrefix,
				MobyService.BIOMOBY_SERVICE_URI);
		SOAPElement rootMessage = body.addChildElement(msName + "_submit",
				mobyPrefix, MobyService.BIOMOBY_SERVICE_URI);
		SOAPElement data = rootMessage.addChildElement("data", mobyPrefix,
				MobyService.BIOMOBY_SERVICE_URI);
		data.addNamespaceDeclaration(xsiPrefix,
				MobyPrefixResolver.XSI_NAMESPACE2001);
		data.addNamespaceDeclaration("xsd", XSD_NS);
		data.addAttribute(env.createName("type", xsiPrefix,
				MobyPrefixResolver.XSI_NAMESPACE2001), "xsd:string");
		data.addTextNode(mobyXML);

		request.saveChanges();
		SOAPMessage outputMessage = dispatch.invoke(request);
		DOMSource output = new DOMSource(outputMessage.getSOAPPart()
				.getEnvelope());

		StringWriter sw = new StringWriter();
		Transformer tr = TransformerFactory.newInstance().newTransformer();
		tr.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
		tr.transform(output, new StreamResult(sw));

		String response = sw.toString();
		return EndpointReference.createFromXML(response);
	} catch (SOAPException pce) {
		throw new MobyException(
				"Unable to create SOAP document builder for MOBY asynchronous call submission",
				pce);
	} catch (TransformerConfigurationException tce) {
		throw new MobyException(
				"Unable to create transformer factory for MOBY asynchronous call response",
				tce);
	} catch (TransformerException te) {
		throw new MobyException(
				"Unable to create transformer for MOBY asynchronous call response",
				te);
	}
}
 
开发者ID:apache,项目名称:incubator-taverna-plugin-bioinformatics,代码行数:81,代码来源:ExecuteAsyncMobyService.java


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