Archive for the ‘java’ Category

  • Create a “New Axis2 Service Project” from WSO2 developer Studio dashboard.
Selection_002
  • Enter project name and service class to expose
    • TestAxis2Service will be the name of the axis2 service and the “TestService” will be the class that will be exposed.

service-class

  • Add operation to expose
    • “sayHello” method will be exposed as a web service.
implemet-service
  • Have a look at the services.xml generated for you.
    • This is the services.xml file which is needed for a axis2 service. Service name and service class are configured according to the values you entered in earlier step. You can change here if you wish.
    services_xml
  • Export the project as a deployable file(.aar file) to into $AXIS2_HOME/repository/services folder.
    • Export the service as a “.aar” file which can be deployed in axis2 engine. Put the “TestAxis2Service_1.0.0.aar” file to the “services” directory of the axis2.
  • rightclick
  • Congratulations ! your service is deployed successfully.
    service_in_axis2
  • This post will describe basic steps in calling an admin service using an axis2 client. Note that if you want to invoke admin services using SOAP UI, please fallow the post by Charitha on Invoking WSO2 Carbon admin services with soapUI
    Let’s say we want to call the admin service name “ProvisioningAdminService” which will give us the set of installed features of the carbon server.

A call to an admin service should be authenticated first. So we call the AuthenticationAdmin admin service first to get a authentication session cookie. We add this session cookie to the subsequent requests so they will be authenticated.

private static String SEVER_URL = "https://backend.appserver.ec2-test.wso2.com/services/";
private static String USER_NAME = "admin";private static String PASSWORD = "admin";
String AUTHENTICATION_ADMIN_SERVICE_URL = "AuthenticationAdmin";

//Create an instance of a Authentication stub
AuthenticationAdminStub authenticationStub = new AuthenticationAdminStub(SEVER_URL +  AUTHENTICATION_ADMIN_SERVICE_URL);

// log in with the username=admin and password=admin.
// They are the default username, passowrd of carbon super admin user.
boolean loginStatus = authenticationStub.login(USER_NAME, PASSWORD,(new URL(SEVER_URL)).getHost());
System.out.println("login " + loginStatus);

ServiceContext serviceContext = authenticationStub._getServiceClient()
.getLastOperationContext()
.getServiceContext();

//Let's get the session cookie string of the last call to authentication admin service. Subsequent requests will be authenticated only if the request contains this session cookie header.
String sessionCookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING);

// Let's try to call ProvisioningAdminService admin service.
serviceEndPoint = SEVER_URL + "ProvisioningAdminService";
ProvisioningAdminServiceStub provisioningAdminService = new ProvisioningAdminServiceStub(serviceEndPoint);

ServiceClient client2 = provisioningAdminService._getServiceClient();
Options option2 = client2.getOptions();
option2.setManageSession(true);

// set the session cookie of the previous call to AuthenticationAdmin service
option2.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, sessionCookie);

//print the installed services
ProvisioningAdminServiceStub.Feature [] features;
features = provisioningAdminService.getAllInstalledFeatures();
for (ProvisioningAdminServiceStub.Feature f : features) {
     System.out.println(f.getFeatureName());
}

}

If you didn’t set the sessionManage to true for the request to the ProvisioningAdminService you will get the following error since your request does not carries the authentication session cookie.

org.apache.axis2.AxisFault: Transport error: 401 Error: Unauthorized
at org.apache.axis2.transport.http.HTTPSender.handleResponse(HTTPSender.java:308)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:194)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:450)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:277)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:442)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:398)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:224)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:149)
at org.wso2.carbon.feature.mgt.services.prov.ProvisioningAdminServiceStub.getAllInstalledFeatures(ProvisioningAdminServiceStub.java:2132)
at org.wso2.carbon.user.mgt.sample.SampleUserRoleMgtClient.main(SampleUserRoleMgtClient.java:148)

Following are recommended for a comprehensive knowledge on WSO2 authentication.
Authentication and Authorization Choices in WSO2 Platform 
Securing Web Service Integration
 

JProfiler is a tool for profiling JVM. In this tutorial I will show how to start WSO2 carbon servers with JProfiler so you can monitor the carbon servers for memory, threads and performance.¬† I will use WSO2 ESB (Enterprise Service Bus) in this guide, however this is same for any carbon server AS, Greg, API Manager …etc.

Step 1 : Dowload the packs

Download the WSO2 ESB from http://wso2.com/products/enterprise-service-bus/ . You can find all the WSO2 products from the Product page of http://wso2.com/.

Download the JProfiler from http://www.ej-technologies.com/download/jprofiler/files

Step 2 : Start JProfiler

Start the JProfiler  sh $JProfiler_HOME/bin/jprofiler

Step 3 : Step into profiling

Click Start centre at the top left

JProfiler Start Center

JProfiler Start Center

Step 4 :  Select Local or remote

2 local or remote

Step 5 : Select the vendor
Select the vendor

Select the vendor

Step 6 : Select the port the ESB will run
Select the port the carbon server will run

Select the port the carbon server will run

Step 7 : Select the startup mood

wait for

Step 8

Copy the selected text

Step 9 : Copy the above selected text to the $ESB_HOme/bin/wso2server.sh
wso2 server sh
Step 9 : Start the ESB server.
Carbon server waiting for JProfiler

Carbon server waiting for JProfiler

You will find ESB is waiting for JProfiler GUI to start. So start KProfiler

Step 11 : Profiler started

Start profiler by pressing OK button and  ESB server will start.

JProfiler started with WSO2 ESB

JProfiler started with WSO2 ESB

$JAVA_HOME/bin/jinfo -flag <flag> <process_id_of_jvm>

As an example, if you want to know the PermSize of the the jvm.

$JAVA_HOME/bin/jinfo -flag PermSize <process_id_of_jvm>