<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Towards better software &#187; JAX-WS</title>
	<atom:link href="http://krzysztofadamczyk.com/tag/jax-ws/feed/" rel="self" type="application/rss+xml" />
	<link>http://krzysztofadamczyk.com</link>
	<description>About software development, domain driven design, code quality and IT in general</description>
	<lastBuildDate>Thu, 25 Aug 2011 06:26:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='krzysztofadamczyk.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Towards better software &#187; JAX-WS</title>
		<link>http://krzysztofadamczyk.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://krzysztofadamczyk.com/osd.xml" title="Towards better software" />
	<atom:link rel='hub' href='http://krzysztofadamczyk.com/?pushpress=hub'/>
		<item>
		<title>Contract-first web services with JBoss 5, Metro &amp; Spring</title>
		<link>http://krzysztofadamczyk.com/2009/11/27/contract-first-web-services-with-jboss-5-metro-spring/</link>
		<comments>http://krzysztofadamczyk.com/2009/11/27/contract-first-web-services-with-jboss-5-metro-spring/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 18:00:15 +0000</pubDate>
		<dc:creator>Krzysztof Adamczyk</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[JAX-WS]]></category>
		<category><![CDATA[JAXB]]></category>
		<category><![CDATA[Jboss]]></category>
		<category><![CDATA[Metro]]></category>
		<category><![CDATA[Spring]]></category>
		<category><![CDATA[WebServices]]></category>

		<guid isPermaLink="false">http://krzysztofadamczyk.com/?p=35</guid>
		<description><![CDATA[In this article I want to show how to build a simple application deployed on JBoss 5 using Metro web services stack and Spring. The main purpose of this article is to show the configuration that needs to be done in order to create project structure, define dependencies and prepare deployable artifacts. That&#8217;s why you [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=krzysztofadamczyk.com&amp;blog=20688394&amp;post=35&amp;subd=krzysztofadamczyk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In this article I want to show how to build a simple application deployed on JBoss 5 using Metro web services stack and Spring. The main purpose of this article is to show the configuration that needs to be done in order to create project structure, define dependencies and prepare deployable artifacts. That&#8217;s why you will find here much more XML than Java code (unfortunately). I chose to package the whole application as an EAR archive that in turn contains web application with our web services. Of course a WAR would be perfectly enough to show web services, but I want this project to be a base for future enhancement.</p>
<p>The complete source code from this example is available <a href="http://code.google.com/p/spring-metro-demo/">here</a>.</p>
<p>What you need?</p>
<ul>
<li><a href="http://www.jboss.org/jbossas/downloads/">JBoss 5</a></li>
<li><a href="http://maven.apache.org/download.html">Maven2</a></li>
<li><a href="http://eclipse.org/">Eclipse</a></li>
<li><a href="http://www.soapui.org/">SoapUI</a></li>
</ul>
<p><span style="font-size:14pt;"><strong>Step 1- Create Maven project</strong></span></p>
<p>First of all let&#8217;s create the main project using Maven</p>
<p><strong>mvn </strong>archetype:create <strong>-DgroupId</strong>=com.krzysztofadamczyk.playground.springmetrodemo -<strong>DartifactId</strong>=spring-metro-demo</p>
<p>Next we&#8217;ll changing packaging to &#8220;pom&#8221; in the main pom file</p>
<pre class="xml">&lt;packaging&gt;pom&lt;/packaging&gt;</pre>
<p>We also have to add <em>dependencyManagement</em> section, where we put our dependencies settings:</p>
<p>For Spring:</p>
<pre class="xml">		&lt;dependency&gt;
		   &lt;groupId&gt;org.springframework&lt;/groupId&gt;
		   &lt;artifactId&gt;spring&lt;/artifactId&gt;
		   &lt;version&gt;2.5.6.SEC01&lt;/version&gt;
		&lt;/dependency&gt;</pre>
<p>Metro:</p>
<pre class="xml">		&lt;dependency&gt;
			&lt;groupId&gt;com.sun.xml.ws&lt;/groupId&gt;
			&lt;artifactId&gt;webservices-rt&lt;/artifactId&gt;
			&lt;version&gt;1.5&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;com.sun.tools.ws&lt;/groupId&gt;
			&lt;artifactId&gt;webservices-tools&lt;/artifactId&gt;
			&lt;version&gt;1.5&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;javax.xml&lt;/groupId&gt;
			&lt;artifactId&gt;webservices-api&lt;/artifactId&gt;
			&lt;version&gt;1.5&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;javax.activation&lt;/groupId&gt;
			&lt;artifactId&gt;activation&lt;/artifactId&gt;
			&lt;version&gt;1.1&lt;/version&gt;
			&lt;scope&gt;provided&lt;/scope&gt;
		&lt;/dependency&gt;</pre>
<p>For JAXWS-Spring integration we will exclude transitive dependencies to JAX-WS, since we already have JAX-WS RI in Metro:</p>
<pre class="xml">		&lt;dependency&gt;
			&lt;groupId&gt;org.jvnet.jax-ws-commons.spring
			&lt;/groupId&gt;
			&lt;artifactId&gt;jaxws-spring&lt;/artifactId&gt;
			&lt;scope&gt;runtime&lt;/scope&gt;
			&lt;version&gt;1.8&lt;/version&gt;
			&lt;exclusions&gt;
				&lt;exclusion&gt;
					&lt;groupId&gt;com.sun.xml.ws&lt;/groupId&gt;
					&lt;artifactId&gt;jaxws-rt&lt;/artifactId&gt;
				&lt;/exclusion&gt;
				&lt;exclusion&gt;
					&lt;groupId&gt;com.sun.xml.ws&lt;/groupId&gt;
					&lt;artifactId&gt;jaxws-local-transport&lt;/artifactId&gt;
				&lt;/exclusion&gt;
				&lt;exclusion&gt;
					&lt;groupId&gt;javax.servlet&lt;/groupId&gt;
					&lt;artifactId&gt;servlet-api&lt;/artifactId&gt;
				&lt;/exclusion&gt;
				&lt;exclusion&gt;
					&lt;groupId&gt;org.springframework&lt;/groupId&gt;
					&lt;artifactId&gt;spring&lt;/artifactId&gt;
				&lt;/exclusion&gt;
				&lt;exclusion&gt;
					&lt;groupId&gt;org.springframework&lt;/groupId&gt;
					&lt;artifactId&gt;spring-core&lt;/artifactId&gt;
				&lt;/exclusion&gt;
				&lt;exclusion&gt;
					&lt;groupId&gt;org.springframework&lt;/groupId&gt;
					&lt;artifactId&gt;spring-context&lt;/artifactId&gt;
				&lt;/exclusion&gt;
				&lt;exclusion&gt;
					&lt;groupId&gt;junit&lt;/groupId&gt;
					&lt;artifactId&gt;junit&lt;/artifactId&gt;
				&lt;/exclusion&gt;
				&lt;exclusion&gt;
					&lt;groupId&gt;javax.jws&lt;/groupId&gt;
					&lt;artifactId&gt;jsr181-api&lt;/artifactId&gt;
				&lt;/exclusion&gt;
				&lt;exclusion&gt;
					&lt;groupId&gt;com.sun.xml.bind&lt;/groupId&gt;
					&lt;artifactId&gt;jaxb-impl&lt;/artifactId&gt;
				&lt;/exclusion&gt;
				&lt;exclusion&gt;
					&lt;groupId&gt;javax.xml.soap&lt;/groupId&gt;
					&lt;artifactId&gt;saaj-api&lt;/artifactId&gt;
				&lt;/exclusion&gt;
				&lt;exclusion&gt;
					&lt;groupId&gt;com.sun.xml.messaging.saaj&lt;/groupId&gt;
					&lt;artifactId&gt;saaj-impl&lt;/artifactId&gt;
				&lt;/exclusion&gt;
				&lt;exclusion&gt;
					&lt;groupId&gt;com.sun.xml.stream.buffer&lt;/groupId&gt;
					&lt;artifactId&gt;streambuffer&lt;/artifactId&gt;
				&lt;/exclusion&gt;
				&lt;exclusion&gt;
					&lt;groupId&gt;com.sun.xml.stream&lt;/groupId&gt;
					&lt;artifactId&gt;sjsxp&lt;/artifactId&gt;
				&lt;/exclusion&gt;
				&lt;exclusion&gt;
					&lt;groupId&gt;com.sun.org.apache.xml.internal&lt;/groupId&gt;
					&lt;artifactId&gt;resolver&lt;/artifactId&gt;
				&lt;/exclusion&gt;
				&lt;exclusion&gt;
					&lt;groupId&gt;org.jvnet.staxex&lt;/groupId&gt;
					&lt;artifactId&gt;stax-ex&lt;/artifactId&gt;
				&lt;/exclusion&gt;
				&lt;exclusion&gt;
					&lt;groupId&gt;javax.activation&lt;/groupId&gt;
					&lt;artifactId&gt;activation&lt;/artifactId&gt;
				&lt;/exclusion&gt;
			&lt;/exclusions&gt;
		&lt;/dependency&gt;</pre>
<p>We must also declare repository for JAXWS-Spring integration:</p>
<pre class="xml">    &lt;repositories&gt;
        &lt;repository&gt;
            &lt;id&gt;maven2-repository.dev.java.net&lt;/id&gt;
            &lt;name&gt;Java.net Maven 2 Repository&lt;/name&gt;
            &lt;url&gt;http://download.java.net/maven/2&lt;/url&gt;
        &lt;/repository&gt;
    &lt;/repositories&gt;</pre>
<p><span style="font-size:14pt;"><strong>Step 2 &#8211; Create web application project</strong></span></p>
<p><strong>mvn </strong>archetype:create <strong>-DartifactId</strong>=services <strong>-DarchetypeArtifactId</strong>=maven-archetype-webapp</p>
<p>Add dependencies (dependencies are marked <em>optional</em>, because I don&#8217;t want them to go into WAR file &#8211; I&#8217;ll keep them on EAR level for future use by other modules):</p>
<pre class="xml">	&lt;dependencies&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework&lt;/groupId&gt;
			&lt;artifactId&gt;spring&lt;/artifactId&gt;
			&lt;optional&gt;true&lt;/optional&gt;
		&lt;/dependency&gt;
		&lt;!-- JAX-WS-Spring integration --&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.jvnet.jax-ws-commons.spring&lt;/groupId&gt;
			&lt;artifactId&gt;jaxws-spring&lt;/artifactId&gt;
			&lt;optional&gt;true&lt;/optional&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;com.sun.xml.ws&lt;/groupId&gt;
			&lt;artifactId&gt;webservices-rt&lt;/artifactId&gt;
			&lt;optional&gt;true&lt;/optional&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;javax.xml&lt;/groupId&gt;
			&lt;artifactId&gt;webservices-api&lt;/artifactId&gt;
			&lt;optional&gt;true&lt;/optional&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;com.sun.tools.ws&lt;/groupId&gt;
			&lt;artifactId&gt;webservices-tools&lt;/artifactId&gt;
			&lt;optional&gt;true&lt;/optional&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;javax.activation&lt;/groupId&gt;
			&lt;artifactId&gt;activation&lt;/artifactId&gt;
			&lt;optional&gt;true&lt;/optional&gt;
		&lt;/dependency&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;junit&lt;/groupId&gt;
			&lt;artifactId&gt;junit&lt;/artifactId&gt;
			&lt;scope&gt;test&lt;/scope&gt;
		&lt;/dependency&gt;
	&lt;/dependencies&gt;</pre>
<p>We will also define ant task that will import our WSDL and create corresponding Java classes:</p>
<pre class="xml">			&lt;plugin&gt;
				&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
				&lt;artifactId&gt;maven-antrun-plugin&lt;/artifactId&gt;
				&lt;executions&gt;
					&lt;execution&gt;
						&lt;id&gt;generate-bindings&lt;/id&gt;
						&lt;phase&gt;generate-sources&lt;/phase&gt;
						&lt;configuration&gt;
							&lt;tasks&gt;
								&lt;mkdir dir="${basedir}/target/generated-sources"&gt;&lt;/mkdir&gt;
								&lt;mkdir dir="${basedir}/target/throwaway-classes"&gt;&lt;/mkdir&gt;

								&lt;taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport"&gt;
									&lt;classpath refid="maven.compile.classpath" /&gt;
									&lt;classpath refid="maven.plugin.classpath" /&gt;
								&lt;/taskdef&gt;

								&lt;wsimport
									wsdl="${basedir}/src/main/webapp/WEB-INF/wsdl/EchoService.wsdl"
									sourcedestdir="${basedir}/target/generated-sources"
									destdir="${basedir}/target/throwaway-classes" fork="true"
									extension="true"&gt;&lt;/wsimport&gt;

							&lt;/tasks&gt;
							&lt;sourceRoot&gt;${basedir}/target/generated-sources&lt;/sourceRoot&gt;
						&lt;/configuration&gt;
						&lt;goals&gt;
							&lt;goal&gt;run&lt;/goal&gt;
						&lt;/goals&gt;
					&lt;/execution&gt;
				&lt;/executions&gt;
			&lt;/plugin&gt;</pre>
<p>We don&#8217;t want to mix &#8220;hand-written&#8221; and generated classes, and therefore we will use separate source directories to keep them. As there can be only one <em>sourceDirectory </em>defined in <em>build </em>section, we have to use the following plug-in to define second source directory:</p>
<pre class="xml">	&lt;build&gt;
		&lt;sourceDirectory&gt;${basedir}/src/main/java&lt;/sourceDirectory&gt;
		&lt;plugins&gt;
             &lt;plugin&gt;
                &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
                &lt;artifactId&gt;build-helper-maven-plugin&lt;/artifactId&gt;
                &lt;executions&gt;
                  &lt;execution&gt;
                    &lt;id&gt;add-source&lt;/id&gt;
                    &lt;phase&gt;generate-sources&lt;/phase&gt;
                    &lt;goals&gt;
                      &lt;goal&gt;add-source&lt;/goal&gt;
                    &lt;/goals&gt;
                    &lt;configuration&gt;
                      &lt;sources&gt;
                          &lt;source&gt;${basedir}/target/generated-sources&lt;/source&gt;
                      &lt;/sources&gt;
                    &lt;/configuration&gt;
                  &lt;/execution&gt;
                &lt;/executions&gt;
            &lt;/plugin&gt;</pre>
<p>We have to configure our web application in web.xml. Things to notice here:</p>
<ul>
<li><em>org.springframework.web.context.ContextLoaderListener</em><br />
Which initializes Spring application context</li>
<li><em>com.sun.xml.ws.transport.http.servlet.WSSpringServlet</em><br />
which handles requests and integrates JAX-WS with Spring</li>
</ul>
<pre class="xml">&lt;!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" &gt;

&lt;web-app&gt;
	&lt;display-name&gt;Spring + Metro on JBoss demo&lt;/display-name&gt;

	&lt;context-param&gt;
		&lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
		&lt;param-value&gt;/WEB-INF/applicationContext.xml&lt;/param-value&gt;
	&lt;/context-param&gt;
	&lt;listener&gt;
		&lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
	&lt;/listener&gt;

	&lt;servlet&gt;
		&lt;servlet-name&gt;jaxws-servlet&lt;/servlet-name&gt;
		&lt;servlet-class&gt;com.sun.xml.ws.transport.http.servlet.WSSpringServlet&lt;/servlet-class&gt;
	&lt;/servlet&gt;
	&lt;servlet-mapping&gt;
		&lt;servlet-name&gt;jaxws-servlet&lt;/servlet-name&gt;
		&lt;url-pattern&gt;/echoService&lt;/url-pattern&gt;
	&lt;/servlet-mapping&gt;

	&lt;session-config&gt;
		&lt;session-timeout&gt;
			30
        &lt;/session-timeout&gt;
	&lt;/session-config&gt;
	&lt;welcome-file-list&gt;
		&lt;welcome-file&gt;redirect.jsp&lt;/welcome-file&gt;
	&lt;/welcome-file-list&gt;
&lt;/web-app&gt;</pre>
<p><span style="font-size:14pt;"><strong>Step 3 &#8211; Create EAR project</strong></span></p>
<p><strong>mvn </strong>archetype:create <strong>-DartifactId</strong>=ear</p>
<p>Ear projects dependencies will be put into EAR file. The main parts of the pom file are shown below:</p>
<pre class="xml">....
  &lt;packaging&gt;ear&lt;/packaging&gt;
  &lt;dependencies&gt;
	&lt;dependency&gt;
		  &lt;groupId&gt;com.krzysztofadamczyk.playground.springmetrodemo&lt;/groupId&gt;
		  &lt;artifactId&gt;services&lt;/artifactId&gt;
		  &lt;type&gt;war&lt;/type&gt;
	&lt;/dependency&gt;

	&lt;dependency&gt;
		&lt;groupId&gt;org.springframework&lt;/groupId&gt;
		&lt;artifactId&gt;spring&lt;/artifactId&gt;
	&lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.jvnet.jax-ws-commons.spring&lt;/groupId&gt;
        &lt;artifactId&gt;jaxws-spring&lt;/artifactId&gt;
	&lt;/dependency&gt;
	&lt;dependency&gt;
		&lt;groupId&gt;com.sun.xml.ws&lt;/groupId&gt;
		&lt;artifactId&gt;webservices-rt&lt;/artifactId&gt;
	&lt;/dependency&gt;
	&lt;dependency&gt;
		&lt;groupId&gt;com.sun.tools.ws&lt;/groupId&gt;
		&lt;artifactId&gt;webservices-tools&lt;/artifactId&gt;
	&lt;/dependency&gt;
	&lt;dependency&gt;
		&lt;groupId&gt;javax.activation&lt;/groupId&gt;
		&lt;artifactId&gt;activation&lt;/artifactId&gt;
	&lt;/dependency&gt;

  &lt;/dependencies&gt;
  &lt;build&gt;
    &lt;plugins&gt;
      &lt;plugin&gt;
        &lt;artifactId&gt;maven-ear-plugin&lt;/artifactId&gt;
        &lt;configuration&gt;
          &lt;modules&gt;
            &lt;webModule&gt;
              &lt;groupId&gt;com.krzysztofadamczyk.playground.springmetrodemo&lt;/groupId&gt;
              &lt;artifactId&gt;services&lt;/artifactId&gt;
              &lt;contextRoot&gt;/spring-metro-webservices&lt;/contextRoot&gt;
            &lt;/webModule&gt;
          &lt;/modules&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;
  &lt;/build&gt;</pre>
<p><span style="font-size:14pt;"><strong>Step 4 &#8211; prepare contracts</strong></span></p>
<p>Now as our project structure is more or less done we can focus on preparing contracts for the web service. In this example we will create a simple echo service which simply returns the given string with &#8220;echo&#8221; prefix. Types are defined into EchoTypes.xsd file:</p>
<pre class="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema"
	targetNamespace="http://www.krzysztofadamczyk.com/echo/" xmlns:tns="http://www.krzysztofadamczyk.com/echo/"
	elementFormDefault="qualified"&gt;

	&lt;xs:element name="EchoRequest"&gt;
		&lt;xs:complexType&gt;
			&lt;xs:all&gt;
				&lt;xs:element name="text" type="xs:string" /&gt;
			&lt;/xs:all&gt;
		&lt;/xs:complexType&gt;
	&lt;/xs:element&gt;

	&lt;xs:element name="EchoResponse"&gt;
		&lt;xs:complexType&gt;
			&lt;xs:all&gt;
				&lt;xs:element name="text" type="xs:string" /&gt;
			&lt;/xs:all&gt;
		&lt;/xs:complexType&gt;
	&lt;/xs:element&gt;
&lt;/schema&gt;</pre>
<p>The WSDL file is presented below:</p>
<pre class="xml">&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;
&lt;wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
	xmlns:tns="http://www.krzysztofadamczyk.com/echo/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
	xmlns:echo="http://www.krzysztofadamczyk.com/echo/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
	name="echo" targetNamespace="http://www.krzysztofadamczyk.com/echo/"&gt;
	&lt;wsdl:types&gt;
		&lt;xsd:schema&gt;
			&lt;xsd:import namespace="http://www.krzysztofadamczyk.com/echo/"
				schemaLocation="EchoTypes.xsd" /&gt;
		&lt;/xsd:schema&gt;
	&lt;/wsdl:types&gt;

	&lt;wsdl:message name="EchoRequest"&gt;
		&lt;wsdl:part name="EchoRequest" element="echo:EchoRequest" /&gt;
	&lt;/wsdl:message&gt;
	&lt;wsdl:message name="EchoResponse"&gt;
		&lt;wsdl:part name="EchoResponse" element="echo:EchoResponse"  /&gt;
	&lt;/wsdl:message&gt;

	&lt;wsdl:portType name="EchoPort"&gt;
		&lt;wsdl:operation name="sayEcho"&gt;
			&lt;wsdl:input message="tns:EchoRequest" /&gt;
			&lt;wsdl:output message="tns:EchoResponse" /&gt;
		&lt;/wsdl:operation&gt;
	&lt;/wsdl:portType&gt;

	&lt;wsdl:binding name="echoSOAP" type="tns:EchoPort"&gt;
		&lt;soap:binding style="document"
			transport="http://schemas.xmlsoap.org/soap/http" /&gt;
		&lt;wsdl:operation name="sayEcho"&gt;
			&lt;soap:operation soapAction="http://www.krzysztofadamczyk.com/echo/SayEcho" /&gt;
			&lt;wsdl:input&gt;
				&lt;soap:body use="literal" /&gt;
			&lt;/wsdl:input&gt;
			&lt;wsdl:output&gt;
				&lt;soap:body use="literal" /&gt;
			&lt;/wsdl:output&gt;
		&lt;/wsdl:operation&gt;
	&lt;/wsdl:binding&gt;
	&lt;wsdl:service name="EchoService"&gt;
		&lt;wsdl:port binding="tns:echoSOAP" name="echoSOAP"&gt;
			&lt;soap:address location="http://www.example.org/" /&gt;
		&lt;/wsdl:port&gt;
	&lt;/wsdl:service&gt;
&lt;/wsdl:definitions&gt;</pre>
<p><span style="font-size:14pt;"><strong>Step 5 &#8211; create service endpoint implementation</strong></span></p>
<p>After building the project with <strong>mvn install</strong> you can see a few Java classes generated in target\generated-sources\. EchoPort is our generated Service Endpoint Interface. We will now create the service implementation as follows:</p>
<pre class="java">package com.krzysztofadamczyk.playground.springmetrodemo;

import javax.jws.WebService;

import com.krzysztofadamczyk.echo.EchoPort;
import com.krzysztofadamczyk.echo.EchoRequest;
import com.krzysztofadamczyk.echo.EchoResponse;

@WebService(name = "EchoPort", targetNamespace = "http://www.krzysztofadamczyk.com/echo/",
endpointInterface = "com.krzysztofadamczyk.echo.EchoPort")
public class EchoServiceImpl implements EchoPort {

    public EchoResponse sayEcho(final EchoRequest echoRequest) {
        final EchoResponse result = new EchoResponse();
        result.setText("echo: " + echoRequest.getText());
        return result;
    }
}</pre>
<p><span style="font-size:14pt;"><strong>Step 6 &#8211; define application context</strong></span></p>
<p>Now it&#8217;s time to define application context. Here we take advantage of JAXWS-Spring integration using specialized schema to define our web service. Note that our endpoint implementation is a standard Spring bean and we can use here dependency injection or any other Spring technique.</p>
<pre class="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:ws="http://jax-ws.dev.java.net/spring/core"
	xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"
	xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-2.0.xsd

	http://jax-ws.dev.java.net/spring/core http://jax-ws.dev.java.net/spring/core.xsd

http://jax-ws.dev.java.net/spring/servlet

        http://jax-ws.dev.java.net/spring/servlet.xsd"&gt;

	&lt;wss:binding url="/echoService"&gt;
		&lt;wss:service&gt;
			&lt;ws:service bean="#echoService" /&gt;
		&lt;/wss:service&gt;
	&lt;/wss:binding&gt;

	&lt;!-- this bean implements web service methods --&gt;
	&lt;bean id="echoService" class="com.krzysztofadamczyk.playground.springmetrodemo.EchoServiceImpl" /&gt;
&lt;/beans&gt;</pre>
<p><span style="font-size:14pt;"><strong>Step 7 &#8211; deploy and test project</strong></span></p>
<p>After successfull build, copy EAR file (which can be found in ear/target) into jboss_home/server/default/deploy, and start server. Run SoapUI and create new project with the following WSDL location:</p>
<pre class="plain">http://localhost:8080/spring-metro-webservices/echoService?wsdl</pre>
<p>Where:</p>
<ul>
<li>spring-metro-webservices &#8211; is the web application context root defined in EAR project pom</li>
<li>echoService &#8211; is an URL pattern (defined in web.xml, associated with WSSpringServlet), and also defined as binding URL in applicationContext.xml</li>
</ul>
<p>SoapUI will generate a sample request for you. The result looks as follows:</p>
<table style="width:auto;" border="0">
<tbody>
<tr>
<td><a href="http://picasaweb.google.com/lh/photo/_urXg7sNy54OiOMaDmPWUg?feat=embedwebsite"><img src="http://lh3.ggpht.com/_0zhWBYvrXoE/Suikb_aHriI/AAAAAAAAANc/XgDr8S3t5IY/s400/springmetro1.jpg" alt="" /></a></td>
</tr>
<tr>
<td style="font-family:arial,sans-serif;font-size:11px;text-align:right;">From <a href="http://picasaweb.google.com/krzysztof.adamczyk/Blog?feat=embedwebsite">Blog</a></td>
</tr>
</tbody>
</table>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/krzysztofadamczyk.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/krzysztofadamczyk.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/krzysztofadamczyk.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/krzysztofadamczyk.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/krzysztofadamczyk.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/krzysztofadamczyk.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/krzysztofadamczyk.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/krzysztofadamczyk.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/krzysztofadamczyk.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/krzysztofadamczyk.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/krzysztofadamczyk.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/krzysztofadamczyk.wordpress.com/35/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/krzysztofadamczyk.wordpress.com/35/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/krzysztofadamczyk.wordpress.com/35/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=krzysztofadamczyk.com&amp;blog=20688394&amp;post=35&amp;subd=krzysztofadamczyk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://krzysztofadamczyk.com/2009/11/27/contract-first-web-services-with-jboss-5-metro-spring/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ef9affbd5f509bd5d4d1ac20cf4651aa?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">krzysztofadamczyk</media:title>
		</media:content>

		<media:content url="http://lh3.ggpht.com/_0zhWBYvrXoE/Suikb_aHriI/AAAAAAAAANc/XgDr8S3t5IY/s400/springmetro1.jpg" medium="image" />
	</item>
	</channel>
</rss>
