Hi there,

so I don't know how this should behave... to be honest.

I don't know if we do something on the whiteboard to alter this behavior or if this is just the way the CXF implementation works.

For what I can see we just register CXF ClientBuilderImpl to be used, so I am guessing this is CXF behaviour.

If this is the default behaviour you will probably need to find how to alter that on CXF implementation if there is no JAX-RS way of doing it.

Sorry I can't be of more help.

Carlos.

El 10/12/19 a las 18:49, Markus Rathgeb escribió:
Hi,

I have a question about the UriBuilder provided by the Aries JAX-RS
Whiteboard implementation.

Assume a very simple REST endpoint:

===
@Component(service = { Resource.class }, scope = ServiceScope.PROTOTYPE)
@JaxrsResource
public class Resource {
     @POST
     @Path("create")
     @Produces(MediaType.APPLICATION_JSON)
     public Object createTest(@Context final UriInfo uriInfo) {
         final URI uri =
uriInfo.getBaseUriBuilder().path("foo").path("bar").build();
         return Response.created(uri).build();
     }
}
===

If I call the post method of that endpoint using the URL
"http://localhost:8080/create"; I get a created location that looks
like "http://localhost:8080/foo/bar";.

All fine.

===
$ curl -v -X POST http://localhost:8080/create
*   Trying ::1:8080...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
POST /create HTTP/1.1
Host: localhost:8080
User-Agent: curl/7.67.0
Accept: */*

* Mark bundle as not supporting multiuse
< HTTP/1.1 201 Created
< Date: Tue, 10 Dec 2019 17:41:47 GMT
< Location: http://localhost:8080/foo/bar
< Content-Length: 0
<
* Connection #0 to host localhost left intact
===

But, I would expect if I access the endpoint using the IP instead of
the hostname "http://127.0.0.1:8080/create"; the created response's
location should look like "http://127.0.0.1:8080/foo/bar";.

But that is not the case...

The response provides "http://localhost:8080/foo/bar";

===
curl -v -X POST http://127.0.0.1:8080/create
*   Trying 127.0.0.1:8080...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
POST /create HTTP/1.1
Host: 127.0.0.1:8080
User-Agent: curl/7.67.0
Accept: */*

* Mark bundle as not supporting multiuse
< HTTP/1.1 201 Created
< Date: Tue, 10 Dec 2019 17:44:00 GMT
< Location: http://localhost:8080/foo/bar
< Content-Length: 0
<
* Connection #0 to host 127.0.0.1 left intact
===

I the website that is accessed using 127.0.0.1 provides a location
using localhost and that one is used by the browser, the browser fails
because of CORS.

Why is not the host of the request used if a new URI is build that way?

Best regards,
Markus

Reply via email to