本文整理匯總了Java中javax.xml.soap.MessageFactory類的典型用法代碼示例。如果您正苦於以下問題:Java MessageFactory類的具體用法?Java MessageFactory怎麽用?Java MessageFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MessageFactory類屬於javax.xml.soap包,在下文中一共展示了MessageFactory類的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: 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;
}
示例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;
}
示例4: newMessageFactory
import javax.xml.soap.MessageFactory; //導入依賴的package包/類
protected MessageFactory newMessageFactory(String protocol)
throws SOAPException {
if (SOAPConstants.SOAP_1_1_PROTOCOL.equals(protocol)) {
return new com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl();
} else if (SOAPConstants.SOAP_1_2_PROTOCOL.equals(protocol)) {
return new com.sun.xml.internal.messaging.saaj.soap.ver1_2.SOAPMessageFactory1_2Impl();
} else if (SOAPConstants.DYNAMIC_SOAP_PROTOCOL.equals(protocol)) {
return new com.sun.xml.internal.messaging.saaj.soap.dynamic.SOAPMessageFactoryDynamicImpl();
} else {
log.log(
Level.SEVERE,
"SAAJ0569.soap.unknown.protocol",
new Object[] {protocol, "MessageFactory"});
throw new SOAPException("Unknown Protocol: " + protocol +
" specified for creating MessageFactory");
}
}
示例5: testEmptyCalendar
import javax.xml.soap.MessageFactory; //導入依賴的package包/類
@Test
@RunAsClient
public void testEmptyCalendar() throws Exception {
URL wsdlURL = new URL(baseURL + "/EndpointService?wsdl");
QName qname = new QName("http://org.jboss.ws/jaxws/calendar", "EndpointService");
Service service = Service.create(wsdlURL, qname);
Dispatch<SOAPMessage> dispatch = service.createDispatch(new QName("http://org.jboss.ws/jaxws/calendar", "EndpointPort"), SOAPMessage.class, Mode.MESSAGE);
String reqEnv = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><ns2:echoCalendar xmlns:ns2=\"http://org.jboss.ws/jaxws/calendar\"><arg0/></ns2:echoCalendar></soap:Body></soap:Envelope>";
SOAPMessage reqMsg = MessageFactory.newInstance().createMessage(null, new ByteArrayInputStream(reqEnv.getBytes()));
SOAPMessage resMsg = dispatch.invoke(reqMsg);
assertNotNull(resMsg);
//TODO improve checks
}
示例6: 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;
}
示例7: newMessageFactory
import javax.xml.soap.MessageFactory; //導入依賴的package包/類
@Override
protected MessageFactory newMessageFactory(String protocol)
throws SOAPException {
if (SOAPConstants.SOAP_1_1_PROTOCOL.equals(protocol)) {
return new com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl();
} else if (SOAPConstants.SOAP_1_2_PROTOCOL.equals(protocol)) {
return new com.sun.xml.internal.messaging.saaj.soap.ver1_2.SOAPMessageFactory1_2Impl();
} else if (SOAPConstants.DYNAMIC_SOAP_PROTOCOL.equals(protocol)) {
return new com.sun.xml.internal.messaging.saaj.soap.dynamic.SOAPMessageFactoryDynamicImpl();
} else {
log.log(
Level.SEVERE,
"SAAJ0569.soap.unknown.protocol",
new Object[] {protocol, "MessageFactory"});
throw new SOAPException("Unknown Protocol: " + protocol +
" specified for creating MessageFactory");
}
}
示例8: 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/"));
}
示例9: 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;
}
示例10: getObject
import javax.xml.soap.MessageFactory; //導入依賴的package包/類
public ACATransmitterManifestReqDtl getObject(File file) {
ACATransmitterManifestReqDtl dtl = null;
try {
String fileContents = FileUtils.readFileToString(file, "UTF-8");
SOAPMessage message = MessageFactory.newInstance().createMessage(null,
new ByteArrayInputStream(fileContents.getBytes()));
Unmarshaller unmarshaller = JAXBContext.newInstance(ACATransmitterManifestReqDtl.class)
.createUnmarshaller();
Iterator iterator = message.getSOAPHeader().examineAllHeaderElements();
while (iterator.hasNext()) {
SOAPHeaderElement element = (SOAPHeaderElement) iterator.next();
QName name = new QName("urn:us:gov:treasury:irs:ext:aca:air:7.0", "ACATransmitterManifestReqDtl",
"urn");
if (element.getElementQName().equals(name)) {
dtl = (ACATransmitterManifestReqDtl) unmarshaller.unmarshal(processElement(element));
}
}
} catch (Exception e) {
LOG.error("Error", e);
}
return dtl;
}
示例11: 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;
}
}
示例12: setUp
import javax.xml.soap.MessageFactory; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
this.authFailPureXML = docBuilder.parse(new File("docs/responseExamples/auth_error.xml"));
MessageFactory messageFactory = MessageFactory.newInstance();
File authSuccess = new File("docs/responseExamples/listStudiesResponse.xml"); //TODO: Replace File with Path
File authFailure = new File("docs/responseExamples/auth_error.xml"); //TODO: Replace File with Path
FileInputStream inSuccess = new FileInputStream(authSuccess);
FileInputStream inFail = new FileInputStream(authFailure);
this.testDocumentAuthSuccess = SoapUtils.toDocument(messageFactory.createMessage(null, inSuccess));
this.testDocumentAuthFail = SoapUtils.toDocument(messageFactory.createMessage(null, inFail));
inSuccess.close();
inFail.close();
}
示例13: 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)));
}
示例14: 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);
}
示例15: setUp
import javax.xml.soap.MessageFactory; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
this.testUser = new OcUser();
this.testUser.setUsername("tester");
this.testSubmission = new UploadSession("submission1", UploadSession.Step.MAPPING, new Date(), this.testUser);
this.factory = new EventDataFactory(testUser, testSubmission);
try {
MessageFactory messageFactory = MessageFactory.newInstance();
FileInputStream in = new FileInputStream(new File("docs/responseExamples/getStudyMetadata3.xml"));
SOAPMessage mockedResponseGetMetadata = messageFactory.createMessage(null, in);
this.metadata = GetStudyMetadataResponseHandler.parseGetStudyMetadataResponse(mockedResponseGetMetadata);
} catch (Exception e) {
e.printStackTrace();
}
}