Thursday, February 11, 2016

How to set up WSO2 Data Analytics Server to collect and analyze runtime statistics from the API Manager using RDBMS

The purpose of this blog post is to elaborate 2 steps given in the documentation [1].

Environment: WSO2APIM 1.10.0, DAS 3.0.0

You can follows the documentation [1] to do the configurations:

I will elaborate more on the steps 7 and 8.

Step 7:
Before saving the Add URL Group make sure you have set the correct thirft port on which DAS is running. You can see the running thrift port in DAS log as shown below.

[2016-02-12 12:01:42,353]  INFO {org.wso2.carbon.databridge.receiver.binary.internal.BinaryDataReceiver} -  Started Binary SSL Transport on port : 9712
[2016-02-12 12:01:42,354]  INFO {org.wso2.carbon.databridge.receiver.binary.internal.BinaryDataReceiver} -  Started Binary TCP Transport on port : 9612

Step 8:
For the Data Analyzer Configurations section set the URL and creadentials of the DAS server.
If offset in DAS is set to 1, the configurations would be

URL:https://localhost:9444
Username : admin
Password: admin

 [1]https://docs.wso2.com/display/AM1100/Publishing+API+Runtime+Statistics+Using+RDBMS

Wednesday, October 14, 2015

Maven Build Lifecycle in a nutshell

Maven is a build automation tool mainly used in java projects.When it comes to maven, Build lifecycles are very important topic.
There are 3 out of the box maven lifecycles know as default, clean and site. Out of these three, most of the time we are using default and clean.
A build lifecycle is made up of number of predefined phases or in other words stages.
A Phase is made up of goals. A goal represents a specif task and they are defined within associated plugin.
These plugin goals can explicitly execute with mvn.
A goal doesn't always need to be associated with a phase. Therefore a goal not bound to any build phase could be executed via direct invocation.

For the clear understanding please find the mvn command provided below:
mvn clean dependency:copy-dependency
  • clean - build phase (Once you execute this command all the build phases up to this build phase will get invoked. In other words, pre-clean and clean will get executed)
See Lifecycle references for more details.
  • dependency:copy-dependency - the goal 'copy-dependency' in 'maven-dependency-plugin' plugin.

There are 2 ways of using these build lifecycles.

1. Packaging (e.g.: war/jar/ear)
The packaging type defined in pom.xml will cause to run list of predefined goals bound to build phases of default lifecycle.
See Plugin Bindings for more details.

2. Plugin
By specifying plugins explicitly in your pom file, you can incorporate goals to specific phases of a build lifecycle.
- A plugin can have one or more goals.
- Each goal can be invoked in multiple phases.
Goal is bound to a lifecycle phase and if there are multiple goals bound to a particular phase, they will be invoked according to the oder in which they have defined.  

mojo - Maven + Pojo
- Mojo is an executable goal in maven.

Reference: https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

Wednesday, September 2, 2015

localhost/127.0.0.1:7000 is in use by another process. Change listen_address:storage_port in cassandra.yaml to values that do not conflict with other services

If you ever get this error in your wso2 server, please check if there is any other wso2 server running on the same machine and check it's port offset in carbon.xml and change the other server's port offset accordingly.

Monday, January 12, 2015

Sending attachements with with WSO2 ESB via MTOM

Prerequisites:

WSO2 ESB 4.8.1
WSO2 ESB 4.8.1 service pack1 (This is yet to release)
SoapUI 4.5.1

Environment:
Ubuntu
Java Runtime

Steps:

Enable backend service

1. Apply the sp1 to ESB 4.8.1
2. Go to /samples/axis2Server/src/MTOMSwASampleService and run 'ant'. Once it is build successfully, go to /samples/axis2Server and start the server as follows:
/axis2server.sh

3.Now you will be able to access the wsdl file of MTOMSwASampleService via below url:
http://localhost:9000/services/MTOMSwASampleService?wsdl

Configure ESB

3.1 Save the wsdl file as MTOMSwASampleService.wsdl and copy it to /repository/samples/resources/proxy directory.

4. Start ESB and login via console.
5. Create three dynamic sequences and save them in config regitry as follows:

Go to Manage->Service Bus->Sequences and click on Add Sequence.
  •  InSeq
Sequence Name: InSeq
Click on Add Child->Core->Send and add a Send mediator.
Select Endpoint Type: Define Inline and click on Add button.
Create Address Endpoint.
Address: http://localhost:9000/services/MTOMSwASampleService

Show Advanced Options->Message Content
Optimize: MTOM
Hit 'Save & Close'.
Hit 'Update'.
Hit 'Save in Registry'.
Hit 'Save & Close'.
  • OutSeq
Sequence Name: OutSeq
Click on Add Child->Core->Send and add a Send mediator.
Hit 'Update'.
Hit 'Save in Registry'.
Hit 'Save & Close'.
  • ErrorSeq
Sequence Name:ErrorSeq
Hit 'Save in Registry'.
Hit 'Save & Close'.

6.  Go to Manage->Service Bus->Source View and paste the config
P.S: Ignore the names as they are dump values
Hit Update.

Setup SoapUI

7. Start SoapUI.
Click on 'New SoapUI project' and paste below wsdl url.
http://localhost:8280/services/StockQuoteProxy?wsdl

8. Click on 'uploadFileUsingMTOM' request in soap11 binding.
10. Edit current url as follows:
http://localhost:8280/services/StockQuoteProxy.StockQuoteProxyHttpSoap12Endpoint

9. Attach a image via attachment window. Click yes for  'cache attachment in request'.
10. Modify the request as depicted in the image below and change the value of image name according to your image name:

11. Now you can send the request. You will receive the attachment as the response as follows:

References:
https://axis.apache.org/axis2/java/core/docs/mtom-guide.html
https://docs.wso2.com/pages/viewpage.action?pageId=33136025

Wednesday, January 7, 2015

WSO2 Identity Server as a Federation Hub

Requirement:
Setup identity federation with two WSO2 IS instance with SAML2 Web SSO, one acts as a Federation hub (primary idp) and the other acts as the IDP (secondary idp).
These are fronted by nginx to hide the original characteristics and the existence of the Identity Servers.

 Prerequisits:
1. WSO2 IS 5.0.0 - two servers
2. Web Server to host Service Provide(s). e.g: Tomcat 7.0.x



Note: In this sample SAML request signing will be done only between primary idp and secondary idp as we already have self signed certificate, public/private key pairs available in WSO2 IS by default (Location:<carbon_home>/repository/resources).
If you want to create your own self signed certificate, refer this blog post.

Steps:

1. Configure nginx and modify /etc/nginx/sites-enabled/default file. You can refer the this blog post.

I have provided the configured file.

2. Use the following link to checkout and configure Service provider (travelocity application)
https://docs.wso2.com/display/IS460/Configuring+SAML2+SSO
(Refere the 'Configuring the web app' section only)
I have provided the configured travelocity.properties file.

3. Change the following configs in Primary IDP.
<carbon_home>/repository/conf/tomcat/catalina-server.xml add proxy port pointing load balancers port(i.e 443).
 
<carbon_home>/repository/conf/carbon.xml change the hostname to identity-dev1.is.com 
4.Login to the Primary IDP console. 

5. Register a identity provider
  • Identity Provider Name: Any meaningful name
  • Identity Provider Public Certificate: Export the public certificate in pem format and upload it.
keytool -export -alias mycert -keystore wso2carbon.jks -storepass wso2carbon -file mycert.pem
  • Alias will be auto generated as follows:
https://identity-dev1.is.com:443/oauth2/token/

5.1 Expand Federated Authenticators and configure SAML2 Web SSO Configuration.
  • Tick Enable SAML2 Web SSO
  • Identity Provider Entity Id: Any meaningful name
  • Service Provider Entity Id: Any meaningful name (This value is required when registering service provider in Secondary IDP)
  • Set the SSO URL to https://identity-dev2.is.com/samlsso/ 
  • Tick Enable Authentication Request Signing
  • Tick Enable Logout
  • Tick Enable Logout Request Signing
  • SAML2 Web SSO User ID Location: Tick User ID found in 'Name Identifier' 
Save the configurations.
6. Register a service provider
  •  Service Provider Name: Any meaningful name
6.1 Expand Inbound Authentication Configuration and configure SAML2 Web SSO Configuration

  • Issuer: travelocity.com (same value provided in travelocity.properties file for SAML.IssuerID)
  • Assertion Consumer URL: http://localhost:8080/travelocity.com/samlsso-home.jsp (same value provided in travelocity.properties file for SAML.ConsumerUrl)
  • Tick Use fully qualified username in the NameID
  • Tick  Enable Single Logout
  • Tick Enable Attribute Profile
Save the configurations.

6.2 Expand Local & Outbound Authentication Configuration and choose Authentication Type as Federated Authentication and select the identity provider created in step 5

 Save the configurations.

7.  Change the following configs in Secondary IDP.
 <carbon_home>/repository/conf/tomcat/catalina-server.xml add proxy port pointing load balancers port(i.e 443).
 
<carbon_home>/repository/conf/carbon.xml change the hostname to identity-dev2.is.com and offset to 1
8. Login to Secondary IDP console
9. Register a service provider
  •  Service Provider Name: Any meaningful name
9.1 Expand Inbound Authentication Configuration and configure SAML2 Web SSO Configuration
  • Issuer: same value provided in 5.1 for Service Provider Entity Id
  • Assertion Consumer URL: Any garbage value as signing SAML with CA certificate will skip this acs URL validation
  • Tick Use fully qualified username in the NameID
  • Tick  Enable Signature Validation in Authentication Requests and Logout Requests 
  • Tick Enable Single Logout
  • Tick Enable Attribute Profile
 Save the configurations.

 Now all the configurations are done.

10. You can access travelocity application with below url:

htttp://localhost:8080/travelocity.com

Note: If you are using firefox  install SSO tracer plugin to view decrypted SAML requests easily.

Friday, December 26, 2014

Write a Simple BPEL Project with WSO2 Developer Studio and Deploy it in WSO2 BPS


Prerequisites:


Create New Server Runtime Environment for Apache ODE

1. Copy the ode.war to apache-tomcat-7.0.47/webapps directory and start the server. when you see the ode directory created under apache-tomcat-7.0.47/webapps directory, stop the server.

2. Configure the server runtime as follows:

Create BPEL Project
 1. Create a new BPEL project as follows:

2. In the next dialog, provide a project name and select the target runtime as Apache ODE. Click Finish.

3. Write click on the project and create a "New BPEL process file" (Same as step 1). Fill the dialog accordingly and make sure you select the Template to 'Synchronous BPEL Process' and click finish.


4. Copy the Hello.wsdl file inside bpelContent folder in Eclipse project.
Sample Hello.wsdl is attached.

5. Open the .bpel file design view. You should be able to see the Palette in the workspace with all the gadgets required to create the BPEL workflow.

6. Drag and drop two Assign actions and an Invoke action as follows:

7. Click on Invoke and rename it to 'invokeHelloService'

8. In the Properties Dialog, click on 'Details' tab.

9. Select 'Create Global Partner link' from Partner Link drop down. A popup will Open.

Provide a 'Partner Link Name' (any meaningful name is sufficient) and click Ok. Choose 'HelloPortType' as depicted below and click Ok.

Provide a 'Partner Link Type Name' (any meaningful name is sufficient) and click Next. Give a 'Role Name' and click Finish.

10. Under the Properties dialog there is a 'Quick Pick section'.
Select 'greetingInSinhala' from that and double click on it.
You will noticed that the Input/Output variables are generated as follows. Save the changes made.


 11. Now it is time to pass the input parameters to the Hello service. In order to do that we have to click on 'Assign' action. In Properties dialog click on 'Details' tab.

12. Click on New and do as depicted below and hit Save. You will be prompted for Initializer dialog. Click yes.
 Here you will assign the input for the Hello Webservice from BPEL input payload.


13. Likewise in 'Assign1' action do the same as follows and hit Save.You will be prompted for Initializer dialog. Click yes.
 Here you will assign the output received from Hello Webservice to BPEL output payload.

 14. Write click on the project and create new  'Apache ODE Deployment Descriptor'. Do the configuration as follows:


15. Create a ZIP archive as follows:


Now the BPEL is ready.

Deply BPEL Project in WSO2 BPS
1. Start the WSO2 BPS and access the carbon console (https://1localhost:9443/carbon/). Login as admin user with admin/admin credentials.

2. Under 'Manage' section click on 'Processes' -> 'Add'. Upload the Zip.

3. Now you can see the uploaded BPEL under 'Processes' -> 'List'.

4. Click on the 'Process ID'. You will see a dialog simillar to below:


5. Use try it and you will get a response as follows:


That is it. Happy Orchestration with BPEL :)

How to convert a simple Java class to a Webservice with Axis2 [Deploying POJOs]

It has never been this easy to convert your class into a Webservice in few steps with Apache Axis2.
Apache Axis2 is a SOAP processing engine and it is hand in hand with WSO2 SOA middleware platform.

Prerequsists:

JDK 1.7/1.6


How to create Axis2 service
1. Create a new Axis2 service project in Eclipse

2. Tick 'Create new Axis2 Service ' and click Next
3. Provide Project Name, package name and Class name and click Finish.




As you can see the project structure will contain the services.xml file which contains the details of the exposed service.

4. Now you can add methods to the Class as follows:

package com.world.hello;

public class Hello{

   
    public String greetInSinhala(String name){
        return "Ayubowan "+ name;
    }
   
    public String greetInEnglish(String name){
        return "Hello "+ name;
    }
}


4. Now you can add methods to the Class as follows:
5. Now create the service archive file (*.aar extension) by right click on the project and select 'Export Project as Deployable Archive'.

 How to deploy *.aar file in Axis2 enabled Tomcat 
 1. Copy the axis2 war file to apache-tomcat-7.0.47/webapps directory and start the server.
You will see the axis2 directory under Tomcat webapps directory once the server is started.
2.Copy the HelloWorld.aar file to apache-tomcat-7.0.47/webapps/axis2/WEB-INF/services directory
3. Access below url and you should be able to see the deployed service and the available methods.

http://localhost:8080/axis2/services/listServices



That is the end of the story :)