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


Java MessageFactory.createMessage方法代碼示例

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


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

示例1: test

import javax.xml.soap.MessageFactory; //導入方法依賴的package包/類
public void test() throws Exception {

        File file = new File("message.xml");
        file.deleteOnExit();

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

        // Save the soap message to file
        try (FileOutputStream sentFile = new FileOutputStream(file)) {
            msg.writeTo(sentFile);
        }

        // See if we get the image object back
        try (FileInputStream fin = new FileInputStream(file)) {
            SOAPMessage newMsg = mf.createMessage(msg.getMimeHeaders(), fin);

            newMsg.writeTo(new ByteArrayOutputStream());

            Iterator<?> i = newMsg.getAttachments();
            while (i.hasNext()) {
                AttachmentPart att = (AttachmentPart) i.next();
                Object obj = att.getContent();
                if (!(obj instanceof StreamSource)) {
                    fail("Got incorrect attachment type [" + obj.getClass() + "], " +
                         "expected [javax.xml.transform.stream.StreamSource]");
                }
            }
        }

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

示例2: createMessage

import javax.xml.soap.MessageFactory; //導入方法依賴的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: createSOAPRequestMessage

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

示例4: serialize

import javax.xml.soap.MessageFactory; //導入方法依賴的package包/類
/**
 * Serializes the given ServiceRequest to SOAPMessage.
 *
 * @param request ServiceRequest to be serialized
 * @return SOAPMessage representing the given ServiceRequest; null if the
 * operation fails
 */
@Override
public final SOAPMessage serialize(final ServiceRequest request) {
    try {
        LOGGER.debug("Serialize ServiceRequest message to SOAP.");
        MessageFactory myMsgFct = MessageFactory.newInstance();
        SOAPMessage message = myMsgFct.createMessage();

        request.setSoapMessage(message);

        // Generate header
        super.serializeHeader(request, message.getSOAPPart().getEnvelope());

        // Generate body
        this.serializeBody(request);

        LOGGER.debug("ServiceRequest message was serialized succesfully.");
        return message;
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    LOGGER.warn("Failed to serialize ServiceRequest message to SOAP.");
    return null;
}
 
開發者ID:vrk-kpa,項目名稱:xrd4j,代碼行數:31,代碼來源:AbstractServiceRequestSerializer.java

示例5: setUp

import javax.xml.soap.MessageFactory; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
    MessageFactory messageFactory = MessageFactory.newInstance();
    File testFile = new File("docs/responseExamples/getStudyMetadata3.xml");
    FileInputStream in = new FileInputStream(testFile);
    SOAPMessage mockedResponseGetMetadata = messageFactory.createMessage(null, in);//soapMessage;
    this.metaData = GetStudyMetadataResponseHandler.parseGetStudyMetadataResponse(mockedResponseGetMetadata);

    this.testUser = new OcUser();
    this.testUser.setUsername("tester");
    this.testSubmission = new UploadSession("submission1", UploadSession.Step.MAPPING, new Date(), this.testUser);
    this.factory = new ClinicalDataFactory(testUser, testSubmission);

    this.testSubjectWithEventsTypeList = TestUtils.createStudySubjectWithEventList();

    this.uploadSession = new UploadSession("submission1", UploadSession.Step.MAPPING, new Date(), this.testUser);

    this.testODMGenerationCorrect = Paths.get("docs/exampleFiles/odmGeneration.txt");
}
 
開發者ID:thehyve,項目名稱:Open-Clinica-Data-Uploader,代碼行數:20,代碼來源:ODMGenerationTests.java

示例6: OSCARFAXSOAPMessage

import javax.xml.soap.MessageFactory; //導入方法依賴的package包/類
public OSCARFAXSOAPMessage(MessageFactory mf)
    throws SOAPException
{
    this.mf = mf;
    msg = mf.createMessage();
    soapPart = msg.getSOAPPart();
    envelope = soapPart.getEnvelope();
    SOAPBody body = envelope.getBody();
    SOAPElement ele = body.addChildElement(envelope.createName("OscarFax", "jaxm", "http://oscarhome.org/jaxm/oscarFax/"));
    sendingProvider = ele.addChildElement("sendingProvider");
    locationId = ele.addChildElement("locationId");
    identifier = ele.addChildElement("identifier");
    faxType = ele.addChildElement("faxType");
    coverSheet = ele.addChildElement("coverSheet");
    from = ele.addChildElement("from");
    comments = ele.addChildElement("comments");
    sendersFax = ele.addChildElement("sendersFax");
    sendersPhone = ele.addChildElement("sendersPhone");
    dateOfSending = ele.addChildElement("dateOfSending");
    recipient = ele.addChildElement("recipient");
    recipientFaxNumber = ele.addChildElement("recipientFaxNumber");
    payLoad = ele.addChildElement(envelope.createName("OscarFaxPayLoad", "jaxm", "http://oscarhome.org/jaxm/oscarFax/"));
}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:24,代碼來源:OSCARFAXSOAPMessage.java

示例7: setUp

import javax.xml.soap.MessageFactory; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
    String username = "tester";
    this.user = new OcUser();
    this.user.setUsername(username);
    this.uploadSession = new UploadSession("testSubmission", UploadSession.Step.MAPPING, new Date(), this.user);
    this.factory = new PatientDataFactory(user, uploadSession);
    try {
        MessageFactory messageFactory = MessageFactory.newInstance();
        FileInputStream in = new FileInputStream(new File("docs/responseExamples/Sjogren_STUDY1.xml"));

        SOAPMessage mockedResponseGetMetadata = messageFactory.createMessage(null, in);
        this.metadata = GetStudyMetadataResponseHandler.parseGetStudyMetadataResponse(mockedResponseGetMetadata);
    } catch (Exception e) {
        e.printStackTrace();
    }
    this.subjectMap = new HashMap<>();
    this.subjectMap.put("test_ssid_1", null);
}
 
開發者ID:thehyve,項目名稱:Open-Clinica-Data-Uploader,代碼行數:20,代碼來源:PatientDataFactoryTests.java

示例8: messageTest

import javax.xml.soap.MessageFactory; //導入方法依賴的package包/類
private void messageTest(String m) throws SOAPException, IOException {
    MessageFactory mf;
    mf = MessageFactory.newInstance();

    ByteArrayInputStream f = new ByteArrayInputStream(m.getBytes());

    SOAPMessage soapMsg = mf.createMessage(null, f);

    Message msg = null;
    try {
        msg = Message.Parse(soapMsg);
    } catch (Exception ex) {
        ex.printStackTrace();
        return;
    }

}
 
開發者ID:navisidhu,項目名稱:libreacs,代碼行數:18,代碼來源:MessageTest.java

示例9: eventStatusCheck

import javax.xml.soap.MessageFactory; //導入方法依賴的package包/類
@Test
    public void eventStatusCheck() throws Exception {
        File testFile = new File("docs/responseExamples/getStudyMetadata3.xml");
        FileInputStream in = new FileInputStream(testFile);
        MessageFactory messageFactory = MessageFactory.newInstance();
        SOAPMessage mockedResponseGetMetadata = messageFactory.createMessage(null, in);//soapMessage;
        MetaData crfVersionMetaData = GetStudyMetadataResponseHandler.parseGetStudyMetadataResponse(mockedResponseGetMetadata);
        List<StudySubjectWithEventsType> incorrectEventStatus = incorrectEventStatusExample();
        List<ClinicalData> incorrectData = new ArrayList<>();
        ClinicalData dPoint = new ClinicalData("Eventful", "age", "ssid1",
                "RepeatingEvent", 1, "MUST-FOR_NON_TTP_STUDY", null, "0.08", null, null, "12");
        incorrectData.add(dPoint);
        clinicalDataOcChecks = new ClinicalDataOcChecks(crfVersionMetaData, incorrectData, incorrectEventStatus);
        in.close();
        List<ValidationErrorMessage> errors = clinicalDataOcChecks.getErrors();
        assertThat(errors, hasSize(1));
        assertThat(errors, hasItem(isA(EventStatusNotAllowed.class)));
//        assertThat(errors, hasItem(isA(MandatoryItemInCrfMissing.class)));
    }
 
開發者ID:thehyve,項目名稱:Open-Clinica-Data-Uploader,代碼行數:20,代碼來源:ClinicalDataOcChecksTests.java

示例10: testSoapConnectionGet

import javax.xml.soap.MessageFactory; //導入方法依賴的package包/類
@Test
@RunAsClient
public void testSoapConnectionGet() throws Exception
{
   final String serviceURL = baseURL + "/greetMe";
   SOAPConnectionFactory conFac = SOAPConnectionFactory.newInstance();

   SOAPConnection con = conFac.createConnection();
   URL endpoint = new URL(serviceURL);
   MessageFactory msgFactory = MessageFactory.newInstance();
   SOAPMessage msg = msgFactory.createMessage();
   msg.getSOAPBody().addBodyElement(new QName("http://www.jboss.org/jbossws/saaj", "greetMe"));
   SOAPMessage response = con.call(msg, endpoint);
   QName greetMeResp = new QName("http://www.jboss.org/jbossws/saaj", "greetMeResponse");

   Iterator<?> sayHiRespIterator = response.getSOAPBody().getChildElements(greetMeResp);
   SOAPElement soapElement = (SOAPElement) sayHiRespIterator.next();
   assertNotNull(soapElement);

   assertEquals(1, response.countAttachments());
}
 
開發者ID:jbossws,項目名稱:jbossws-cxf,代碼行數:22,代碼來源:JBWS3084CxfTestCase.java

示例11: testSOAP12SoapFaultExceptionOnHTTP400UsingSAAJ

import javax.xml.soap.MessageFactory; //導入方法依賴的package包/類
@Test
@RunAsClient
public void testSOAP12SoapFaultExceptionOnHTTP400UsingSAAJ() throws Exception
{
   try
   {
      //<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body><ns2:throwSoapFaultException xmlns:ns2="http://server.exception.samples.jaxws.ws.test.jboss.org/"/></soap:Body></soap:Envelope>
      
      SOAPConnectionFactory conFac = SOAPConnectionFactory.newInstance();

      SOAPConnection con = conFac.createConnection();
      MessageFactory msgFactory = MessageFactory.newInstance();
      SOAPMessage msg = msgFactory.createMessage();
      msg.getSOAPBody().addBodyElement(new QName(targetNS, "throwSoapFaultException"));
      SOAPMessage response = con.call(msg, new URL(targetEndpoint + "Servlet"));
      Element el = (Element)response.getSOAPBody().getChildElements().next();
      assertEquals("Fault", el.getLocalName());
   }
   catch (Exception e)
   {
      fail(e);
   }
}
 
開發者ID:jbossws,項目名稱:jbossws-cxf,代碼行數:24,代碼來源:JBWS3945TestCase.java

示例12: sendMessage

import javax.xml.soap.MessageFactory; //導入方法依賴的package包/類
public SOAPMessage sendMessage() throws Exception {
    SOAPConnectionFactory conFactory = SOAPConnectionFactory.newInstance();

    SOAPConnection connection = conFactory.createConnection();
    MessageFactory msgFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
    SOAPMessage msg = msgFactory.createMessage();
    SOAPBodyElement bodyElement = msg.getSOAPBody().addBodyElement(new QName("urn:switchyard-quickstart:soap-attachment:1.0", "echoImage"));
    bodyElement.addTextNode("cid:switchyard.png");

    // CXF does not set content-type.
    msg.getMimeHeaders().addHeader("Content-Type", "multipart/related; type=\"text/xml\"; start=\"<[email protected]>\"");
    msg.getSOAPPart().setContentId("<[email protected]>");

    AttachmentPart ap = msg.createAttachmentPart();
    ap.setDataHandler(new DataHandler(new StreamDataSource()));
    ap.setContentId("<switchyard.png>");
    msg.addAttachmentPart(ap);

    return connection.call(msg, new URL(SWITCHYARD_WEB_SERVICE));
}
 
開發者ID:jboss-switchyard,項目名稱:switchyard,代碼行數:21,代碼來源:SoapAttachmentQuickstartTest.java

示例13: testProviderMessageNullResponse

import javax.xml.soap.MessageFactory; //導入方法依賴的package包/類
@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());
      }
   }
}
 
開發者ID:jbossws,項目名稱:jbossws-cxf,代碼行數:22,代碼來源:ProviderMessageTestCase.java

示例14: testEnvelopeWithCommentInBody

import javax.xml.soap.MessageFactory; //導入方法依賴的package包/類
@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);
    }
 
開發者ID:wso2,項目名稱:wso2-axis2,代碼行數:26,代碼來源:SOAPEnvelopeTest.java

示例15: testFaultCodeWithPrefix2

import javax.xml.soap.MessageFactory; //導入方法依賴的package包/類
@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);
}
 
開發者ID:wso2,項目名稱:wso2-axis2,代碼行數:17,代碼來源:SOAPFaultTest.java


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