use of com.sun.xml.ws.developer.StreamingDataHandler in project gdmatrix by gdmatrix.
the class DocumentManagerClient method saveContent.
private void saveContent(Content content) throws IOException {
String contentId = content.getContentId();
// **** save content data ****
DataHandler data = content.getData();
if (data != null) {
File tempFile = File.createTempFile(contentId, ".data");
if (data instanceof StreamingDataHandler)
((StreamingDataHandler) data).moveTo(tempFile);
else {
try (FileOutputStream os = new FileOutputStream(tempFile)) {
data.writeTo(os);
}
}
// rename file to actual filename
File contentFile = getContentFile(content);
if (!tempFile.renameTo(contentFile)) {
// file already exits
tempFile.delete();
}
content.setData(new DataHandler(new FileDataSource(contentFile)));
}
// **** save content properties ****
{
File tempFile = File.createTempFile(contentId, ".xml");
FileOutputStream os = new FileOutputStream(tempFile);
try {
Properties properties = new Properties();
if (content.getContentType() != null) {
properties.setProperty("contentType", content.getContentType());
}
if (content.getFormatId() != null) {
properties.setProperty("formatId", content.getFormatId());
}
if (content.getLanguage() != null) {
properties.setProperty("language", content.getLanguage());
}
if (content.getSize() != null) {
properties.setProperty("size", String.valueOf(content.getSize()));
}
if (content.getCreationDate() != null) {
properties.setProperty("creationDate", content.getCreationDate());
}
if (content.getCaptureDateTime() != null) {
properties.setProperty("captureDate", content.getCaptureDateTime());
}
if (content.getCaptureUserId() != null) {
properties.setProperty("captureUser", content.getCaptureUserId());
}
if (content.getUrl() != null) {
properties.setProperty("url", content.getUrl());
}
properties.storeToXML(os, contentId);
} finally {
os.close();
}
// rename file to actual filename
File propertiesFile = getPropertiesFile(contentId);
if (!tempFile.renameTo(propertiesFile)) {
// file already exits
tempFile.delete();
}
}
}
use of com.sun.xml.ws.developer.StreamingDataHandler in project gdmatrix by gdmatrix.
the class DocumentManager method getDataFile.
private File getDataFile(Content content) throws Exception {
File dataFile = null;
DataHandler dh = content.getData();
if (// internal
dh != null) {
DataSource ds = dh.getDataSource();
if (ds instanceof javax.activation.FileDataSource) {
dataFile = ((javax.activation.FileDataSource) ds).getFile();
} else if (dh instanceof StreamingDataHandler) {
StreamingDataHandler sdh = (StreamingDataHandler) dh;
String contentType = content.getContentType() != null ? content.getContentType() : sdh.getContentType();
dataFile = createTempFile(contentType);
sdh.moveTo(dataFile);
} else if (ds != null) {
String contentType = content.getContentType();
dataFile = createTempFile(contentType);
try (InputStream dis = ds.getInputStream()) {
IOUtils.writeToFile(dis, dataFile);
}
}
}
return dataFile;
}
use of com.sun.xml.ws.developer.StreamingDataHandler in project metro-jax-ws by eclipse-ee4j.
the class MimeApp method validateDataHandler.
private static void validateDataHandler(int expTotal, DataHandler dh) throws IOException {
// readOnce() doesn't store attachment on the disk in some cases
// for e.g when only one attachment is in the message
StreamingDataHandler sdh = (StreamingDataHandler) dh;
InputStream in = sdh.readOnce();
byte[] buf = new byte[8192];
int total = 0;
int len;
while ((len = in.read(buf, 0, buf.length)) != -1) {
for (int i = 0; i < len; i++) {
if ((byte) ('A' + (total + i) % 26) != buf[i]) {
System.out.println("FAIL: DataHandler data is different");
}
}
total += len;
if (total % (8192 * 250) == 0) {
System.out.println("Total so far=" + total);
}
}
System.out.println();
if (total != expTotal) {
System.out.println("FAIL: DataHandler data size is different. Expected=" + expTotal + " Got=" + total);
}
in.close();
sdh.close();
}
use of com.sun.xml.ws.developer.StreamingDataHandler in project metro-jax-ws by eclipse-ee4j.
the class SAAJMessageTest method testMtomAttachmentCid.
public void testMtomAttachmentCid() throws Exception {
String testMtomMessageReload_01 = "multipart/related;type=\"application/xop+xml\";boundary=\"----=_Part_0_1145105632.1353005695468\";start=\"<cbe648b3-2055-413e-b8ed-877cdf0f2477>\";start-info=\"text/xml\"";
MessageContext m1 = mcf.createContext(getResource("testMtomMessageReload_01.msg"), testMtomMessageReload_01);
Packet packet = (Packet) m1;
Message riMsg = packet.getInternalMessage();
// This will cause all the attachments to be created ...
// Iterator<Attachment> as = packet.getInternalMessage().getAttachments().iterator();
// SAAJFactory:
SOAPVersion soapVersion = packet.getMessage().getSOAPVersion();
SOAPMessage saajMsg = soapVersion.getMessageFactory().createMessage();
SaajStaxWriterEx writer = new SaajStaxWriterEx(saajMsg, soapVersion.nsUri);
try {
riMsg.writeTo(writer);
} catch (XMLStreamException e) {
throw (e.getCause() instanceof SOAPException) ? (SOAPException) e.getCause() : new SOAPException(e);
}
saajMsg = writer.getSOAPMessage();
int counter = 0;
String hredCid = null;
for (Attachment a : riMsg.getAttachments()) {
hredCid = ((StreamingDataHandler) a.asDataHandler()).getHrefCid();
counter++;
}
assertTrue(writer.ma.size() == counter);
AttachmentPart ap = null;
// for (Iterator<AttachmentPart> itr = saajMsg.getAttachments(); itr.hasNext(); ) {
// System.out.println("\r\n itr.next().getContentId() " + itr.next().getContentId() );
// }
StreamingDataHandler sdh = (StreamingDataHandler) writer.ma.get(0);
assertEquals(hredCid, sdh.getHrefCid());
}
use of com.sun.xml.ws.developer.StreamingDataHandler in project metro-jax-ws by eclipse-ee4j.
the class SAAJMessageTest method testMtomAttachment.
public void testMtomAttachment() throws Exception {
String testMtomMessageReload_01 = "multipart/related;type=\"application/xop+xml\";boundary=\"----=_Part_0_1145105632.1353005695468\";start=\"<cbe648b3-2055-413e-b8ed-877cdf0f2477>\";start-info=\"text/xml\"";
MessageContext m1 = mcf.createContext(getResource("testMtomMessageReload_01.msg"), testMtomMessageReload_01);
Packet packet = (Packet) m1;
Message message = packet.getInternalMessage();
Iterator<Attachment> as = packet.getInternalMessage().getAttachments().iterator();
Attachment att = null;
int counter = 0;
String cid1 = null;
while (as.hasNext()) {
att = as.next();
cid1 = att.getContentId();
counter++;
}
assertTrue(counter == 1);
// SAAJFactory:
SOAPVersion soapVersion = packet.getMessage().getSOAPVersion();
SOAPMessage msg = soapVersion.getMessageFactory().createMessage();
SaajStaxWriterEx writer = new SaajStaxWriterEx(msg, soapVersion.nsUri);
try {
message.writeTo(writer);
} catch (XMLStreamException e) {
throw (e.getCause() instanceof SOAPException) ? (SOAPException) e.getCause() : new SOAPException(e);
}
msg = writer.getSOAPMessage();
counter = 0;
String cid2 = null;
for (Attachment a : message.getAttachments()) {
counter++;
cid2 = a.getContentId();
}
assertTrue(writer.ma.size() == counter);
StreamingDataHandler sdh = (StreamingDataHandler) writer.ma.get(0);
assertEquals(cid1, sdh.getHrefCid());
assertEquals(cid2, sdh.getHrefCid());
}
Aggregations