uCosminexus Application Server, Web Service Development Guide
When using Streaming, if you receive a SOAP message of MIME Multipart/Related structure containing an attachment, the received attachment is mapped to the com.sun.xml.ws.developer.StreamingDataHandler class instead of the javax.activation.DataHandler class in JAX-WS, and can be handled as a streamed attachment.
For the com.sun.xml.ws.developer.StreamingDataHandler class, see 19.2.4 (2) com.sun.xml.ws.developer.StreamingDataHandler class.
The following is an example of operating a streamed attachment. In this example, the streamed attachment is output with a different name as "C:/portrait.png":
package com.sample;
......
@MTOM
@StreamingAttachment(dir="C:/TMP", parseEagerly=true, memoryThreshold=50000L)
@BindingType(...)
public class UserInfoImpl implements UserInfo {
public DataHandler getUserInfo(DataHandler dataHandler)
throws UserDefinedException {
if (dataHandler instanceof StreamingDataHandler) {
File file = new File("C:/portrait.png");
StreamingDataHandler sdh = null;
try {
sdh = (StreamingDataHandler)dataHandler;
sdh.moveTo(file);
......
} finally {
try {
if (sdh != null) {
sdh.close();
}
} catch(Exception ex) {
......
}
}
}
}
}
|
The following are the points to be noted when operating the streamed attachments:
package com.sample;
...
@MTOM
@StreamingAttachment(...)
...
public class UserInfoImpl implements UserInfo {
public @XmlMimeType("application/octet-stream")
DataHandler getUserInfo(
@XmlMimeType("application/octet-stream")
DataHandler dataHandler)
throws ... {
if (dataHandler instanceof StreamingDataHandler) {
StreamingDataHandler sdh = null;
try {
sdh = (StreamingDataHandler)dataHandler;
...
InputStream inputStream = sdh.readOnce();
...
// read all the data of the attachment from the input stream
while ((inputStream.read()) != -1);
//close the input stream
inputStream.close();
} finally {
try {
if (sdh != null) {
//invoke the close() method of the StreamingDataHandler
//class
sdh.close();
}
} catch(Exception ex) {
...
}
}
}
...
}
}
|
package com.sample;
...
@MTOM
@StreamingAttachment(...)
...
public class UserInfoImpl implements UserInfo {
public @XmlMimeType("application/octet-stream")
DataHandler getUserInfo(
@XmlMimeType("application/octet-stream")
DataHandler dataHandler)
throws ... {
if (dataHandler instanceof StreamingDataHandler) {
StreamingDataHandler sdh = null;
try {
File file = new File(...);
sdh = (StreamingDataHandler)dataHandler;
...
sdh.moveTo(file);
} catch(Exception e)
try {
if (sdh != null) {
InputStream inputStream = sdh.readOnce();
//read all the data of the attachment from the
//input stream
while ((inputStream.read()) != -1);
//close the input stream
inputStream.close();
}
} catch(Exception ex) {
...
}
} finally {
try {
if (sdh != null) {
//invoke the close()method of the StreamingDataHandler class
sdh.close();
}
} catch(Exception ex) {
...
}
}
}
...
}
}
|
All Rights Reserved. Copyright (C) 2013, Hitachi, Ltd.