Results 1 to 5 of 5
  1. #1
    sfeher is offline Member
    Join Date
    Jul 2013
    Posts
    3
    Rep Power
    0

    Default File upload with web service (SWING + Apache CXF)

    Hi,

    I'm just started a new project including file upload function.
    At server side I created a service endpoint based this tutorial.

    My client will be SWING based so I generated stubs from the service created before.

    My problem is that the upload does not work for files bigger than 300 Mb. If the file is bigger than 300M then my client throws OOM error.
    With SoapUI I can upload 1.2Gb easily so I suspect the problem at client side.

    Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
    at java.util.Arrays.copyOf(Arrays.java:2271)
    at java.io.ByteArrayOutputStream.grow(ByteArrayOutput Stream.java:113)
    at java.io.ByteArrayOutputStream.ensureCapacity(ByteA rrayOutputStream.java:93)
    at java.io.ByteArrayOutputStream.write(ByteArrayOutpu tStream.java:140)
    at sun.net.http://www.http.PosterOutputStream.w...tream.java:78)
    at javax.activation.DataHandler.writeTo(DataHandler.j ava:309)
    at com.sun.xml.internal.ws.encoding.MtomCodec$ByteArr ayBuffer.write(MtomCodec.java:191)
    at com.sun.xml.internal.ws.encoding.MtomCodec.encode( MtomCodec.java:158)
    at com.sun.xml.internal.ws.encoding.SOAPBindingCodec. encode(SOAPBindingCodec.java:267)
    at com.sun.xml.internal.ws.transport.http.client.Http TransportPipe.process(HttpTransportPipe.java:196)
    at com.sun.xml.internal.ws.transport.http.client.Http TransportPipe.processRequest(HttpTransportPipe.jav a:122)
    at com.sun.xml.internal.ws.transport.DeferredTranspor tPipe.processRequest(DeferredTransportPipe.java:95 )
    at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fib er.java:626)
    at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fibe r.java:585)
    at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber .java:570)
    at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fib er.java:467)
    at com.sun.xml.internal.ws.client.Stub.process(Stub.j ava:308)
    at com.sun.xml.internal.ws.client.sei.SEIStub.doProce ss(SEIStub.java:146)
    at com.sun.xml.internal.ws.client.sei.SyncMethodHandl er.invoke(SyncMethodHandler.java:98)
    at com.sun.xml.internal.ws.client.sei.SyncMethodHandl er.invoke(SyncMethodHandler.java:78)
    at com.sun.xml.internal.ws.client.sei.SEIStub.invoke( SEIStub.java:129)
    at com.sun.proxy.$Proxy21.upload(Unknown Source)
    at test.Main.main(Main.java:28)


    Here is my project.

    Servers I tested tomcat 7 and jetty 7 with JDK 7 1.7.0_25-b17 x64.

    Apache CXF 2.7.5

    TIA., Sandor

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,776
    Rep Power
    5

    Default Re: File upload with web service (SWING + Apache CXF)

    Post the relevant code, don't make people go to an external site and dig through your project. If you want help, make an effort.

    Likely you are getting OOM because you are tanking the entire data bulk into memory, which is not a good idea. Research I/O streams to stream the data from the source to the destination. Any half-decent java API supports it.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    sfeher is offline Member
    Join Date
    Jul 2013
    Posts
    3
    Rep Power
    0

    Default Re: File upload with web service (SWING + Apache CXF)

    Quote Originally Posted by gimbal2 View Post
    Post the relevant code, don't make people go to an external site and dig through your project. If you want help, make an effort.
    I intended to make others' life easier putting the whole project at github. I can be accessed and tested easily.
    But here is the relevant part.

    BigData.class
    package test;

    import javax.activation.DataHandler;
    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlMimeType;
    import javax.xml.bind.annotation.XmlRootElement;

    @XmlRootElement
    @XmlAccessorType(XmlAccessType.FIELD)
    public class BigData {
    @XmlElement
    private String str;

    @XmlMimeType("application/octet-stream")
    private DataHandler data;

    public String getStr() {
    return this.str;
    }

    public void setStr(final String str) {
    this.str = str;
    }

    public DataHandler getData() {
    return this.data;
    }

    public void setData(final DataHandler data) {
    this.data = data;
    }
    }
    Main.class
    package test;

    import java.io.IOException;
    import java.net.URL;
    import javax.activation.DataHandler;
    import javax.activation.FileDataSource;
    import javax.xml.namespace.QName;
    import javax.xml.ws.BindingProvider;
    import javax.xml.ws.Endpoint;
    import javax.xml.ws.Service;
    import javax.xml.ws.soap.SOAPBinding;

    public class Main {

    public static void main(final String[] args) throws IOException {
    final Endpoint endpoint = Endpoint.publish("http://localhost:9090/service", new TestService());
    ((SOAPBinding)endpoint.getBinding()).setMTOMEnable d(true);

    final QName qname = new QName("http://test/", "TestServiceService");
    final Service service = Service.create(new URL("http://localhost:9090/service?wsdl"), qname);
    final ITestService client = service.getPort(ITestService.class);
    final SOAPBinding clientBinding = (SOAPBinding)((BindingProvider)client).getBinding( );
    clientBinding.setMTOMEnabled(true);

    final BigData data = new BigData();
    data.setStr("string");
    final FileDataSource ds = new FileDataSource(args[0]);
    data.setData(new DataHandler(ds));
    client.upload(data);
    System.exit(0);
    }
    }


    Likely you are getting OOM because you are tanking the entire data bulk into memory, which is not a good idea. Research I/O streams to stream the data from the source to the destination. Any half-decent java API supports it.
    As you can see I use streams for sending data. Despite of this I get OOM.

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,776
    Rep Power
    5

    Default Re: File upload with web service (SWING + Apache CXF)

    Thanks for taking the time to figure out how to post code.

    Because that DataHandler class you're using is internally tanking everything into a ByteArrayOutputStream, in other words: into memory. You can easily see that happening in the stacktrace you posted. Likely you need to use another data handler class then, or another means of -truly- streaming the data. Perhaps a revisit to the documentation is in order.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    sfeher is offline Member
    Join Date
    Jul 2013
    Posts
    3
    Rep Power
    0

    Default Re: File upload with web service (SWING + Apache CXF)

    I look like retarded but I'm just partially. I could analyze the stacktrace by myself and concluded that the root of the problem is copying whole file into ByteArrayOutputStream. Because this example works for others (I have no tools to check if it really works for them) but not for me then I have one questions left. Why it does not work for me ?
    Almost every example uses DataHandler for streaming so I truly expect that it should work for me as well.
    After your explanation I looked for DataHandler replacements.

    I found so far com.sun.xml.ws.developer.StreamingDataHandler which is not recommended for using according to Oracle.
    So I will have a try with org.jvnet.staxex.StreamingDataHandler. I hope some of them solve the problem.

    Thank you, Sandor

Similar Threads

  1. org.apache.wicket.markup.html.form.upload.FileUplo ad class
    By aydeger in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 12-10-2011, 02:19 PM
  2. Replies: 5
    Last Post: 11-30-2011, 09:27 AM
  3. Apache Axis Web Service Create Error
    By richierich in forum Advanced Java
    Replies: 0
    Last Post: 04-19-2011, 07:58 AM
  4. how to upload a file using swing
    By ravi.virgoo@gmail.com in forum AWT / Swing
    Replies: 2
    Last Post: 11-20-2009, 05:49 AM
  5. :large file upload to server(chunk upload)
    By tommy_725 in forum Networking
    Replies: 0
    Last Post: 10-16-2009, 12:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •