About Me

My photo
Ernakulam, Kerala, India
I am Sajadh, author of this blog. I run this with loads of passion.
If you are into java, you may find lot of interesting things around ...
Advance thanks for your queries to sajadhaja90@gmail.com.

Wednesday, 2 October 2013

REST with Java (JAX-RS) using Jersey

Refer From :- http://www.vogella.com/articles/REST/article.html

REST is an architectural style which is based on web-standards and the HTTP protocol.
In a REST based architecture everything is a resource. A resource is accessed via a common interface based on the HTTP standard methods.
In a REST based architecture you typically have a REST server which provides access to the resources and a REST client which accesses and modify the REST resources.
Every resource should support the HTTP common operations. Resources are identified by global IDs

HTTP methods
The PUT, GET, POST and DELETE methods are typical used in REST based architectures.

JAX-RS with Jersey

JAX-RS:- Java defines REST support via the Java Specification Request 311

Jersey :- contains basically a REST server and a REST client.

On the server side Jersey uses a servlet which scans predefined classes to identify RESTful resources. Via the web.xml configuration file for your web application, registers this servlet which is provided by the Jersey distribution 

The base URL of this servlet is:
http://your_domain:port/display-name/url-pattern/path_from_rest_class 

This servlet analyzes the incoming HTTP request and selects the correct class and method to respond to this request. This selection is based on annotations in the class and methods.

Table 1. JAX-RS annotations
Annotation
Description
@PATH(your_path)
Sets the path to base URL + /your_path. The base URL is based on your application name, the servlet and the URL pattern from the web.xml" configuration file.
@POST
Indicates that the following method will answer to a HTTP POST request
@GET
Indicates that the following method will answer to a HTTP GET request
@PUT
Indicates that the following method will answer to a HTTP PUT request
@DELETE
Indicates that the following method will answer to a HTTP DELETE request
@Produces(MediaType.TEXT_PLAIN [, more-types ])
@Produces defines which MIME type is delivered by a method annotated with @GET. In the example text ("text/plain") is produced. Other examples would be "application/xml" or "application/json".
@Consumes(type [, more-types ])
@Consumes defines which MIME type is consumed by this method.
@PathParam
Used to inject values from the URL into a method parameter. This way you inject for example the ID of a resource into the method to get the correct object.
Please Refer Site : - http://www.vogella.com/articles/REST/article.html

Friday, 5 April 2013

My Stuff Doc - jasper-export-1.0.jar


1 .Export To PDF

Tools needed :-  jasper-export-1.0.jar  (owner : Mohammed Sajadh N.A)
4 Steps :-
         1. Take Connection from database
           eg:-  Connection con = new com.sajadhaja.connection.DatabaseConnection().getConnection();
         2.  Set all dynamic parameters that in jrxml file to Hash Map like
           eg:-  Map<String, Object> hm = new HashMap<String, Object>();
                   hm.put("p1_in_jrxml", 1);
                   hm.put("p2_in_jrxml ", "12 Aug 2013");
        3. Import class JasperExport  from my jar (jasper-export-1.0.jar)   and set  all parameters like
                  eg:- JasperExport jp = new JasperExport("jrxml/jasper file location",
                                                                  "out PDF file location",connection, hashmap);
       4. Call function exportToPDF()

Sample Example :-
Public class ExportToPDF{
public static void main(String args[]) {
        Connection con = new com.sajadhaja.connection.DatabaseConnection().getConnection();
        Map<String, Object> hm = new HashMap<String, Object>();
        hm.put("p1", 1);
        hm.put("p2", "");
        JasperExport jp = new JasperExport("D:\\sample.jasper", "D:\\sample.pdf", con, hm);
        jp.exportToPDF();
    }
}

OTHER FUNCTIONS

To customize PDF for having following functions:-
1.      Default Magnification
2.      Encrypt PDF
3.      Setting MetaData
4.      Compress PDF
Replace function used in STEP 4 with   exportToCustomPDF(JasperPDFParam pm);
Where class JasperPDFParam contain all funtions to do the same.
1.      Default Magnification
To open the PDF doc in default zoom level, you can set it here
Syntax:-  void setDefaultZoom(int Zoompercentage)
Eg:-
JasperPDFParam pm = new JasperPDFParam();
pm.setDefaultZoom(100);  
2.      Encrypt PDF
Syntax:- void setEncryption(boolean is128bitkey, String userPassword, String ownerPassword, int permissions)
Where field ‘permissions’ have following values
                 JasperPDFParam.PERMISSION_AllowPrinting
                 JasperPDFParam.PERMISSION_AllowModifyContents
                 JasperPDFParam.PERMISSION_AllowCopy
                 JasperPDFParam.PERMISSION_AllowModifyAnnotations
                 JasperPDFParam.PERMISSION_AllowFillIn
                 JasperPDFParam.PERMISSION_AllowScreenReaders
                 JasperPDFParam.PERMISSION_AllowAssembly
                 JasperPDFParam PERMISSION_AllowDegradedPrinting
Eg:-
JasperPDFParam pm = new JasperPDFParam();
pm.setEncryption(true, "12345", "0000",
new Integer(JasperPDFParam.PERMISSION_AllowAssembly|JasperPDFParam.PERMISSION_AllowCopy));
       
3.      Setting MetaData
Syntax:- void setMetadata(String tittle, String author, String subject, String keywords, String creator);
Eg:-
JasperPDFParam pm = new JasperPDFParam();
pm.setMetadata("Jasper Notes", "Mohammed", "Export pdf notes", "jasper jar", "sajadhaja.blogspot.in");

4.      Compress PDF
Syntax :- void pm.setCompressed(boolean isCompressed);
Eg:-
JasperPDFParam pm = new JasperPDFParam();
pm.setCompressed(true);


Sample Example :-
Public class ExportToPDF{
public static void main(String args[]) {
Connection con = new com.sajadhaja.connection.DatabaseConnection().getConnection();
            Map<String, Object> hm = new HashMap<String, Object>();
            hm.put("p1", 1);
            hm.put("p2", "");
            JasperExport jp = new JasperExport("D:\\sample.jasper", "D:\\sample.pdf", con, hm);
            JasperPDFParam pm = new JasperPDFParam();
            pm.setMetadata("mohammed tittle", "mohamed author", "mohammed subject", "mohammed keywords", "mohamed    creator");
            pm.setEncryption(true, "12345", "0000", new Integer(JasperPDFParam.PERMISSION_AllowAssembly|JasperPDFParam.PERMISSION_AllowCopy));
            pm.setDefaultZoom(100);
            pm.setCompressed(true);
            jp.exportToCustomPDF(pm);
     }}


Thursday, 4 April 2013

My Stuffs - Jar & Js (Created by Me)

1. Drag-and-Drop File Uploads  (Java Script)
          File Name           :- filedrag.js
          Dated                   :- 10 Jan 2013
          Version                :-  1.0
          Download Link    :-
          Purpose               :- to enable Drag For File Upload

2. Jasper Export to PDF  (Jar)

          File Name              :-  jasper-exports-1.0.jar
          Dated                     :- 04 Apr 2013
          Version                  :- 1.0
          Notes                     :-  Click Here
          Download Link      :-
          Purpose                 :- to use Jasper Technology easier to export PDF