aspose file tools*
The moose likes Tomcat and the fly likes mapping a URL to a java class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "mapping a URL to a java class" Watch "mapping a URL to a java class" New topic
Author

mapping a URL to a java class

Erik Yuzwa
Greenhorn

Joined: Feb 28, 2008
Posts: 6
Hey all,

I'm trying to configure our Tomcat6 instance to map a URL request to a specific class within a jar file, and I'm having no luck thus far.

I've tried a few failed approaches, but I'm convincing myself a starting point for this communication is via the Context:



I've been hunting down anything I can find in the Tomcat documentation via google, but I can't see a way to do this...

Is it even possible?

thanks and much appreciate any help!
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Map it as a servlet or filter in web.xml.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61434
    
  67

You can't just do this willy-nilly.

You need to set up a proper web application, and the Java class being mapped needs to be a servlet.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Erik Yuzwa
Greenhorn

Joined: Feb 28, 2008
Posts: 6
Bauke Scholtz wrote:Map it as a servlet or filter in web.xml.


Thanks, that's a great idea. I thought I already went down this road, but maybe there's something I overlooked in the servlet/filter tag
docs?
Erik Yuzwa
Greenhorn

Joined: Feb 28, 2008
Posts: 6
Bear Bibeault wrote:You can't just do this willy-nilly.

You need to set up a proper web application, and the Java class being mapped needs to be a servlet.


Thanks Bear,

Not sure if you're commenting on my original post, or the suggestion of the servlet / filter....

I'm supporting a vendor object that is currently being served by an ancient / no-longer-support application server. I'm just attempting to migrate it into Tomcat..
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Erik Yuzwa wrote:
Bauke Scholtz wrote:Map it as a servlet or filter in web.xml.


Thanks, that's a great idea. I thought I already went down this road, but maybe there's something I overlooked in the servlet/filter tag
docs?

Hard to say as you never told us something about the actual problem.
Erik Yuzwa
Greenhorn

Joined: Feb 28, 2008
Posts: 6
Sorry about that @Bauke

I don't want to "overpost", just because I don't want to bog this thread down with unneccessary information. I'll try to hyper-condense it.

problem: I have a URL request that needs to eventually find it's way to a specific Java object hosted by Tomcat: eg. /admin ---> com.foo.a

solution path:

1. Do nothing and hope for magic URL parsing by Tomcat. Result: unsuccessfull

2. Create a Servlet-Mapping within the web.xml of the Tomcat server. Result: unsuccessfull

3. Create a Filter mapping within the web.xml of the Tomcat server. Result: unsuccessfull

4. Create a new Context within the Tomcat server. Result: unsuccessfull

5. *new attempt* I'm changing focus to looking at the uriworkermap.properties definitions. Perhaps there's a way of defining the mapping there..

thanks again for any suggestions!



Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Sounds like that you need to enable the Tomcat's InvokerServlet.

Documentation here: http://tomcat.apache.org/tomcat-6.0-doc/funcspecs/fs-invoker.html

This is appserver specific stuff though. It won't work nor behave same on another appservers, so your webapp would be tight coupled to the appserver which may not be a good idea at all.

By the way, I should say that the InvokerServlet is by default disabled since Tomcat 5.5 due to security reasons. Please think twice about your design and choices.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
Why not just create a custom servlet that knows how to invoke the desired method in the class?

What does this class of yours produce that needs to go back to the client?

If the client side software is a browser, the servlet can provide the needed formatting to make an intelligible page.

Right off hand it looks like you are creating complexity where none needs to be.

Bill
 
Consider Paul's rocket mass heater.
 
subject: mapping a URL to a java class