Tag: Web Service

Web services are technology neutral web based components or applications that use XML-based open standards to enable interoperability in integration. Java introduced Java API for XML Web Services (JAX-WS) for creating web services. JAX-WS API is part of the Java EE platform and supports annotations. It simplifies the development of web service providers and web service clients.

Our goal is to locally design, develop and test a web service and finally deploy it to the AWS Elastic Beanstalk. We will develop a simple web service with top-down approach meaning we will design our web service interface first and then implement it using JAX-WS. To generate Java classes from XML schemas and WSDL, we will use Apache CXF framework. We will also follow best practices while designing and developing our web service.

Let’s design generic XML schemas and a simple, generic, WS-I compliant WSDL. A good practice is to design business objects and messages that envelope business object in web service operations, separately and in different namespaces.
First, we create a library project (general project in Eclipse IDE) and design two business schemas and three messages for our operation:

  • MyBusinesssEntity.xsd
  • MyBusinessFault.xsd
  • DoSomethingRequest.xsd
  • DoSomethingResponse.xsd
  • DoSometingFault.xsd

Sample schema:


Now, we can design a web service interface (WSDL) with a single “doSomething” operation with an input, output and business fault. Best practice is to use envelope messages for input, output and fault. In our case we use three messages – request, response and fault message defined above.

To ensure true interoperability and be compliant with WS-I we should follow best practices and use document/literal SOAP binding. You can read about WSDL styles here.

Now we can start with top-down development of our web service. To enable this, we must configure our environment. We use:

In Eclipse we generate a new Dynamic Web Project with configured Apache CXF and Tomcat 7.0 runtime (make sure your web service runtime is also set to Tomcat 7.0 and Apache CXF). Note we use jdk 1.6.

We add a new top-down web service, select our WSDL from the library project and let Apache CXF and wsdl2java to generate JAX-WS stubs and JAXB Java classes we can use in the implementation.



If we take a look at the generated classes we can see they are annotated with JAXB and JAX-WS annotations. We can implement our service in the MyServiceImpl.java class. In the interface we can cleary see the JAX-WS annotations.


The service endpoint is defined in the copied WSDL in the WebContent/wsdl foler. In our case the service looks like this:


To test it we deploy it locally on the Tomcat 7.0 server and use SoapUI to test it.

Now we are ready to deploy our web service on the AWS Elastic Beanstalk that automatically handles the deployment, capacity provisioning, load balancing, auto-scaling and application health monitoring. It supports Apache Tomcat 6 and 7, Microsoft IIS 7.5 and 8, PHP 5.3, Phyton, Ruby 1.8.7 and 1.9.3.

To deploy our application on the AWS Elastic Beanstalk from Eclipse we need the AWS Toolkit for Eclipse. When we configure our AWS credentials (access key ID and secret key are accessible in the AWS portal) in the AWS toolkit, we add a new Server > Amazon Web Services > AWS Elastic Beanstalk for Tomcat 7.0. We choose the region (in our case – Ireland) and configure our application and environment.


Next, we can deploy the application with specific key pair, enable SSL, assign CNAME to the server, set the application health check URL and assign the email address for notifications. In our case, we will leave all fields empty. Then we add the project on the server, start it and wait (in our case it took about 8 minutes).



After the deployment we can take a look at our AWS Managemen Conolse > Elastic Beanstalk. Here we can manage our AWS Elastic Beanstalk applications.


Our application is hosted in the AWS S3 bucket in the same region as the AWS Elastic Beanstalk application.



WSDL of our web service is located on:

  • http://mytestenv-s2y4skscv5.elasticbeanstalk.com/services/MyServiceSOAP?wsdl

Finally, we can test the web service, running on AWS Elastic Beanstalk using SoapUI.



You can download the sample here.


, , , , Hide

This article serves as a tutorial on how to develop Web Service using Axis2 and JAXB XML data binding.

Current version of Axis2 framework at the time of writing this tutorial is 1.6.1. Its integration in Eclipse java development tool supports two types of wizards for creating web services: Web Service Wizard and Web Service Client Wizard. Using these two wizards enables us to build client-side and server-side web service artefacts for Axis2. Its preferences include selecting XML data binding type. Supported types in these wizards are ADB and XMLBEANS. Although when using supplied Web Service wizards there are only those two supported data bindings in fact Axis2 also supports JiBX and JAXB data bindings.

Because the standard development of Web Services compliant to JAX-WS 2.1 is using JAXB 2.0 data binding we will show how to develop web services under these technologies. For this we will not use supported wizards, but WSDL2Java command line tool. This tool is supplied in downloaded Axis2 package. Be aware that WAR (Web Archive) Axis2 distribution does not include mentioned tool.

For this tutorial we will develop a Top Down Web Service from supported WSDL.

We will assume that we already have installed Tomcat server version 7.

Preparing Eclipse environment.

To prepare Eclipse environment for implementing our web service we must set Axis2 runtime location. In Eclipse we enter “Preferences” (Window -> Preferences), than we navigate to “Web Services” -> “Axis2 Preferences”, where we set “Axis Runtime Location” to the location of extracted Axis2 folder (Image below). After this we can also prepare User Libraries under “Java” -> “Build Path” -> “User Libraries” where we first add new Library, and then we add all JAR files from “lib” directory under extracted Axis2 directory to this library.

After this we must add AXIS2_HOME environment variable (assuming we already have JAVA_HOME environment variable set) which points to installation directory of Axis2 e.g. “C:\axis2-1.6.1”.

Preparing project for developing Web Service.

We will develop our sample Web Service into Dynamic Web Project. For creating project with support for Axis2 we must select proper facets. We can do this when creating new “Dynamic Web Project” using button “Modify” (Image below).

We must select “Axis2 Web Services”. Since current version of Axis2 runs on Servlet version 2.5 or less it is also necessary to change “Dynamic Web Module” version to 2.5. Note that this is not necessary if we are using target runtime that does not support Web Module higher than 2.5.

At this stage we have prepared our project for building a web service.

Preparing WSDL Web Service description.

For the purpose of this tutorial creating WSDL description does not hold high priority. That is why we will skip the part of creating one and will use one supported on this link: WeatherServiceWSDL

Generating Java skeleton.

As mentioned earlier in this tutorial we will Casino Online use WSDL2Java command line tool (we can find it in axis2 installation directory under directory “bin”). For generating Java Skeleton classes we will use the following command shown on image below:

wsdl2java.bat –o C:\EclipseWorkspaces\DefaultWorkspace\WeatherService -ss -d jaxbri -uri C:\WeatherService.wsdl

Attributes explanation:

  • o – Path where Java skeleton will be generated (usually web project path).
  • ss – Marks generating server side artefacts
  • d – Selected data binding for generating Java skeleton, “jaxbri” marks JAXB Reference Implementation data binding.
  • uri – supported is local disk path or URL of WSDL file.


After generation Java skeleton we must implement web service. Image below shows generated classes.

Implementation classes are named “*Skeleton.java”. There we implement generated method that represents our Web Service operation. Note that sometimes it is necessary to refresh file list in Eclipse Project Explorer for generated files to be visible.

Packaging Web Service.

When generating web service Java Skeleton, WSDL2Java tool also creates ant build file for building and packaging generated web service. This file is “build.xml”. Our next task is to run this Ant task. For the purpose of this tutorial we will add a builder that uses generated Ant task to prepare our web service for deployment. Another option would be manually running this task with Ant.
This we will do by Right Clicking on project that holds generated classes and selecting “properties”. Under “builders” we add new Ant builder. Only thing we must do when configuring this builder is to select build file. We must select generated “build.xml” file as seen on image below. Recommended is also to change builder name.

After setting new builder we see build log on console. Building must be successful.

Deploying Web Service.

Result of successful building is Axis Archive package, which includes build web service. Procedure in previous stage creates this kind of package under “build/lib” folder in our project. Archive name in the case of this tutorial is “WeatherService.aar” and it includes developed services class files. We have different possibilities on how to deploy Web Service packed this way. We can deploy it under Axis administrative console, or we can manually add it to Axis service repository. For the purpose of this tutorial we will manually deploy it on Axis runtime which has been already added into our project at stage 2. We must do two things. First one is copying Axis archive file, in our case is “WeatherService.aar” to “WebContent/WEB-INF/services” folder that represents Axis2 repository. Next step is to add “WeatherService.aar” into “services.list” text file situated in the “services” folder.

Files used at this stage of the tutorial are shown in image below.

Running Web Service.

After completed all this steps successfully, we are now able to test developed Web Service. WSDL should be accessible, when using default configuration, at address like: http://localhost:8080/WeatherService/services/WeatherService?wsdl

Source Project

You can download a Eclipse snapshot of this project from this link: WeatherService

, , , Hide