Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can I create a Web Service for an application that is constructed using Servlets and JSPs?

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am new to Web Services. I am trying to develop a web service that will interact with the servlets of an existing application.

Please let me know whether I need to use Restful Web Services for this purpose or not?

Also please provide some pointers of sample for such web services.

Thanks in advance.
 
Saloon Keeper
Posts: 7612
177
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does "interact" mean? Do both WS and web app run on the same server?

Whether a REST or SOAP WS is the better choice depends on lots of circumstances about which we know nothing. For example, what kinds of data are to be sent back and forth? What kinds of clients do you envision? What are your security requirements? etc.
 
H S Kumar
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:What does "interact" mean? Do both WS and web app run on the same server?

Whether a REST or SOAP WS is the better choice depends on lots of circumstances about which we know nothing. For example, what kinds of data are to be sent back and forth? What kinds of clients do you envision? What are your security requirements? etc.



Interact means that WS will send request to Servlet and Servlet will return HTTP response. And this response will be converted as SOAP response by WS.
Both WS and Webapp will run in same machine and in one other configuration will be there in which WS and webapp will run on different machine.

The kind of data i am sending is just username and passwords to Servlet. Further I will need to send an attachment also.
 
Tim Moores
Saloon Keeper
Posts: 7612
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This should be possible. The WS -whether it's implemented using SOAP or REST is immaterial- can access a servlet via an HTTP library like Apache HttpClient; that can handle file uploads (which is what I assume you mean by "attachement") as well.

Start by writing a standalone app that accesses the servlet using HttpClient. Once you have that, you can incorporate it into the WS.
 
H S Kumar
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:This should be possible. The WS -whether it's implemented using SOAP or REST is immaterial- can access a servlet via an HTTP library like Apache HttpClient; that can handle file uploads (which is what I assume you mean by "attachement") as well.

Start by writing a standalone app that accesses the servlet using HttpClient. Once you have that, you can incorporate it into the WS.



Please help me by giving some links(sample code or any online sample code) to develop a Http client that can send requests to Servlets
 
Tim Moores
Saloon Keeper
Posts: 7612
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not "a HTTP client" - Apache HttpClient, which a search will find quickly. Its web site has lots of documentation and example code.
 
H S Kumar
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:Not "a HTTP client" - Apache HttpClient, which a search will find quickly. Its web site has lots of documentation and example code.



Hi Tim,

I have made a Apache Http client. That is working fine. Here is the code :
package pack;

import org.apache.commons.httpclient.HttpException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import java.io.IOException;


public class HttpClentSample {
public static void main(String args[]) throws HttpException, IOException {

DefaultHttpClient client = new DefaultHttpClient();
System.out.println("Trace 1");
HttpGet get = new HttpGet("http://localhost:8080/18-JUNE-2012-HttpWS-2/ServletInsert");
System.out.println("Trace 2");
HttpResponse response = client.execute(get);
System.out.println("Trace 3");
HttpEntity entity = response.getEntity();

if (entity != null)
{
long len = entity.getContentLength();
if (len != -1 )
{
System.out.println(EntityUtils.toString(entity));
}
}
}
}




But When I try to create a web Service for this Apache HttpCleint file and create .aar file and try to upload the file on Axis-2, I got error ar "Faulty Service"

I am copying the error trace that comes on Axis-2 admin console :

Error: java.lang.NoClassDefFoundError: org/apache/http/client/methods/HttpUriRequest at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at org.apache.axis2.description.java2wsdl.DefaultSchemaGenerator.(DefaultSchemaGenerator.java:136) at org.apache.axis2.deployment.util.Utils.fillAxisService(Utils.java:499) at org.apache.axis2.deployment.ServiceBuilder.populateService(ServiceBuilder.java:386) at org.apache.axis2.deployment.repository.util.ArchiveReader.buildServiceGroup(ArchiveReader.java:101) at org.apache.axis2.deployment.repository.util.ArchiveReader.processServiceGroup(ArchiveReader.java:143) at org.apache.axis2.deployment.ServiceDeployer.deploy(ServiceDeployer.java:81) at org.apache.axis2.deployment.repository.util.DeploymentFileData.deploy(DeploymentFileData.java:136) at org.apache.axis2.deployment.DeploymentEngine.doDeploy(DeploymentEngine.java:659) at org.apache.axis2.deployment.repository.util.WSInfoList.update(WSInfoList.java:144) at org.apache.axis2.deployment.RepositoryListener.update(RepositoryListener.java:337) at org.apache.axis2.deployment.RepositoryListener.checkServices(RepositoryListener.java:241) at org.apache.axis2.deployment.RepositoryListener.startListener(RepositoryListener.java:331) at org.apache.axis2.deployment.scheduler.SchedulerTask.checkRepository(SchedulerTask.java:64) at org.apache.axis2.deployment.scheduler.SchedulerTask.run(SchedulerTask.java:71) at org.apache.axis2.deployment.scheduler.Scheduler$SchedulerTimerTask.run(Scheduler.java:90) at java.util.TimerThread.mainLoop(Unknown Source) at java.util.TimerThread.run(Unknown Source) Caused by: java.lang.ClassNotFoundException: Class Not found : org.apache.http.client.methods.HttpUriRequest at org.apache.axis2.deployment.DeploymentClassLoader.findClass(DeploymentClassLoader.java:86) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 19 more


Please help me in Creating a Web Service for Apache HTTP Client java program.
 
I like you because you always keep good, crunchy cereal in your pantry. This tiny ad agrees:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic