本文整理汇总了Java中javax.xml.soap.AttachmentPart.getContent方法的典型用法代码示例。如果您正苦于以下问题:Java AttachmentPart.getContent方法的具体用法?Java AttachmentPart.getContent怎么用?Java AttachmentPart.getContent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.soap.AttachmentPart
的用法示例。
在下文中一共展示了AttachmentPart.getContent方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import javax.xml.soap.AttachmentPart; //导入方法依赖的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: getXMLAttachmentResponse
import javax.xml.soap.AttachmentPart; //导入方法依赖的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;
}
示例3: getXMLSWARefResponse
import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
/**
* Get the response for an XML and an MTOM Attachment request
* @param request
* @param dataElement
* @return SOAPMessage
*/
private SOAPMessage getXMLSWARefResponse(SOAPMessage request, SOAPElement dataElement) throws Exception {
SOAPMessage response;
// Additional assertion checks
assertTrue(countAttachments(request) == 1);
AttachmentPart requestAP = (AttachmentPart) request.getAttachments().next();
assertTrue(requestAP.getContentId().equals(ID));
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 + SWAREF_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;
}
示例4: testGetContent
import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
@Validated @Test
public void testGetContent() throws Exception {
try {
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage msg = factory.createMessage();
AttachmentPart ap = msg.createAttachmentPart();
Image image = ImageIO.read(TestUtils.getTestFileURL("attach.gif"));
ap = msg.createAttachmentPart(image, "image/gif");
//Getting Content should return an Image object
Object o = ap.getContent();
if (o != null) {
if (o instanceof Image) {
//Image object was returned (ok)
} else {
fail("Unexpected object was returned");
}
}
} catch (Exception e) {
fail("Exception: " + e);
}
}
示例5: extractDocument
import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
public static Document extractDocument(SOAPMessage message, ExchangeServlet caller)
throws SAXException,DocumentException, SOAPException, IOException {
Document doc=null;
if (message != null) {
Iterator iter = message.getAttachments();
AttachmentPart af = (AttachmentPart) iter.next();
String attcontent=null;
if(af.getContentType().equalsIgnoreCase("application/x-gzip")){
java.io.InputStream zippedStream = (java.io.InputStream)af.getContent();
attcontent=GzipUtility.unzipFromStream(zippedStream);
attcontent.trim();
caller.setZipIt(true);
if(MessagingEnvironment.DEBUG==1)
System.out.println("Received zipped content "+attcontent);
}else{
InputStream in=af.getRawContent();
BufferedReader br=new BufferedReader(new InputStreamReader(in,"UTF-8"));
String temp;
attcontent=new String();
while((temp=br.readLine())!=null)
attcontent+=temp;
br.close();
if(MessagingEnvironment.DEBUG==1)
System.out.println("received: "+attcontent);
}
SAXReader builder;
builder=new SAXReader("org.apache.xerces.parsers.SAXParser");
builder.setFeature("http://xml.org/sax/features/validation", false);
builder.setFeature("http://apache.org/xml/features/validation/schema", false);
builder.setFeature("http://apache.org/xml/features/validation/schema-full-checking", false);
builder.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",MessagingEnvironment.getReqSchemaURL());
doc = builder.read(new StringReader(attcontent));
}
return doc;
}
示例6: getXMLMTOMResponse
import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
/**
* Get the response for an XML and an MTOM Attachment request
* @param request
* @param dataElement
* @return SOAPMessage
*/
private SOAPMessage getXMLMTOMResponse(SOAPMessage request, SOAPElement dataElement) throws Exception {
SOAPMessage response;
System.out.println("Received MTOM Message");
// 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));
System.out.println("The MTOM Request Message appears correct.");
// Build the Response
MessageFactory factory = MessageFactory.newInstance();
String responseXML = responseMsgStart + MTOM_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);
System.out.println("Returning the Response Message");
return response;
}
示例7: getXMLMTOMResponse
import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
/**
* Get the response for an XML and an MTOM Attachment request
* @param request
* @param dataElement
* @return SOAPMessage
*/
private SOAPMessage getXMLMTOMResponse(SOAPMessage request, SOAPElement dataElement) throws Exception {
SOAPMessage response;
TestLogger.logger.debug("Received MTOM Message");
// 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));
TestLogger.logger.debug("The MTOM Request Message appears correct.");
// Build the Response
MessageFactory factory = MessageFactory.newInstance();
String responseXML = responseMsgStart + MTOM_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);
TestLogger.logger.debug("Returning the Response Message");
return response;
}
示例8: parseResponse
import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
private Element parseResponse(SOAPMessage response)
throws SOAPException,
TransformerConfigurationException,
TransformerException {
Element ret = null;
SOAPPart soapPart = response.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
SOAPBody soapBody = soapEnvelope.getBody();
java.util.Iterator children = soapBody.getChildElements();
while(children.hasNext()) {
SOAPElement child = (SOAPElement)children.next();
if(child.getElementName().getLocalName().equalsIgnoreCase("Attachment")) {
Name href = soapEnvelope.createName("href");
String hrefValue = child.getAttributeValue(href);
java.util.Iterator attachments = response.getAttachments();
while(attachments.hasNext()) {
AttachmentPart ap = (AttachmentPart)attachments.next();
if(ap.getContentLocation().equals(hrefValue)) {
if(null != ap.getContent()) {
DOMResult domResult = new DOMResult(UtilXML.newDocument());
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.transform((Source)ap.getContent(), domResult);
ret = ((Document)domResult.getNode()).getDocumentElement();
}
}
}
}
}
return ret;
}
示例9: extractResponse
import javax.xml.soap.AttachmentPart; //导入方法依赖的package包/类
public Document extractResponse(SOAPMessage reply){
Document doc=null;
if (reply != null) {
try{
Iterator iter = reply.getAttachments();
AttachmentPart af = (AttachmentPart) iter.next();
String attcontent=null;
if(af.getContentType().equalsIgnoreCase("application/x-gzip")){
java.io.InputStream zippedStream = (java.io.InputStream)af.getContent();
attcontent=GzipUtility.unzipFromStream(zippedStream);
attcontent.trim();
zippedStream.close();
if(MessagingEnvironment.DEBUG==1)
System.out.println("Unziped xml:\n"+attcontent);
}else{
InputStream in=af.getRawContent();
BufferedReader br=new BufferedReader(new InputStreamReader(in,"UTF-8"));
String temp;
attcontent=new String();
while((temp=br.readLine())!=null)
attcontent+=temp;
br.close();
if(MessagingEnvironment.DEBUG==1)
System.out.println("Content\n"+attcontent);
}
setProxyFromINI(true);
SAXReader builder;
builder=new SAXReader("org.apache.xerces.parsers.SAXParser");
builder.setFeature("http://xml.org/sax/features/validation", true);
builder.setFeature("http://apache.org/xml/features/validation/schema", true);
builder.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);
builder.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",MessagingEnvironment.getRespSchemaURL());
doc = builder.read(new StringReader(attcontent));
setProxyFromINI(false);
}catch(Exception e){
e.printStackTrace();
}
}
return doc;
}