Show TOC

Processing Large Data by Web ServicesLocate this document in the navigation structure

Prerequisites

The implementation bean of the Web service is available.

Context

Processing large data using Web services may cause low performance on your system. Due to the large information volume, the system may respond with a session timeout exception. To avoid this, we recommend that you create and use Web services and Web service clients, which are designed to transfer and operate smaller chunks of data. This approach uses simple SOAP protocol for data transfer instead of MIME attachments. From memory consumption and performance point of view, data transfer over a SOAP protocol does not differ from the MIME attachments. Moreover, we recommend that you use chunked information transfer as it allows you to interact with other vendors.

This procedure enables you to increase system performance by splitting the large data that is transferred by the Web services into numerous smaller pieces. The data is sent over a simple SOAP protocol and do not block additional resources. At a later stage, the Web service client merges the split information and thus provides the result of the consumed Web service reliably to the consumer.

Procedure

  1. Create the Web service implementation bean and implement its business logic.

    More information: Providing Web Services

  2. Create a chunking mechanism in the Web service business logic.

    You design the Web service to transfer the attached response in smaller pieces of information. This way the Web service sends the requested information in series and at a later stage, the Web service client merges the chunks and provides the response.

    The following sample code provides information about the implementation of a chunking mechanism in the Web services (provider side).

                      package test.ejb;
    import java.util.StringTokenizer;
    import javax.ejb.Stateful;
    import javax.jws.WebService;
    import javax.jws.WebMethod;
    @WebService(targetNamespace="http://ejb.test/", serviceName="ChunkingService",
             portName="ChunkingBeanPort", name="Chunking")
    @Stateful
    public class ChunkingBean implements ChunkingLocal {
            private String data = "This is large data that cannot be handled in one "+
                    "response and should be returned in several responses.";
            private StringTokenizer tokenizer = new StringTokenizer(data, " ");
            @WebMethod(exclude=false, operationName="getData")
            public String getData() {
                    while (tokenizer.hasMoreTokens()) {
                            return tokenizer.nextToken();
                    }       
                    return "/n";            
            }
    }
    
                   
  3. Create a chunking mechanism to the Web service client.

    You design the Web service client to receive the response from the Web service in smaller pieces of information. This way the Web service client receives the requested information in series, merges the chunks, and provides the response. To merge the information and handle it reliably, create a chunking mechanism in the business logic of the client application.

    More information: Consuming Web Services

    The following sample code provides information about an implementation of a chunking mechanism in the client application of a Web service client (consumer side).

                      ...
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
             throws ServletException, IOException {
            Chunking port = service.getChunkingBeanPort();
            StringBuffer text = new StringBuffer();
            String data = null;
            
            while (!("/n".equals(data = port.getData()))) {
                    text.append(data);
                    text.append(" ");
            }
    ...