<?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/"
	>

<channel>
	<title>Frank&#039;s Java Development Blog &#187; JBoss</title>
	<atom:link href="http://javablog.franksalinas.net/category/jboss/feed/" rel="self" type="application/rss+xml" />
	<link>http://javablog.franksalinas.net</link>
	<description>Java Enterprise Development &#38; Technology</description>
	<lastBuildDate>Sat, 24 Jul 2010 17:06:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Java Web Services: Getting Started</title>
		<link>http://javablog.franksalinas.net/2010/03/09/java-web-services-getting-started/</link>
		<comments>http://javablog.franksalinas.net/2010/03/09/java-web-services-getting-started/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 04:49:22 +0000</pubDate>
		<dc:creator>Frank Salinas</dc:creator>
				<category><![CDATA[JBoss]]></category>
		<category><![CDATA[JEE]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[EJB]]></category>
		<category><![CDATA[JAX-RPC]]></category>
		<category><![CDATA[JAX-WS]]></category>
		<category><![CDATA[POJO]]></category>
		<category><![CDATA[Servlet]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[WSDL]]></category>

		<guid isPermaLink="false">http://javablog.franksalinas.net/?p=640</guid>
		<description><![CDATA[When it came time for me to tackle my first web service implementation I ran into a lot of problems. Here I will write a series of articles to address the questions and problems I encountered in hopes of helping you get started in developing web services faster than I did. The following example will show [...]


Related posts:<ol><li><a href='http://javablog.franksalinas.net/2008/10/29/web-services-on-jboss/' rel='bookmark' title='Permanent Link: Web Services on JBoss'>Web Services on JBoss</a> <small>I&#8217;ve been working on a project which requires developing some...</small></li>
<li><a href='http://javablog.franksalinas.net/2009/03/01/the-ejb-specification-concurrency-and-batch-processing/' rel='bookmark' title='Permanent Link: The EJB Specification, Concurrency, and Batch Processing'>The EJB Specification, Concurrency, and Batch Processing</a> <small>The EJB specification does not leave much room for implementing...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>When it came time for me to tackle my first web service implementation I ran into a lot of problems. Here I will write a series of articles to address the questions and problems I encountered in hopes of helping you get started in developing web services faster than I did. The following example will show you how to create a web service using JAX-WS and packaged as a servlet.<span id="more-640"></span></p>
<h4>A Simple Service</h4>
<p>To start out you <span style="text-decoration: underline;">should</span> create an interface defining your business methods. I will keep the implementation extremely simple so we can focus on the details of web services. Here&#8217;s our interface named <code>SimpleServiceWS</code></p>
<pre class="brush:java; smart-tabs:true; wrap-lines:false">public interface SimpleServiceWS {

	public String simpleMethod();

}</pre>
<p>The next step is to create a plain java class (POJO) which implements this interface. I&#8217;ll name it <code>SimpleServiceImpl</code></p>
<pre class="brush:java; smart-tabs:true; wrap-lines:false">public class SimpleServiceImpl implements SimpleServiceWS {

	public String simpleMethod() {
		return "Simple response";
	}

}</pre>
<p><em><span style="color: #808080;"><span style="color: #000000;">Please note that it is not required to create and implement an interface and almost every web service example I found did not do so. I feel it is good practice and consistent with Java programming practices to program against interfaces.</span></span></em></p>
<p>What we have so far is just a plain Java class (POJO) that returns a simple string. Now we have to decorate our class with some annotations to make it behave as a web services.</p>
<pre class="brush:java; smart-tabs:true; wrap-lines:false">import javax.jws.WebService;

@WebService(
		serviceName="SimpleService",
		portName="SimpleServicePort",
		endpointInterface="net.franksalinas.javablog.SimpleServiceWS")
public class SimpleServiceImpl implements SimpleServiceWS {

	public String simpleMethod() {
		return "Simple response";
	}

}</pre>
<p>I added the <code>@WebService</code> annotation and supplied some values to the annotation attributes. You can simply add the <code>@WebService</code> annotation without specifying any of the attributes and they will pick up default values based on the class and package names. However, there is one exception. If you choose to define and implement an interface you must do two things:</p>
<ol>
<li>You must decorate the interface with the <code>@WebService</code> annotation.</li>
<li>You must also supply the <code>endpointInterface</code> annotation attribute with the fully qualified name of the interface in the implementation class.</li>
</ol>
<pre class="brush:java; smart-tabs:true; wrap-lines:false">import javax.jws.WebService;

@WebService()
public interface SimpleServiceWS {

	public String simpleMethod();

}</pre>
<p>As far as code goes this is all there is to it. The remaing steps describe how to package and deploy these objects.</p>
<h4>Package and Deploy</h4>
<p>As I mentioned above we will package and deploy these classes as a servlet implementation. I am most familiar with JBoss so that is the application server I will use but any servlet container should work fine.</p>
<p>Create a new xml file named <code>web.xml</code> and define the servlet mappings for the <code>SimpleServiceImpl</code> class as shown here.</p>
<pre class="brush:xml; smart-tabs:true; wrap-lines:false">&lt;?xml version="&gt;&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&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;servlet&gt;
		&lt;servlet-name&gt;SimpleServiceWS&lt;/servlet-name&gt;
		&lt;servlet-class&gt;net.franksalinas.javablog.SimpleServiceImpl&lt;/servlet-class&gt;
	&lt;/servlet&gt;

	&lt;servlet-mapping&gt;
		&lt;servlet-name&gt;SimpleServiceWS&lt;/servlet-name&gt;
		&lt;url-pattern&gt;/SimpleService&lt;/url-pattern&gt;
	&lt;/servlet-mapping&gt;
&lt;/web-app&gt;</pre>
<p>Now create a <code>WEB-INF</code> directory and place this file there. Compile your Java files and place them in a folder named <code>classes</code>. Create a folder named <code>dist</code>. Copy the <code>WEB-INF</code> and <code>classes</code> directory to this new folder. Now create a JAR file named <code>SimpleService.war</code> containing the contents of <code>dist</code> directory. (Visit <a title="Sun WAR File Format (Wikipedia)" href="http://en.wikipedia.org/wiki/Sun_WAR_(file_format)" target="_blank">http://en.wikipedia.org/wiki/Sun_WAR_(file_format)</a> for more info on the WAR file structure.)</p>
<p>You should now have a WAR file with the following structure:</p>
<pre class="brush:xml; smart-tabs:true; wrap-lines:false">META-INF/
META-INF/MANIFEST.MF
WEB-INF/
WEB-INF/web.xml
classes/
classes/net/
classes/net/franksalinas/
classes/net/franksalinas/javablog/
classes/net/franksalinas/javablog/SimpleServiceImpl.class
classes/net/franksalinas/javablog/SimpleServiceWS.class</pre>
<p>Now you can copy this <code>SimpleService.war</code> file to your application server&#8217;s deployment directory <em>(&lt;jboss_home&gt;/server/default/deploy</em>) and start the server. Your web service will be deployed. On JBoss you can see the deployment and access the WSDL for the service at url http://127.0.0.1:8080/SimpleService/SimpleService?wsdl</p>
<p>That&#8217;s all there is to it!</p>
<p><em>Note that we did not implement the <code>javax.servlet.http.HttpServlet</code> interface in the service class. It is not required but may be considered good practice to do so depdending on your implementation.</em></p>
<h4>Summary</h4>
<p>In this example we created a simple web service using JAX-WS and packaged and deployed the implementation as a servlet configuration. We learned that web services are nothing more than plain old Java objects (POJOs) that are decorated with a few simple annotations and that servlet configurations do not require the web service class to implement the <code>javax.servlet.http.HttpServlet</code> interface. We covered packaging the code as a WAR file and deploying on the JBoss application server.</p>
<p>This is a very simple example and there&#8217;s a lot more material to cover. I hope you found this posting informative and helpful. You can download all the source code for this example here: <a href="http://javablog.franksalinas.net/wp-content/uploads/2010/02/SimpleService.zip">SimpleService.zip</a>.</p>
<p><a title="Sun WAR File Format (Wikipedia)" href="http://en.wikipedia.org/wiki/Sun_WAR_(file_format)" target="_blank"></a></p>

<div style="font-size:0px;height:0px;line-height:0px;margin:0;padding:0;clear:both"></div>

<p>Related posts:<ol><li><a href='http://javablog.franksalinas.net/2008/10/29/web-services-on-jboss/' rel='bookmark' title='Permanent Link: Web Services on JBoss'>Web Services on JBoss</a> <small>I&#8217;ve been working on a project which requires developing some...</small></li>
<li><a href='http://javablog.franksalinas.net/2009/03/01/the-ejb-specification-concurrency-and-batch-processing/' rel='bookmark' title='Permanent Link: The EJB Specification, Concurrency, and Batch Processing'>The EJB Specification, Concurrency, and Batch Processing</a> <small>The EJB specification does not leave much room for implementing...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://javablog.franksalinas.net/2010/03/09/java-web-services-getting-started/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The EJB Specification, Concurrency, and Batch Processing</title>
		<link>http://javablog.franksalinas.net/2009/03/01/the-ejb-specification-concurrency-and-batch-processing/</link>
		<comments>http://javablog.franksalinas.net/2009/03/01/the-ejb-specification-concurrency-and-batch-processing/#comments</comments>
		<pubDate>Sun, 01 Mar 2009 19:54:51 +0000</pubDate>
		<dc:creator>Frank Salinas</dc:creator>
				<category><![CDATA[JBoss]]></category>
		<category><![CDATA[JEE]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Batch Processing]]></category>
		<category><![CDATA[Concurrency]]></category>
		<category><![CDATA[EJB]]></category>
		<category><![CDATA[JMS]]></category>
		<category><![CDATA[Specifications]]></category>
		<category><![CDATA[ThreadPoolExecutor]]></category>
		<category><![CDATA[Threads]]></category>

		<guid isPermaLink="false">http://javablog.franksalinas.net/?p=211</guid>
		<description><![CDATA[The EJB specification does not leave much room for implementing concurrent processing within the EJB container. This poses a problem to developers who need to implement solutions for processing long running batch processes as part of the business logic of an application. The EJB specification states the following: The enterprise bean must not attempt to [...]


Related posts:<ol><li><a href='http://javablog.franksalinas.net/2010/03/09/java-web-services-getting-started/' rel='bookmark' title='Permanent Link: Java Web Services: Getting Started'>Java Web Services: Getting Started</a> <small>When it came time for me to tackle my first...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>The EJB specification does not leave much room for implementing concurrent processing within the EJB container. This poses a problem to developers who need to implement solutions for processing long running batch processes as part of the business logic of an application. The EJB specification states the following:</p>
<blockquote><p>The enterprise bean must not attempt to manage threads. The enterprise bean must not attempt to start, stop, suspend, or resume a thread, or to change a thread’s priority or name. The enterprise bean must not attempt to manage thread groups.</p>
<p><em>These functions are reserved for the EJB container. Allowing the enterprise bean to manage threads would decrease the container’s ability to properly manage the runtime environment.</em></p></blockquote>
<p><span id="more-211"></span>Researching this topic I found that while the specification states the restrictions, the EJB containers do not actually enforce the rule. I was able to test an implementation using a ThreadPoolExecutor in JBoss with no problems. Most implementations addressing long running batch processing solutions specify developing applications outside the EJB container. While the design respects the EJB programming restrictions it is not always a feasible solution for developers. Currently, I am confronted with business requirements to process a large set of files within the process flow of a business method.  The process flow would be to select files based on some criteria, specify what to do with the file collection, and submit the task asynchronously as a background process through JMS to a message-driven bean (MDB) for processing. When the job is done, update the database with the new file paths and notify the user of successful completion. There are several underlying issues:</p>
<ol>
<li>The user submits a request to process a very large set of files. The time to process this request may take hours to complete and will most-likely exceed the default configured transaction time-out of the message-driven bean at which point a TransactionTimeOut Exception is thrown and the operation halts. This can be overcome to a certain extent by increasing the transaction timeout period in the application server settings.</li>
<li>The single large task executes in a sequential manner, and does not take advantage of all available CPU&#8217;s on a multi-processor machine.</li>
<li>It would be more efficient and reduce execution time if the task could be broken up into smaller tasks (or batches) and executed in parallel, or distributed across a group of servers which can process each sub-task individually.</li>
</ol>
<p>The design concepts are relatively simple but the implementation details are complex due to the programming restrictions in the EJB specification. This screams concurrency! The most commonly suggested solution for concurrency is to use JMS. One solution I found is to break up the task, create multiple JMS messages that reply to an acknowledgment queue. Then set the Session Bean to listen to that ack queue using a message filter to collect the results of each sub-task. This is a good solution but a bit more complex to implement than bending the rules and using a ThreadPoolExecutor. I think the real issue with managing threads within the EJB container is the topic of <a href="http://www.oreillynet.com/cs/user/view/cs_msg/17107" target="_blank">reentrancy</a>. In my case, I am calling a remote service so there is no chance of that.</p>
<p>There are many factors to consider when implementing a batch processing framework for your application. There is no one size fits all solution. You really have to evaluate all the options, weigh the pros and cons of each, and decide on your own which approach works best in your environment. Here is a list of articles I found very helpful in making that decision:</p>
<ul>
<li><a title="High Performance Batch Processing" href="http://java.sys-con.com/node/415321" target="_blank">High Performance Batch Processing with Java Enterprise Edition</a></li>
<li><a href="http://www.javaworld.com/javaworld/jw-07-2003/jw-0718-mdb.html?page=1" target="_blank">Add Concurrent Processing with Message Driven Beans</a></li>
<li><a href="http://www.devx.com/Java/Article/20184/0/page/1" target="_blank">JMS Enables Concurrent Processing in EJB</a></li>
<li><a href="http://www.devx.com/java/article/20791" target="_blank">High Volume Transaction Processing in J2EE</a></li>
</ul>

<div style="font-size:0px;height:0px;line-height:0px;margin:0;padding:0;clear:both"></div>

<p>Related posts:<ol><li><a href='http://javablog.franksalinas.net/2010/03/09/java-web-services-getting-started/' rel='bookmark' title='Permanent Link: Java Web Services: Getting Started'>Java Web Services: Getting Started</a> <small>When it came time for me to tackle my first...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://javablog.franksalinas.net/2009/03/01/the-ejb-specification-concurrency-and-batch-processing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Web Services on JBoss</title>
		<link>http://javablog.franksalinas.net/2008/10/29/web-services-on-jboss/</link>
		<comments>http://javablog.franksalinas.net/2008/10/29/web-services-on-jboss/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 03:26:50 +0000</pubDate>
		<dc:creator>Frank Salinas</dc:creator>
				<category><![CDATA[JBoss]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JAX-RPC]]></category>
		<category><![CDATA[JAX-WS]]></category>
		<category><![CDATA[JBossWS]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://javablog.franksalinas.net/?p=45</guid>
		<description><![CDATA[I&#8217;ve been working on a project which requires developing some web service endpoints. This is the first time I&#8217;ve had to develop Java web services and I came across a couple of issues which slowed me down. I am using JBoss 4.0.5.GA which comes packaged with JBossWS 1.0.3.SP1. I started out by going through the [...]


Related posts:<ol><li><a href='http://javablog.franksalinas.net/2010/03/09/java-web-services-getting-started/' rel='bookmark' title='Permanent Link: Java Web Services: Getting Started'>Java Web Services: Getting Started</a> <small>When it came time for me to tackle my first...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a project which requires developing some web service endpoints. This is the first time I&#8217;ve had to develop Java web services and I came across a couple of issues which slowed me down. I am using JBoss 4.0.5.GA which comes packaged with JBossWS 1.0.3.SP1. I started out by going through the examples provided in <a href="http://docs.jboss.org/jbossas/jboss4guide/r5/html/ch12.html" target="_blank">Chapter 12 of the J2EE Users Guide</a> which helped me get a template for my project. As I attempted to expand my project with multiple service endpoints I received errors during deployment using JBossWS 1.0.3.SP1.  I decided to upgrade to JBossWS 1.2.1.GA which is packaged in the 4.2.3.GA certified distribution of JBoss Application Server. The upgrade solved some of my initial issues but introduced a couple more, some of which are not documented in the official JBossWS users guide.<span id="more-45"></span></p>
<p>It&#8217;s been a frustrating experience so far. I&#8217;ve spent the past week troubleshooting and prototyping various web service implementations with different versions of JBossWS rather than developing my application code. The issues have revolved primarily around different versions of JBossWS and deployment. For instance, I found that I could successfully deploy multiple web service endpoints configured as servlets on JBossWS 1.2.0.SP1 which I could not do in 1.0.3.SP1. That being fixed my next task was to refactor the code as EJB service endpoints. Prior to doing that I decided to upgrade JBossWS to version 1.2.1.GA. Logically it is a minor upgrade 1.2.0 to 1.2.1 and should just contain minor bug fixes. However, after upgrading and refractoring my service endpoints as stateless session beans I fired up JBoss to encounter this error:</p>
<p><strong>org.jboss.deployment.DeploymentException: Cannot create service endpoint; &#8211; nested throwable: (org.jboss.ws.WSException: Multiple context root not supported)</strong></p>
<p>I cut-and-paste the error into Google and shortly thereafter I stumbled upon the <a href="http://www.jboss.com/index.html?module=bb&amp;op=viewtopic&amp;p=4046101#4046101" target="_blank">answer</a>. Apparently, there was quite a major change in functionality between JBossWS 1.2.0 and 1.2.1 which is not documented very well.</p>
<blockquote><p>Posted: Wed May 16, 2007 07:55 AM    Post subject: Re: If I deploy more than one web service I get</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</p>
<p>Thanks for the valuable discussion. I will try to explain what changes between 1.2.0 and 1.2.1 are causing the problems you encounter.</p>
<p>1.) For EJB3 deployments we need to create a web app for HTTP invocations (obviously)</p>
<p>2.) EJB&#8217;s don&#8217;t contain web context information, so we derive it automagically.</p>
<p>3.) Until 1.2.0 the context name was derived from the ear/jar name.</p>
<p>4.) This changed with 1.2.1 to an algorithm that derives it from the bean class name</p>
<p>So what&#8217;s happening when you deploy a EJB3 jar that contains multiple beans?<br />
The default algorithm derives different context names for each bean in this deployment, which in turn we cannot use to setup the HTTP endpoint and thus throw an exception.</p>
<p>This also explains why the following did work:</p>
<p>@WebContext(contextRoot=&#8221;/beans&#8221;)</p>
<p>Unfortunately this is left out in the specs and thus has been changed many times.<br />
Until we a have a definite solution i suggest you refer to the @WebContext annotation, even though it&#8217;s not the most elegant solution.</p>
<p>&#8211;<br />
Heiko</p></blockquote>
<p>Finally an answer! Well sort of. I didn&#8217;t want to use the annotations. I found an alternative solution in the <a href="http://jbossws.jboss.org/mediawiki/index.php/JBossWS_FAQs#How_do_I_know_what_endpoint_address_is_being_used.3F" target="_blank">JBossWS FAQ</a> which described setting the context root explicitly but no information on how to set the context root. Some more searching and I found the <a href="http://www.jboss.org/community/docs/DOC-10309" target="_blank">DTD</a> for the jboss.xml file which described the XML tags required to set the web service context root. After adding these tags and specifying a context root I successfully deployed my multiple EJB endpoints.</p>
<p>Wow! That&#8217;s a lot of work and I haven&#8217;t written any of my own business logic yet. Needless to say these issues put me a bit behind schedule on my project. The examples provided in the <a href="http://docs.jboss.org/jbossas/jboss4guide/r5/html/ch12.html" target="_blank">JBoss J2EE  Guide</a> for creating web services are simple enough to follow and are good for getting started but that&#8217;s about it. The provided examples work on all of the above mentions versions of JBossWS but fail when you want to get a little more complex with your service. Notice the documentation only provides examples for creating web services that pass primitive types. What about passing custom types? What about passing an array or collection of custom types? None of this is covered and you must refer to outside books and resources to find the answers. In following post I plan to address these topics in detail.</p>

<div style="font-size:0px;height:0px;line-height:0px;margin:0;padding:0;clear:both"></div>

<p>Related posts:<ol><li><a href='http://javablog.franksalinas.net/2010/03/09/java-web-services-getting-started/' rel='bookmark' title='Permanent Link: Java Web Services: Getting Started'>Java Web Services: Getting Started</a> <small>When it came time for me to tackle my first...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://javablog.franksalinas.net/2008/10/29/web-services-on-jboss/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced) (user agent is rejected)

Served from: javablog.franksalinas.net @ 2010-09-06 09:15:53 -->