Translate

lunes, 9 de febrero de 2015

WSO2: add log4j traces for your service

When you are using WSO2 application server to create your web services, you may want to log debug traces in your web services, but by default the log4j WSO2 configuration doesn't show this kind of debug traces.

In order to show this debug messages you only need to consider your webservice implementation package and add it to log4j WSO2 configuration.

Imagine that your application or webservice package is com.antuansoft.myapp you have to add this lines:

#MY APP DEBUG TRACES:
log4j.logger.com.antuansoft.myapp=DEBUG


at the end of the log4j.properties file that is situated in the next path:

[WSO2-Intallation-path]/repository/conf/log4j.properties

miércoles, 4 de febrero de 2015

Webservice Example with axis2 part 4: How to create the web service using maven and the template class

This is the fourth post to show how to create a web service with a simple operation and a complex operation based on Axis2.

In this series of posts we are going to show this points:




  • Setting up the environtment
  • Understanding  a web service
  • How to define the web services operations in a template class
  • How to create the  web service using maven and the template class
  • How to package the web service using maven and deploy it.
  • How to test the deployed web service using maven.


In this post we are going to learn about how to use maven to create a WSDL file based on the template class created in the part 3 of these seral of posts. And after that based on the created WSDL we are going to create the basic architeture of the web service generating the server side stubs also with maven.

Note: You need to have medium knowledge of apache maven, especially with maven profiles and maven plugins.

With maven you can build the pom.xml but you can build a profile also, this profile contains a subset of tasks to be executed.

The maven plugin that we are going to use are:


  • maven-compiler-plugin: To compile the template class and all classed used by it.
  • axis2-java2wsdl-maven-plugin: To create the WSDL based on template class
  • axis2-wsdl2code-maven-plugin: To create the server side stubs based on the WSDL
  • maven-antrun-plugin: Move and rename the generated files.



To do this tasks we only need to modify the pom.xml adding to this profile the 4 plugins. Look at the pom.xml file from lines 290 to 413 and execute the next maven command.

mvn -P java2wsdl2code clean compile -e

-P parameter means that we are going to appy the java2wsdl2code.
- e parameter means more detailed message if an error happen.

The first part of the profile consists on compile the template class created in the step 3 of this tutorial series. It compile the class Axis2ServiceExample, and his related classes ComplexOperationResponse and Axis2ServiceException. Here I had added some configuration to use de compile plugin in the generate-sources phase and avoid the default phase of this plugin (compile phase)



The second plugin is one of the important plugins, axis2-java2wsdl-maven-plugin this plugin generates the WSDL file and service-xml based on the compiled classes by the last plugin. The input parameters are

  1. the main class to read Axis2ServiceExample
  2. the target name space for that webservice.
  3. The path and name of the WSDL where is going to be generated.
--
--

At this point in the target folder should be generated an Axis2ServiceExample.wsdl and a services.xml. Now we are going to generate the server Stubs based on this WSDL file. These server stubs are .class and .java files and all the generated classes will be the architecture of the web service. The databinding framework selected to create the architecture is XMLBEAMS the axis2-wsdl2code plugin provides the next posible framework options XMLBEANS, ADB, AXIOM and JIBX.

The input parameters applied to this plugin are:

  1. packageName: The package where the class files will be created,
  2. wsdlFile: Location of the WSDL file generated in the last step.
  3. databindingName: The Databinding framework selected
  4. outputDirectory: Directory where the source files will be created
  5. generateServerSide: True to generate server side stubs of the WSDL, false to generated clients of the WSDL.
  6. generateServerSideInterface
  7. generateServicesXml
  8. generateServicesXml: Specify the name space.

--
--
Besides the java classes and the source code, a build.xml file is generated it will be used in the next maven pluglin, it will help to package all the classes generated.


The last plugin aplied is the maven-antrun-plugin, is only a special plugin to apply ant sentences in a maven phase. The objetive of this step is only execute the build.xml file generated in the last step and move the files generated to the build directory.

--
--

To execute all of this actions yoy have to execute the next command:

mvn -P  java2wsdl2code clean compile 

We are going execute the clean and copile phases executing the java2wsdl2code  profile, and after maven execution the results are in the target directory.



You will find the source code generated in target/wsdl2java/src folder, the compiled classes in target/build folder and the generated artifacts in wsdl2java folder.

Now we have to copy

  1. The Axis2ServiceExample.wsdl and service.xml to the [ProjectHome]/src/main/resources. This files are needed to describe the web service created based on the template file
  2. The Axis2ServiceExampleServerStubs.jat and XBeans-packaged.jar to [ProjectHome]/lib foder. This files cotains all the classes generated based on the template file 
  3. Axis2ServiceExampleSkeleton.java to [ProjectHome]\src\main\java\com\antuansoft\services\template this file is  needed to add functionaly to the web service operations.

Now we are ready to codify, we will see in the next chapter.