Dynamic WebService Execution in Java

Dynamic WebService Execution in Java

Hi All,

I’ve recently had the need to find a way to execute a web service dynamically in java. After doing some research and testing I’m leaving my two cents so the next one might have a starting point.

I needed a java version of the Unit Test Framework component and for that it was necessary to port a few of the extensions.

A couple of them were not very hard (the web service discovery was done using the predic8 SOA Model API http://www.membrane-soa.org/soa-model/) and the caching control is quite similar with the .NET version.

The hardest part was to find a way to dynamically invoke a WebService specifying the method name and parameters in runtime (something that in .NET is as easy as submitting a http post :)).

After some research (and experimentation) I was able to do it in Java using Apache’s CXF framework (http://cxf.apache.org/).
Following their example of creating dynamic clients here (http://cxf.apache.org/docs/dynamic-clients.html) I successfully packaged an extension module with the CXF required libraries and dependencies.

Attached is a solution that contains the extension module WSExecution that you could use if necessary as the base for something similar.

One quick note is that I wasn’t able to make this work when used from a screen action. Even though the WS action is invoked successfully you get an error.
After some troubleshooting (and reading) it seems that this happens because CXF dynamic client rely on the spring framework which in turn messes up the servlet Factory (I couldn’t really find out why). I also found out that if the invokation is done not from the UI directly (Timer, Process, etc) it executes fine.

So in order to test my developments from a screen what I did was to create a wrapper that exposes a WebService which in turn uses the extension to invoke dynamically the WS. With this approach the usage of CXF is done in the background and doesn’t produce errors.
Inside the attached solution are also 3 modules that you may use as an example:
  • the testing app (WSExecutionApp)
  • the wrapper (WSExecutionWrapper)
  • and a module that exposes webservices for dynamic execution (WSExecutionService).
I hope this may save some precious time to someone in the future.

Good job Guilherme!

Just a question: What application server was did done/tested with?
I ask because the native webservices in jboss 6/7 are based on cxf, and including in extensions libraries already present in the application service is usually not a good idea.

João Rosado
Hi João,

This was done on JBoss 7. I wasn't aware of cxf being present and so far haven't detected any incompatibilities but I'll perform additional testing to make sure that nothing is broken.

Can you highlight possible side effects of having the library duplicated? (even though its a different version as I'm using 3.0.1 and from what I can see my installation has 2.4)

The problems depend on the library and the application server.

One of them main architectural changes in jboss7 is to prevent modules conflicts (and yes its way better than on other servers), but problems still do happen.

There basically 2 types of problems:
  - with different versions your code can reference a class that on exists only in your version, but then common classes will be loaded from the system version (it always have priority). This usually leads to Linkage Errors, Class or Methods not found.
  - With same versions is rarer to have problems... but I have bad problems with classes that assume that they prefer to be loaded in the System Classloader. This happened A LOT in jboss 5 code and expecially on some Apache components.

João Rosado

Hi Guilherme and João,

I was trying to use the Unit Test Framework for Java (cloud on WildFly 2.7.13) and we are having an error due to the fact that CXF libraries already exist in Wildfly. 

Is there a version of this extension that works with WildFly?

Thank you.


Pedro Saraiva


{"JBAS014671: Failed services" => {"jboss.deployment.unit.\"UTF.war\".PARSE" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"UTF.war\".PARSE: JBAS018733: Failed to process phase PARSE of deployment \"UTF.war\"
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS015599: Apache CXF library (cxf-rt-bindings-soap-3.0.1.jar) detected in ws endpoint deployment; either provide a proper deployment replacing embedded libraries with container module dependencies or disable the webservices subsystem for the current deployment adding a proper jboss-deployment-structure.xml descriptor to it. The former approach is recommended, as the latter approach causes most of the webservices Java EE and any JBossWS specific functionality to be disabled."}}