Saturday, November 1, 2008

AXIS2 session management - Transport Session

This post takes you through transport session scope under Axis2 to session management.

It is highly recommended that you go through this article on Axis2 Session Management written by Deepal.

Here I will take a practical scenario used by WSAS - in it's admin services.

WSO2 WSAS is an enterprise ready Web services engine powered by Apache Axis2. It is a lightweight, high performing platform for Service Oriented Architectures, enabling business logic and applications. Bringing together a number of Apache Web services projects, WSO2 WSAS provides a secure, transactional and reliable runtime for deploying and managing Web services.

You can learn more about WSAS admin services from my previous post.

This post uses following two admin services as illustrated by the diagram.

Let me briefly show how IS_AUTHENTICATED property being set in the ServiceGroupContext, which can be accessed by all the services belong to the same service group.
ServiceGroupContext groupCtx =  MessageContext.getCurrentMessageContext().getServiceGroupContext();

groupCtx.setProperty(IS_AUTHENTICATED,true);
Let's move to the client code - you need to login first and then access ServerAdmin.
final static String ADMIN_SERVICE = "https://localhost:9443/services/ServerAdmin";
final static String GLOBAL_SERVICE = "https://localhost:9443/services/GlobalAdmin";

public static void main(String[] args) throws Exception {
ConfigurationContext context = null;
OMElement response = null;
ServiceClient client = null;
boolean isLoggedIn = false;
String path = null;

path = System.getProperty("user.dir");

// You can copy wso2wsas.jks from [WSAS_HOME]\conf  
System.setProperty("javax.net.ssl.trustStore", path + "/src/wso2wsas.jks");
System.setProperty("javax.net.ssl.trustStorePassword", "wso2wsas");

// You can copy axis2.xml from [AXIS2_HOME]\conf
context = ConfigurationContextFactory.createConfigurationContextFromFileSystem("repo","repo/conf/axis2.xml");
client = new ServiceClient(context, null);

client.setOptions(getOptions("urn:login", GLOBAL_SERVICE));
response = client.sendReceive(getPayload("admin", "admin"));
isLoggedIn = Boolean.parseBoolean(response.getFirstChildWithName(new QName("return")).getText());

if (isLoggedIn) {
client.setOptions(getOptions("urn:getServerVersion", ADMIN_SERVICE));
response = client.sendReceive(getPayload());
System.out.println("Server version: " + response.getFirstChildWithName(new QName("return")).getText());
}
}

private static Options getOptions(String operation, String epr) {
Options options = null;
options = new Options();
options.setAction(operation);
options.setManageSession(true);
options.setTo(new EndpointReference(epr));
return options;
}

private static OMElement getPayload(String userName, String password) throws Exception {
String bodyXML = "<ns1:login  xmlns:ns1=\"http://org.apache.axis2/xsd\">\n" + "<arg0>"
+ userName + "</arg0>\n" + "<arg1>" + password + "</arg1>\n" 
+ "</ns1:login>\n";
return AXIOMUtil.stringToOM(bodyXML);
}

private static OMElement getPayload() throws Exception {
String bodyXML = "<ns1:getServerVersion  xmlns:ns1=\"http://org.apache.axis2/xsd\"></ns1:getServerVersion>";
return AXIOMUtil.stringToOM(bodyXML);
}
You can find more details on Transport session handling from here.

13 comments:

crystal said...

Thank you so much!!polo shirt men'ssweate,Burberry Polo Shirts lacoste sweater, ralph lauren Columbia Jackets,ski clothing. Free Shipping, PayPal Payment. Enjoy your shopping experience on mensclothingus.com.You can find the father who desire fashionable, intellectual mens clothing simultaneously.

crystal said...

Awesome!!!Best wishes for you !!cheap polo shirts is the father of the summer should be prepared to most commonly used item, it has both style and shape of Ralph Lauren Polo, and vest with a random function polo ralph lauren, so that in the short-sleeved apply to both on many occasions, the pink and black color men's polo shirts brought into effect, lightweight cotton, linen texture to demonstrate masculine temperament and sense of fashion exhaustively.

crystal said...

God bless you!I really agree with your opinions.Also,there are some new fashion things here,gillette razor blades.gillette mach3 razor bladesfor men.As for ladies,gillette venus razor blades must the best gift for you in summer,gillette fusion blades are all the best choice for you.

crystal said...

Perfect!!You are a outstanding person!Have you ever wore chaussures puma,Here are the most popular puma CAT,Puma shoes store gives some preview of puma speed cat,and casual but no sweat puma basket.

venus said...

Do not mean bad.Thank you so much!I just want to show some fashion things to all of you.I like puma speed, puma femmes and other puma shoes. These puma sport items are at store recently and available for anyone.

venus said...

Fantastic!God bless you!Meanwhile,you can visit my China Wholesale,we have the highest quality but the lowest price fashion products wholesale from China.Here are the most popular China Wholesale productsfor all of you.You can visit http://chinaclothes.net.Also the polo clothing is a great choice for you.

Deeps M said...

Hello Prabath,

Is it possible to define scope of web-service session from the web-service client. For my implementation of web-service, I want to use both soapsession and transportsession, but in services.xml you can specify just one of them. So I tried specifying the scope from web-service client, but that did not work either. Could you please suggest what can be done here.

Regards,
Deepali.

Deeps M said...
This comment has been removed by the author.
caiyan said...

coach outlet store
adidas nmd
nike store
coach outlet
adidas nmd
coach outlet
adidas nmd
michael kors canada
ray bans
ralph lauren outlet online
2061019caiyan

chenmeinv0 said...

ugg boots
canada goose online
moncler jackets
rolex watches clearance
giuseppe zanotti sneakers
canada goose jackets
ugg outlet online
coach factory outlet
steelers jerseys
timberland boots outlet
2016.12.27xukaimin

John said...

michael kors outlet online
moncler coats
rolex replica watches for sale
dansko
mlb jerseys whgolesale
discount nike shoes
tods shoes
eahawks jerseys
longchamp bag
coach factory outlet
20170714yuanyuan

raybanoutlet001 said...

michael kors handbags outlet
ralph lauren
michael kors outlet
true religion outlet store
nike air force 1
mont blanc outlet
longchamp handbags
toms shoes
jordan shoes
toms shoes

1111141414 said...

lacoste polo
patriots jersey
fitflops sale
adidas nmd
nike roshe run
yeezy boost 350
michael kors outlet
atlanta falcons jersey
nike huarache sale
pandora bracelet