Java 类javax.xml.soap.SOAPPart 实例源码

项目:scribe    文件:SOAPExecutor.java   
/**
 * 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;
}
项目:oscm    文件:SoapRequestParserTest.java   
@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);
}
项目:atf-toolbox-java    文件:WebServiceAutomationManager.java   
/**
 * 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;
}
项目:soap-wrapper-lambda    文件:ExampleSoapMessage.java   
public static SOAPMessage create() throws SOAPException {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage message = messageFactory.createMessage();
    SOAPPart soapPart = message.getSOAPPart();

    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("codecentric", "https://www.codecentric.de");

    SOAPBody envelopeBody = envelope.getBody();
    SOAPElement soapBodyElem = envelopeBody.addChildElement("location", "codecentric");

    SOAPElement place = soapBodyElem.addChildElement("place", "codecentric");
    place.addTextNode("Berlin");

    MimeHeaders headers = message.getMimeHeaders();
    headers.addHeader("SOAPAction", "https://www.codecentric.de/location");

    message.saveChanges();
    return message;
}
项目:Camel    文件:TesterBean.java   
public SOAPMessage processSOAP(Exchange exchange) {
    // Since the Camel-CXF endpoint uses a list to store the parameters
    // and bean component uses the bodyAs expression to get the value
    // we'll need to deal with the parameters ourself
    SOAPMessage soapMessage = (SOAPMessage)exchange.getIn().getBody(List.class).get(0);
    if (soapMessage == null) {
        System.out.println("Incoming null message detected...");
        return createDefaultSoapMessage("Greetings from Apache Camel!!!!", "null");
    }

    try {
        SOAPPart sp = soapMessage.getSOAPPart();
        SOAPEnvelope se = sp.getEnvelope();
        SOAPBody sb = se.getBody();
        String requestText = sb.getFirstChild().getTextContent();
        System.out.println(requestText);
        return createDefaultSoapMessage("Greetings from Apache Camel!!!!", requestText);
    } catch (Exception e) {
        e.printStackTrace();
        return createDefaultSoapMessage("Greetings from Apache Camel!!!!", e.getClass().getName());
    }
}
项目:development    文件:SoapRequestParserTest.java   
@Test
public void parseApiVersion_cm_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("cm.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);
}
项目:development    文件:SoapRequestParserTest.java   
@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);
}
项目:jbossws-cxf    文件:ProviderMessageTestCase.java   
@Test
@RunAsClient
public void testProviderMessageNullResponse() throws Exception
{
   MessageFactory msgFactory = MessageFactory.newInstance();
   SOAPMessage reqMsg = msgFactory.createMessage(null, new ByteArrayInputStream(msgStringForNullResponse.getBytes()));

   URL epURL = baseURL;
   SOAPConnection con = SOAPConnectionFactory.newInstance().createConnection();
   SOAPMessage resMsg = con.call(reqMsg, epURL);
   if (resMsg != null)
   {
      SOAPPart soapPart = resMsg.getSOAPPart();
      //verify there's either nothing in the reply or at least the response body is empty
      if (soapPart != null && soapPart.getEnvelope() != null && soapPart.getEnvelope().getBody() != null)
      {
         SOAPBody soapBody = soapPart.getEnvelope().getBody();
         assertFalse(soapBody.getChildElements().hasNext());
      }
   }
}
项目:PDFReporter-Studio    文件:MetadataDiscover.java   
/**
 * Return an array of the datasources in the server, could be null
 * @return array of datasources
 */
public DataSourceTreeElement[] getDatasources() {
    setRequestType("DISCOVER_DATASOURCES");
    SOAPMessage response = executeDiscover(new HashMap<String, String>());
    SOAPPart soapPart = response.getSOAPPart();
    SOAPEnvelope soapEnvelope;
    try {            
        soapEnvelope = soapPart.getEnvelope();
        SOAPElement rowSet = getRowsSet(response, soapEnvelope);
        List<DataSourceTreeElement> result = new ArrayList<DataSourceTreeElement>();
        Name rowElement = soapEnvelope.createName("row", "", ROW_URI);
        Iterator<?> rowValuesElement = rowSet.getChildElements(rowElement);
        while (rowValuesElement.hasNext())
        {
            SOAPElement cellElement = (SOAPElement)rowValuesElement.next();
            result.add(new DataSourceElement(this, cellElement));
        }
        return result.toArray(new DataSourceTreeElement[result.size()]);
    } catch (SOAPException e) {
        e.printStackTrace();
    }
    return null;
}
项目:PDFReporter-Studio    文件:MetadataDiscover.java   
/**
 * Return an array of the catalogs in the server for a specific datasource, could be null
 * @param datasourceName the name of the datasource
 * @return array of catalogs
 */
public DataSourceTreeElement[] getCatalogList(String datasourceName) {
    setRequestType("DBSCHEMA_CATALOGS");
    HashMap<String, String> param = new HashMap<String, String>();
    param.put("DataSourceInfo", datasourceName);
    SOAPMessage response = executeDiscover(param);
    SOAPPart soapPart = response.getSOAPPart();
    SOAPEnvelope soapEnvelope;
    try {
        soapEnvelope = soapPart.getEnvelope();
        SOAPElement rowSet = getRowsSet(response, soapEnvelope);
        List<DataSourceTreeElement> result = new ArrayList<DataSourceTreeElement>();
        Name rowElement = soapEnvelope.createName("row", "", ROW_URI);
        Iterator<?> rowValuesElement = rowSet.getChildElements(rowElement);
        while (rowValuesElement.hasNext())
        {
            SOAPElement cellElement = (SOAPElement)rowValuesElement.next();
            result.add(new CatalogElement(this, cellElement, datasourceName));
        }
        return result.toArray(new DataSourceTreeElement[result.size()]);
    } catch (SOAPException e) {
        e.printStackTrace();
    }
    return null;
}
项目:PDFReporter-Studio    文件:MetadataDiscover.java   
/**
 * Return an array of the cubes in the server for a specific datasource and catalog, could be null
 * @param datasourceName the name of the datasource
 * @param catalogName the name of the catalog
 * @return array of cubes
 */
public DataSourceTreeElement[] getCubeList(String datasourceName, String catalogName) {
    setRequestType("MDSCHEMA_CUBES");
    HashMap<String, String> param = new HashMap<String, String>();
    param.put("DataSourceInfo", datasourceName);
    param.put("Catalog", catalogName);
    SOAPMessage response = executeDiscover(param);
    SOAPPart soapPart = response.getSOAPPart();
    SOAPEnvelope soapEnvelope;
    try {
        soapEnvelope = soapPart.getEnvelope();
        SOAPElement rowSet = getRowsSet(response, soapEnvelope);
        List<DataSourceTreeElement> result = new ArrayList<DataSourceTreeElement>();
        Name rowElement = soapEnvelope.createName("row", "", ROW_URI);
        Iterator<?> rowValuesElement = rowSet.getChildElements(rowElement);
        while (rowValuesElement.hasNext())
        {
            SOAPElement cellElement = (SOAPElement)rowValuesElement.next();
            result.add(new CubeElement(this, cellElement, datasourceName));
        }
        return result.toArray(new DataSourceTreeElement[result.size()]);
    } catch (SOAPException e) {
        e.printStackTrace();
    }
    return null;
}
项目:j-road    文件:SOAPUtil.java   
/**
 * Substitutes all occurences of some given string inside the given {@link WebServiceMessage} with another value.
 *
 * @param message message to substitute in
 * @param from the value to substitute
 * @param to the value to substitute with
 * @throws TransformerException
 */
public static void substitute(WebServiceMessage message, String from, String to) throws TransformerException {
  SaajSoapMessage saajSoapMessage = (SaajSoapMessage) message;
  SOAPPart soapPart = saajSoapMessage.getSaajMessage().getSOAPPart();

  Source source = new DOMSource(soapPart);
  StringResult stringResult = new StringResult();

  TransformerFactory.newInstance().newTransformer().transform(source, stringResult);

  String content = stringResult.toString().replaceAll(from, to);

  try {
    soapPart.setContent(new StringSource(content));
  } catch (SOAPException e) {
    throw new TransformerException(e);
  }
}
项目:wso2-axis2    文件:SoapMessageCheckMTOMProvider.java   
/**
 * Very simple operation.
 * If there are no attachments, an exception is thrown.
 * Otherwise the message is echoed.
 */
public SOAPMessage invoke(SOAPMessage soapMessage)  {
    System.out.println(">> SoapMessageCheckMTOMProvider: Request received.");


    int numAttachments = soapMessage.countAttachments();
    if (numAttachments == 0) {
        System.out.println(">> SoapMessageCheckMTOMProvider: No Attachments.");
        throw new WebServiceException("No Attachments are detected");
    }
    SOAPMessage response = null;
    try {
        MessageFactory factory = MessageFactory.newInstance();
        response = factory.createMessage();
        SOAPPart soapPart = response.getSOAPPart();
        SOAPBody soapBody = soapPart.getEnvelope().getBody();
        soapBody.addChildElement((SOAPBodyElement) 
                                 soapMessage.
                                 getSOAPBody().getChildElements().next());
        response.addAttachmentPart((AttachmentPart) soapMessage.getAttachments().next());
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
    System.out.println(">> SoapMessageCheckMTOMProvider: Returning.");
    return response;  // echo back the same message
}
项目:wso2-axis2    文件:IntegrationTest.java   
@Validated @Test
public void testSendReceiveMessageWithEmptyNSPrefix() throws Exception {
    MessageFactory mf = MessageFactory.newInstance();
    SOAPMessage request = mf.createMessage();

    SOAPPart sPart = request.getSOAPPart();
    SOAPEnvelope env = sPart.getEnvelope();
    SOAPBody body = env.getBody();

    //Namespace prefix is empty
    body.addBodyElement(new QName("http://fakeNamespace2.org","echo"))
                                .addTextNode("This is some text");

    SOAPConnection sCon = SOAPConnectionFactory.newInstance().createConnection();
    SOAPMessage response = sCon.call(request, getAddress());
    assertFalse(response.getAttachments().hasNext());
    assertEquals(0, response.countAttachments());

    String requestStr = printSOAPMessage(request);
    String responseStr = printSOAPMessage(response);
    assertTrue(responseStr.indexOf("echo") > -1);
    sCon.close();
}
项目:wso2-axis2    文件:IntegrationTest.java   
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");
}
项目:wso2-axis2    文件:IntegrationTest.java   
@Validated @Test
public void testCallMTOM() throws Exception {
    MessageFactory mf = MessageFactory.newInstance();

    MimeHeaders headers = new MimeHeaders();
    headers.addHeader("Content-Type", TestUtils.MTOM_TEST_MESSAGE_CONTENT_TYPE);
    InputStream in = TestUtils.getTestFile(TestUtils.MTOM_TEST_MESSAGE_FILE);
    SOAPMessage request = mf.createMessage(headers, in);
    SOAPEnvelope envelope = request.getSOAPPart().getEnvelope();

    // Remove the headers since they have mustunderstand=1 
    envelope.getHeader().removeContents();
    // Change the name of the body content so that the request is routed to the echo service
    ((SOAPElement)envelope.getBody().getChildElements().next()).setElementQName(new QName("echo"));

    SOAPConnection sCon = SOAPConnectionFactory.newInstance().createConnection();
    SOAPMessage response = sCon.call(request, getAddress());
    sCon.close();

    SOAPPart soapPart = response.getSOAPPart();
    SOAPElement textElement =
            (SOAPElement)soapPart.getEnvelope().getElementsByTagName("text").item(0);
    AttachmentPart ap = response.getAttachment((SOAPElement)textElement.getChildNodes().item(0));
    assertNotNull(ap);
}
项目:wso2-axis2    文件:SOAPEnvelopeTest.java   
public void _testEnvelopeWithLeadingComment() throws Exception {
    String soapMessageWithLeadingComment =
            "<?xml version='1.0' encoding='UTF-8'?>" +
                    "<!-- Comment -->" +
                    "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" +
                    "<env:Body><echo><arg0>Hello</arg0></echo></env:Body>" +
                    "</env:Envelope>";

    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage message =
            factory.createMessage(new MimeHeaders(),
                                  new ByteArrayInputStream(
                                          soapMessageWithLeadingComment.getBytes()));
    SOAPPart part = message.getSOAPPart();
    SOAPEnvelope envelope = part.getEnvelope();
    message.writeTo(System.out);
    assertTrue(envelope != null);
    assertTrue(envelope.getBody() != null);
}
项目:wso2-axis2    文件:SOAPEnvelopeTest.java   
@Validated @Test
    public void testEnvelopeWithCommentInEnvelope() throws Exception {

        String soapMessageWithLeadingComment =
                "<?xml version='1.0' encoding='UTF-8'?>\n" +
                        "<soapenv:Envelope  xmlns='http://somewhere.com/html'\n" +
                        "                   xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'\n" +
                        "                   xmlns:xsd='http://www.w3.org/2001/XMLSchema'\n" +
                        "                   xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>\n" +
                        "<!-- Comment -->" +
                        " <soapenv:Body>\n" +
                        "    <echo><arg0>Hello</arg0></echo>" +
//                "    <t:echo xmlns:t='http://test.org/Test'><t:arg0>Hello</t:arg0></t:echo>" +
                        " </soapenv:Body>\n" +
                        "</soapenv:Envelope>";

        MessageFactory factory = MessageFactory.newInstance();
        SOAPMessage message =
                factory.createMessage(new MimeHeaders(),
                                      new ByteArrayInputStream(
                                              soapMessageWithLeadingComment.getBytes()));
        SOAPPart part = message.getSOAPPart();
        SOAPEnvelope envelope = part.getEnvelope();
        assertTrue(envelope != null);
        assertTrue(envelope.getBody() != null);
    }
项目:wso2-axis2    文件:SOAPEnvelopeTest.java   
@Validated @Test
    public void testEnvelopeWithCommentInBody() throws Exception {

        String soapMessageWithLeadingComment =
                "<?xml version='1.0' encoding='UTF-8'?>\n" +
                        "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'\n" +
                        "                   xmlns:xsd='http://www.w3.org/2001/XMLSchema'\n" +
                        "                   xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>\n" +
                        " <soapenv:Body>\n" +
                        "<!-- Comment -->" +
//                "    <echo><arg0>Hello</arg0></echo>" +
                        "    <t:echo xmlns:t='http://test.org/Test'><t:arg0>Hello</t:arg0></t:echo>" +
                        " </soapenv:Body>\n" +
                        "</soapenv:Envelope>";

        MessageFactory factory = MessageFactory.newInstance();
        SOAPMessage message =
                factory.createMessage(new MimeHeaders(),
                                      new ByteArrayInputStream(
                                              soapMessageWithLeadingComment.getBytes()));
        SOAPPart part = message.getSOAPPart();
        SOAPEnvelope envelope = part.getEnvelope();
        assertTrue(envelope != null);
        assertTrue(envelope.getBody() != null);
    }
项目:wso2-axis2    文件:SOAPElementTest.java   
@Validated @Test
public void testGetChildElements2() throws Exception {
    MessageFactory fact = MessageFactory.newInstance();
    SOAPMessage message = fact.createMessage();
    SOAPPart soapPart = message.getSOAPPart();
    SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
    SOAPBody soapBody = soapEnvelope.getBody();

    Name name = soapEnvelope.createName("MyChild1");
    SOAPElement se = soapBody.addChildElement(name);
    Iterator childElementsCount = soapBody.getChildElements();
    Iterator childElements = soapBody.getChildElements();

    int childCount = 0;
    while (childElementsCount.hasNext()) {
        Node node = (Node)childElementsCount.next();
        childCount++;
    }
    assertEquals(childCount, 1);
    SOAPElement se2 = (SOAPElement)childElements.next();
    if (!se.equals(se2)) {
        fail();
    } else {
        System.out.println("SOAPElement se = se2 (expected)");
    }

    Name n = se.getElementName();
    assertEquals(n, name);
}
项目:wso2-axis2    文件:SOAPElementTest.java   
@Validated @Test
public void testGetChildElements3() throws Exception {
    MessageFactory fact = MessageFactory.newInstance();
    SOAPMessage message = fact.createMessage();
    SOAPPart soapPart = message.getSOAPPart();
    SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
    SOAPBody soapBody = soapEnvelope.getBody();

    //Name name = soapEnvelope.createName("MyChild1");
    QName name = new QName("MyChild1");
    SOAPElement se = soapBody.addChildElement(name);
    Iterator childElementsCount = soapBody.getChildElements();
    Iterator childElements = soapBody.getChildElements();

    int childCount = 0;
    while (childElementsCount.hasNext()) {
        Node node = (Node)childElementsCount.next();
        childCount++;
    }
    assertEquals(childCount, 1);
    SOAPElement se2 = (SOAPElement)childElements.next();
    assertEquals(se, se2);

    QName n = se.getElementQName();
    assertEquals(n, name);
}
项目:wso2-axis2    文件:SOAPElementTest.java   
@Validated @Test
public void testSetElementQName() throws Exception {
    MessageFactory factory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
    SOAPMessage message = factory.createMessage();
    SOAPPart soapPart = message.getSOAPPart();
    SOAPEnvelope envelope = soapPart.getEnvelope();
    SOAPBody body = envelope.getBody();

    QName qname1 = new QName("http://fooURI.com", "fooElement", "foo");
    QName qname2 = new QName("http://foo2URI.com", "fooElement2", "foo2");
    SOAPElement se = body.addChildElement(qname1);
    QName qname = se.getElementQName();
    se = se.setElementQName(qname2);
    qname = se.getElementQName();

    if (!qname.getNamespaceURI().equals(qname2.getNamespaceURI()) ||
            !qname.getLocalPart().equals(qname2.getLocalPart()) ||
            !qname.getPrefix().equals(qname2.getPrefix())) {
        System.out.println("setElementQName() did not reset " +
                "element qname\nexpected: <URI=" + qname2.getNamespaceURI() +
                ", prefix=" + qname2.getPrefix() + ", localpart=" + qname2.getLocalPart() +
                ">\ngot:      <URI=" + qname.getNamespaceURI() + ", prefix=" +
                qname.getPrefix() +
                ", localpart=" + qname.getLocalPart() + ">");
    }
}
项目:wso2-axis2    文件:SOAPPartTest.java   
@Validated @Test
public void testAddSource2() throws Exception {
    SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
    SOAPEnvelope soapEnv = soapMessage.getSOAPPart().getEnvelope();
    SOAPHeader header = soapEnv.getHeader();
    SOAPBody body = soapEnv.getBody();

    assertTrue(header.addChildElement("ebxmlms1", "ch2",
                                      "http://test.apache.org") instanceof SOAPHeaderElement);
    assertTrue(header.addHeaderElement(
            soapEnv.createName("ebxmlms2", "ch3", "http://test2.apache.org")) != null);
    assertTrue(header.addHeaderElement(
            new PrefixedQName("http://test3.apache.org", "ebxmlms3", "ch5")) != null);

    body.addChildElement("bodyEle1", "ele1", "http://ws.apache.org");
    soapMessage.saveChanges();

    SOAPMessage soapMessage2 = MessageFactory.newInstance().createMessage();
    SOAPPart soapPart = soapMessage2.getSOAPPart();
    soapPart.setContent(soapMessage.getSOAPPart().getContent());
    soapMessage2.saveChanges();
    assertNotNull(soapMessage2);
}
项目:wso2-axis2    文件:SOAPPartTest.java   
@Validated @Test
public void testAddSource3() throws Exception {
    SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
    SOAPEnvelope soapEnv = soapMessage.getSOAPPart().getEnvelope();
    SOAPHeader header = soapEnv.getHeader();
    SOAPBody body = soapEnv.getBody();

    assertTrue(header.addChildElement("ebxmlms1", "ch2",
                                      "http://test.apache.org") instanceof SOAPHeaderElement);
    assertTrue(header.addHeaderElement(
            soapEnv.createName("ebxmlms2", "ch3", "http://test2.apache.org")) != null);
    assertTrue(header.addHeaderElement(
            new PrefixedQName("http://test3.apache.org", "ebxmlms3", "ch5")) != null);

    body.addChildElement("bodyEle1", "ele1", "http://ws.apache.org");
    soapMessage.saveChanges();

    SOAPMessage soapMessage2 = MessageFactory.newInstance().createMessage();
    SOAPPart soapPart = soapMessage2.getSOAPPart();
    soapPart.setContent(soapMessage.getSOAPPart().getContent());
    soapMessage2.saveChanges();
    assertNotNull(soapMessage2);
}
项目:wso2-axis2    文件:SOAPPartTest.java   
public void _testInputEncoding() throws Exception {
        DOMSource domSource;
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document document = builder.parse(new File(System.getProperty("basedir", ".") +
                "/test-resources" + File.separator + "soap-part.xml"));
        domSource = new DOMSource(document);

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

        // Get the SOAP part and set its content to domSource
        SOAPPart soapPart = message.getSOAPPart();
        soapPart.setContent(domSource);
        message.saveChanges();

        SOAPPart sp = message.getSOAPPart();

//            String inputEncoding = sp.getInputEncoding();
//            assertNotNull(inputEncoding);
    }
项目:wso2-axis2    文件:SOAPPartTest.java   
/**
 * Check parent processing of SOAPMessage
 */
// TODO: check why this fails with Sun's SAAJ implementation
@Test
public void test_parentAccess2() throws Exception {

    MessageFactory mf = MessageFactory.newInstance();
    SOAPMessage m = mf.createMessage();
    SOAPPart sp = m.getSOAPPart();
    SOAPEnvelope se = sp.getEnvelope();
    Node node = se.getParentNode();
    assertTrue(node == sp);
    node = node.getParentNode();
    assertTrue(node == null);

    SOAPElement e = se.getParentElement();
    assertTrue(node == null);
}
项目:wso2-axis2    文件:SOAPPartTest.java   
@Test
public void testNodeTypes() throws Exception {
    MessageFactory fact = MessageFactory.newInstance();
    SOAPMessage message = fact.createMessage();
    SOAPPart soapPart = message.getSOAPPart();     

    assertTrue("first child", soapPart.getFirstChild() instanceof SOAPEnvelope);
    assertTrue("last child", soapPart.getLastChild() instanceof SOAPEnvelope);

    NodeList nodes = soapPart.getChildNodes();

    assertEquals(1, nodes.getLength());
    for (int i = 0; i < nodes.getLength(); i++) {
        assertTrue(nodes.item(i) instanceof SOAPEnvelope);
    }             
}
项目:wso2-axis2    文件:SOAPFaultTest.java   
@Validated @Test
public void testAddDetailsTwice() throws Exception {
    MessageFactory fac = MessageFactory.newInstance();

    //Create the response to the message
    SOAPMessage soapMessage = fac.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("cwmp", "http://cwmp.com");
    SOAPBody body = envelope.getBody();

    body.addFault().addDetail();
    try {
        body.getFault().addDetail();
        fail("Expected Exception did not occur");
    } catch (SOAPException e) {
        assertTrue(true);
    }
}
项目:wso2-axis2    文件:SOAPFaultTest.java   
@Validated @Test
public void testAppendSubCode() throws Exception {
    MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
    SOAPMessage soapMessage = fac.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("cwmp", "http://cwmp.com");
    SOAPBody body = envelope.getBody();
    SOAPFault soapFault = body.addFault();
    QName qname = new QName("http://example.com", "myfault1", "flt1");
    soapFault.appendFaultSubcode(qname);

    QName qname2 = new QName("http://example2.com", "myfault2", "flt2");
    soapFault.appendFaultSubcode(qname2);

    QName qname3 = new QName("http://example3.com", "myfault3", "flt3");
    soapFault.appendFaultSubcode(qname3);

    soapMessage.saveChanges();

    Iterator faultSubCodes = soapFault.getFaultSubcodes();
    assertNotNull(faultSubCodes);
}
项目:wso2-axis2    文件:SOAPFaultTest.java   
public void _testGetFaultReasonTexts() throws Exception {
    MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);

    SOAPMessage soapMessage = fac.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();

    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("cwmp", "http://cwmp.com");
    SOAPBody body = envelope.getBody();
    SOAPFault soapFault = body.addFault();
    soapFault.addFaultReasonText("myReason", new Locale("en"));
    soapFault.addFaultReasonText("de-myReason", new Locale("de"));
    soapFault.addFaultReasonText("si-myReason", new Locale("si"));
    soapMessage.saveChanges();
    Iterator reasonTexts = soapFault.getFaultReasonTexts();
    while (reasonTexts.hasNext()) {
        String reasonText = (String)reasonTexts.next();
        assertNotNull(reasonText);
    }
}
项目:wso2-axis2    文件:SOAPFaultTest.java   
public void _testGetFaultReasonText() throws Exception {
    MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);

    SOAPMessage soapMessage = fac.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();

    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("cwmp", "http://cwmp.com");
    SOAPBody body = envelope.getBody();
    SOAPFault soapFault = body.addFault();
    soapFault.addFaultReasonText("myReason", new Locale("en"));
    soapFault.addFaultReasonText("de-myReason", new Locale("de"));
    soapFault.addFaultReasonText("si-myReason", new Locale("si"));
    soapMessage.saveChanges();

    String faultReasonText = soapFault.getFaultReasonText(new Locale("si"));
    assertNotNull(faultReasonText);
    faultReasonText = soapFault.getFaultReasonText(new Locale("ja"));
    assertNull(faultReasonText);
}
项目:wso2-axis2    文件:SOAPFaultTest.java   
public void _testGetFaultCodeAsQName() throws Exception {
    //MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
    MessageFactory fac = MessageFactory.newInstance();

    SOAPMessage soapMessage = fac.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();

    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("cwmp", "http://cwmp.com");
    SOAPBody body = envelope.getBody();
    SOAPFault soapFault = body.addFault();
    soapFault.addFaultReasonText("myReason", new Locale("en"));
    soapFault.setFaultCode("mycode");
    soapMessage.saveChanges();

    QName qname = soapFault.getFaultCodeAsQName();
    assertNotNull(qname);
}
项目:wso2-axis2    文件:SOAPFaultTest.java   
@Validated @Test
public void testHasDetail() throws Exception {
    MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
    //MessageFactory fac = MessageFactory.newInstance();

    SOAPMessage soapMessage = fac.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();

    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.addNamespaceDeclaration("cwmp", "http://cwmp.com");
    SOAPBody body = envelope.getBody();
    SOAPFault soapFault = body.addFault();
    Detail detail = soapFault.addDetail();
    detail.setAttribute("test", "myvalue");
    soapMessage.saveChanges();
}
项目:wso2-axis2    文件:SOAPFaultTest.java   
@Validated @Test
public void testSetFaultStringLocale() throws Exception {
    MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
    //MessageFactory fac = MessageFactory.newInstance();
    SOAPMessage soapMessage = fac.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    SOAPEnvelope envelope = soapPart.getEnvelope();
    SOAPBody body = envelope.getBody();
    SOAPFault sf = body.addFault();

    Locale expected = Locale.ENGLISH;
    sf.setFaultString("this is the fault string", expected);
    Locale result = sf.getFaultStringLocale();
    assertNotNull(result);
    assertTrue(result.equals(expected));
}
项目:wso2-axis2    文件:SOAPFaultTest.java   
@Test
public void testFaultCodeWithPrefix1() throws Exception {
    MessageFactory fac = MessageFactory.newInstance();
    SOAPMessage soapMessage = fac.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    SOAPEnvelope envelope = soapPart.getEnvelope();
    SOAPBody body = envelope.getBody();
    SOAPFault sf = body.addFault();

    String prefix = "wso2";
    sf.setFaultCode(prefix + ":Server");
    String result = sf.getFaultCode();

    assertNotNull(result);
    assertEquals(prefix + ":Server", result);
}
项目:wso2-axis2    文件:SOAPFaultTest.java   
@Test
public void testFaultCodeWithPrefix2() throws Exception {
    MessageFactory fac = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
    SOAPMessage soapMessage = fac.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    SOAPEnvelope envelope = soapPart.getEnvelope();
    SOAPBody body = envelope.getBody();
    SOAPFault sf = body.addFault();

    String prefix = "wso2";
    sf.setFaultCode(prefix + ":Server");
    String result = sf.getFaultCode();

    assertNotNull(result);
    assertEquals(prefix + ":Server", result);
}
项目:wso2-axis2    文件:SOAPBodyTest.java   
@Validated @Test
public void testAddFault() {
    try {
        MessageFactory fact = MessageFactory.newInstance();
        SOAPMessage message = fact.createMessage();
        SOAPPart soapPart = message.getSOAPPart();
        SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
        SOAPBody soapBody = soapEnvelope.getBody();

        QName qname = new QName("http://test.apache.org/", "Child1", "ch");
        String value = "MyFault";
        SOAPFault soapFault = soapBody.addFault(qname, value);
        message.saveChanges();
        assertNotNull(soapFault);
        assertTrue(soapFault instanceof SOAPFault);
    } catch (Exception e) {
        fail("Unexpected Exception : " + e);
    }
}
项目:wso2-axis2    文件:PrefixesTest.java   
@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);
}
项目:juddi-scout    文件:SaajTransport.java   
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;
}