I have an AXIS servlet which deployed on an apache tomcat server on windows.
I wrote a web service which I want to run on AXIS.
When I want to deploy my web service, I make a jar file from the classes, and then I copy them to "axis\WEB-INF\lib" directory. Then I deploy the web service using a wsdd file.
My question is - how can I pass parameters to the web service, and how can I read them?
The only web.xml file that I have, is the AXIS web.xml file. Should I put them there?
I came across with exactly same issue. I have a not so perfect solution. I am using a properties file to store params and access this properties file in the service classes. I am facing problem when I put all my classes in to a jar file. I am able to access properties file in my service class if I place properties file inside the jar file. I am unable to access properties file (without hardcoding the path) when I place it outside jar file. For maintainance point of view it is good practice to keep properties file accessible easyly.
-Rao
Related
I am working on a web application, developed using spring mvc and server is tomcat. Now one of the requirement is that admin can upload a spring related service configuration file(which is different from the spring service configuration file residing in src code) with some changes because we want to make it configurable. Now server will be restarted to get the modified changes.
Now I am confused about one thing, where I should upload this file(file system?) so that when server is started then configured listener will pick up new configuration file.
Pls suggest solution considering it as enterprose aplication.
Find out the reasonable place to keep your system files, other than in webapps/.
(I had kept next to log folder.)
Use Spring's PropertyPlaceholderConfigurer to read file locations from properties file.
Use same locations and Create ApplicationContext object, in a factory method (You can pass any number of files).
Use getBean on applicationContext object to use beans.
Dear fellow Developers,
I am working on improving my Java Web Services, and I am trying to use a more delicate way of getting the directory path of properties files in a Java Web Service.
In order to make my Java Web Application easier to be deployed on an Apache Tomcat Server, I add the following line to the web.xml file:
<env-entry>
<env-entry-name>loggerPropertyFile</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>/Some/Long/Directory/File/Path/Which/May/Change/conf/LoggerInfo.properties</env-entry-value>
</env-entry>
As the above xml code depicts, I have placed a Properties file somewhere in the local Filesystem, and I want my Web Service to initialize its logger class, based on that configuration. As you can realize this path changes every time I deploy my web service to another server.
Thus, I figured out that I may be able to use the $CATALINA_BASE property, in order to make the environment entry path smaller. How can I retrieve the CATALINA_BASE value from inside my Java Web Service's Code (how is done on Linux and how is done on Windows)??
Thank you.
try System.getProperty("catalina.base");
I'm trying to run a website using Tomcat and Eclipse. I created a Dynamic Web Project, I configured web.xml file and I also used Maven. In a directory src/main/webapp I put an index.html file. I also made a simple REST service in the same project. So this REST service is working for me (for example, when I put "http://localhost:8080/RESTfulService/rest/item" in an address bar. But what is the address that I should write to get an access to a website I put in a webapp folder? I thought "http://localhost:8080/RESTfulService/" should be working, but it's not.
From what i understand of your setup, try "http://localhost:8080/index.html". Do you have a context path called 'RESTfulService' setup?
Do you have a context element listed in your server.xml? If so, what does it say?
I am attempting to do some xml marshalling from with spring/tomcat ... my app is deployed as normal as a war file. The file is indeed copied to the correct location WEB-INF/classes/myData.xml but I am unsure how to access this from with Java and specifically my spring service layer. As normally I access files from with the app context itself.
I want to do this :
final File xml = new File("WEB-INF/classes/myData.xml");
but in my dev build it goes to F:\eclipse\WEB-INF\classes\myData.xml and not the deployment directory inside tomcat
In Spring, a clean way to do this with Java is using ClasspathResource:
Resource myData = new ClasspathResource("myData.xml"):
Alternatively, if this is a Spring bean doing the work, then you can inject it from XML, e.g.
<property name="myResource" value="classpath:myData.xml"/>
... assuming that myResource is a javabean property on your Spring bean of type Resource.
The WEB-INF/classes directory is automatically on the server's classpath, you don't need to (not should you) specify that in the path explicitly.
The Spring Resource interface offers various ways to get hold of the data itself (e.g. getInputStream())
If you are determined to get the path leading to your resource, you can retrieve its URL and then parse it, like this:
URL url = getClass().getResource("/WEB-INF/web.xml");
String path = url.toString();
if (path.startsWith("file:/")) {
path = path.substring("file:/".length());
File file = new File(path);
...do something with the file...
}
There is, however, a caveat: your resource may be read directly from the JAR archive, not from a flat file in your filesystem, and thus not really accessible via a File object. The above snipped worked in JBoss (which includes Tomcat), but JBoss explodes a WAR archive before deploying it - not sure if a pure Tomcat will do this as well.
The main question is: why would you really want to get the resource in the form of a File object? Maybe getting its URL is enough for you? Or maybe you just need read access?
If all you need is read access, the simplest way to get any resource on your classpath (like the above web.xml) is by simply calling:
InputStream in = getClass().getResourceAsStream("/WEB-INF/web.xml")
If you want write access to the file, a much better solution would be to pre-configure a directory (for example, via the web.xml), unpack all your needed files there (for example, via the above getResourceAsStream method) and then edit and access them from your predefined directory which is independent from your application server.
Specifically, is it more or less secure having the file on the outside?
This is assuming you put the configuration files in the root directory (of the web server). And that there are only standard restrictions to files applied (no special lock down tools).
Depends on where you put your configuration files in your WAR. In you put it in WEB-INF or META-INF you will not be able route to those files.
/app/WEB-INF/web.xml gives a HTTP 404.
Unless there is some other exploit that would allow someone access to files on the server, I would say its no more secure in the WAR in the right place then outside the WAR file.
Yes it can be secure, although I would not use the root directory of the web server.
Typically a web server is configured to run as its own user (for instance, tomcat on Linux runs as user tomcat). So if the file can only be read by tomcat only the web server can access it.
You can use Context.xml in tomcat's conf directory to either directly inject the settings in the applications context, or add a property there pointing to the file location. That way the location need not be fixed.