Skip to main content

New Java Tech Article: Web Service Simulation Using Servlets

Posted by editor on February 16, 2010 at 11:36 AM PST

We've just published a new article, in our Java Tech series: Web Service Simulation Using Servlets, by Adhir Mehta. In this article, Adhir demonstrates the concept of using servlets during the project development stage to simulate the responses that a live web service would provide. Adhir explains:

Web service simulation is a growing need for every web service based assignment. Many of the assignments do not have the ready-to-use web service available during development stage, so the developers try to write their own mock implementation.

Typically, the developers will write a simple web service that returns a properly formatted result, deploy it to a web server, and use the simple deployed service as part of their development test bed. However, it's time consuming to do this, especially if you need to simulate lots of different web services.

Adhir presents an alternative to this approach:

Let's go into the basics of web services and soap envelopes. The intended message resides in the soap body and is based on the message/content of the body; the response from the file system is picked up and can be returned to the caller. This task simply can be achieved with servlets using following steps.

  1. Extract the soap envelop from input stream.
  2. Retrieve the first node of soap body.
  3. Apply the algorithm to generate the response file name using input message. (I'll discuss one of the algorithm in following sections).
  4. Read the response from file system.
  5. Prepare the soap envelop and send it to the caller

Adhir presents and discusses a SOAP-based algorithm for generating a file name based on an input message, as an example application. Then he makes the algorithm configurable using XSD XML, and shows how to apply the code, resulting in the simulated web service.

If you're in a situation where you need to simulate web services as part of your development process, take a look at Adhir Mehta's Web Service Simulation Using Servlets. His SOAP and servlet based web service simulation method may save you and your team time and effort.

In Java Today, Neal Gafter discusses A Syntax Option for Project Lambda (Closures for Java):

It was noted recently on the Project Lambda mailing list that allowing arrays of function type would undermine the type system. The reason for this is a combination of Java's covariant arrays, the natural subtypes among function types (they are covariant on return type and contravariant on argument types), exception checking, and the erasure implementation of generics. We certainly can't remove covariant arrays or checked exceptions, and removing the subtype relationship among function types really reduces their utility. Unfortunately, it is almost certainly too late to reify generics too...

The NetBeans wiki is featuring JavaFXComposerNewInPreview2. The page contents include: JavaFX Shapes, Animations on States, Improved Data Support, JavaFX Effects, Colors, Templates, Charts (experimental), New Samples.

On Twitter oracletechnet reminds people who are interested the future of Java that they should "Remember to land at tomorrow at 10am PT for my live chat with Mark Reinhold. We want your questions!" That's 18:00 GMT.

In today's Weblogs, Fabrizio Giudici presents My Oracle wishes (1): SwingX:

With this post, I'm starting a short series of thoughts about what I hope Oracle will do for a set of popular Java APIs, that haven't been dealt in detail in their strategic keynote. Today I start with SwingX. I think it's really good to see Oracle's commitment with Java on the desktop, a thing that in the past Sun started to do, but near to the beginning of their decline. Now the initiative could have a better success with fresh resources, but there are many things to do...

Sahoo addresses the question of How to embed GlassFish in an existing OSGi runtime?:

Typical users of GlassFish use GlassFish in a separate process and they start GlassFish by using commands like the following: java -jar glassfish.jar or asadmin start-domain. The above commands first launch an OSGi framework and then deploy the necessary bundles. What if you want to embed GlassFish in an existing OSGi runtime? The bootstrapping code was slightly complicated IMO. Recently when Apache Camel committer Charles Moulliard asked me some questions around embedding GlassFish v3 in an OSGi runtime, I decided to revisit the bootstrap module in order to simplify it so that I had less explaining to do...

Markus Karg presents Unicode™: Write Once, Read Nowhere:

Back in the early 80ies "of the past millenium" (As journalists call it these days - don't you feel as old as I do when reading that phrase? For me it is just "Childhood" and feels not so far ago. At least not a Millenium ago.), when I was a young boy, I teached myself BASIC programming on my father's Sinclair ZX Spectrum 48K and started coding small arcade games (what else will ten year old boys do with a micro computer? The web was not invented back then.). That wonder machine unfortunately had everything but not the possibility to do pixel or vector graphics in pure BASIC. You had to learn Assembler for that...

In the Forums, ossaert has a problem where Glasfish v3 Webservice does not work after restart: When I deploy a webservice to GFv3 then I can see the WSDL-file. When I restart the server, nothing comes (resource not found) until I restart the application manually. What is wrong with the Webservices? ...

In the Metro and JAXB forum, soysalyu is Rewriting a web service with Spring and JAXWS: Hello, I am trying to re-write a web service which is build by Weblogic's jwsc task. Since there is a WSDL file created by Weblogic already, I have to preserve this WSDL and use it in my new web service. I am using Spring 3.0 and...

In the ME Interest forum, digitalsol has a General question regarding mobile browser apps: Hello all, I was wondering something, I've heard that there is a tendency to create browser applications directly which will run on the browser of any smart phone, instead of writing J2ME apps for example. Some people think this is the future...

Our current Spotlight is the Intel Software Network's Parallel Programming Talk: Parallel Programming Talk is a weekly broadcast topics related to parallel programming (including Java) for multicore processors. Listen to Parallel Programming Talk LIVE every Tuesday at 8:00AM Pacific Time on Blog Talk Radio. Watch Parallel Programming Talk LIVE every Tuesday at 8:00AM Pacific Time on Intel Software Network Television.

Our current Poll asks Do you think you'll be attending JavaOne 2010?. Voting will be open through the end of the week.

Our latest Feature Articles include Adhir Mehta's new Java Tech article, Web Service Simulatino Using Servlets; Maven Repository Managers for the Enterprise, by John Smart; and Jeff Friesen's Reading Newsfeeds in JavaFX with FeedRead.

The latest Java Mobility Podcast is Java Mobile Podcast 92: MIDP 3.0 in Depth: Tutorials and Demonstrations: Excerpts from the JavaOne 2009 MIDP 3.0 In Depth: Tutorials and Demonstrations session with Roger Riggs, Lakshmi Dontamsetti and Stan Kao.

Current and upcoming Java Events:

Registered users can submit event listings for the Events Page using our events submission form. All submissions go through an editorial review before being posted to the site.

Archives and Subscriptions: This blog is delivered weekdays as the Java Today RSS feed. Also, once this page is no longer featured as the front page of it will be archived along with other past issues in the Archive.

-- Kevin Farnham
O'Reilly Media
Twitter: @kevin_farnham