#Path("/assetViewCount/{path}")
above annotation can be used to retrive myValue into path for url like /assetViewCount/myValue.
How can I get myValue/nextValue from /assetViewCount/myValue/nextValue in path
Actually I found the solution to my problem, following annotation gives whatever there is after /assetViewCount/ into {path}
#Path("/assetViewCount/{path:.*}")
You can use an embedded parameter in Path like this:
#Path("/assetViewCount/{path}/nextValue")
Related
in jax-rs is it possible to send path param like this "http://localhost:8080/"?
I mean there is no problem when I want to send path param like "1" or "6". But how can I send this? "http://localhost:8080/"
#Edit
For example I've path like this:
/api/media/{url}
and I want to transfer http://localhost:8080/ under {url}
You can pass it by encoding all special characters using percent encoding. Recommended way is to pass as query parameter with percentage encoding
Say I have the URL:
http://185.112.249.77:9999/Api/Search?search=#9QLU9CY8
And then code:
String search = request.getParameter("search");
Then search is blank...
I need a way to get around this. The url is visited directly. Is there something I can do in Tomcat's config to make this work?
I tried replacing "#" with "%23" with a search.replace but that also didn't work.
Thanks!
That's because the '#' character is not part of the parameter but is a fragment identifier. So your parameter is actually empty
see this link to get more info about url params structure
[https://www.rfc-editor.org/rfc/rfc3986#section-3.5]
Or
[https://www.rfc-editor.org/rfc/rfc3986#appendix-A]
For the formal definition
If I have a directory called temp with the following files:
a_file1.jpg
a_file2.jpg
b_file1.jpg
b_file2.jpg
It's possible to get all files like this:
VFS.getManager().resolveFile("temp").getChildren();
But, what I actually want to do is get a_file1.jpg and a_file2.jpg. Maybe like:
VFS.getManager().resolveFile("temp/a*").getChildren();
But this throws an exception:
org.apache.commons.vfs.FileSystemException: Could not list the contents of "temp/a*" because it is not a folder.
So, does anyone know how to resolve a set of files based on a regex with VFS?
You could use the findFiles method, with a FileFilterSelector.
You'll need to create your own FileFilter that accepts the files that match your desired regex.
I am trying to load properties from a file (test.properties)
The code I use is as follows:
URL url = getClass().getResource("../resources/test.properties");
properties.load(url.openStream());
But when executing the second line I get a NPE. (null pointer exception)
I'm not sure what's wrong here... I have checked that the file exists at the location where URL points to...
Any help is appreciated....
The javadoc for Class.getResource(String) says:
Returns: a URL object or null if no resource with this name is found
Most likely, the problem is that getResource is not finding the resource it is looking for. I am very suspicious of the use of ".." in the resource name. The javadoc does not say that getResource treats "." or ".." path components as having special meaning.
It is also possible that properties is null ...
I could be wrong, but I don't believe you can use ".." like that in a call to getResource(). I suggest you try an "absolute" resource:
URL url = getClass().getResource("/path/to/resources/test.properties");
Is it perhaps the properties object that is null?
The answer to whether or not getResource will find your file depends on your system classloader. The classloader is called, but before the classloader is called, the following transformation is made on the string you pass in.
From the Class javadoc:
If the name begins with a '/' ('\u002f'), then the absolute name of
the resource is the portion of the name following the '/'.
Otherwise, the absolute name is of the following form:
modified_package_name/name
Where the modified_package_name is the package name of this object
with '/' substituted for '.' ('\u002e').
So, the question becomes: will the classloader you are using be able to resolve modified_package_name/../resources/test.properties?
getClass().getResource() resolves the resource relative to the given class. Try getClass().getClassLoader().getResource().
You can also use Apache's PropertiesConfiguration
In Java web application, Suppose if I want to get the InputStream of an XML file, which is placed in the CLASSPATH (i.e. inside the sources folder), how do I do it?
ClassLoader.getResourceAsStream().
As stated in the comment below, if you are in a multi-ClassLoader environment (such as unit testing, webapps, etc.) you may need to use Thread.currentThread().getContextClassLoader(). See http://stackoverflow.com/questions/2308188/getresourceasstream-vs-fileinputstream/2308388#comment21307593_2308388.
ClassLoader.class.getResourceAsStream("/path/file.ext");
That depends on where exactly the XML file is. Is it in the sources folder (in the "default package" or the "root") or in the same folder as the class?
In for former case, you must use "/file.xml" (note the leading slash) to find the file and it doesn't matter which class you use to try to locate it.
If the XML file is next to some class, SomeClass.class.getResourceAsStream() with just the filename is the way to go.
ClassLoader.class.getResourceAsStream("/path/to/your/xml") and make sure that your compile script is copying the xml file to where in your CLASSPATH.
someClassWithinYourSourceDir.getClass().getResourceAsStream();
Some of the "getResourceAsStream()" options in this answer didn't work for me, but this one did:
SomeClassWithinYourSourceDir.class.getClassLoader().getResourceAsStream("yourResource");
I tried proposed solution and forward slash in the file name did not work for me, example: ...().getResourceAsStream("/my.properties"); null was returned
Removing the slash worked: ....getResourceAsStream("my.properties");
Here is from doc API:
Before delegation, an absolute resource name is constructed from the given resource name using this algorithm:
If the name begins with a '/' ('\u002f'), then the absolute name of the resource is the portion of the name following the '/'.
Otherwise, the absolute name is of the following form:
modified_package_name/name
Where the modified_package_name is the package name of this object with '/' substituted for '.' ('\u002e').