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


Java SOAPBody.addBodyElement方法代码示例

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


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

示例1: createSimpleSOAPPart

import javax.xml.soap.SOAPBody; //导入方法依赖的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

示例2: createDefaultSoapMessage

import javax.xml.soap.SOAPBody; //导入方法依赖的package包/类
public static SOAPMessage createDefaultSoapMessage(String responseMessage, String requestMessage) {
    try {
        SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
        SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody();

        QName payloadName = new QName("http://apache.org/hello_world_soap_http/types", "greetMeResponse", "ns1");

        SOAPBodyElement payload = body.addBodyElement(payloadName);

        SOAPElement message = payload.addChildElement("responseType");

        message.addTextNode(responseMessage + " Request was  " + requestMessage);
        return soapMessage;
    } catch (SOAPException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:TesterBean.java

示例3: testAddingPrefixesForChildElements

import javax.xml.soap.SOAPBody; //导入方法依赖的package包/类
@Validated @Test
public void testAddingPrefixesForChildElements() throws Exception {
    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage msg = factory.createMessage();
    SOAPPart sp = msg.getSOAPPart();
    SOAPEnvelope se = sp.getEnvelope();
    SOAPBody sb = se.getBody();
    SOAPElement el1 = sb.addBodyElement(se.createName("element1",
                                                      "prefix1",
                                                      "http://www.sun.com"));
    el1.addChildElement(se.createName("element2",
                                      "prefix2",
                                      "http://www.apache.org"));

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    msg.writeTo(baos);

    String xml = new String(baos.toByteArray());
    assertTrue(xml.indexOf("prefix1") != -1);
    assertTrue(xml.indexOf("prefix2") != -1);
    assertTrue(xml.indexOf("http://www.sun.com") != -1);
    assertTrue(xml.indexOf("http://www.apache.org") != -1);
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:24,代码来源:PrefixesTest.java

示例4: createSOAPMessage

import javax.xml.soap.SOAPBody; //导入方法依赖的package包/类
private SOAPMessage createSOAPMessage(Element elem) throws Exception {
    String prefix = "";
    MessageFactory msgFactory = MessageFactory.newInstance();
    SOAPFactory factory = SOAPFactory.newInstance();

    SOAPMessage message = msgFactory.createMessage();
    message.getSOAPHeader().detachNode();
    SOAPPart soapPart = message.getSOAPPart();
    SOAPBody soapBody = soapPart.getEnvelope().getBody();
    //Create the outer body element
    Name bodyName = factory.createName(elem.getNodeName(), prefix, UDDI_V2_NAMESPACE);
    SOAPBodyElement bodyElement = soapBody.addBodyElement(bodyName);
    bodyElement.addNamespaceDeclaration(prefix, UDDI_V2_NAMESPACE);
    appendAttributes(bodyElement, elem.getAttributes(), factory);
    appendElements(bodyElement, elem.getChildNodes(), factory);
    return message;
}
 
开发者ID:apache,项目名称:juddi-scout,代码行数:18,代码来源:SaajTransport.java

示例5: process

import javax.xml.soap.SOAPBody; //导入方法依赖的package包/类
public void process(Exchange exchange) throws Exception {

        byte[] body2 = (byte[])exchange.getOut().getBody();

        if (body2 != null) {
            ByteArrayInputStream bais = new ByteArrayInputStream(body2);

            SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
            SOAPBody soapBody = soapMessage.getSOAPPart().getEnvelope().getBody();
            QName payloadName = new QName("http://soap.jax.drools.org/", "executeResponse", "ns1");
            QName responseName = new QName("http://soap.jax.drools.org/", "return", "ns1");
            SOAPBodyElement payload = soapBody.addBodyElement(payloadName);
            SOAPElement response = payload.addChildElement(responseName);
            response.addTextNode(StringUtils.toString(bais));

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            soapMessage.writeTo(baos);

            exchange.getOut().setBody(new String(baos.toByteArray()));
        }
    }
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:22,代码来源:PostCxfTransportSoapProcessor.java

示例6: process

import javax.xml.soap.SOAPBody; //导入方法依赖的package包/类
public void process(Exchange exchange) throws Exception {
    InputStream is = (InputStream)exchange.getIn().getBody();
    // Bad Hack - Need to remote it and fix it in Camel (if it's a camel problem)
    // I need to copy the results here because I loose them at the end of the method
    if (is != null) {
        String results = StringUtils.toString(is);
        SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
        SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody();
        QName payloadName = new QName("http://soap.jax.drools.org/", "executeResponse", "ns1");
        QName responseName = new QName("http://soap.jax.drools.org/", "return", "ns1");
        SOAPBodyElement payload = body.addBodyElement(payloadName);
        SOAPElement response = payload.addChildElement(responseName);
        // Bad Hack - Need to remote it and fix it in Camel (if it's a camel problem)
        // response.addTextNode( StringUtils.toString( is ) );
        response.addTextNode(results);
        exchange.getOut().setBody(soapMessage);
    }
}
 
开发者ID:jboss-integration,项目名称:fuse-bxms-integ,代码行数:19,代码来源:PostCxfSoapProcessor.java

示例7: serializeBody

import javax.xml.soap.SOAPBody; //导入方法依赖的package包/类
/**
 * Generates SOAP body, including the request element.
 *
 * @param request ServiceRequest to be serialized
 * @throws SOAPException if there's a SOAP error
 * @throws XRd4JException if there's a XRd4J error
 */
private void serializeBody(final ServiceRequest request) throws SOAPException, XRd4JException {
    LOGGER.debug("Generate SOAP body.");
    LOGGER.debug("Use producer namespace \"{}\".", request.getProducer().getNamespaceUrl());
    // Body - Start
    SOAPEnvelope envelope = request.getSoapMessage().getSOAPPart().getEnvelope();
    SOAPBody body = request.getSoapMessage().getSOAPBody();
    Name bodyName;
    boolean hasNamespace = false;
    
    // Is namespace defined?
    if (request.getProducer().getNamespaceUrl() != null && !request.getProducer().getNamespaceUrl().isEmpty()) {
        bodyName = envelope.createName(request.getProducer().getServiceCode(),
            request.getProducer().getNamespacePrefix(), request.getProducer().getNamespaceUrl());
        hasNamespace = true;
    } else {
        bodyName = envelope.createName(request.getProducer().getServiceCode());
    }
    
    SOAPBodyElement gltp = body.addBodyElement(bodyName);
    if (request.getRequestData() != null) {
        SOAPElement soapRequest;
        // Check if it is needed to process "request" and "response" wrappers
        if (request.isProcessingWrappers()) {
            LOGGER.debug("Adding \"request\" wrapper to request message.");
            soapRequest = gltp.addChildElement(envelope.createName("request"));
        } else {
            LOGGER.debug("Skipping addition of \"request\" wrapper to request message.");
            soapRequest = gltp;
        }
        LOGGER.trace("Passing processing to subclass implementing \"serializeRequest\" method.");
        // Generate request
        this.serializeRequest(request, soapRequest, envelope);
        // Is namespace defined and should it be added to the request?
        if (hasNamespace && request.isAddNamespaceToRequest()) {
            SOAPHelper.addNamespace(soapRequest, request);
        }
    }
    LOGGER.debug("SOAP body was generated succesfully.");
}
 
开发者ID:vrk-kpa,项目名称:xrd4j,代码行数:47,代码来源:AbstractServiceRequestSerializer.java

示例8: serializeBody

import javax.xml.soap.SOAPBody; //导入方法依赖的package包/类
/**
 * Generates SOAP body, including the request and response elements.
 *
 * @param response ServiceResponse to be serialized
 * @param soapRequest request's SOAP message object that's used for copying
 * the request element
 * @throws SOAPException if there's a SOAP error
 */
private void serializeBody(final ServiceResponse response, final SOAPMessage soapRequest) throws SOAPException, XRd4JException {
    LOGGER.debug("Generate SOAP body.");
    if (response.isAddNamespaceToServiceResponse() || response.isAddNamespaceToRequest() || response.isAddNamespaceToResponse()) {
        if (response.getProducer().getNamespaceUrl() == null || response.getProducer().getNamespaceUrl().isEmpty()) {
            throw new XRd4JException("Producer namespace URI can't be null or empty.");
        }
        LOGGER.debug("Producer namespace \"{}\".", response.getProducer().getNamespaceUrl());
    }

    // Body - Start
    SOAPEnvelope envelope = response.getSoapMessage().getSOAPPart().getEnvelope();
    SOAPBody body = envelope.getBody();
    Name bodyName;
    if (response.isAddNamespaceToServiceResponse()) {
        LOGGER.debug("Create service response with namespace.");
        bodyName = envelope.createName(response.getProducer().getServiceCode() + "Response",
            response.getProducer().getNamespacePrefix(), response.getProducer().getNamespaceUrl());
    } else {
        LOGGER.debug("Create service response without namespace.");
        bodyName = envelope.createName(response.getProducer().getServiceCode() + "Response");
    }
    SOAPBodyElement gltp = body.addBodyElement(bodyName);
    // Process SOAP body
    SOAPElement soapResponse = processBody(gltp, response, soapRequest, envelope);
    // Process the actual payload
    processBodyContent(soapResponse, response, envelope);
    LOGGER.debug("SOAP body was generated succesfully.");
}
 
开发者ID:vrk-kpa,项目名称:xrd4j,代码行数:37,代码来源:AbstractServiceResponseSerializer.java

示例9: process

import javax.xml.soap.SOAPBody; //导入方法依赖的package包/类
public void process(SOAPEnvelope req, SOAPEnvelope resp) throws javax.xml.soap.SOAPException {
	SOAPBody body = resp.getBody();
	Name ns0 =  resp.createName("TestNS0", "ns0", "http://example.com");
	Name ns1 =  resp.createName("TestNS1", "ns1", "http://example.com");
	SOAPElement bodyElmnt = body.addBodyElement(ns0);
	SOAPElement el = bodyElmnt.addChildElement(ns1);
	el.addTextNode("TEST RESPONSE");
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:9,代码来源:MessageService.java

示例10: searchUDDI

import javax.xml.soap.SOAPBody; //导入方法依赖的package包/类
public static void searchUDDI(String name, String url) throws Exception {
    // Create the connection and the message factory.
    SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
    SOAPConnection connection = scf.createConnection();
    MessageFactory msgFactory = MessageFactory.newInstance();

    // Create a message
    SOAPMessage msg = msgFactory.createMessage();

    // Create an envelope in the message
    SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();

    // Get hold of the the body
    SOAPBody body = envelope.getBody();

    javax.xml.soap.SOAPBodyElement bodyElement = body.addBodyElement(envelope.createName("find_business", "",
            "urn:uddi-org:api"));

    bodyElement.addAttribute(envelope.createName("generic"), "1.0")
            .addAttribute(envelope.createName("maxRows"), "100")
            .addChildElement("name")
            .addTextNode(name);

    URLEndpoint endpoint = new URLEndpoint(url);
    msg.saveChanges();

    SOAPMessage reply = connection.call(msg, endpoint);
    //System.out.println("Received reply from: " + endpoint);
    //reply.writeTo(System.out);
    connection.close();
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:32,代码来源:UddiPing.java

示例11: getStockQuote

import javax.xml.soap.SOAPBody; //导入方法依赖的package包/类
public String getStockQuote(String tickerSymbol) throws Exception {
    SOAPConnectionFactory scFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection con = scFactory.createConnection();

    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage message = factory.createMessage();

    SOAPPart soapPart = message.getSOAPPart();
    SOAPEnvelope envelope = soapPart.getEnvelope();

    SOAPHeader header = envelope.getHeader();
    SOAPBody body = envelope.getBody();

    header.detachNode();

    Name bodyName = envelope.createName("getQuote", "n", "urn:xmethods-delayed-quotes");
    SOAPBodyElement gltp = body.addBodyElement(bodyName);

    Name name = envelope.createName("symbol");
    SOAPElement symbol = gltp.addChildElement(name);
    symbol.addTextNode(tickerSymbol);

    URLEndpoint endpoint = new URLEndpoint("http://64.124.140.30/soap");
    SOAPMessage response = con.call(message, endpoint);
    con.close();

    SOAPPart sp = response.getSOAPPart();
    SOAPEnvelope se = sp.getEnvelope();
    SOAPBody sb = se.getBody();
    Iterator it = sb.getChildElements();
    while (it.hasNext()) {
        SOAPBodyElement bodyElement = (SOAPBodyElement) it.next();
        Iterator it2 = bodyElement.getChildElements();
        while (it2.hasNext()) {
            SOAPElement element2 = (SOAPElement) it2.next();
            return element2.getValue();
        }
    }
    return null;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:41,代码来源:DelayedStockQuote.java

示例12: echoUsingSAAJ

import javax.xml.soap.SOAPBody; //导入方法依赖的package包/类
/**
 * This method sends a file as an attachment then 
 *  receives it as a return.  The returned file is
 *  compared to the source. Uses SAAJ API.
 *  @param The filename that is the source to send.
 *  @return True if sent and compared.
 */
public boolean echoUsingSAAJ(String filename) throws Exception {
    String endPointURLString =  "http://localhost:" +opts.getPort() + "/axis/services/urn:EchoAttachmentsService";

    SOAPConnectionFactory soapConnectionFactory =
            javax.xml.soap.SOAPConnectionFactory.newInstance();
    SOAPConnection soapConnection =
            soapConnectionFactory.createConnection();

    MessageFactory messageFactory =
            MessageFactory.newInstance();
    SOAPMessage soapMessage =
            messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    SOAPEnvelope requestEnvelope =
            soapPart.getEnvelope();
    SOAPBody body = requestEnvelope.getBody();
    SOAPBodyElement operation = body.addBodyElement
            (requestEnvelope.createName("echo"));

    Vector dataHandlersToAdd = new Vector();
    dataHandlersToAdd.add(new DataHandler(new FileDataSource(new
            File(filename))));

    if (dataHandlersToAdd != null) {
        ListIterator dataHandlerIterator =
                dataHandlersToAdd.listIterator();

        while (dataHandlerIterator.hasNext()) {
            DataHandler dataHandler = (DataHandler)
                    dataHandlerIterator.next();
            javax.xml.soap.SOAPElement element =
                    operation.addChildElement(requestEnvelope.createName("source"));
            javax.xml.soap.AttachmentPart attachment =
                    soapMessage.createAttachmentPart(dataHandler);
            soapMessage.addAttachmentPart(attachment);
            element.addAttribute(requestEnvelope.createName
                                 ("href"), "cid:" + attachment.getContentId());
        }
    }
    javax.xml.soap.SOAPMessage returnedSOAPMessage =
            soapConnection.call(soapMessage, endPointURLString);
    Iterator iterator = returnedSOAPMessage.getAttachments();
    if (!iterator.hasNext()) {
        //The wrong type of object that what was expected.
        System.out.println("Received problem response from server");
        throw new AxisFault("", "Received problem response from server", null, null);

    }
    //Still here, so far so good.
    //Now lets brute force compare the source attachment
    // to the one we received.
    DataHandler rdh = (DataHandler) ((AttachmentPart)iterator.next()).getDataHandler();

    //From here we'll just treat the data resource as file.
    String receivedfileName = rdh.getName();//Get the filename. 

    if (receivedfileName == null) {
        System.err.println("Could not get the file name.");
        throw new AxisFault("", "Could not get the file name.", null, null);
    }


    System.out.println("Going to compare the files..");
    boolean retv = compareFiles(filename, receivedfileName);

    java.io.File receivedFile = new java.io.File(receivedfileName);

    receivedFile.delete();

    return retv;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:79,代码来源:EchoAttachment.java

示例13: sendJaxmMsg

import javax.xml.soap.SOAPBody; //导入方法依赖的package包/类
private void sendJaxmMsg (String aMsg, String u)  {
	try	{
		System.setProperty("javax.net.ssl.trustStore", u);

		SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
		SOAPConnection connection = scf.createConnection();

		MessageFactory mf = MessageFactory.newInstance();
	    SOAPMessage message = mf.createMessage();

		SOAPPart sp = message.getSOAPPart();
	    SOAPEnvelope envelope = sp.getEnvelope();

		SOAPHeader header = envelope.getHeader();
	    SOAPBody body = envelope.getBody();

		SOAPHeaderElement headerElement = header.addHeaderElement(envelope.createName("OSCAR", "DT", "http://www.oscarhome.org/"));
	    headerElement.addTextNode("header");

		SOAPBodyElement bodyElement = body.addBodyElement(envelope.createName("Service"));
	    bodyElement.addTextNode("compete");

		AttachmentPart ap1 = message.createAttachmentPart();
		ap1.setContent(aMsg, "text/plain");

		message.addAttachmentPart(ap1);

		URLEndpoint endPoint = new URLEndpoint (URLService);  //"https://67.69.12.115:8443/OscarComm/DummyReceiver");
		SOAPMessage reply = connection.call(message, endPoint);

		connection.close();
	} catch (Exception e)	{
		MiscUtils.getLogger().error("Error", e);
	}
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:36,代码来源:FrmStudyXMLClientSend.java

示例14: createSoapRequest

import javax.xml.soap.SOAPBody; //导入方法依赖的package包/类
/**
 * Populate the SOAP request message.
 */
protected SOAPMessage createSoapRequest(Object requestObj) throws ActivityException {
    try {
        MessageFactory messageFactory = getSoapMessageFactory();
        SOAPMessage soapMessage = messageFactory.createMessage();
        Map<Name,String> soapReqHeaders = getSoapRequestHeaders();
        if (soapReqHeaders != null) {
            SOAPHeader header = soapMessage.getSOAPHeader();
            for (Name name : soapReqHeaders.keySet()) {
                header.addHeaderElement(name).setTextContent(soapReqHeaders.get(name));
            }
        }

        SOAPBody soapBody = soapMessage.getSOAPBody();

        Document requestDoc = null;
        if (requestObj instanceof String) {
            requestDoc = DomHelper.toDomDocument((String)requestObj);
        }
        else {
            Variable reqVar = getProcessDefinition().getVariable(getAttributeValue(REQUEST_VARIABLE));
            XmlDocumentTranslator docRefTrans = (XmlDocumentTranslator)VariableTranslator.getTranslator(getPackage(), reqVar.getType());
            requestDoc = docRefTrans.toDomDocument(requestObj);
        }

        SOAPBodyElement bodyElem = soapBody.addBodyElement(getOperation());
        String requestLabel = getRequestLabelPartName();
        if (requestLabel != null) {
            SOAPElement serviceNameElem = bodyElem.addChildElement(requestLabel);
            serviceNameElem.addTextNode(getRequestLabel());
        }
        SOAPElement requestDetailsElem = bodyElem.addChildElement(getRequestPartName());
        requestDetailsElem.addTextNode("<![CDATA[" + DomHelper.toXml(requestDoc) + "]]>");

        return soapMessage;
    }
    catch (Exception ex) {
        throw new ActivityException(ex.getMessage(), ex);
    }
}
 
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:43,代码来源:MdwRpcWebServiceAdapter.java

示例15: invokeAdd2

import javax.xml.soap.SOAPBody; //导入方法依赖的package包/类
private void invokeAdd2(int firstArg, int secondArg) {
int sum = 0;

/** Create SOAPMessage request. **/
try {
    MessageFactory mf = MessageFactory
	    .newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
    // Create a message.
    SOAPMessage request = mf.createMessage();

    // Specify operation in a HTTP header
    addOperationHTTPHdr("add");

    // Obtain the SOAP body from SOAPEnvelope.
    SOAPEnvelope soapEnv = request.getSOAPPart().getEnvelope();

    // Construct the message payload.
    Name bodyName = soapEnv
	    .createName("operation", "ns", NAMESPACE_URI);
    SOAPBody body = soapEnv.getBody();
    SOAPBodyElement operation = body.addBodyElement(bodyName);

    populateOperationArgs(operation, firstArg, secondArg);

    request.saveChanges();

    /** Invoke the service endpoint. **/
    SOAPMessage response = dispatch.invoke(request);

    sum = getResult(response);
} catch (Exception e) {
    e.printStackTrace();
}

System.out.println("Sum of " + firstArg + " and " + secondArg + " is "
	+ sum);
   }
 
开发者ID:asarkar,项目名称:jax-ws,代码行数:38,代码来源:JAXWSProviderDispatchClient.java


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