You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by "Julien Wajsberg (JIRA)" <ji...@apache.org> on 2010/02/04 15:32:28 UTC

[jira] Created: (CXF-2652) UriInfo.getAbsolutePath throws "java.net.URISyntaxException: Illegal character in path" when there is an encoded space in the request URI

UriInfo.getAbsolutePath throws "java.net.URISyntaxException: Illegal character in path" when there is an encoded space in the request URI
-----------------------------------------------------------------------------------------------------------------------------------------

                 Key: CXF-2652
                 URL: https://issues.apache.org/jira/browse/CXF-2652
             Project: CXF
          Issue Type: Bug
          Components: JAX-RS
    Affects Versions: 2.2.6
         Environment: Used with Spring
            Reporter: Julien Wajsberg


I tried this simple code :

package mypackage;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;

@Path("uri")
public class UriService {
    @GET
    @Path("something/{id}")
    public void addSomething(String string, @Context UriInfo uriInfo, @PathParam("id") String id) {
    	System.out.println("getPath -> " + uriInfo.getPath());
    	System.out.println("getBasePath -> " + uriInfo.getBaseUri());
    	System.out.println("getAbsolutePath -> " + uriInfo.getBaseUri().resolve(uriInfo.getPath(false)));
    	System.out.println("getAbsolutePath -> " + uriInfo.getAbsolutePath());
    }
}

With a Spring-based setup and default beans.xml taken from the user guide.

Then we can use a normal browser .

With "http://localhost:9080/Uritest/rest/uri/something/3", we get in stdout :
getPath -> /uri/something/3
getBasePath -> http://localhost:9080/Uritest/rest
getAbsolutePath -> http://localhost:9080/uri/something/3
getAbsolutePath -> http://localhost:9080/Uritest/rest/uri/something/3

But with "http://localhost:9080/Uritest/rest/uri/something/3 4", we get an exception :
java.net.URISyntaxException: Illegal character in path at index 50: http://localhost:9080/Uritest/rest/uri/something/3 4

And in stdout :

getPath -> /uri/something/3 4
getBasePath -> http://localhost:9080/Uritest/rest
getAbsolutePath -> http://localhost:9080/uri/something/3%204

NB : in JAX-RS javadoc, it's said that "getAbsolutePath()" is a shortcut to uriInfo.getBase().resolve(uriInfo.getPath())", which is plain wrong, because :
1 - getBase doesn't exist, that's getBaseUri
2 -  getPath as returned by CXF begins with a slash ("/") so "resolve" doesn't do what we want here.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CXF-2652) UriInfo.getAbsolutePath throws "java.net.URISyntaxException: Illegal character in path" when there is an encoded space in the request URI

Posted by "Julien Wajsberg (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-2652?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12829651#action_12829651 ] 

Julien Wajsberg commented on CXF-2652:
--------------------------------------

Plese note that if getPath doesn't start with "/" and if getBaseUri ends with "/", we just need to do a "resolve". I'm not sure of what the spec says.

Though the easiest way could be to just use good old string concatenation ?

> UriInfo.getAbsolutePath throws "java.net.URISyntaxException: Illegal character in path" when there is an encoded space in the request URI
> -----------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-2652
>                 URL: https://issues.apache.org/jira/browse/CXF-2652
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.2.6
>         Environment: Used with Spring
>            Reporter: Julien Wajsberg
>
> I tried this simple code :
> {code}
> package mypackage;
> import javax.ws.rs.GET;
> import javax.ws.rs.Path;
> import javax.ws.rs.PathParam;
> import javax.ws.rs.core.Context;
> import javax.ws.rs.core.UriInfo;
> @Path("uri")
> public class UriService {
>     @GET
>     @Path("something/{id}")
>     public void addSomething(String string, @Context UriInfo uriInfo, @PathParam("id") String id) {
>     	System.out.println("getPath -> " + uriInfo.getPath());
>     	System.out.println("getBasePath -> " + uriInfo.getBaseUri());
>     	System.out.println("getAbsolutePath -> " + uriInfo.getBaseUri().resolve(uriInfo.getPath(false)));
>     	System.out.println("getAbsolutePath -> " + uriInfo.getAbsolutePath());
>     }
> }
> {code}
> With a Spring-based setup and default beans.xml taken from the user guide.
> Then we can use a normal browser .
> With "http://localhost:9080/Uritest/rest/uri/something/3", we get in stdout :
> {panel}
> getPath -> /uri/something/3
> getBasePath -> http://localhost:9080/Uritest/rest
> getAbsolutePath -> http://localhost:9080/uri/something/3
> getAbsolutePath -> http://localhost:9080/Uritest/rest/uri/something/3
> {panel}
> But with "http://localhost:9080/Uritest/rest/uri/something/3 4", we get an exception :
> {noformat}
> java.net.URISyntaxException: Illegal character in path at index 50: http://localhost:9080/Uritest/rest/uri/something/3 4
> {noformat}
> And in stdout :
> {panel}
> getPath -> /uri/something/3 4
> getBasePath -> http://localhost:9080/Uritest/rest
> getAbsolutePath -> http://localhost:9080/uri/something/3%204
> {panel}
> NB : in JAX-RS javadoc, it's said that "getAbsolutePath()" is a shortcut to uriInfo.getBase().resolve(uriInfo.getPath())", which is plain wrong, because :
> # getBase doesn't exist, that's getBaseUri
> # getPath as returned by CXF begins with a slash ("/") so "resolve" doesn't do what we want here. (maybe another bug ? tell me and I'll create another issue)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CXF-2652) UriInfo.getAbsolutePath throws "java.net.URISyntaxException: Illegal character in path" when there is an encoded space in the request URI

Posted by "Julien Wajsberg (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CXF-2652?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Julien Wajsberg updated CXF-2652:
---------------------------------

    Description: 
I tried this simple code :

{code}
package mypackage;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;

@Path("uri")
public class UriService {
    @GET
    @Path("something/{id}")
    public void addSomething(String string, @Context UriInfo uriInfo, @PathParam("id") String id) {
    	System.out.println("getPath -> " + uriInfo.getPath());
    	System.out.println("getBasePath -> " + uriInfo.getBaseUri());
    	System.out.println("getAbsolutePath -> " + uriInfo.getBaseUri().resolve(uriInfo.getPath(false)));
    	System.out.println("getAbsolutePath -> " + uriInfo.getAbsolutePath());
    }
}
{code}

With a Spring-based setup and default beans.xml taken from the user guide.

Then we can use a normal browser .

With "http://localhost:9080/Uritest/rest/uri/something/3", we get in stdout :
{panel}
getPath -> /uri/something/3
getBasePath -> http://localhost:9080/Uritest/rest
getAbsolutePath -> http://localhost:9080/uri/something/3
getAbsolutePath -> http://localhost:9080/Uritest/rest/uri/something/3
{panel}

But with "http://localhost:9080/Uritest/rest/uri/something/3 4", we get an exception :
{noformat}
java.net.URISyntaxException: Illegal character in path at index 50: http://localhost:9080/Uritest/rest/uri/something/3 4
{noformat}

And in stdout :

{panel}
getPath -> /uri/something/3 4
getBasePath -> http://localhost:9080/Uritest/rest
getAbsolutePath -> http://localhost:9080/uri/something/3%204
{panel}

NB : in JAX-RS javadoc, it's said that "getAbsolutePath()" is a shortcut to uriInfo.getBase().resolve(uriInfo.getPath())", which is plain wrong, because :
# getBase doesn't exist, that's getBaseUri
# getPath as returned by CXF begins with a slash ("/") so "resolve" doesn't do what we want here. (maybe another bug ? tell me and I'll create another issue)


  was:
I tried this simple code :

{code}
package mypackage;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;

@Path("uri")
public class UriService {
    @GET
    @Path("something/{id}")
    public void addSomething(String string, @Context UriInfo uriInfo, @PathParam("id") String id) {
    	System.out.println("getPath -> " + uriInfo.getPath());
    	System.out.println("getBasePath -> " + uriInfo.getBaseUri());
    	System.out.println("getAbsolutePath -> " + uriInfo.getBaseUri().resolve(uriInfo.getPath(false)));
    	System.out.println("getAbsolutePath -> " + uriInfo.getAbsolutePath());
    }
}
{code}

With a Spring-based setup and default beans.xml taken from the user guide.

Then we can use a normal browser .

With "http://localhost:9080/Uritest/rest/uri/something/3", we get in stdout :
{panel}
getPath -> /uri/something/3
getBasePath -> http://localhost:9080/Uritest/rest
getAbsolutePath -> http://localhost:9080/uri/something/3
getAbsolutePath -> http://localhost:9080/Uritest/rest/uri/something/3
{panel}

But with "http://localhost:9080/Uritest/rest/uri/something/3 4", we get an exception :
{noformat}
java.net.URISyntaxException: Illegal character in path at index 50: http://localhost:9080/Uritest/rest/uri/something/3 4
{noformat}

And in stdout :

{panel}
getPath -> /uri/something/3 4
getBasePath -> http://localhost:9080/Uritest/rest
getAbsolutePath -> http://localhost:9080/uri/something/3%204
{panel}

NB : in JAX-RS javadoc, it's said that "getAbsolutePath()" is a shortcut to uriInfo.getBase().resolve(uriInfo.getPath())", which is plain wrong, because :
# getBase doesn't exist, that's getBaseUri
# getPath as returned by CXF begins with a slash ("/") so "resolve" doesn't do what we want here.



> UriInfo.getAbsolutePath throws "java.net.URISyntaxException: Illegal character in path" when there is an encoded space in the request URI
> -----------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-2652
>                 URL: https://issues.apache.org/jira/browse/CXF-2652
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.2.6
>         Environment: Used with Spring
>            Reporter: Julien Wajsberg
>
> I tried this simple code :
> {code}
> package mypackage;
> import javax.ws.rs.GET;
> import javax.ws.rs.Path;
> import javax.ws.rs.PathParam;
> import javax.ws.rs.core.Context;
> import javax.ws.rs.core.UriInfo;
> @Path("uri")
> public class UriService {
>     @GET
>     @Path("something/{id}")
>     public void addSomething(String string, @Context UriInfo uriInfo, @PathParam("id") String id) {
>     	System.out.println("getPath -> " + uriInfo.getPath());
>     	System.out.println("getBasePath -> " + uriInfo.getBaseUri());
>     	System.out.println("getAbsolutePath -> " + uriInfo.getBaseUri().resolve(uriInfo.getPath(false)));
>     	System.out.println("getAbsolutePath -> " + uriInfo.getAbsolutePath());
>     }
> }
> {code}
> With a Spring-based setup and default beans.xml taken from the user guide.
> Then we can use a normal browser .
> With "http://localhost:9080/Uritest/rest/uri/something/3", we get in stdout :
> {panel}
> getPath -> /uri/something/3
> getBasePath -> http://localhost:9080/Uritest/rest
> getAbsolutePath -> http://localhost:9080/uri/something/3
> getAbsolutePath -> http://localhost:9080/Uritest/rest/uri/something/3
> {panel}
> But with "http://localhost:9080/Uritest/rest/uri/something/3 4", we get an exception :
> {noformat}
> java.net.URISyntaxException: Illegal character in path at index 50: http://localhost:9080/Uritest/rest/uri/something/3 4
> {noformat}
> And in stdout :
> {panel}
> getPath -> /uri/something/3 4
> getBasePath -> http://localhost:9080/Uritest/rest
> getAbsolutePath -> http://localhost:9080/uri/something/3%204
> {panel}
> NB : in JAX-RS javadoc, it's said that "getAbsolutePath()" is a shortcut to uriInfo.getBase().resolve(uriInfo.getPath())", which is plain wrong, because :
> # getBase doesn't exist, that's getBaseUri
> # getPath as returned by CXF begins with a slash ("/") so "resolve" doesn't do what we want here. (maybe another bug ? tell me and I'll create another issue)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CXF-2652) UriInfo.getAbsolutePath throws "java.net.URISyntaxException: Illegal character in path" when there is an encoded space in the request URI

Posted by "Sergey Beryozkin (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-2652?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12829619#action_12829619 ] 

Sergey Beryozkin commented on CXF-2652:
---------------------------------------

thanks, after looking at the code I can see UriInfo.getRequestURI will fail too if encoded chars are included....Will fix it shortly.



> UriInfo.getAbsolutePath throws "java.net.URISyntaxException: Illegal character in path" when there is an encoded space in the request URI
> -----------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-2652
>                 URL: https://issues.apache.org/jira/browse/CXF-2652
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.2.6
>         Environment: Used with Spring
>            Reporter: Julien Wajsberg
>
> I tried this simple code :
> {code}
> package mypackage;
> import javax.ws.rs.GET;
> import javax.ws.rs.Path;
> import javax.ws.rs.PathParam;
> import javax.ws.rs.core.Context;
> import javax.ws.rs.core.UriInfo;
> @Path("uri")
> public class UriService {
>     @GET
>     @Path("something/{id}")
>     public void addSomething(String string, @Context UriInfo uriInfo, @PathParam("id") String id) {
>     	System.out.println("getPath -> " + uriInfo.getPath());
>     	System.out.println("getBasePath -> " + uriInfo.getBaseUri());
>     	System.out.println("getAbsolutePath -> " + uriInfo.getBaseUri().resolve(uriInfo.getPath(false)));
>     	System.out.println("getAbsolutePath -> " + uriInfo.getAbsolutePath());
>     }
> }
> {code}
> With a Spring-based setup and default beans.xml taken from the user guide.
> Then we can use a normal browser .
> With "http://localhost:9080/Uritest/rest/uri/something/3", we get in stdout :
> {panel}
> getPath -> /uri/something/3
> getBasePath -> http://localhost:9080/Uritest/rest
> getAbsolutePath -> http://localhost:9080/uri/something/3
> getAbsolutePath -> http://localhost:9080/Uritest/rest/uri/something/3
> {panel}
> But with "http://localhost:9080/Uritest/rest/uri/something/3 4", we get an exception :
> {noformat}
> java.net.URISyntaxException: Illegal character in path at index 50: http://localhost:9080/Uritest/rest/uri/something/3 4
> {noformat}
> And in stdout :
> {panel}
> getPath -> /uri/something/3 4
> getBasePath -> http://localhost:9080/Uritest/rest
> getAbsolutePath -> http://localhost:9080/uri/something/3%204
> {panel}
> NB : in JAX-RS javadoc, it's said that "getAbsolutePath()" is a shortcut to uriInfo.getBase().resolve(uriInfo.getPath())", which is plain wrong, because :
> # getBase doesn't exist, that's getBaseUri
> # getPath as returned by CXF begins with a slash ("/") so "resolve" doesn't do what we want here. (maybe another bug ? tell me and I'll create another issue)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CXF-2652) UriInfo.getAbsolutePath throws "java.net.URISyntaxException: Illegal character in path" when there is an encoded space in the request URI

Posted by "Julien Wajsberg (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CXF-2652?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Julien Wajsberg updated CXF-2652:
---------------------------------

    Description: 
I tried this simple code :

{code}
package mypackage;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;

@Path("uri")
public class UriService {
    @GET
    @Path("something/{id}")
    public void addSomething(String string, @Context UriInfo uriInfo, @PathParam("id") String id) {
    	System.out.println("getPath -> " + uriInfo.getPath());
    	System.out.println("getBasePath -> " + uriInfo.getBaseUri());
    	System.out.println("getAbsolutePath -> " + uriInfo.getBaseUri().resolve(uriInfo.getPath(false)));
    	System.out.println("getAbsolutePath -> " + uriInfo.getAbsolutePath());
    }
}
{code}

With a Spring-based setup and default beans.xml taken from the user guide.

Then we can use a normal browser .

With "http://localhost:9080/Uritest/rest/uri/something/3", we get in stdout :
{panel}
getPath -> /uri/something/3
getBasePath -> http://localhost:9080/Uritest/rest
getAbsolutePath -> http://localhost:9080/uri/something/3
getAbsolutePath -> http://localhost:9080/Uritest/rest/uri/something/3
{panel}

But with "http://localhost:9080/Uritest/rest/uri/something/3 4", we get an exception :
java.net.URISyntaxException: Illegal character in path at index 50: http://localhost:9080/Uritest/rest/uri/something/3 4

And in stdout :

{panel}
getPath -> /uri/something/3 4
getBasePath -> http://localhost:9080/Uritest/rest
getAbsolutePath -> http://localhost:9080/uri/something/3%204
{panel}

NB : in JAX-RS javadoc, it's said that "getAbsolutePath()" is a shortcut to uriInfo.getBase().resolve(uriInfo.getPath())", which is plain wrong, because :
# getBase doesn't exist, that's getBaseUri
# getPath as returned by CXF begins with a slash ("/") so "resolve" doesn't do what we want here.


  was:
I tried this simple code :

package mypackage;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;

@Path("uri")
public class UriService {
    @GET
    @Path("something/{id}")
    public void addSomething(String string, @Context UriInfo uriInfo, @PathParam("id") String id) {
    	System.out.println("getPath -> " + uriInfo.getPath());
    	System.out.println("getBasePath -> " + uriInfo.getBaseUri());
    	System.out.println("getAbsolutePath -> " + uriInfo.getBaseUri().resolve(uriInfo.getPath(false)));
    	System.out.println("getAbsolutePath -> " + uriInfo.getAbsolutePath());
    }
}

With a Spring-based setup and default beans.xml taken from the user guide.

Then we can use a normal browser .

With "http://localhost:9080/Uritest/rest/uri/something/3", we get in stdout :
getPath -> /uri/something/3
getBasePath -> http://localhost:9080/Uritest/rest
getAbsolutePath -> http://localhost:9080/uri/something/3
getAbsolutePath -> http://localhost:9080/Uritest/rest/uri/something/3

But with "http://localhost:9080/Uritest/rest/uri/something/3 4", we get an exception :
java.net.URISyntaxException: Illegal character in path at index 50: http://localhost:9080/Uritest/rest/uri/something/3 4

And in stdout :

getPath -> /uri/something/3 4
getBasePath -> http://localhost:9080/Uritest/rest
getAbsolutePath -> http://localhost:9080/uri/something/3%204

NB : in JAX-RS javadoc, it's said that "getAbsolutePath()" is a shortcut to uriInfo.getBase().resolve(uriInfo.getPath())", which is plain wrong, because :
1 - getBase doesn't exist, that's getBaseUri
2 -  getPath as returned by CXF begins with a slash ("/") so "resolve" doesn't do what we want here.


> UriInfo.getAbsolutePath throws "java.net.URISyntaxException: Illegal character in path" when there is an encoded space in the request URI
> -----------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-2652
>                 URL: https://issues.apache.org/jira/browse/CXF-2652
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.2.6
>         Environment: Used with Spring
>            Reporter: Julien Wajsberg
>
> I tried this simple code :
> {code}
> package mypackage;
> import javax.ws.rs.GET;
> import javax.ws.rs.Path;
> import javax.ws.rs.PathParam;
> import javax.ws.rs.core.Context;
> import javax.ws.rs.core.UriInfo;
> @Path("uri")
> public class UriService {
>     @GET
>     @Path("something/{id}")
>     public void addSomething(String string, @Context UriInfo uriInfo, @PathParam("id") String id) {
>     	System.out.println("getPath -> " + uriInfo.getPath());
>     	System.out.println("getBasePath -> " + uriInfo.getBaseUri());
>     	System.out.println("getAbsolutePath -> " + uriInfo.getBaseUri().resolve(uriInfo.getPath(false)));
>     	System.out.println("getAbsolutePath -> " + uriInfo.getAbsolutePath());
>     }
> }
> {code}
> With a Spring-based setup and default beans.xml taken from the user guide.
> Then we can use a normal browser .
> With "http://localhost:9080/Uritest/rest/uri/something/3", we get in stdout :
> {panel}
> getPath -> /uri/something/3
> getBasePath -> http://localhost:9080/Uritest/rest
> getAbsolutePath -> http://localhost:9080/uri/something/3
> getAbsolutePath -> http://localhost:9080/Uritest/rest/uri/something/3
> {panel}
> But with "http://localhost:9080/Uritest/rest/uri/something/3 4", we get an exception :
> java.net.URISyntaxException: Illegal character in path at index 50: http://localhost:9080/Uritest/rest/uri/something/3 4
> And in stdout :
> {panel}
> getPath -> /uri/something/3 4
> getBasePath -> http://localhost:9080/Uritest/rest
> getAbsolutePath -> http://localhost:9080/uri/something/3%204
> {panel}
> NB : in JAX-RS javadoc, it's said that "getAbsolutePath()" is a shortcut to uriInfo.getBase().resolve(uriInfo.getPath())", which is plain wrong, because :
> # getBase doesn't exist, that's getBaseUri
> # getPath as returned by CXF begins with a slash ("/") so "resolve" doesn't do what we want here.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (CXF-2652) UriInfo.getAbsolutePath throws "java.net.URISyntaxException: Illegal character in path" when there is an encoded space in the request URI

Posted by "Julien Wajsberg (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-2652?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12829611#action_12829611 ] 

Julien Wajsberg edited comment on CXF-2652 at 2/4/10 3:01 PM:
--------------------------------------------------------------

(sorry for spamming)

A code which gives the correct value is :
{code}
private URI getAbsolutePathUri(UriInfo uriInfo) {
	String path = uriInfo.getPath(false);
	if (path.startsWith("/")) {
		path = path.replaceFirst("\\/+", "");
	}
	URI baseUri = uriInfo.getBaseUri();
	String base = baseUri.toString();
	if (! base.endsWith("/")) {
		base += "/";
		baseUri = URI.create(base);
	}
	URI location = baseUri.resolve(path);
	return location;
}
{code}

      was (Author: flashfr):
    (sorry for spamming)

A code which gives the correct value is :
{code}
private URI getAbsolutePathUri(UriInfo uriInfo) {
	String path = uriInfo.getPath(false);
	if (path.startsWith("/")) {
		path = path.replaceFirst("\\/+", "");
	}
	URI location = uriInfo.getBaseUri().resolve(path);
	return location;
}
{code}
  
> UriInfo.getAbsolutePath throws "java.net.URISyntaxException: Illegal character in path" when there is an encoded space in the request URI
> -----------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-2652
>                 URL: https://issues.apache.org/jira/browse/CXF-2652
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.2.6
>         Environment: Used with Spring
>            Reporter: Julien Wajsberg
>
> I tried this simple code :
> {code}
> package mypackage;
> import javax.ws.rs.GET;
> import javax.ws.rs.Path;
> import javax.ws.rs.PathParam;
> import javax.ws.rs.core.Context;
> import javax.ws.rs.core.UriInfo;
> @Path("uri")
> public class UriService {
>     @GET
>     @Path("something/{id}")
>     public void addSomething(String string, @Context UriInfo uriInfo, @PathParam("id") String id) {
>     	System.out.println("getPath -> " + uriInfo.getPath());
>     	System.out.println("getBasePath -> " + uriInfo.getBaseUri());
>     	System.out.println("getAbsolutePath -> " + uriInfo.getBaseUri().resolve(uriInfo.getPath(false)));
>     	System.out.println("getAbsolutePath -> " + uriInfo.getAbsolutePath());
>     }
> }
> {code}
> With a Spring-based setup and default beans.xml taken from the user guide.
> Then we can use a normal browser .
> With "http://localhost:9080/Uritest/rest/uri/something/3", we get in stdout :
> {panel}
> getPath -> /uri/something/3
> getBasePath -> http://localhost:9080/Uritest/rest
> getAbsolutePath -> http://localhost:9080/uri/something/3
> getAbsolutePath -> http://localhost:9080/Uritest/rest/uri/something/3
> {panel}
> But with "http://localhost:9080/Uritest/rest/uri/something/3 4", we get an exception :
> {noformat}
> java.net.URISyntaxException: Illegal character in path at index 50: http://localhost:9080/Uritest/rest/uri/something/3 4
> {noformat}
> And in stdout :
> {panel}
> getPath -> /uri/something/3 4
> getBasePath -> http://localhost:9080/Uritest/rest
> getAbsolutePath -> http://localhost:9080/uri/something/3%204
> {panel}
> NB : in JAX-RS javadoc, it's said that "getAbsolutePath()" is a shortcut to uriInfo.getBase().resolve(uriInfo.getPath())", which is plain wrong, because :
> # getBase doesn't exist, that's getBaseUri
> # getPath as returned by CXF begins with a slash ("/") so "resolve" doesn't do what we want here. (maybe another bug ? tell me and I'll create another issue)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CXF-2652) UriInfo.getAbsolutePath throws "java.net.URISyntaxException: Illegal character in path" when there is an encoded space in the request URI

Posted by "Julien Wajsberg (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CXF-2652?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Julien Wajsberg updated CXF-2652:
---------------------------------

    Description: 
I tried this simple code :

{code}
package mypackage;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;

@Path("uri")
public class UriService {
    @GET
    @Path("something/{id}")
    public void addSomething(String string, @Context UriInfo uriInfo, @PathParam("id") String id) {
    	System.out.println("getPath -> " + uriInfo.getPath());
    	System.out.println("getBasePath -> " + uriInfo.getBaseUri());
    	System.out.println("getAbsolutePath -> " + uriInfo.getBaseUri().resolve(uriInfo.getPath(false)));
    	System.out.println("getAbsolutePath -> " + uriInfo.getAbsolutePath());
    }
}
{code}

With a Spring-based setup and default beans.xml taken from the user guide.

Then we can use a normal browser .

With "http://localhost:9080/Uritest/rest/uri/something/3", we get in stdout :
{panel}
getPath -> /uri/something/3
getBasePath -> http://localhost:9080/Uritest/rest
getAbsolutePath -> http://localhost:9080/uri/something/3
getAbsolutePath -> http://localhost:9080/Uritest/rest/uri/something/3
{panel}

But with "http://localhost:9080/Uritest/rest/uri/something/3 4", we get an exception :
{noformat}
java.net.URISyntaxException: Illegal character in path at index 50: http://localhost:9080/Uritest/rest/uri/something/3 4
{noformat}

And in stdout :

{panel}
getPath -> /uri/something/3 4
getBasePath -> http://localhost:9080/Uritest/rest
getAbsolutePath -> http://localhost:9080/uri/something/3%204
{panel}

NB : in JAX-RS javadoc, it's said that "getAbsolutePath()" is a shortcut to uriInfo.getBase().resolve(uriInfo.getPath())", which is plain wrong, because :
# getBase doesn't exist, that's getBaseUri
# getPath as returned by CXF begins with a slash ("/") so "resolve" doesn't do what we want here.


  was:
I tried this simple code :

{code}
package mypackage;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;

@Path("uri")
public class UriService {
    @GET
    @Path("something/{id}")
    public void addSomething(String string, @Context UriInfo uriInfo, @PathParam("id") String id) {
    	System.out.println("getPath -> " + uriInfo.getPath());
    	System.out.println("getBasePath -> " + uriInfo.getBaseUri());
    	System.out.println("getAbsolutePath -> " + uriInfo.getBaseUri().resolve(uriInfo.getPath(false)));
    	System.out.println("getAbsolutePath -> " + uriInfo.getAbsolutePath());
    }
}
{code}

With a Spring-based setup and default beans.xml taken from the user guide.

Then we can use a normal browser .

With "http://localhost:9080/Uritest/rest/uri/something/3", we get in stdout :
{panel}
getPath -> /uri/something/3
getBasePath -> http://localhost:9080/Uritest/rest
getAbsolutePath -> http://localhost:9080/uri/something/3
getAbsolutePath -> http://localhost:9080/Uritest/rest/uri/something/3
{panel}

But with "http://localhost:9080/Uritest/rest/uri/something/3 4", we get an exception :
java.net.URISyntaxException: Illegal character in path at index 50: http://localhost:9080/Uritest/rest/uri/something/3 4

And in stdout :

{panel}
getPath -> /uri/something/3 4
getBasePath -> http://localhost:9080/Uritest/rest
getAbsolutePath -> http://localhost:9080/uri/something/3%204
{panel}

NB : in JAX-RS javadoc, it's said that "getAbsolutePath()" is a shortcut to uriInfo.getBase().resolve(uriInfo.getPath())", which is plain wrong, because :
# getBase doesn't exist, that's getBaseUri
# getPath as returned by CXF begins with a slash ("/") so "resolve" doesn't do what we want here.



> UriInfo.getAbsolutePath throws "java.net.URISyntaxException: Illegal character in path" when there is an encoded space in the request URI
> -----------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-2652
>                 URL: https://issues.apache.org/jira/browse/CXF-2652
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.2.6
>         Environment: Used with Spring
>            Reporter: Julien Wajsberg
>
> I tried this simple code :
> {code}
> package mypackage;
> import javax.ws.rs.GET;
> import javax.ws.rs.Path;
> import javax.ws.rs.PathParam;
> import javax.ws.rs.core.Context;
> import javax.ws.rs.core.UriInfo;
> @Path("uri")
> public class UriService {
>     @GET
>     @Path("something/{id}")
>     public void addSomething(String string, @Context UriInfo uriInfo, @PathParam("id") String id) {
>     	System.out.println("getPath -> " + uriInfo.getPath());
>     	System.out.println("getBasePath -> " + uriInfo.getBaseUri());
>     	System.out.println("getAbsolutePath -> " + uriInfo.getBaseUri().resolve(uriInfo.getPath(false)));
>     	System.out.println("getAbsolutePath -> " + uriInfo.getAbsolutePath());
>     }
> }
> {code}
> With a Spring-based setup and default beans.xml taken from the user guide.
> Then we can use a normal browser .
> With "http://localhost:9080/Uritest/rest/uri/something/3", we get in stdout :
> {panel}
> getPath -> /uri/something/3
> getBasePath -> http://localhost:9080/Uritest/rest
> getAbsolutePath -> http://localhost:9080/uri/something/3
> getAbsolutePath -> http://localhost:9080/Uritest/rest/uri/something/3
> {panel}
> But with "http://localhost:9080/Uritest/rest/uri/something/3 4", we get an exception :
> {noformat}
> java.net.URISyntaxException: Illegal character in path at index 50: http://localhost:9080/Uritest/rest/uri/something/3 4
> {noformat}
> And in stdout :
> {panel}
> getPath -> /uri/something/3 4
> getBasePath -> http://localhost:9080/Uritest/rest
> getAbsolutePath -> http://localhost:9080/uri/something/3%204
> {panel}
> NB : in JAX-RS javadoc, it's said that "getAbsolutePath()" is a shortcut to uriInfo.getBase().resolve(uriInfo.getPath())", which is plain wrong, because :
> # getBase doesn't exist, that's getBaseUri
> # getPath as returned by CXF begins with a slash ("/") so "resolve" doesn't do what we want here.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CXF-2652) UriInfo.getAbsolutePath throws "java.net.URISyntaxException: Illegal character in path" when there is an encoded space in the request URI

Posted by "Julien Wajsberg (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-2652?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12829611#action_12829611 ] 

Julien Wajsberg commented on CXF-2652:
--------------------------------------

(sorry for spamming)

A code which gives the correct value is :
{code}
private URI getAbsolutePathUri(UriInfo uriInfo) {
	String path = uriInfo.getPath(false);
	if (path.startsWith("/")) {
		path = path.replaceFirst("\\/+", "");
	}
	URI location = uriInfo.getBaseUri().resolve(path);
	return location;
}
{code}

> UriInfo.getAbsolutePath throws "java.net.URISyntaxException: Illegal character in path" when there is an encoded space in the request URI
> -----------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-2652
>                 URL: https://issues.apache.org/jira/browse/CXF-2652
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.2.6
>         Environment: Used with Spring
>            Reporter: Julien Wajsberg
>
> I tried this simple code :
> {code}
> package mypackage;
> import javax.ws.rs.GET;
> import javax.ws.rs.Path;
> import javax.ws.rs.PathParam;
> import javax.ws.rs.core.Context;
> import javax.ws.rs.core.UriInfo;
> @Path("uri")
> public class UriService {
>     @GET
>     @Path("something/{id}")
>     public void addSomething(String string, @Context UriInfo uriInfo, @PathParam("id") String id) {
>     	System.out.println("getPath -> " + uriInfo.getPath());
>     	System.out.println("getBasePath -> " + uriInfo.getBaseUri());
>     	System.out.println("getAbsolutePath -> " + uriInfo.getBaseUri().resolve(uriInfo.getPath(false)));
>     	System.out.println("getAbsolutePath -> " + uriInfo.getAbsolutePath());
>     }
> }
> {code}
> With a Spring-based setup and default beans.xml taken from the user guide.
> Then we can use a normal browser .
> With "http://localhost:9080/Uritest/rest/uri/something/3", we get in stdout :
> {panel}
> getPath -> /uri/something/3
> getBasePath -> http://localhost:9080/Uritest/rest
> getAbsolutePath -> http://localhost:9080/uri/something/3
> getAbsolutePath -> http://localhost:9080/Uritest/rest/uri/something/3
> {panel}
> But with "http://localhost:9080/Uritest/rest/uri/something/3 4", we get an exception :
> {noformat}
> java.net.URISyntaxException: Illegal character in path at index 50: http://localhost:9080/Uritest/rest/uri/something/3 4
> {noformat}
> And in stdout :
> {panel}
> getPath -> /uri/something/3 4
> getBasePath -> http://localhost:9080/Uritest/rest
> getAbsolutePath -> http://localhost:9080/uri/something/3%204
> {panel}
> NB : in JAX-RS javadoc, it's said that "getAbsolutePath()" is a shortcut to uriInfo.getBase().resolve(uriInfo.getPath())", which is plain wrong, because :
> # getBase doesn't exist, that's getBaseUri
> # getPath as returned by CXF begins with a slash ("/") so "resolve" doesn't do what we want here. (maybe another bug ? tell me and I'll create another issue)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (CXF-2652) UriInfo.getAbsolutePath throws "java.net.URISyntaxException: Illegal character in path" when there is an encoded space in the request URI

Posted by "Sergey Beryozkin (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CXF-2652?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sergey Beryozkin resolved CXF-2652.
-----------------------------------

       Resolution: Fixed
    Fix Version/s: 2.3
                   2.2.7
         Assignee: Sergey Beryozkin

It has been fixed. There's a couple of things to note :

- UriInfo.getPath() will return "/" only if the actual path value (the one to be returned from getPath()) is empty, no leading slash will be there otherwise. This is consistent with what is returned for the list of PathSegments. I remember asking a question on the jaxrs list  about the value of PathSegment.getPath() for a value '/' and the answer was '/'.

- UriInfo has getBaseUriBuilder() - please use this builder one instead of Uri.resolve(). The reason UriBuilder was introduced was to let users not to worry about ensuring the concatenation works well and to hide some of limitations of URI. There's really nothing we can do if baseUri ends with '/' for URI.resolve to work... So you can do 

URI uri = uriInfo.getBaseUriBuilder().path(uriInfo.getPath()).build()

and this will work irrespectively of various variations with leading/trailing slashes

thanks, Sergey

> UriInfo.getAbsolutePath throws "java.net.URISyntaxException: Illegal character in path" when there is an encoded space in the request URI
> -----------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-2652
>                 URL: https://issues.apache.org/jira/browse/CXF-2652
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.2.6
>         Environment: Used with Spring
>            Reporter: Julien Wajsberg
>            Assignee: Sergey Beryozkin
>             Fix For: 2.2.7, 2.3
>
>
> I tried this simple code :
> {code}
> package mypackage;
> import javax.ws.rs.GET;
> import javax.ws.rs.Path;
> import javax.ws.rs.PathParam;
> import javax.ws.rs.core.Context;
> import javax.ws.rs.core.UriInfo;
> @Path("uri")
> public class UriService {
>     @GET
>     @Path("something/{id}")
>     public void addSomething(String string, @Context UriInfo uriInfo, @PathParam("id") String id) {
>     	System.out.println("getPath -> " + uriInfo.getPath());
>     	System.out.println("getBasePath -> " + uriInfo.getBaseUri());
>     	System.out.println("getAbsolutePath -> " + uriInfo.getBaseUri().resolve(uriInfo.getPath(false)));
>     	System.out.println("getAbsolutePath -> " + uriInfo.getAbsolutePath());
>     }
> }
> {code}
> With a Spring-based setup and default beans.xml taken from the user guide.
> Then we can use a normal browser .
> With "http://localhost:9080/Uritest/rest/uri/something/3", we get in stdout :
> {panel}
> getPath -> /uri/something/3
> getBasePath -> http://localhost:9080/Uritest/rest
> getAbsolutePath -> http://localhost:9080/uri/something/3
> getAbsolutePath -> http://localhost:9080/Uritest/rest/uri/something/3
> {panel}
> But with "http://localhost:9080/Uritest/rest/uri/something/3 4", we get an exception :
> {noformat}
> java.net.URISyntaxException: Illegal character in path at index 50: http://localhost:9080/Uritest/rest/uri/something/3 4
> {noformat}
> And in stdout :
> {panel}
> getPath -> /uri/something/3 4
> getBasePath -> http://localhost:9080/Uritest/rest
> getAbsolutePath -> http://localhost:9080/uri/something/3%204
> {panel}
> NB : in JAX-RS javadoc, it's said that "getAbsolutePath()" is a shortcut to uriInfo.getBase().resolve(uriInfo.getPath())", which is plain wrong, because :
> # getBase doesn't exist, that's getBaseUri
> # getPath as returned by CXF begins with a slash ("/") so "resolve" doesn't do what we want here. (maybe another bug ? tell me and I'll create another issue)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.