url path parameter with % sign - java

I am using rg.glassfish.jersey.server.ApplicationHandler
need to capture the url path
URL: video/Id19%2Fabc%3D/title?sub=CDA
I have tried the following to capture but this doesn't capture % sign.
#Path("/video/{Id:.*}/title/")

Is this what you're looking for?
https://regex101.com/r/qYs7gQ/3
Regex: video\/Id(?<ID>.*)\/title

I found a way to handle URL encoding request. It is handled on Application server level and in my case, it is apache tomcat. So all I need to do is set
org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true in catalina.properties file.

Related

Request returning 400 bad request in Tomcat 8

I have a Java Web application deployed in tomcat.
I receive 400 Bad request from Tomcat 8 if my URL is like this
https://<serverurl>?cmisSelector=object&objectId=TyNGT0wjJSMwMDAjMDAjIyMj&filter=cmis:createdBy,a:b:ab,a:b:abc&renditionFilter=cmis:thumbnail,application/pdf,image/bmp,image/gif,image/jpeg,image/png
Which is encoded as
https%3A%2F%2F%3Cserverurl%3E%3FcmisSelector%3Dobject%26objectId%3DTyNGT0wjJSMwMDAjMDAjIyMj%26filter%3Dcmis%3AcreatedBy%2Ca%3Ab%3Aab%2Ca%3Ab%3Aabc%26renditionFilter%3Dcmis%3Athumbnail%2Capplication%2Fpdf%2Cimage%2Fbmp%2Cimage%2Fgif%2Cimage%2Fjpeg%2Cimage%2Fpng
But if i remove the a:b:ab,a:b:abc and renditionFilter=cmis:thumbnail,application/pdf,image/bmp,image/gif,image/jpeg,image/png from the URL then the it works, this URL is formed like below
https://<serverurl>?cmisSelector=object&objectId=TyNGT0wjJSMwMDAjMDAjIyMj&filter=cmis:createdBy
Seems to be some URL encoding issue but not able to find out the exact issue.
By default Tomcat returns a HTTP Bad Request (400) if the URL contains a forward or backward slash / (%2F) and \ (%5C) respectively. This is done as a security measure.
You can disable that feature and allow those characters by setting the following system properties (for instance in catalina.properties or in CATALINA_OPTS):
-Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true
### You may not need this one, as you only have forward slashes
-Dorg.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH=true

URL works when append #

I have a url which is not working when i tried hitting it directly, but it works when I append /# to the url.
But for QA when I hit the url it is working where it automatically adding the /# and goes to required login page. In QA it was manually deployed not through VSTS pipeline
Actual url(not Working): https://<applicationurl>.azurewebsites.net
URL(working one): https://<applicationurl>.azurewebsites.net/#
Deployment: VSTS build and release
Hosting: Azure App Service
Application: Java, Angular6
In Java a URI of the form "http://x.y.z" has a null path.
A URI of the form "http://x.y.z/" has an absolute path which is "/".
Some browsers will automatically correct an URL by appending "/" if the URL does not have a path, but programmatic interfaces and servers may not.
I suspect that what you describe is just a user error - you need to make sure the input URL has a path. This is what happens when you append "/#" - but I don't think the # makes any difference (that's just adding an empty fragment).

How to make jboss accept %2F encoded slash in URL path

URL:http://localhost:8080/admin/users/8VHlQMoMAeGAfwADT%2FtM2Q%3D%3D
When i try to hit the above URL using advanced rest client, i am getting 400:Bad Request.
I need special characters to be passed in URl path via URL encoding only. But %2F is not being accepted.How to enable jboss to accept encoded slash in url? kindly help.
First of all you have to know that JBoss by default is not allowing the escaped slashes in paths for security reasons.
However you can set the following system property to true
org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH

How to add Context Path to request URI?

The default path of my app is localhost:8080/myapp .
If I click something on the page which is supposed to redirect me to localhost:8080/myapp/page1 I get 404 back (The requested resource is not available.)
because the actual request made is localhost:8080/page1 .
Fair enough, my RequestMapping is "/page1".
The question is how do I enforce the contextpath as a prefix to all requests ?
What is the best way to deal with this ?
P.S. I don't want to rename my app to Root
I recommend using JSTL.
for example.
LINK

Get Absolute path of a url in java

Is there a way to retrieve the absolute path of url (http://localhost:8080/myApp) in java. The scenario is, i need to connect to csv file located in tomcat server. The statement works well if I enter the absolute path, but is there a solution to retrieve url's path using getAbsolutePath().Sorry if I'm wrong.
Connection conn = DriverManager(getConnection("jdbc:relique:csv:/home/apache-tomcat-6.0.26/webapps/myApp/"))
Thanks in advance.
You can use ServletContext.getRealPath(), which does exactly what you want.
Note that it does not necessarily work in all situations. For example, if your Tomcat is configured to deploy the .war file without unpacking it, then this will return null.
I don't know much about JAVA.
May be getServletContext().getContextPath() is something you are looking for
EDIT:
Or may be getRealPath()
Tomcat is not a http server. All tomcat urls reference services, not files.
You'll have to implement another service that sends the csv file on request, if you want to get it through any http URL. URL's like http://localhost/myapp/input.csv require a http server like apache httpd.
(Hope I got your question correct...)

Categories