Thursday, March 31, 2011

How to view the Actual SOAP Request and Response XML being transferred behind the screen in AXIS

From the MessageContext instance, we can get the SOAP request and the SOAP response.

In the generated Stub class(for Apache AXIS), go to the web method and we can use the instance org.apache.axis.client.Call _call = createCall(); to print the actual SOAP request and response.

System.out.println(" Request is ====>>> "+_call.getMessageContext().getRequestMessage().getSOAPPartAsString());
System.out.println(" Response is ====>>> "+_call.getMessageContext().getResponseMessage().getSOAPPartAsString());

Adding security information in the SOAP Header

I was supposed to add the following security information in the SOAP request.

<soapenv:Header>
<wsse:Security>
<wsse:UsernameToken>
<wsse:Username>aro_ext
<wsse:Password>5b5mCfNfJn
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>





Adding the above security information in the SOAP Header from the Stub,

SOAPHeaderElement wsseSecurity = new SOAPHeaderElement(new PrefixedQName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security","wsse"));
MessageElement usernameToken = new MessageElement(new PrefixedQName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "UsernameToken","wsse"));
MessageElement username = new MessageElement(new PrefixedQName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Username","wsse"));
MessageElement password = new MessageElement(new PrefixedQName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Password","wsse"));

username.setObjectValue("coolbaski");
usernameToken.addChild(username);
password.setObjectValue("baskirocks");
usernameToken.addChild(password);
wsseSecurity.addChild(usernameToken);
stub.setHeader(wsseSecurity);

NameSpace can be had from envelop tag,
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"

We may have setUsername & setPassword methods in the generated stub class.

stub.setUsername("coolbaski");
stub.setPassword("baskirocks");


Setting the above will set the values in HTTP header and not in the SOAP Header.
There is one more way to set in the HTTP header.

s._setProperty( javax.xml.rpc.Call.USERNAME_PROPERTY, "coolbaski" );
s._setProperty( javax.xml.rpc.Call.PASSWORD_PROPERTY, "baskirocks" );

Eclipse: Using the -clean command line argument

Problem :

When i tried to open the velocity file in eclipse, i got the following error.

Could not open the editor: The editor class could not be instantiated. This usually indicates a missing no-arg constructor or that the editor's class name was mistyped in plugin.xml

Solution :

Start eclipse with -clean option. This will do many wonders.

Using the -clean command line argument when starting up Eclipse can help a lot of strange problems disappear that can be related to stale plugin cache information. The way it is used is as an argument to the Eclipse executable, on Windows that is eclipse.exe:
Code:

eclipse.exe -clean

Additionally with Eclipse 3.1 there is a new eclipse.ini file that you can include -clean in on it's own line near the top of the file. This command tells Eclipse to erase and rebuild it's plugin cache to avoid conflicts with incorrect plugin information. This is very important to use when upgrading between major releases or trying to fix a strange behavior in your workspace. After you have used -clean once, you are free to remove it from your command line arguments.