Maven CXF wsdl2java : WSDL to Java – Example

September 6, 2013 1 comment

Sample POM.xml DOWNLOAD Project

<?xml version="1.0"?>
<project xsi:schemaLocation="" xmlns=""
	<description>Abdul Aziz</description>
          <!-- cxf codegen plugin for WSDL to Java -->          

DOWNLOAD Project here

Categories: Uncategorized

Six Lessons

April 8, 2013 Leave a comment
Lesson 1:
A man is getting into the shower, just as his wife is finishing up her shower, when the doorbell rings.
The wife quickly wraps herself in a towel and runs downstairs.
When she opens the door, there stands David, the next-door neighbor.
Before she says a word, David says, ‘I’ll give you $800 to drop that towel.’
After thinking for a moment, the woman drops her towel and stands naked in front of David.
After a few seconds, David hands her $800 and leaves.
The woman wraps back up in the towel and goes back upstairs.
When she gets to the bathroom, her husband asks, ‘ Who was that?’
‘It was David, the next door neighbor,’ she replies.
‘Great,’ the husband says, ‘did he say anything about the $800 he owes me?’
Moral of the story:
If you share critical information pertaining to credit and risk with your shareholders in time, you may be in a position to prevent avoidable exposure.
Lesson 2:
A priest offered a Nun a lift.
She got in and crossed her legs, forcing her gown to reveal a leg.
The priest nearly had an accident.
After controlling the car, he stealthily slid his hand up her leg.
The nun said, ‘Father, remember Psalm 129?’
The priest removed his hand. But, changing gears, he let his hand slide up her leg again. The nun once again said, ‘Father, remember Psalm 129?’
The priest apologized ‘Sorry sister but the flesh is weak.’
Arriving at the convent, the nun sighed heavily and went on her way.
On his arrival at the church, the priest rushed to look up Psalm 129. It said, ‘Go forth and seek, further up, you will find glory.’
Moral of the story:
If you are not well informed in your job, you might miss a great opportunity.
Lesson 3:
A sales rep, an administration clerk, and the manager are walking to lunch when they find an antique oil lamp.
They rub it and a Genie comes out. The Genie says, ‘I’ll give each of you just one wish.’
‘Me first! Me first!’ says the admin clerk.. ‘I want to be in the Bahamas , driving a speedboat, without a care in the world.’ Poof! She’s gone.
‘Me next! Me next!’ says the sales rep. ‘I want to be in Hawaii , relaxing on the beach with my personal masseuse, an endless supply of Pina Coladas, and the love of my life.’ Poof! He’s gone.
‘OK, you’re up,’ the Genie says to the manager. The manager says, ‘I want those two back in the office after lunch.’
Moral of the story:
Always let your boss have the first say.
Lesson 4:
An eagle was sitting on a tree resting, doing nothing.
A small rabbit saw the eagle and asked him, ‘Can I also sit like you and do nothing?’ The eagle answered: ‘Sure, why not.’
So, the rabbit sat on the ground below the eagle and rested. All of a sudden, a fox appeared, jumped on the rabbit and ate it.
Moral of the story:
To be sitting and doing nothing, you must be sitting very, very high up
Lesson 5:
A turkey was chatting with a bull. ‘I would love to be able to get to the top of that tree’ sighed the turkey, ‘but I haven’t got the energy.’
‘Well, why don’t you nibble on some of my droppings?’ replied the bull. ‘It’s full of nutrients.’
The turkey pecked at a lump of dung, and found it actually gave him enough strength to reach the lowest branch of the tree.
The next day, after eating some more dung, he reached the second branch
Finally after a fourth night, the turkey was proudly perched at the top of the tree.
He was promptly spotted by a farmer, who shot him out of the tree.
Moral of the story:
Bull Shit might get you to the top, but it won’t keep you there…
Lesson 6:
A little bird was flying south for the winter. It was so cold the bird froze and fell to the ground into a large field.
While he was lying there, a cow came by and dropped some dung on him.
As the frozen bird lay there in the pile of cow dung, he began to realize how warm he was.
The dung was actually thawing him out!
He lay there all warm and happy, and soon began to sing for joy. A passing cat heard the bird singing and came to investigate.
Following the sound, the cat discovered the bird under the pile of cow dung, and promptly dug him out and ate him.
Moral of the story:
(1) Not everyone who shits on you is your enemy.
(2) Not everyone who gets you out of shit is your friend.
(3) And when you’re in deep shit, it’s best to keep your mouth shut!
Categories: Uncategorized

Address already in use: JVM_Bind:8080

July 13, 2011 1 comment

Do this..

To find the application which is using the 80 port number
In “Command Prompt” type the following command:
(1) netstat -o -n -a | findstr 0.0:8080
and then
(2) taskkill /F /PID 988
Change the PID value from 988to your required port value

Developing Web Services using jax-ws, spring and maven

June 15, 2011 13 comments

Using the following steps you can develop soap Web Services using jax-ws, spring and maven plugin

  1. Define service interface
  2. Define service Implementation
  3. Web.xml – add JAX-WS commons spring ext servlet
  4. Spring beans configuration using annotations
  5. Spring configurations for Web Services
  6. pom.xml – Add ‘jaxws-maven-plugin’ plugin
  7. Build deployment using maven
  8. Check the web service
  9. Test web service using sopaUI
  10. Download Source Code
    or war file mo-ws.war

(1) Define service interface

//TemperatureService .java

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;


public interface TemperatureService {
	public Weather toCelsius(@WebParam(name="fahrenheit") double fahrenheit);
	public Weather toFahrenheit(@WebParam(name="celsius") double celsius);



import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlType(name = "Weather", propOrder = { "city", "celsius" , "fahrenheit"})
@XmlRootElement(name = "Weather")
public class Weather {
	@XmlElement(name = "Ciy", required = false)
	private String city;

	@XmlElement(name = "Celsius", required = true)
	private double celsius;
	@XmlElement(name = "Fahrenheit", required = true)
	private double fahrenheit;
	public String getCity() {
		return city;
	public void setCity(String city) { = city;
	public double getCelsius() {
		return celsius;
	public void setCelsius(double celsius) {
		this.celsius = celsius;
	public double getFahrenheit() {
		return fahrenheit;
	public void setFahrenheit(double fahrenheit) {
		this.fahrenheit = fahrenheit;

(2) Define service Implementation

//TemperatureServiceImple .java

import javax.jws.WebService;

import org.springframework.stereotype.Service;


@WebService(endpointInterface = "",serviceName="temperatureService")
public class TemperatureServiceImple implements TemperatureService {

	public Weather toCelsius(double fahrenheit) {
		double celsius = (5.0 / 9.0) * (fahrenheit - 32.0);
		//C° = (5 / 9)x (F° - 32)  
		Weather w = new Weather();
		return w;

	public Weather toFahrenheit(double celsius) {
		double fahrenheit = (celsius *1.8)+32.0;
		//F° = (C° x 1.8) + 32
		Weather w = new Weather();
		return w;


(3) Web.xml – add JAX-WS commons spring ext servlet

 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "" >

  <!-- spring framework context configuration -->
  <!-- Spring Context Listener -->
  <!-- this is for JAX-WS commons spring ext. -->

(4) Spring beans configuration using annotations

<!-- main-application-context.xml-->
<beans xmlns=""
	    <!—scan annotations -->         
       <context:component-scan base-package=""/>
       <!-- Web Services -->         
       <import resource="ws-context.xml"/>        

(5) Spring configurations for Web Services

<!--  ws-context.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""
   <!-- Temperature Web Service -->
	<wss:binding url="/webservice/temperaturewebservice"> 
         <ws:service bean="#temperatureServiceImple">             


(6) pom.xml – Add ‘jaxws-maven-plugin’ plugin

<!-- pom.xml-->

(7) Build deployment using maven: Run (1) “mvn clean package” and again (2) “mvn package”

"mvn clean package" - it will create required WSDL files at "/target/jaxws/wsgen/wsdl"
"mvn package" it will create some files at "/target/mo-ws/WEB-INF/classes/uk/co/mo/training/ws/jaxws"

(8) Deploy in the tomcat

<!-- server.xml-->

(9) Check the web service http://localhost:8080/ws/webservice/temperaturewebservice

(10) Using soapUI test web service

(11) Download Source Code or war file at mo-ws.war

Testing Using Junit 4, Jmock & Spring mock

February 7, 2010 4 comments

What If the Code Has Dependencies?

The solution is Using Mock Objects

We use mock objects during testing for two main reasons: to isolate the class under test from outside influence and to control dependencies.

If the dependency is a simple POJO, using the new operator is an easy way to create an instance used just for the test. However, if the dependency is not easily created or requires heavyweight resources such as database connections, using the new operator isn’t often possible. Mock objects step in to “mock” the dependency, thus allowing the code under test to operate without invoking outside resources.

Mock objects are used when you need to either replace a heavyweight dependency with a lightweight instance just for testing, or when you need to use an intelligent stub. Those two situations often occur simultaneously, making mock objects a perfect addition to any testing tool belt.

The following example shows how we can test application component that has DAO (heavy weight) dependency using jmock objects  and web layer (Controller)  using spring mock api.

public class HomeControllerTest {

	Mockery context = new JUnit4Mockery();
	//mock object : ContactDAO (using JMock)
	ContactDAOInterface contactDAO = context.mock(ContactDAOInterface.class);
	// Spring MVC controller
	HomeController cc = new HomeController();
	// mock objects (using spring mock)
	private MockHttpServletRequest request;
	private MockHttpServletResponse response;

	public void init() throws Exception
		// mock objects created
		request = new MockHttpServletRequest();
		response = new MockHttpServletResponse();

	public void HomePage() throws Exception
		// define expectations for mock object
		context.checking(new Expectations() {{
			ArrayList<ContactData> data = new ArrayList<ContactData>();
			data.add(new ContactData(1,"Abdul Aziz","07525776781"));
	        oneOf (contactDAO).getContacts(); will(returnValue(data));

		// test
		ModelAndView mav= cc.handleRequest(request, response);
		Assert.assertEquals("viewContacts", mav.getViewName());
		ArrayList<ContactData> obj=(ArrayList<ContactData>)mav.getModel().get("contacts");
		Assert.assertEquals("Abdul Aziz",obj.get(0).getName());

Spring Security: Authorization (Controlling Access) Configurations

January 23, 2010 Leave a comment

An access decision manager
is responsible for deciding whether the user has the proper privileges to access secured resources. Access decision managers are defined by the



interface AccessDecisionManager {


decide(Authentication authentication, Object object,

            ConfigAttributeDefinition config)

            throws AccessDeniedException,


supports(ConfigAttribute attribute);

supports(Class clazz);



The decide()method is where the ultimate decision is made. If it returns without throwing an AccessDeniedException
or InsufficientAuthenticationException, access to the secured resource is granted. Otherwise, access is denied.


Decision by Voting:

Spring Security’s access decision managers are ultimately responsible for determining the access rights for an authenticated user. They poll one or more objects that vote on whether or not a user is granted access to a secured resource. Once all votes are in, the decision manager tallies the votes and arrives at its final decision.



<bean id=“accessDecisionManager” class=“”>

<property name=“decisionVoters”>


<ref bean=“roleVoter”/>





The decisionVoters property is where you provide the access decision manager with its list of voters.


<bean id=“roleVoter” class=“”/>


RoleVoter only votes when the secured resource has configuration attributes that are prefixed with ROLE_


By default, all the access decision managers deny access to a resource if all the voters abstain. However, you can override this default behavior by setting the allowIfAllAbstain
property on the access decision manager to true.

Spring Web Services

January 21, 2010 Leave a comment

Spring provides full support for standard Java web services APIs: Web services using JAX-RPC and
Web services using JAX-WS

 Spring Web Services, a solution for contract-first, document-driven web services;