Archive for the 'Apache' Category

Web-Services and Me

Monday, November 2, 2009 | Email This Post | | 16 views
(Apache, J2EE, Programming/Coding)

Very personally speaking -

I love Web-services

if (you are a developer, don’t know what they are and interested)

{

      start with Apache Axis2

} else if (you know what they are, know Spring basics and curious about me falling in love with them all-over again

{

      try Apache CXF

}

  

1 Comment » | Spread the word:

Asynchronous ServiceClient invocation exception in AXIS2

Monday, May 4, 2009 | Email This Post | | 755 views
(AXIS2, Apache, J2EE, Problems, Programming/Coding)

Following error may disguise the actual problem in AXIS2 implementation which starts as -

 

   1:  java.lang.ClassCastException: org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver cannot be cast to org.apache.axis2.engine.MessageReceiver
   2:  at org.apache.axis2.deployment.DescriptionBuilder.loadMessageReceiver(DescriptionBuilder.java:190)

 

In most of the situations, this error comes up when you think everything is fine and it should work. You should be able to transmit message from one end to other without any problem and it actually happens.

You send something from end 1 to end 2, end 2 receives it, processes it and then end 2 tries to send something back to end 1, but then, this error appears.

 

The problem isn’t in the implementation but in the the usage. Generally we try to invoke asynchronous behavior out of synchronous web-service structure. Let us do the post-mortem of above example -

 

Scenario 1

  • end 1 sends abc and wait for return of message-flow
  • end 2 receives abc
  • end 2 processes abc
  • end 2 tries to send xyz to end 1 (than returning the value for message-flow abc)
  • end 1 which is waiting for abc message-flow return value, receives xyz which isn’t expected and hence it throws ClassCastException

 

And the ideal flow should be -

Scenario 2

  • end 1 sends abc and wait for return of message-flow
  • end 2 receives abc
  • end 2 processes abc
  • end 2 sends return value for abc message flow
  • end 1 receives and process return value for abc message flow
  • end 2 tries to send xyz to end 1
  • end 1 receives xyz…(and the flow continues)

 

This is still an open issue over AXIS2 website (https://issues.apache.org/jira/browse/AXIS2-2972?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel).

 

If you don’t want want to proceed in this (synchronous) way, then you can implement asynchronous web-services using AXIS2 (which isn’t in scope of this topic – so wouldn’t be explaining here) but if you can’t change the existing synchronous web-service and have access to only the code which invokes the web-service plus flow can also not be changed as explained in scenario 1, then there is one temporary solution -

Maintain the pool of Stub or ServiceClient instances from start of server and use another Stub instance when starting a new message flow

No Comments » | Spread the word:

createConfigurationContextFromFileSystem in Axis2

Friday, February 27, 2009 | Email This Post | | 1,265 views
(AXIS2, Apache, Eclipse, J2EE, Problems, Programming/Coding)

There is a problem when you try to start building web-service of auto-generated Axis2 java model from WSDL file. When you start working on stub, default constructor creates ConfigurationContext with null parameters which means it is empty and therefore you can’t engage any module with thw ServiceClient created from this ConfigurationContext. For example you may want to engage addressing module for dual mode asynchronous web-service implementation as -

_serviceClient.engageModule("addressing");

And you keep getting error that addressing module can’t be engaged as –

org.apache.axis2.AxisFault: Unable to engage module : addressing
at org.apache.axis2.client.ServiceClient.engageModule(ServiceClient.java:333)

To overcome this problem, you need to specify the axis2 locations specifically while creating ConfigurationContext. Therefore  instead using default constructor which goes like -

ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null)

, you need to change it to -

ConfigurationContext ctx =
ConfigurationContextFactory.createConfigurationContextFromFileSystem(repository, path)

 

Here repository is location of axis2 module/package folder and path is the respective location of axis2.xml (configuration file). Make sure that the respective modules are placed inside modules/repository folder of repository path given. Foe example, you can try following sample code for creating ConfigurationContext - 

ConfigurationContext ctx =
ConfigurationContextFactory.createConfigurationContextFromFileSystem(“c:\\axis2\\WEB-INF”, “conf/axis2.xml”)

This syntax will work if you have axis2 path set in your class path. Otherwise, you may need to use following syntax - 

ConfigurationContext ctx =
ConfigurationContextFactory.createConfigurationContextFromFileSystem(“c:\\axis2\\WEB-INF”, “c:\\axis2\\conf\\axis2.xml”)

In this way, you get handle of axis2 modules and related dependencies. Now you can engage any addressing module after ceating the ServiceClient from this ConfigurationContext. The sample code goes as follows –

…

ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(“c:\\axis2\\WEB-INF”, “c:\\axis2\\conf\\axis2.xml”);

ServiceClient service = new ServiceClient( configContext, null );

…

…

service.engageModule("addressing");

…

Or you can try storing these static path variables in system resources/classpath and then referring them in your code as those variables like -

…

ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(“axisPath”, “axisXMLPath”);

ServiceClient service = new ServiceClient( configContext, null );

…

…

service.engageModule("addressing");

…

You may also like to visit Apache Axis2 FAQ page – http://ws.apache.org/axis2/faq.html

  

1 Comment » | Spread the word:

Axis 2 Web service error

Wednesday, December 24, 2008 | Email This Post | | 131 views
(AXIS2, Apache, J2EE, Problems, Programming/Coding)

An error in web-services -

 

exception in stub ==java.lang.LinkageError: loader constraint violation: when resolving method "com.TestClass.getOMElement(Ljavax/xml/namespace/QName;Lorg/apache/axiom/om/OMFactory;)Lorg/apache/axiom/om/OMElement;" the class loader (instance of org/apache/axis2/deployment/DeploymentClassLoader) of the current class, com/TestServiceClass, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, com/ibm/ecris/service/components/TestClass, have different Class objects for the type org/apache/axiom/om/OMFactory used in the signature

 

It comes up when another class with same name is already loaded in ClassLoader (generally during start of web-server, perhaps in different project) and we don’t know about it. The already loaded class is different than the class being loaded at this time. In this case, class being initialized/loaded/used is TestClass which is already loaded with different signatures and therefore this error pops up. So make sure that you load only one instance of right class at right time.

  

No Comments » | Spread the word:

Eclipse and Axis2

Monday, November 17, 2008 | Email This Post | | 730 views
(AXIS2, Apache, Eclipse, Problems, Programming/Coding)

Even after so many years of development there is something even Eclipse can’t help out with and that is – too many unknown errors which Eclipse team keeps trying to figure out. One such recent error that I came across is when you are integrating Apache Axis2 with Eclipse. It reads like –

 

"Exception occurred while reading or writing file {0}The Axis2 facets cannot be installed since the Axis2 runtime location has not been set.

Please go to the Web Services preference page and set the Axis2 runtime location under Axis2 Preferences."

 

And comes up even when Axis2 is configured properly. So not a matter of worry for the developer but it is a thing Eclipse messes up internally and you can’t get it right after repeated tries. So what you are supposed to do to get out of this problem? Simplest solution –

Clean install Eclipse, set Axis2 preferences once again to point to a clean fresh Axis2 directory inside Preferences > Web-Services (the way you did with previous one) and there you go. No more problems which proves it was an error which had to do with Eclipse only.

 

Long way to go for Open Source. Oh yes, why long way because still it demands an out-of-world hardware configuration which can make a PC not just run but fly. Have you got a chance to run Eclipse on a system with 501 MB RAM, even if it was by a mistake? It was just a fantasy that I wanted to happen and when it happened, it turned out to be more like a tragedy than fantasy but then there is one thing common between both – they can never be forgotten!!

  

2 Comments » | Spread the word: