10-11-2010 01:48 PM
ObjectServicePort port = Service.create(wsdlUrl, serviceName).getPort(ObjectServicePort.class, new MTOMFeature());
CmisContentStreamType content = port.getContentStream(repoId, largeObjectId, null, null, null, null);
DataHandler stream = content.getStream();
OutputStream os = new FileOutputStream(DOWNLOAD_PATH);
stream.writeTo(os);
os.close();
uses single small buffer multiple times to transfer the file from Alfresco. It doesn't allocate a buffer of the size of the file, so it doesn't need much memory to run.
ObjectServicePort port = Service.create(wsdlUrl, serviceName).getPort(ObjectServicePort.class, new MTOMFeature());
CmisContentStreamType content = port.getContentStream(repoId, largeObjectId, null, null, null, null);
// These are required to turn MTOM on in jax-ws client
Map<String, Object> ctxt = ((BindingProvider)port).getRequestContext();
ctxt.put(JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE, 8192);
final FileInputStream is = new FileInputStream(FILE_TO_UPLOAD);
DataHandler stream = new DataHandler(new DataSource() {
@Override
public OutputStream getOutputStream() throws IOException {
return null;
}
@Override
public String getName() {
return "";
}
@Override
public InputStream getInputStream() throws IOException {
return is;
}
@Override
public String getContentType() {
return "application/octet-stream";
}
});
CmisContentStreamType contentStream = new CmisContentStreamType();
contentStream.setMimeType("application/octet-stream");
contentStream.setStream(stream);
port.setContentStream(repoId, new Holder<String>(largeObjectId), true, null, contentStream, null);
it tries to allocate a buffer to hold the whole file read from FileInputStream and ends up with "java.lang.OutOfMemoryError: Java heap space"10-12-2010 11:26 AM
class SecurityHandler implements SOAPHandler<SOAPMessageContext>{
@Override
public boolean handleMessage(SOAPMessageContext messageContext) {
if ((Boolean) messageContext.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)) {
try {
SOAPMessage msg = messageContext.getMessage();
SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
SOAPHeader soapHeader;
if (envelope.getHeader() != null) {
soapHeader = envelope.getHeader();
} else {
soapHeader = envelope.addHeader();
}
SOAPHeaderElement headerElement = soapHeader.addHeaderElement(
new QName(WS_SECEXT, "Security", "wsse"));
headerElement.setMustUnderstand(true);
SOAPElement timestamp = headerElement.addChildElement(
new QName(WS_SECUTILITY, "Timestamp", "wsu"));
…
The statement SOAPMessage msg = messageContext.getMessage();
forces preparation of the whole message though we need only the headers.
import org.w3c.dom.Document;
import org.w3c.dom.Element;
…
DatatypeFactory factory = DatatypeFactory.newInstance();
GregorianCalendar now = new GregorianCalendar();
GregorianCalendar fiveMinutesLater = new GregorianCalendar();
fiveMinutesLater.add(GregorianCalendar.MINUTE, 5);
XMLGregorianCalendar xmlNow = factory.newXMLGregorianCalendar(now);
XMLGregorianCalendar xmlFiveMinutesLater = factory.newXMLGregorianCalendar(fiveMinutesLater);
String xmlNowDate = xmlNow.toXMLFormat().substring(0, xmlNow.toXMLFormat().length() - 6) + "Z";
String xmlFiveMinutesLaterDate = xmlFiveMinutesLater.toXMLFormat()
.substring(0, xmlFiveMinutesLater.toXMLFormat().length() - 6) + "Z";
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
Element header = doc.createElementNS(WS_SECEXT, "wsse:Security");
Element timestamp = doc.createElementNS(WS_SECUTILITY, "wsu:Timestamp");
timestamp.setAttributeNS(WS_SECUTILITY, "wsu:Id", "Timestamp");
Element created = doc.createElementNS(WS_SECUTILITY, "wsu:Created");
created.appendChild(doc.createTextNode(xmlNowDate));
timestamp.appendChild(created);
Element expired = doc.createElementNS(WS_SECUTILITY, "wsu:Expired");
expired.appendChild(doc.createTextNode(xmlFiveMinutesLaterDate));
timestamp.appendChild(expired);
header.appendChild(timestamp);
Element usernameToken = doc.createElementNS(WS_SECEXT, "wsse:UsernameToken");
Element username = doc.createElementNS(WS_SECEXT, "wsse:Username");
username.appendChild(doc.createTextNode(getUsername()));
usernameToken.appendChild(username);
Element password = doc.createElementNS(WS_SECEXT, "wsse:Password");
password.setAttribute("Type", WS_USER_TOKEN_PROFILE);
password.appendChild(doc.createTextNode(getPassword()));
usernameToken.appendChild(password);
header.appendChild(usernameToken);
ObjectServicePort port = service.getObjectServicePort();
((WSBindingProvider)port).setOutboundHeaders(Headers.create(header));
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.