Solved

set up jar file as web service

Posted on 2004-09-28
5
164 Views
Last Modified: 2013-11-24
Hello all,

I have created a jar program that takes two required parameters and two optional parameters.  From the DOS command line editor, it works great.  However, the whole reason of creating the program was to turn it into a web service.  This program will not be run from a browser but I need it to accept the parameters from user input (in a browser) and then run on the web server itself.  Any clues as to where I can start?

My web server is IIS 5.0 running on a WinXP machine.

Any help is appreciated.

Thanks.
0
Comment
Question by:dds110
  • 2
  • 2
5 Comments
 
LVL 4

Expert Comment

by:gdrnec
Comment Utility
Not sure exectly what you mean by not be run from a browser. I guess you mean not client side (applet style).

Eaiest way to start is to download tomcat from www.apache.org and install it as a connector with IIS and deploy your jar there. Of course, to run as a web service, you will need to wrap your code in a servlet so that Tomcat can execute it.

As far as creating servlets go, I would look at http://www.java.sun.com and check out the tutorials. Pretty simple though.

If you need more help, come back.

Geoff
0
 
LVL 8

Author Comment

by:dds110
Comment Utility
OK, maybe web service was the wrong phrase to use.  Basically, I need a CGI program.  A program that will take parameters passed to it via server variables and then run.
0
 
LVL 4

Accepted Solution

by:
gdrnec earned 250 total points
Comment Utility
Right, I figured that was what you were getting at.

If your code is already in java, you might as well proceed down that path.

Installing Tomcat is relatively easy and getting IIS to talk to it is pretty simple as well, just connect over 8080.

To change what you have in your jar (probably a class with a main method) to something that Tomcat likes is quite simple. Just create a servlet (extend javax.servlet.http.HttpServlet and call your class's methods from the doPost/doGet methods. Any response you want to send back to the browser just gets written to the javax.servlet.ServletResponse.getWriter().

When you re package your jar will need to package like a web app and have a web-inf directory that holds a web.xml file that looks like the following and a classes directory that holds your servlet and other classes pointed to by the web.xml file.

Other than that, nothing to it. More information at www.java.sun.com

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

    <servlet>
        <servlet-name>LogViewerServlet</servlet-name>
        <servlet-class>com.loadsaenergy.awthandheld.server.LogViewerServlet</servlet-class>
    </servlet>    
                         
    <servlet-mapping>
        <servlet-name>LogViewerServlet</servlet-name>
        <url-pattern>/viewlogs</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
      <welcome-file>
            index.html
        </welcome-file>
    </welcome-file-list>

</web-app>



Hope this helps.

Geoff
0
 
LVL 8

Author Comment

by:dds110
Comment Utility
This all seems a bit extreme just to be able to pass a few parameters to a jar file.  I've used Tomcat before and I agree that it is simple.  However, I don't think this is the road I want to travel down.  I've seen some articles that mention passing the server variables to a script file (windows batch or linux script) and then having the script file call on the jar.

I can assure you gdrnec that at this point, you are more than well-deserving of the points.  You've put a good bit of effort into your comments and I'm sure they work.  I was just looking for something a bit simpler.
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
> I've seen some articles that mention passing the server variables to a script file (windows batch or linux
> script) and then having the script file call on the jar.

you're still going to need something that accepts the requests, extracts the parameters, and calls the script.
If you don't want to use a servlet then you're probably asking the q in the wrong TA. The CGI TA may be more appropriate.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now