Showing posts with label Weblogic. Show all posts
Showing posts with label Weblogic. Show all posts

Monday, May 12, 2014

Develop and Deploy Jersey RESTful service using JDeveloper in Weblogic

Jersey is one of reference implementations of JAX-WS specification which is to describe how REST should be implemented using annotation-driven POJO in Java. Jersey is the one that is most widely used in development and production. WebLogic Server ships with a set of pre-built shared libraries, packaged as Web applications. Jesery is one of these and it is required to run applications that are based on the Jersey JAX-RS RI. The version of Jsersey in weblogic 10.3 is 1.9 which implements JAX-RS 1.1.

This jersey war file is located in:  $Middleware/wlserver_10.3/common/deployable-libraries/jersey-bundle-1.9.war.


Register Jersey as the shared library in Weblogic server 


Before the REST application can be deployed and run on Weblogic the Jersey JAX-RS RI shared libraries needs to be registered in Weblogic Servcre instance. It can be done via Weblogic Console. 
Login into Weblogic Console Click on Deployments in Domain Structure
Click on Lock & Edit button to enable Install button and then click on Install button


The path should be:  /u01/app/fmwsodev/Middleware/wlserver_10.3/common/deployable-libraries
Select jersey-bundle-1.9.war and click on Next button

Select Install this deployment as a library and click on Next button

Select target and click on Next button


Select target and click on Next button


Confirm the library name, version and implementation version as below and click on Finish button



Now Jersey JAX-RS RI is registered as shared library in Weblogic server.  Any application deployed on the server can use this library for implementation of REST service using Jersey.



Develop Jersey REST service using JDeveloper


Create a generic project in JDeveloper




In order to develop Java codes which use Jersey to implement RESTful service, two jar files are needed to add into User Managed Libraries in JDeveloper.


First jar is jersey-bundle-1.9.jar which can be downloaded from:

http://repo1.maven.org/maven2/com/sun/jersey/jersey-bundle/1.9/jersey-bundle-1.9.jar


Since jersey-bundle-1.9.jar doesn't include JAX-RS API classes.  So JAX-RS API jar is also needed.   The jar file can be found from Weblogic server installation folder: $Middleware/modules/javax.ws.rs_1.0.0.0_1-1-1.jar


After two jar files are added into the libraries use these two libaries in the project: RESTProject by using Add Library in Libraries and Classpath from Project Properties... menu item.


Now create a POJO which will implement the service:

The source codes of Java class: RESTService are as below:


package com.toic.rest;

import com.toic.model.Folder;

import java.util.logging.Logger;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;


@Path("/folders")
public class RESTService {
    
    private Logger logger = Logger.getLogger(RESTService.class.getName());
    
    public RESTService() {
        super();
    }
    
    @GET
    @Path("/guid/{folderguid}")
    @Produces(MediaType.APPLICATION_JSON)
    public Response getFoldersByGUID(@PathParam("folderguid") String folderguid) {
        
        Folder folder = Folder.makeFolders();
        
        return Response.status(Response.Status.OK).entity(folder).build();
    }
}
The below is one domain class Folder which is used in RESTService class.


package com.toic.model;

import java.util.ArrayList;
import java.util.List;

public class Folder {
    
    private String folderName;
    
    private String owner;
    
    private String folderGUID;
    
    private String folderType;
    
    private List childFolders = new ArrayList();
    
    
    public Folder() {
        super();
    }

    public String getFolderName() {
        return folderName;
    }

    public void setFolderName(String folderName) {
        this.folderName = folderName;
    }

    public String getOwner() {
        return owner;
    }

    public void setOwner(String owner) {
        this.owner = owner;
    }

    public String getFolderGUID() {
        return folderGUID;
    }

    public void setFolderGUID(String folderGUID) {
        this.folderGUID = folderGUID;
    }

    public String getFolderType() {
        return folderType;
    }

    public void setFolderType(String folderType) {
        this.folderType = folderType;
    }

    public List getChildFolders() {
        return childFolders;
    }

    public void addChildFolder(Folder childFolder) {
        this.childFolders.add(childFolder);
    }
    
    public static Folder makeFolders() {
        Folder rootFolder = new Folder();
        
        rootFolder.setFolderName("Root Folder");
        rootFolder.setOwner("Mark");
        rootFolder.setFolderGUID("123456");
        rootFolder.setFolderType("NATIVE");
        
        Folder childFolder1 = new Folder();
        
        childFolder1.setFolderName("Folder1");
        childFolder1.setOwner("Mark");
        childFolder1.setFolderGUID("100234");
        childFolder1.setFolderType("NATIVE");
        
        Folder childFolder2 = new Folder();
        
        childFolder2.setFolderName("Folder2");
        childFolder2.setOwner("Mark");
        childFolder2.setFolderGUID("200234");
        childFolder2.setFolderType("NATIVE");

        rootFolder.addChildFolder(childFolder1);
        
        rootFolder.addChildFolder(childFolder2);
        
        return rootFolder;
    }
}


In RESTService.java editor click on Quick Fix to configure web.xml for this service.



web.xml is created under WEB-INF.


Update url-pattern to *


Then create Weblogic Deployment Descriptor


weblogic.xml file is created under WEB-INF as shown as below:


In run time the deployed service will use the shared library of Weblogic.  Here in weblogic.xml the library reference should be created as below:


Next step is to update the deployment profile of the service which is deployed as web application,


The service is called RESTService.


Update the context root as: Demo.



Deploy Jersey REST service and test the service


After all is done the service is ready to deploy to Weblogic server from JDeveloper.



If the deployment is successful RESTService will appear in the deployments of Weblogic Console.


Click on RESTService and click on Testing tab



Click on the Test Point URL to start browser and type in the url as: http://weblogicserverhost:8001/Demo/folders/guid/123456 and the service will respond as below:

















Tuesday, February 12, 2013

Configure Weblogic JMS Resources


Before we can configure Weblogic JMS resources such as ConnectionFactory, Queue, Topic, it is better to understand some concepts in Weblogic JMS.  

JMS Server


JMS server is the management container for JMS resources defined in JMS modules targeted to.   A JMS server's main responsibility is to maintain persistent storage for these resources, maintain the state of durable subscriber and etc.
JMS servers are persisted in the domain's config.xml file and multiple JMS servers can be configured on the various WebLogic Server instances in a cluster, as long as they are uniquely named.
One domain can have one or more than one JMS server. 
A JMS server can manage one or more JMS modules.
One cluster node has own JMS server targeted to managed node.
For example there are two managed nodes in a clustered environment: osb_ms1 and osb_ms2.
We create two JMS servers: OSB_JMSServer_01 and OSB_JMSServer_02 which are targeting osb_ms01 and osb_ms02 respectively.

JMS Module


JMS modules group JMS configuration resources (such as queues, topics, and connections factories).  These are outside domain configuration.  
JMS module targets the servers.   If it is clustered environment it will target all servers in the cluster.

Subdeployment


Subdeployment is also known as Advanced Targeting.  
Subdeployment resource is a bridge between the group of JMS resources and JMS Servers.   Without Subdeployment the JMS resources cannot target any JMS server.
When you create a JMS resource you need to choose one Subdeployment.
In clustered environment one Subdeployment targets multiple JMS server for each cluster node.

The below diagram shows the relationship between them.


 

Steps to configure JMS resources


The following is an example which demostrate the configuration steps for JMS resources in Oracle using Oracle Weblogic Console. This example is done with a single node environment. 

 

1. Create JMS Server

The first step is to create a JMS server.  Select the domain in Console.  Then click on YourDomain-->Services-->Messaging-->JMS Servers. In the right panel click on New button. And then type in the name for JMS server to be created and select the Persistence Store.  If Persistemce Store doesn't exist create a new Persistence Store.   Then click on Next button.


Select the Weblogic server node and then click on Finish button.  Then a JMS server called Demo-JMSServer is created.  This Demo-JMSServer is targeted to AdminServer.















2. Create JMS Module

The second step is to create a JMS Module. Select the domain in Console. Then click on YourDomain-->Services-->Messaging-->JMS Modules.   In the right panel click on New button.  And then type in the name for JMS Module.  Then click on Next button.
 
 

 
Then select the target of Weblogic server node.


Then click on Next button.

Then click on Finish button.  DemoJMSModule is created.











3. Create JMS Resource

The third step is to create a JMS resource such as connection factory, queue or topic in above created JMS Module.
Click the JMS Module where a resource is created.


Then click on New button.


Select the resource type to be created.   Here we create a Queue.   Then click on Next button.


Type in the Queue nama and JNDI name for this Queue and then click on Next button.



Select the Subdeployment.  If no existing Subdeployment can be used click on Create a New Subdeployment buttn.





Type in the name for a new Subdeployment and then click on OK button.




Then select the JMSServer and then click on Finish button.