Thursday, July 24, 2014

How to subscribe and access published API in WSO2 API Cloud

In this video I'm going to show how to subscribe and access published API in WSO2 API Cloud. You can view the first step of this video series from here.



How to create simple API using WSO2 API Cloud and publish it

In this video I'm going to show how to create simple API uisng WSO2 API Cloud and publish it. This is the first step of this video series. You can view the second part of the video "How to subscribe and access published API in WSO2 API Cloud" from here.





Friday, July 18, 2014

SaaS App Development with Windows Cartridge in Apache Stratos

Software as a Service (SaaS) is a software delivery method that provides access to software and its functionalities as a service, and it has become a common delivery model for many business applications. Apache Stratos is a polyglot PaaS framework, which helps to run Tomcat, PHP and MySQL apps as a service on all major cloud infrastructures. It brings self-service management, elastic scaling, multi-tenant deployment, and usage monitoring as well. Apache Stratos has the capability to develop and deploy SaaS applications in different environments, such as Linux and Windows.
In this webinar, Reka Thirunavukkarasu, senior software engineer and Manula Thanthriwatte, software engineer at WSO2 will demonstrate the functionality of SaaS app development in the Windows environment and demonstrate how you can develop a windows cartridge with .NET and deploy the application using Apache Stratos.
Topics to be covered include
  • Introduction to Apache Stratos as PaaS framework
  • Pluggable architecture of different environments to stratos
  • Capabilities of Apache Stratos to provide self service management for your windows environment
  • SaaS app development using .NET in a distributed environment
If you are a windows app developer and seeking ways to provide monitoring, elastic scaling, and security in the cloud for your app, this webinar is for you.

Friday, June 20, 2014

WSO2 Private PaaS Demo Setup

In this video I'm going to show how to configure and run the WSO2 Private PaaS in EC2 environment. You can download WSO2 Private PaaS from here and find the WSO2 Private PaaS documentation from here.


Wednesday, April 16, 2014

How to write subscriber and publisher to JBOSS MQ topic

This Post explains Topics in JBOSS MQ with Subscribing and Publishing. For this we will write two java clients.

  • TopicSubscriber.java to Subcribe for messages
  • TopicPublisher.java to to Publish the messages
First you have to download JBOSS Application Server from here. In this sample I'm using jboss-4.2.2.GA. Before starting the JBOSS application server you have to create a topic in JBOSS server. To do that, you have to create myTopoc-service.xml (you can used what every name you want) under the <JBOSS_SERVER>/server/default/deploy and enter following xml into it.


1
2
3
<mbean code="org.jboss.mq.server.jmx.Topic" name="jboss.mq.destination:service=Queue,name=topicA">
        <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
</mbean>

After that you can start the JBOSS application server. From the console log you can verify the topicA was created.

Now you can create the sample project on IDE that you preferred. Also make sure to add client and lib directory jars in the JBOSS application server to the project. Now you can create TopicSubscriber.java and TopicPublisher.java sample programs as follows.

TopicSubscriber.java sample program

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package simple;

import java.util.Properties;

import javax.jms.*;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class TopicSubscriber {

    private String topicName = "topic/topicA";

    private boolean messageReceived = false;

    private static javax.naming.Context mContext = null;
    private static TopicConnectionFactory mTopicConnectionFactory = null;
    private TopicConnection  topicConnection = null;

    public static void main(String[] args) {
        TopicSubscriber subscriber = new TopicSubscriber();
        subscriber.subscribeWithTopicLookup();
    }

    public void subscribeWithTopicLookup() {

        Properties properties = new Properties();
        properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
        properties.put(Context.PROVIDER_URL, "jnp://localhost:1099");
        properties.put("topic." + topicName, topicName);

        try {

            mContext = new InitialContext(properties);
            mTopicConnectionFactory = (TopicConnectionFactory)mContext.lookup("ConnectionFactory");

            topicConnection = mTopicConnectionFactory.createTopicConnection();

            System.out.println("Create Topic Connection for Topic " + topicName);

            while (!messageReceived) {
                try {
                    TopicSession topicSession = topicConnection
                            .createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

                    Topic topic = (Topic) mContext.lookup(topicName);
                    // start the connection
                    topicConnection.start();

                    // create a topic subscriber
                    javax.jms.TopicSubscriber topicSubscriber = topicSession.createSubscriber(topic);

                    TestMessageListener messageListener = new TestMessageListener();
                    topicSubscriber.setMessageListener(messageListener);

                    Thread.sleep(5000);
                    topicSubscriber.close();
                    topicSession.close();
                } catch (JMSException e) {
                    e.printStackTrace();
                } catch (NamingException e) {
                    e.printStackTrace();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        } catch (NamingException e) {
            throw new RuntimeException("Error in initial context lookup", e);
        } catch (JMSException e) {
            throw new RuntimeException("Error in JMS operations", e);
        } finally {
            if (topicConnection != null) {
                try {
                    topicConnection.close();
                } catch (JMSException e) {
                    throw new RuntimeException(
                            "Error in closing topic connection", e);
                }
            }
        }
    }

    public class TestMessageListener implements MessageListener {
        public void onMessage(Message message) {
            try {
                System.out.println("Got the Message : "
                        + ((TextMessage) message).getText());
                messageReceived = true;
            } catch (JMSException e) {
                e.printStackTrace();
            }
        }
    }

}

TopicPublisher.java sample program

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package simple;

import javax.jms.*;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.Properties;

public class TopicPublisher {
    private String topicName = "topic/topicA";

    private static javax.naming.Context mContext = null;
    private static TopicConnectionFactory mTopicConnectionFactory = null;

    public static void main(String[] args) {
        TopicPublisher publisher = new TopicPublisher();
        publisher.publishWithTopicLookup();
    }

    public void publishWithTopicLookup() {
        Properties properties = new Properties();
        TopicConnection topicConnection = null;
        properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
        properties.put(Context.PROVIDER_URL, "jnp://localhost:1099");
        properties.put("topic." + topicName, topicName);

        try {

            mContext = new InitialContext(properties);
            mTopicConnectionFactory = (TopicConnectionFactory)mContext.lookup("ConnectionFactory");
            topicConnection = mTopicConnectionFactory.createTopicConnection();

            try {
                TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

                // create or use the topic
                System.out.println("Use the Topic " + topicName);
                Topic topic = (Topic) mContext.lookup(topicName);

                javax.jms.TopicPublisher topicPublisher = topicSession.createPublisher(topic);

                String msg = "Hi, I am Test Message";
                TextMessage textMessage = topicSession.createTextMessage(msg);

                topicPublisher.publish(textMessage);
                System.out.println("Publishing message " + textMessage);

                topicPublisher.close();
                topicSession.close();

                Thread.sleep(20);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        } catch (JMSException e) {
            throw new RuntimeException("Error in JMS operations", e);
        } catch (NamingException e) {
            throw new RuntimeException("Error in initial context lookup", e);
        }
    }

}u

You have to used PROVIDER_URL as "java.naming.provider.url" and INITIAL_CONTEXT_FACTORY as "java.naming.factory.initial".

First you have to run TopicSubscriber and then run the TopicPublisher. Here are the output of them.

TopicSubscriber;
Create Topic Connection for Topic topic/topicA
Got the Message : Hi, I am Test Message

TopicPublisher;
Use the Topic topic/topicA
Publishing message SpyTextMessage {
Header {
   jmsDestination  : TOPIC.topicA
   jmsDeliveryMode : 2
   jmsExpiration   : 0
   jmsPriority     : 4
   jmsMessageID    : ID:2-13977171929621
   jmsTimeStamp    : 1397717192962
   jmsCorrelationID: null
   jmsReplyTo      : null
   jmsType         : null
   jmsRedelivered  : false
   jmsProperties   : {}
   jmsPropReadWrite: true
   msgReadOnly     : false
   producerClientId: ID:2
}
Body {
   text            :Hi, I am Test Message
}

}


Java Code Geeks

Wednesday, April 9, 2014

How to run Apache Stratos and subscribe to cartridges and how autoscaling is happen

In this video I'm going to show,


  • How do I run Stratos on my laptop
  • PaaS story video on how to get it done
  • How to deploy apps - PHP and Tomcat 
  • JMeter to load up and instances popping up 




Wednesday, January 29, 2014

Import SSL Certificate to WSO2 Identity Server

The following post shows how to import SSL cetificate to WSO2 Identity Server and configure it.


1) You can import your certificate to wso2carbon.jsk by using following keytool command 
keytool -importkeystore -srckeystore <YOUR_KEY_STORE> -destkeystore wso2carbon.jks -srcstoretype <YOUR_KEY_STORE_TYPE> -deststoretype jks -srcstorepass <PASSWORD> -deststorepass wso2carbon 

2) In WSO2 IS, you cannot have two private keys. So you have to delete wso2carbon private key. You can do it by using following command 
keytool -delete -alias wso2carbon -keystore wso2carbon.jks -storepass wso2carbon 

3) In WSO2 IS, your wso2carbon.jks password and your private key password should be same. Otherwise it gives an error. Current wso2carbon.jks password is "wso2carbon". If your password is different from that you have to change it. You can change wso2carbon.jks password by using following command. 
keytool -storepasswd -keystore wso2carbon.jks 

4) You don't need to import your private key to client-truststore.jks. It's incorrect. You have to import your public key to it. To do that you have to export your public key from the wso2carbon.jks and import it to client-truststore.jks. You can do these things from the following commands. 

keytool -export -keystore wso2carbon.jks -alias <YOUR_ALIAS> -file test.cer 
keytool -import -alias <YOUR_ALIAS> -file test.cer -keystore client-truststore.jks 

5) After that you have to edit carbon.xml and identity.xml files with your new certificate settings. You can find those files in <CARBON_HOME>/repository/conf 

In carbon.xml, under the <Security> tag you can find <KeyStore>. In that <KeyStore> block you have to change Password, KeyAlias and KeyPasswords attributes according to your settings. 

In identity.xml, under the <EntitlementSettings> you can find <ThirftBasedEntitlementConfig> tag. Please change the Password attribute according to your settings. 

After completion of the about steps, start the server.