1

I am building a java web services server that needs to scale and to be highly available. User can upload large file (~20M) through the services. SOAP is preferred.

My question are: is there any such a web service framework which support large file streaming? Any building blocks that I should consider? Any good practices?

Any thoughts would be appreciated. Thanks.

baklarz2048
  • 10,699
  • 2
  • 31
  • 37
stones333
  • 8,588
  • 1
  • 25
  • 27
  • Are you more interested in upload (user->server) or download (server->user)? – mindas Jan 22 '13 at 09:56
  • To let user to upload the file. But, I am more interested in providing a web service which allow file content being transfered between different servers automatically. – stones333 Jan 22 '13 at 23:33

1 Answers1

3

If you need high performance, webservices are not great.

You can try (Streaming SOAP Attachments):

File : ImageServer.java //Service Endpoint Interface

package com.mkyong.ws;     
import java.awt.Image; 
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;



@WebService
@SOAPBinding(style = Style.RPC)
public interface ImageServer{

    //download a image from server
    @WebMethod Image downloadImage(String name);

    //update image to server
    @WebMethod String uploadImage(Image data);

}

//File : ImageServerImpl.java
package com.mkyong.ws;

import java.awt.Image;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.jws.WebService;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.soap.MTOM;

//Service Implementation Bean
@MTOM
@WebService(endpointInterface = "com.mkyong.ws.ImageServer")
public class ImageServerImpl implements ImageServer{

    @Override
    public Image downloadImage(String name) {

        try {

            File image = new File("c:\\images\\" + name);
            return ImageIO.read(image);

        } catch (IOException e) {

            e.printStackTrace();
            return null; 

        }
    }

    @Override
    public String uploadImage(Image data) {

        if(data!=null){
            //store somewhere
            return "Upload Successful";
        }

        throw new WebServiceException("Upload Failed!");

    }

}
baklarz2048
  • 10,699
  • 2
  • 31
  • 37
  • This is one possible solution. Thanks. Does MTOM increase the size of the payload? Is it efficient if I want to send a large file, ie, video file? – stones333 Jan 26 '13 at 01:14
  • Yes and no. If you want to use it internally (some WAN connection and not many users) it's good enough. If you will have thousands of users uploading content forget about Java. It will be still possible but $/req ratio will be unacceptable. – baklarz2048 Jan 27 '13 at 13:09