0

I am currently trying to use embeded Tomcat for my application and am trying to set it up to get the URL of the http request.

Some Background:

I am using the same code as in the first answer for the post here : Howto embed Tomcat 6?

The only change I have made is :

private String   catalinaHome = "/home/xyz/tomcat"; // This dir is created and has full access permissions

Also , I am looking at: http://tomcat.apache.org/tomcat-5.5-doc/catalina/docs/api/org/apache/catalina/startup/Embedded.html

There are no server.xml and tomcat-users.xml that I could find, so I created a tomcat-users.xml since I was getting an exception :Memory database file /home/xyz/tomcat/conf/tomcat-users.xml cannot be read .

tomcat-users.xml:
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <user username="tomcat" password="tomcat" roles="tomcat"/>
  <user username="both" password="tomcat" roles="tomcat,role1"/>
  <user username="role1" password="tomcat" roles="role1"/>
</tomcat-users>

The code uses container.setRealm(new MemoryRealm()); It appears from here : http://tomcat.apache.org/tomcat-4.1-doc/catalina/funcspecs/fs-memory-realm.html that I should have a server.xml file and there should already be one created by default.

1] Do I need to create a server.xml, what should be the default in it ? I have put a file with default from here : http://www.akadia.com/download/soug/tomcat/html/tomcat_server_xml.html , but just want to know what is the right thing to do ?

2]When I access http://localhost:8089/mywebapp/index.html, all i get is The requested resource () is not available, though I have an index.html page at the "webappDir" in the code

3] My only need from the embedded tomcat is to intercept so as to get the URL passed to tomcat in my code. I can then parse the URL [do my stuff] and then create a http payload and send an http response back.

I would appreciate any pointers, especially for 3] ?

Thanks!

Community
  • 1
  • 1
codeObserver
  • 6,521
  • 16
  • 76
  • 121

2 Answers2

3

Ok, for your first question, yo do not need server.xml. If you check the code of your initial post they are setting the parameters there. So that is what server.xml would encapsulate. In reality what happens is that Tomcat will parse server.xml for the properties you are defining on your java file where you instanciate the catalina call to start. But since it is embedded you are setting all those parameters on you class instead.

For your second question, check your logs directory and see what is being parsed. Something is happening after your service starts because it should already redirect you once you call the port. either way, just try http://localhost:8089 and see what you get back in return from tomcat. It should give you some kind of response back from the server itself. if you do it like this "http://localhost:8089/mywebapp/index.html" you are trying to access a created context, and that might not be configured correctly, but that is just a guess right now.

Try this first and tell me what you get back. we can troubleshoot from this point and see if I can help more in that sense.

Truesky
  • 221
  • 2
  • 12
  • Thankx, that explains the 1] question. http://localhost:8089 just gives a blank page. This I assumed probably because there is no static file so it turns out blank. Also if you want to chat, I have made a new chat room so that we can discuss any questions in real time: http://chat.stackoverflow.com/rooms/709/tomcat . Thanks again. – codeObserver Apr 14 '11 at 05:31
  • i need you to approve my answer first. I am still new on stackoverflow, so I don't have enough reputation yet for chat. The approval will bump me up for it. – Truesky Apr 14 '11 at 05:33
  • I approved the answer, since that answered part 1] of the question – codeObserver Apr 14 '11 at 05:36
  • piece of C.... is not allowing me in for some weird reason. Anyways, what is the directory structure of the tomcat folder in the meantime while I figure out what is going on with the chat room. The directory structure should lead you to the right place of the file contect to place your index.html in that regards – Truesky Apr 14 '11 at 05:40
  • ok, can't make it work. I'll keep posting here to help you out. Maybe we can figure out what is going on. I was thinking that the webapps root is not the root context of the tomcat, or is not well defined on your class. I would start the troubleshooting there in the meantime. Because if the webpage came back empty is because there is no index.html file to refer to in that case. EDIT:: private String catalinaHome = "/home/xyz/tomcat"; that is your root tomcat instalation for embedded. try placing index inside tomcat and go back to localhost:8089 – Truesky Apr 14 '11 at 06:05
  • I had tried placing index inside tomcat directory as well as inside /home/xyz/mywebapp directory but it did not help. – codeObserver Apr 14 '11 at 06:14
  • what do you get when you put in http://localhost:8089/mywebapp is still the same error? – Truesky Apr 14 '11 at 06:16
  • My guess is this line here --> private String classesDir = "target/classes"; because everything else seems to be correct if you check the code of the main post. – Truesky Apr 14 '11 at 06:29
  • check this link out. it seems very similar to what you are trying. They are adding JNDI at the end, but you can get the idea. http://blog.jesc.ch/2009/05/29/embedding-tomcat-in-eclipse-with-maven-jndi-et-tutti-quanti/ – Truesky Apr 14 '11 at 06:41
  • thnkx. Apparently we decided to not go with embedded tomcat for now. Thanks for your help though. I had some question related to pipelining , probably you have some insights there : http://stackoverflow.com/questions/5748897/pipelining-in-tomcat – codeObserver Apr 21 '11 at 19:45
0

Quick question, is this windows or linux you are installing on? If it is linux the configurations filea are located usually on /etc/tomcat6. (at least on ubuntu they are). Reply back with the version you have installed. I might be able to help you out. I guess I should also elaborate here a little more. Tomcat is a service in linux as well, so in ubuntu you have to start tomcat in order to access it.

$: sudo service tomcat6 start

then it starts tomcat on port 8080 (usually if not changed) of your localhost. hence you type localhost:8080 to access the website for configuration of tomcat that gives you a It works prompt for you. Let me know if you have more questions, I will try to respond to the best of my knowledge

Truesky
  • 221
  • 2
  • 12
  • Thnx Truesky for the reply. I am using RedHat Linux. – codeObserver Apr 14 '11 at 04:49
  • What version of RHL are you using? – Truesky Apr 14 '11 at 04:54
  • Thnx Truesky for the replying to my post. I want to make sure that I stress that I am using embedded Tomcat and not actually doing a Tomcat installation, when I run the code I am able to start the service. From the code I pointed in my post, I am using port 8089. I would really appreciate if you can answer my question 1] and 2] . above . Thanks again for looking .. – codeObserver Apr 14 '11 at 05:06
  • I am using Red Hat Enterprise Linux Client release 5.4 (Tikanga) – codeObserver Apr 14 '11 at 05:07
  • not a Problem, I was just trying to get a background of the system you are working on since there could be a couple different ways to do things in that sense. I am doing a quick readup on the embedded tomcat to answer your question as best as I can to try to guide you on what you are trying to do. gimme a few minutes while I do so. – Truesky Apr 14 '11 at 05:12