Month: November 2015

How to Deploy Web Services in WSO2 Application Server using WSO2 Developer Studio

How to Deploy Web Services in WSO2 Application Server using WSO2 Developer Studio

Introduction

This post mainly target to give you the process of deploying web services in WSO2 Application Server. We will use WSO2 Developer Studio 3.8.0 and WSO2 Application server 5.3.0 for this tutorial.

Create a simple Web Service

Create a simple JAX-RS service following the post “Develop JAX-RS Web Service Easily Using WSO2 Developer Studio”

webserviceprojectCreate a C-APP Project

Go to Developer Studio Dashboard and click Composite Application Project listed in Distribution section. And create a CAPP project named CAPP_Application_server and select check button of the Web service project you want to host in Application Server.capp_creation

Developer Studio will create you a CAPP project which can be deploy directly into WSO2 Application server. Isn’t that great!!!

Add and Start WSO2 Application Server from Developer Studio

There are two ways to do this.
  1. Application server can be add to Developer Studio as a server and then you can do every server operation through Developer Studio.
    • Go to Server tab in Developer Studio. This window can be found in bottom section or by following
      • Menu-bar-> Window -> Show view->Serversservers_tab
    • Right click inside window and go for New->Server Menu. Select
      • WSO2 -> WSO2 Carbon 4.4 based server (Since WSO2 AS 5.3.0 is based on WSO2 Carbon 4.4.0)add_new_server
    • Go to Next page of wizard add AS server distribution home folder location as CARBON_HOME section.carbon_server_path
    • Next page shows port configurations and other useful information. Then finish the configuration and start server.
  2. Application server can be started externally and add to Developer Studio as a remote server.
    • Start Application Server externally server_externally_startAS_server_started_externallyhttps://192.168.1.4:9443/carbon/ will be the default server url.
    • Go to server tab and New-> Server menu. Select
      • WSO2 -> remote Serverremote_server_urlFill the server url with running server url and finish the configuration.

Add CAPP to Application Server

Now WSO2 server is up and running in our system. You can now deploy the your web service.

  • Right click on Developer Studio server tab we created in previous step and goto command Add and Removeadd_remove
  • Then Dialog will pop-up listing available CAPP’s in the workspace. Select your CAPP created in previous step and finish the configuration.
  • Your service will deploy in to Application server and up and running.succesfullydeployed
  • You can go to Application Server management console from browser and see your service

servicemanagementconsole

Develop JAX-RS Web Service Easily Using WSO2 Developer Studio

Develop JAX-RS Web Service Easily Using WSO2 Developer Studio

INTRODUCTION

This post will guide you to develop a JAX-RS Web Service using WSO2 Developer Studio and host it in WSO2 Application server and test it.

First if you don’t have WSO2 Developer Studio installed, install developer studio. We will use WSO2 Application Server to host our application and test it by using Rest Easy extension in Firefox or Google Chrome.

SAMPLE SCENARIO

We will implement an employee information web service for a company. In this sample service, information is stored in a HashMap. This web service is able to register an employee, get information using the employee ID and update or modify information.

IMPLEMENTING SERVICE CLASSES

  1. Open the Developer Studio Dashboard and click JAX-RS Service Project.
  2. Click Create New JAX-RS Service and then click Next.
  3. Enter EmployeeManagementJAXRSProject as the project name, com.employee.management.jaxrs.service as the package name and EmployeeManagementService as the class name.
  4. Click Finish. The project structure is created.
  5. Implement the service class and two bean classes for response messages, as shown below:
EmployeeManagementService.java
package com.employee.management.jaxrs.service;
import java.util.HashMap;
import java.util.Map;
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import com.employee.management.jaxrs.beans.Employee;
import com.employee.management.jaxrs.beans.Message;
@Path("/employee")
public class EmployeeManagementService {
    public static Map<String, Map<String, String>> employees = new HashMap<>();
    @POST
    @Consumes("text/plain")
    @Produces("text/xml")
    @Path("/insert/query")
    public Response insertEmployee(@QueryParam("id") String id,
         @QueryParam("name") String name,
         @QueryParam("designation") String designation,
         @QueryParam("salary") String salary) {
     id = id.trim();
     if (!employees.containsKey(id)) {
         Map<String, String> info = new HashMap<>();
         info.put("name", name);
         info.put("designation", designation);
         info.put("salary", salary);
         employees.put(id, info);
         Message msg = new Message();
         msg.setMessage("Successfully registered");
         return Response.ok(msg).build();
     }
     Message msg = new Message();
     msg.setMessage("Employee id already registered");
     return Response.ok(msg).build();
    }
    @POST
    @Consumes("text/plain")
    @Produces("text/xml")
    @Path("/update/designation")
    public Response updateEmployeeDesignation(@QueryParam("id") String id,
         @QueryParam("designation") String designation) {
     id = id.trim();
     if (employees.containsKey(id)) {
         Map<String, String> info = new HashMap<>();
         info = employees.get(id);
         info.put("designation", designation);
         Message msg = new Message();
         msg.setMessage("Successfully updated");
         return Response.ok(msg).build();
     }
     Message msg = new Message();
     msg.setMessage("Employee id is not registered");
     return Response.ok(msg).build();
    }
    @POST
    @Consumes("text/plain")
    @Produces("text/xml")
    @Path("/update/salary")
    public Response updateEmployeeSalary(@QueryParam("id") String id,
         @QueryParam("salary") String salary) {
     id = id.trim();
     if (employees.containsKey(id)) {
         Map<String, String> info = new HashMap<>();
         info = employees.get(id);
         info.put("salary", salary);
         Message msg = new Message();
         msg.setMessage("Successfully updated");
         return Response.ok(msg).build();
     }
     Message msg = new Message();
     msg.setMessage("Employee id is not registered");
     return Response.ok(msg).build();
    }
    @POST
    @Consumes("text/plain")
    @Produces("text/xml")
    @Path("/update/name")
    public Response updateEmployeeName(@QueryParam("id") String id,
         @QueryParam("name") String name) {
     id = id.trim();
     if (employees.containsKey(id)) {
         Map<String, String> info = new HashMap<>();
         info = employees.get(id);
         info.put("name", name);
         Message msg = new Message();
         msg.setMessage("Successfully updated");
         return Response.ok(msg).build();
     }
     Message msg = new Message();
     msg.setMessage("Employee id is not registered");
     return Response.ok(msg).build();
    }
    @GET
    @Consumes("text/plain")
    @Produces("text/xml")
    @Path("/get/{id}")
    public Response getEmployee(@PathParam("id") String id) {
     id = id.trim();
     if (employees.containsKey(id)) {
         Map<String, String> info = new HashMap<>();
         info = employees.get(id);
         Employee entity = new Employee();
         entity.setId(id);
         entity.setName(info.get("name"));
         entity.setDesignation(info.get("designation"));
         entity.setSalary(info.get("salary"));
         return Response.ok(entity).build();
     }
     Message msg = new Message();
     msg.setMessage("ID is not registered");
     return Response.ok(msg).build();
    }
}
Employee.java
package com.employee.management.jaxrs.beans;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "Employee")
public class Employee {
    private String id;
    private String name;
    private String designation;
    private String salary;
    public String getId() {
     return id;
    }
    public void setId(String id) {
     this.id = id;
    }
    public String getName() {
     return name;
    }
    public void setName(String name) {
     this.name = name;
    }
    public String getDesignation() {
     return designation;
    }
    public void setDesignation(String designation) {
     this.designation = designation;
    }
    public String getSalary() {
     return salary;
    }
    public void setSalary(String salary) {
     this.salary = salary;
    }
}
Message.java
package com.employee.management.jaxrs.beans;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "Message")
public class Message {
    private String message;
    public String getMessage() {
     return message;
    }
    public void setMessage(String message) {
     this.message = message;
    }
    
}

6 Create a C-App project and deploy it to the Application Server.

Testing the service

You can test the sample service using the REST Easy extension from Firefox or Google Chrome.

Test the operations for registering an employee, update/modify and get information, as shown below.

Register employee

http://localhost:9763/EmployeeManagementJAXRSProject-1.0.0/services/employee_management_service/employee/insert/query?id=1&name=NAME&designation=DESIGNATION&salary=SALARY_AMOUNT

Get employee information

http://localhost:9763/EmployeeManagementJAXRSProject-1.0.0/services/employee_management_service/employee/get/index

Update employee name

http://localhost:9763/EmployeeManagementJAXRSProject-1.0.0/services/employee_management_service/employee/update/name?id=1&name=NAME_MODIFIED

Update employee designation

http://10.100.7.83:9763/EmployeeManagementJAXRSProject-1.0.0/services/employee_management_service/employee/update/designation?id=1&designation=DESIGNATION_MODIFIED

Update employee salary

http://10.100.7.83:9763/EmployeeManagementJAXRSProject-1.0.0/services/employee_management_service/employee/update/salary?id=1&salary=SALARY_MODIFIED

Information after modifications

How to Download and Install WSO2 Developer Studio

How to Download and Install WSO2 Developer Studio

INTRODUCTION

WSO2 Developer Studio is a complete tooling platform where you can easily develop, deploy, test and debug your SOA applications. Developer Studio works in the popular open-source integrated development environment (IDE) Eclipse. By integrating with the award-winning WSO2 Carbon platform, Developer Studio enables you to create, deploy, and manage a variety of artifacts.

INSTALLATION

You can find developer studio in Eclipse Market place and install into your Eclipse. Or you can go to Developer Studio site and download directly.There you can find two options.

  • Download Developer Studio with Eclipse.

If you don’t have eclipse already go ahead and download developer studio installed eclipse. You can simply download from site, extract and run.

  • Download Developer Studio distribution and install manually.

But if you have a compatible eclipse version with developer studio, you can download the developer studio distribution and install it manually. If you have download the distribution follow below steps to install.

  • Go to Eclipse install new software menu.install new software command
  • Browse through file system and locate distribution zip file into location.Locate the developer studio distribution
  • Select Developer studio features to install. (remove check box selection for contact all update sites …)Select Features to install
  • Then accept license and install.

After successfully installing Developer Studio, you are ready to start develop, test and deploy composite middleware applications easily and faster.