本文整理匯總了Java中javax.xml.soap.MessageFactory.newInstance方法的典型用法代碼示例。如果您正苦於以下問題:Java MessageFactory.newInstance方法的具體用法?Java MessageFactory.newInstance怎麽用?Java MessageFactory.newInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.xml.soap.MessageFactory
的用法示例。
在下文中一共展示了MessageFactory.newInstance方法的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]");
}
}
}
}
示例2: 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;
}
示例3: 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;
}
示例4: 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);
}
示例5: create
import javax.xml.soap.MessageFactory; //導入方法依賴的package包/類
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;
}
示例6: 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");
}
示例7: SOAPOverUDPMessage
import javax.xml.soap.MessageFactory; //導入方法依賴的package包/類
public SOAPOverUDPMessage(String soapAsXML, String soapProtocol, Charset encoding) throws SOAPOverUDPException {
MessageFactory factory;
SOAPMessage message = null;
try {
factory = MessageFactory.newInstance(soapProtocol);
message = factory.createMessage();
if (soapAsXML != null) {
ByteArrayInputStream i = new ByteArrayInputStream(soapAsXML.getBytes(encoding));
message.getSOAPPart().setContent(new StreamSource(i));
this.soapMessage = message;
this.readWSAHeader(); // read header
} else
this.soapMessage = message;
} catch (SOAPException ex) {
throw new SOAPOverUDPException("Unable to create SOAP message.");
}
}
示例8: createSoapMessage
import javax.xml.soap.MessageFactory; //導入方法依賴的package包/類
protected SOAPMessage createSoapMessage(Object soapRequestElem, boolean needAuthentification) throws SOAPException, ParserConfigurationException,
JAXBException {
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPMessage soapMessage = messageFactory.createMessage();
Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
Marshaller marshaller = JAXBContext.newInstance(soapRequestElem.getClass()).createMarshaller();
marshaller.marshal(soapRequestElem, document);
soapMessage.getSOAPBody().addDocument(document);
// if (needAuthentification)
createSoapHeader(soapMessage);
soapMessage.saveChanges();
return soapMessage;
}
示例9: 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");
msg.getSOAPPart().setContentId("<[email protected]>");
AttachmentPart ap = msg.createAttachmentPart();
ap.setDataHandler(new DataHandler(new StreamDataSource()));
ap.setContentId("<switchyard.png>");
msg.addAttachmentPart(ap);
msg.saveChanges();
// SWITCHYARD-2818/CXF-6665 - CXF does not set content-type properly.
String contentType = msg.getMimeHeaders().getHeader("Content-Type")[0];
contentType += "; start=\"<[email protected]>\"; start-info=\"application/soap+xml\"; action=\"urn:switchyard-quickstart:soap-attachment:1.0:echoImage\"";
msg.getMimeHeaders().setHeader("Content-Type", contentType);
return connection.call(msg, new URL(SWITCHYARD_WEB_SERVICE));
}
示例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());
}
示例11: testIllegalMessageAccess
import javax.xml.soap.MessageFactory; //導入方法依賴的package包/類
@Test
@RunAsClient
public void testIllegalMessageAccess() throws Exception
{
MessageFactory msgFactory = MessageFactory.newInstance();
SOAPConnection con = SOAPConnectionFactory.newInstance().createConnection();
String reqEnv =
"<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" +
" <env:Header/>" +
" <env:Body>" +
" <ns1:noWebMethod xmlns:ns1='" + targetNS + "'>" +
" <String_1>Hello</String_1>" +
" </ns1:noWebMethod>" +
" </env:Body>" +
"</env:Envelope>";
SOAPMessage reqMsg = msgFactory.createMessage(null, new ByteArrayInputStream(reqEnv.getBytes()));
URL epURL = new URL(baseURL + "/TestService");
SOAPMessage resMsg = con.call(reqMsg, epURL);
SOAPFault soapFault = resMsg.getSOAPBody().getFault();
assertNotNull("Expected SOAPFault", soapFault);
String faultString = soapFault.getFaultString();
assertTrue(faultString, faultString.indexOf("noWebMethod") > 0);
}
示例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));
}
示例13: testEnvelopeWithCommentInEnvelope
import javax.xml.soap.MessageFactory; //導入方法依賴的package包/類
@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);
}
示例14: getXMLAttachmentResponse
import javax.xml.soap.MessageFactory; //導入方法依賴的package包/類
/**
* Get the response for an XML and an Attachment request
* @param request
* @param dataElement
* @return SOAPMessage
*/
private SOAPMessage getXMLAttachmentResponse(SOAPMessage request, SOAPElement dataElement) throws Exception {
SOAPMessage response;
// Additional assertion checks
assertTrue(countAttachments(request) == 1);
AttachmentPart requestAP = (AttachmentPart) request.getAttachments().next();
StreamSource contentSS = (StreamSource) requestAP.getContent();
String content = getAsString(contentSS);
assertTrue(content.contains(SoapMessageProvider.TEXT_XML_ATTACHMENT));
// Build the Response
MessageFactory factory = MessageFactory.newInstance();
String responseXML = responseMsgStart + ATTACHMENT_RETURN + responseMsgEnd;
response = factory.createMessage(null, new ByteArrayInputStream(responseXML.getBytes()));
// Create and attach the attachment
AttachmentPart ap = response.createAttachmentPart(SoapMessageProvider.TEXT_XML_ATTACHMENT, "text/xml");
ap.setContentId(ID);
response.addAttachmentPart(ap);
return response;
}
示例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);
}