Thursday 11 April 2013

jsp code to download file from server

<%
File file = new File("/ed63/ora510/eld611i2comn/html/eisrs/data/backuploadbalance.xlsx");
String resultXLS="excelfileName1441.xlsx";
response.setHeader("Content-Length", ""+file.length());
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=UTF-8");
response.setHeader("content-disposition", "attachement; filename=\"" + resultXLS + "\"");
response.setHeader("Content-Transfer-Encoding", "binary");

FileInputStream fileIn = new FileInputStream(file);
OutputStream outExcel = response.getOutputStream();

byte[] outputByte = new byte[8192];
//copy binary contect to output stream
while(fileIn.read(outputByte, 0, 8192) != -1)
{
outExcel.write(outputByte, 0, 8192);
}

fileIn.close();
outExcel.flush();
outExcel.close();

%>

Wednesday 10 April 2013

Stubs and Skeletons

Stubs and Skeletons
RMI uses a standard mechanism (employed in RPC systems) for communicating with remote objects: stubs and skeletons. A stub for a remote object acts as a client's local representative or proxy for the remote object. The caller invokes a method on the local stub which is responsible for carrying out the method call on the remote object. In RMI, a stub for a remote object implements the same set of remote interfaces that a remote object implements.

When a stub's method is invoked, it does the following:

1) initiates a connection with the remote JVM containing the remote object,
2) marshals (writes and transmits) the parameters to the remote JVM,
3) waits for the result of the method invocation,
4) unmarshals (reads) the return value or exception returned, and
5) returns the value to the caller.

The stub hides the serialization of parameters and the network-level communication in order to present a simple invocation mechanism to the caller.

In the remote JVM, each remote object may have a corresponding skeleton (in Java 2 platform-only environments, skeletons are not required).

The skeleton is responsible for dispatching the call to the actual remote object implementation.

When a skeleton receives an incoming method invocation it does the following:

1) unmarshals (reads) the parameters for the remote method,
2) invokes the method on the actual remote object implementation, and
3) marshals (writes and transmits) the result (return value or exception) to the caller.

In the Java 2 SDK, Standard Edition, v1.2 an additional stub protocol was introduced that eliminates the need for skeletons in Java 2 platform-only environments. Instead, generic code is used to carry out the duties performed by skeletons in JDK1.1. Stubs and skeletons are generated by the rmic compiler.

Reference:
http://java.sun.com/j2se/1.5.0/docs/guide/rmi/spec/rmi-arch2.html