Thursday, August 27, 2009

Webservice Client for sending attachments using apace axis

Today i am going to share for my experience how to send binary attachments to a webservice using apache axis.The following piece of code will help you to do the same.

String endpoint = "http://localhost:9000/ecm/yourwebservice.jws";
javax.activation.DataHandler dataHandler = new javax.activation.DataHandler(
new FileDataSource(
"C:\\WINDOWS\\TEMP\\user\\data\\metadata.xml"));
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
QName qnameAttachment = new QName("uploadUser", "DataHandler");
call.addParameter("source", qnameAttachment, ParameterMode.IN);
call.registerTypeMapping(dataHandler.getClass(), // Add serializer for attachment.
qnameAttachment, JAFDataHandlerSerializerFactory.class,
JAFDataHandlerDeserializerFactory.class);
call.setOperationName("uploadUser");
call.invoke(new Object[] { dataHandler});

The above code is the client.


The webservice will be something like this

public void uploadUser(DataHandler handler){
InputStream in = handler.getInputStream();
//in is the bytes send by the client to the webservice

}

Thats all how we can send attachments to webservice.

Happy Coding

Wednesday, July 29, 2009

Escape Analysis

Well today i have come for blogging after great frustration as i was whole day in my office to get the LDAP url for testing my application by i didnt got till now as now it is evening and i raised the request in the morning.Well let me now come to the key feature of the article.Today i am going to write something on Escape Analysis.It a new terminology used by Sun Microsytem
in their current JVM version 6.What this Escape Analysis does is it allocates object memory if necessary and also converts Heap Based memory to Stack based as per when required.As a result it improves application performance in terms of memory creation as we know that memory creation is time consuming .If you haven't started using Java 6 please start using as it has lots of performance improvement as comapred to previous version.

Wednesday, May 20, 2009

XML Vs JSON

All these days we were learing about XML as only the data transfer technology and the whole world were crazy for learning XML and institutes were earning bucks in the name of XML as it was highly demanded in the era of web technology.But after the incubation of Java Script object notation(JSON) XML has lost its glossiness to some extent in the field of web application.Because the truth behind this is JSON is much more faster than XML as it occupies less memory than its counterpart XML.So imagine if u have to transfer data and with XML it comes 1 MB .By using JSON you can transfer the same data with just 1/2 MB of size.So start using JSON for any server and client data transfer.Also we have java based JSON library a good news for java developer

Ext JS

Ext JS is a javascript api for desktop looks and feels for a web application.It follows the concept of oops as wells as lots of good design pattern is integrated with it.It heavily depends on JSON for data to and forth between the server and the client.
The beautiful advantage of Ext Js is it faster than other javascript libraries as it caches the data and also it uses JSON String for Ajax type data transfer.As JSON takes less memory from its counterpart XML data transfer.I have spoken the good part of Ext JS,but let me tell about its sad part its a licenced based api.But can be used free if you are not making any profit from your apps where you are using Ext Js.Also Ext JS can be integrated with JSF for developing ajax based custom components.