On Tuesday, April 26, 2011 10:52:32 AM petrmiko wrote:
> Hello,
>
> I've got a web service for downloading file, but in case of larger files,
> org.apache.cxf.interceptor.Fault: Java heap space occurs. MTOM should be
> enabled (so it should stream and don't do this) and I'm kind of helpless
> about this.
From the stack trace, the heap space issue is on the Server side, not the
client. The server isn't streaming it.
.............snip.........
> Server implemented method
> public DataHandler downloadFile(int dataFileId) throws SOAPException {
>
> List<DataFile> files =
> experimentDao.getDataFilesWhereId(dataFileId);
> DataFile file = files.get(0);
>
> ByteArrayDataSource rawData = null;
> try {
> rawData = new
> ByteArrayDataSource(file.getFileContent().getBinaryStream(),
> "fileBinaryStream");
This is likely the problem. The ByteArrayDataSource loads the entire stream
into a byte[] internally. Thus, it doesn't really "stream". You would
definitely need to switch to a DataSource implementation that can stream.
If the "file" is really a "java.io.File", you could use the
javax.activation.FileDataSource. Otherwise, you could likely do something
like:
final InputStream in = file.getFileContent().getBinaryStream();
rawData = new DataSource() {
public String getContentType() {
return "application/octet-stream";
}
public InputStream getInputStream() throws IOException {
return in;
}
public String getName() {
return "application/octet-stream";
}
public OutputStream getOutputStream() throws IOException {
return null;
}
});
....
Hope that helps!
Dan
> log.debug("User " + personDao.getLoggedPerson().getUsername() +
> " retrieved file " + dataFileId);
> } catch (IOException e) {
> log.error("User " + personDao.getLoggedPerson().getUsername() +
> " did NOT retrieve file " + dataFileId);
> log.error(e);
> throw new SOAPException(e);
> } catch (SQLException e) {
> log.error("User " + personDao.getLoggedPerson().getUsername() +
> " did NOT retrieve file " + dataFileId);
> log.error(e);
> throw new SOAPException(e);
> }
>
> return new DataHandler(rawData);
> }
>
> And client code (no Spring):
> public void userLogIn(String username, String password, String endpoint)
> throws WebServiceException, ConnectException {
>
> AuthorizationPolicy auth = new AuthorizationPolicy();
> auth.setUserName(username);
> auth.setPassword(password);
>
> JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
>
> factory.setServiceClass(UserDataService.class);
> factory.setAddress(endpoint);
>
> service = (UserDataService) factory.create();
>
> client = ClientProxy.getClient(service);
> client.getEndpoint().put("mtom-enabled", "true");
>
> conduit = (HTTPConduit) client.getConduit();
> conduit.setAuthorization(auth);
>
> TLSClientParameters params = new TLSClientParameters();
> params.setDisableCNCheck(true);
> params.setUseHttpsURLConnectionDefaultSslSocketFactory(false);
> params.setTrustManagers(new TrustManager[]{new
> AcceptAllTrustManager()});
> conduit.setTlsClientParameters(params);
>
> HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
> httpClientPolicy.setConnectionTimeout(1000 * 60 * 60);
> httpClientPolicy.setReceiveTimeout(1000 * 60 * 60 * 60);
>
> conduit.setClient(httpClientPolicy);
>
> }
>
> public void userLogout() {
>
> if (conduit != null)
> conduit.close();
>
> if (client != null)
> client.destroy();
>
> conduit = null;
> client = null;
> }
>
> The fault is:
>
> Java heap space
>
>
> Message:
> javax.xml.ws.soap.SOAPFaultException: Java heap space
> Level:
> SEVERE
> Stack Trace:
> Java heap space
> org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:146)
> $Proxy57.downloadFile(Unknown Source)
>
> ch.ethz.origo.jerpa.application.perspective.ededb.logic.FileDownload.run(Fi
> leDownload.java:94)
> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
> java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
> java.util.concurrent.FutureTask.run(FutureTask.java:138)
>
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.j
> ava:886)
>
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:
> 908) java.lang.Thread.run(Thread.java:662)
> Java heap space
>
> org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.unmarshalF
> ault(Soap11FaultInInterceptor.java:75)
>
> org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMess
> age(Soap11FaultInInterceptor.java:46)
>
> org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMess
> age(Soap11FaultInInterceptor.java:35)
>
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChai
> n.java:243)
>
> org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(Ab
> stractFaultChainInitiatorObserver.java:99)
>
> org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage
> (CheckFaultInterceptor.java:69)
>
> org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage
> (CheckFaultInterceptor.java:34)
>
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChai
> n.java:243)
> org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:700)
>
> org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleRespons
> eInternal(HTTPConduit.java:2261)
>
> org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleRespons
> e(HTTPConduit.java:2134)
>
> org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPCon
> duit.java:1988)
> org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:66)
> org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:639)
>
> org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInte
> rceptor.handleMessage(MessageSenderInterceptor.java:62)
>
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChai
> n.java:243) org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:487)
> org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:313)
> org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:265)
> org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
> org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:124)
> $Proxy57.downloadFile(Unknown Source)
>
> ch.ethz.origo.jerpa.application.perspective.ededb.logic.FileDownload.run(Fi
> leDownload.java:94)
> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
> java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
> java.util.concurrent.FutureTask.run(FutureTask.java:138)
>
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.j
> ava:886)
>
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:
> 908) java.lang.Thread.run(Thread.java:662)
>
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/MTOM-Heap-space-fault-tp4341098p4341098.ht
> ml Sent from the cxf-user mailing list archive at Nabble.com.
--
Daniel Kulp
[email protected]
http://dankulp.com/blog
Talend - http://www.talend.com