You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by ellen <el...@163.com> on 2015/04/28 08:19:54 UTC

The logic of Response getAllLinks method is not good?

Hi all,

I'm using response getLink method from CXF.

The code is:

    private Map<String, Link> getAllLinks() {
        List linkValues = metadata.get(HttpHeaders.LINK);
        if (linkValues == null) {
            return Collections.emptyMap();
        } else {
            Map<String, Link> links = new LinkedHashMap<String, Link>();
            for (Object o : linkValues) {
                Link link = o instanceof Link ? (Link)o :
Link.valueOf(o.toString());
                if (!link.getUri().isAbsolute()) {
                    *URI requestURI =
URI.create((String)outMessage.get(Message.REQUEST_URI));*
                    link = Link.fromLink(link).baseUri(requestURI).build();
                }
                links.put(link.getRel(), link);
            }
            return links;
        }
    }

But from the code you can see therequestURI comes from Message REQUEST_URI.

If my request uri is http://www.test.com/resource/get

then I continue use the link to invoke like this:

Link link = response.getLink(linkName);
response = client.invocation(link).post(null);

The url which response use is joined like this:
http://www.test.com/resource/get/post,

but this http://www.test.com/resource/get/post is not exist (correct lin
should be http://www.test.com/resource/post). So I think this is not good.

I'm looking at Jersey getLink method, and found they use:
URI result = baseUri.resolve(refUri);

to get Request url, and I found the result is correct for me.

Could you please take a look this issue?

Thanks a lot!



--
View this message in context: http://cxf.547215.n5.nabble.com/The-logic-of-Response-getAllLinks-method-is-not-good-tp5756610.html
Sent from the cxf-dev mailing list archive at Nabble.com.

Re: The logic of Response getAllLinks method is not good?

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

Thanks, this is fixed now, see
https://issues.apache.org/jira/browse/CXF-6378

Cheers, Sergey
On 29/04/15 03:15, jordan wrote:
> Hi Sergey,
>
> The resource class like this:
>
> @Path("resource")
> public class Resource {
>
> 	public static final long SLEEP_TIME = 1500L;
>
> 	@GET
> 	@Path("get")
> 	public String get() {
> 		return "get";
> 	}
> 	
> 	@POST
> 	@Path("post")
> 	public String post(String value) {
> 		return value;
> 	}
>
>
>
> And my Link is got from:
>
> Link.Builder builder = Link.fromMethod(Resource.class,
> 						"post").rel(linkName);
> Link link = builder.build();
>
> So the link value is "post"
>
> Thanks!
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/The-logic-of-Response-getAllLinks-method-is-not-good-tp5756610p5756692.html
> Sent from the cxf-dev mailing list archive at Nabble.com.
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Re: The logic of Response getAllLinks method is not good?

Posted by jordan <zh...@cn.ibm.com>.
Hi Sergey,

The resource class like this:

@Path("resource")
public class Resource {

	public static final long SLEEP_TIME = 1500L;

	@GET
	@Path("get")
	public String get() {
		return "get";
	}
	
	@POST
	@Path("post")
	public String post(String value) {
		return value;
	}



And my Link is got from:

Link.Builder builder = Link.fromMethod(Resource.class,
						"post").rel(linkName);
Link link = builder.build();

So the link value is "post"

Thanks!



--
View this message in context: http://cxf.547215.n5.nabble.com/The-logic-of-Response-getAllLinks-method-is-not-good-tp5756610p5756692.html
Sent from the cxf-dev mailing list archive at Nabble.com.

Re: The logic of Response getAllLinks method is not good?

Posted by Sergey Beryozkin <sb...@gmail.com>.
One more option "/post" ?

So is it "post", "../post", or "/post" ?

Sergey
On 28/04/15 10:26, Sergey Beryozkin wrote:
> Hi
>
> Thanks for this analysis, I'm looking at the docs, example
>
> https://jax-rs-spec.java.net/nonav/2.0-rev-a/apidocs/javax/ws/rs/core/Response.html#getLink(java.lang.String)
>
>
> it says:
>
> "A relative link is resolved with respect to the actual request URI that
> produced this response".
>
> What is the link value in your case, "../post" or "post" ?
>
> Thanks, Sergey
>
>
>
> On 28/04/15 07:19, ellen wrote:
>> Hi all,
>>
>> I'm using response getLink method from CXF.
>>
>> The code is:
>>
>>      private Map<String, Link> getAllLinks() {
>>          List linkValues = metadata.get(HttpHeaders.LINK);
>>          if (linkValues == null) {
>>              return Collections.emptyMap();
>>          } else {
>>              Map<String, Link> links = new LinkedHashMap<String, Link>();
>>              for (Object o : linkValues) {
>>                  Link link = o instanceof Link ? (Link)o :
>> Link.valueOf(o.toString());
>>                  if (!link.getUri().isAbsolute()) {
>>                      *URI requestURI =
>> URI.create((String)outMessage.get(Message.REQUEST_URI));*
>>                      link =
>> Link.fromLink(link).baseUri(requestURI).build();
>>                  }
>>                  links.put(link.getRel(), link);
>>              }
>>              return links;
>>          }
>>      }
>>
>> But from the code you can see therequestURI comes from Message
>> REQUEST_URI.
>>
>> If my request uri is http://www.test.com/resource/get
>>
>> then I continue use the link to invoke like this:
>>
>> Link link = response.getLink(linkName);
>> response = client.invocation(link).post(null);
>>
>> The url which response use is joined like this:
>> http://www.test.com/resource/get/post,
>>
>> but this http://www.test.com/resource/get/post is not exist (correct lin
>> should be http://www.test.com/resource/post). So I think this is not
>> good.
>>
>> I'm looking at Jersey getLink method, and found they use:
>> URI result = baseUri.resolve(refUri);
>>
>> to get Request url, and I found the result is correct for me.
>>
>> Could you please take a look this issue?
>>
>> Thanks a lot!
>>
>>
>>
>> --
>> View this message in context:
>> http://cxf.547215.n5.nabble.com/The-logic-of-Response-getAllLinks-method-is-not-good-tp5756610.html
>>
>> Sent from the cxf-dev mailing list archive at Nabble.com.
>>
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Re: The logic of Response getAllLinks method is not good?

Posted by Sergey Beryozkin <sb...@gmail.com>.
One more option "/post" ?

So is it "post", "../post", or "/post" ?

Sergey
On 28/04/15 10:26, Sergey Beryozkin wrote:
> Hi
>
> Thanks for this analysis, I'm looking at the docs, example
>
> https://jax-rs-spec.java.net/nonav/2.0-rev-a/apidocs/javax/ws/rs/core/Response.html#getLink(java.lang.String)
>
>
> it says:
>
> "A relative link is resolved with respect to the actual request URI that
> produced this response".
>
> What is the link value in your case, "../post" or "post" ?
>
> Thanks, Sergey
>
>
>
> On 28/04/15 07:19, ellen wrote:
>> Hi all,
>>
>> I'm using response getLink method from CXF.
>>
>> The code is:
>>
>>      private Map<String, Link> getAllLinks() {
>>          List linkValues = metadata.get(HttpHeaders.LINK);
>>          if (linkValues == null) {
>>              return Collections.emptyMap();
>>          } else {
>>              Map<String, Link> links = new LinkedHashMap<String, Link>();
>>              for (Object o : linkValues) {
>>                  Link link = o instanceof Link ? (Link)o :
>> Link.valueOf(o.toString());
>>                  if (!link.getUri().isAbsolute()) {
>>                      *URI requestURI =
>> URI.create((String)outMessage.get(Message.REQUEST_URI));*
>>                      link =
>> Link.fromLink(link).baseUri(requestURI).build();
>>                  }
>>                  links.put(link.getRel(), link);
>>              }
>>              return links;
>>          }
>>      }
>>
>> But from the code you can see therequestURI comes from Message
>> REQUEST_URI.
>>
>> If my request uri is http://www.test.com/resource/get
>>
>> then I continue use the link to invoke like this:
>>
>> Link link = response.getLink(linkName);
>> response = client.invocation(link).post(null);
>>
>> The url which response use is joined like this:
>> http://www.test.com/resource/get/post,
>>
>> but this http://www.test.com/resource/get/post is not exist (correct lin
>> should be http://www.test.com/resource/post). So I think this is not
>> good.
>>
>> I'm looking at Jersey getLink method, and found they use:
>> URI result = baseUri.resolve(refUri);
>>
>> to get Request url, and I found the result is correct for me.
>>
>> Could you please take a look this issue?
>>
>> Thanks a lot!
>>
>>
>>
>> --
>> View this message in context:
>> http://cxf.547215.n5.nabble.com/The-logic-of-Response-getAllLinks-method-is-not-good-tp5756610.html
>>
>> Sent from the cxf-dev mailing list archive at Nabble.com.
>>
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Re: The logic of Response getAllLinks method is not good?

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

Thanks for this analysis, I'm looking at the docs, example

https://jax-rs-spec.java.net/nonav/2.0-rev-a/apidocs/javax/ws/rs/core/Response.html#getLink(java.lang.String)

it says:

"A relative link is resolved with respect to the actual request URI that 
produced this response".

What is the link value in your case, "../post" or "post" ?

Thanks, Sergey



On 28/04/15 07:19, ellen wrote:
> Hi all,
>
> I'm using response getLink method from CXF.
>
> The code is:
>
>      private Map<String, Link> getAllLinks() {
>          List linkValues = metadata.get(HttpHeaders.LINK);
>          if (linkValues == null) {
>              return Collections.emptyMap();
>          } else {
>              Map<String, Link> links = new LinkedHashMap<String, Link>();
>              for (Object o : linkValues) {
>                  Link link = o instanceof Link ? (Link)o :
> Link.valueOf(o.toString());
>                  if (!link.getUri().isAbsolute()) {
>                      *URI requestURI =
> URI.create((String)outMessage.get(Message.REQUEST_URI));*
>                      link = Link.fromLink(link).baseUri(requestURI).build();
>                  }
>                  links.put(link.getRel(), link);
>              }
>              return links;
>          }
>      }
>
> But from the code you can see therequestURI comes from Message REQUEST_URI.
>
> If my request uri is http://www.test.com/resource/get
>
> then I continue use the link to invoke like this:
>
> Link link = response.getLink(linkName);
> response = client.invocation(link).post(null);
>
> The url which response use is joined like this:
> http://www.test.com/resource/get/post,
>
> but this http://www.test.com/resource/get/post is not exist (correct lin
> should be http://www.test.com/resource/post). So I think this is not good.
>
> I'm looking at Jersey getLink method, and found they use:
> URI result = baseUri.resolve(refUri);
>
> to get Request url, and I found the result is correct for me.
>
> Could you please take a look this issue?
>
> Thanks a lot!
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/The-logic-of-Response-getAllLinks-method-is-not-good-tp5756610.html
> Sent from the cxf-dev mailing list archive at Nabble.com.
>


Re: The logic of Response getAllLinks method is not good?

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi

Thanks for this analysis, I'm looking at the docs, example

https://jax-rs-spec.java.net/nonav/2.0-rev-a/apidocs/javax/ws/rs/core/Response.html#getLink(java.lang.String)

it says:

"A relative link is resolved with respect to the actual request URI that 
produced this response".

What is the link value in your case, "../post" or "post" ?

Thanks, Sergey



On 28/04/15 07:19, ellen wrote:
> Hi all,
>
> I'm using response getLink method from CXF.
>
> The code is:
>
>      private Map<String, Link> getAllLinks() {
>          List linkValues = metadata.get(HttpHeaders.LINK);
>          if (linkValues == null) {
>              return Collections.emptyMap();
>          } else {
>              Map<String, Link> links = new LinkedHashMap<String, Link>();
>              for (Object o : linkValues) {
>                  Link link = o instanceof Link ? (Link)o :
> Link.valueOf(o.toString());
>                  if (!link.getUri().isAbsolute()) {
>                      *URI requestURI =
> URI.create((String)outMessage.get(Message.REQUEST_URI));*
>                      link = Link.fromLink(link).baseUri(requestURI).build();
>                  }
>                  links.put(link.getRel(), link);
>              }
>              return links;
>          }
>      }
>
> But from the code you can see therequestURI comes from Message REQUEST_URI.
>
> If my request uri is http://www.test.com/resource/get
>
> then I continue use the link to invoke like this:
>
> Link link = response.getLink(linkName);
> response = client.invocation(link).post(null);
>
> The url which response use is joined like this:
> http://www.test.com/resource/get/post,
>
> but this http://www.test.com/resource/get/post is not exist (correct lin
> should be http://www.test.com/resource/post). So I think this is not good.
>
> I'm looking at Jersey getLink method, and found they use:
> URI result = baseUri.resolve(refUri);
>
> to get Request url, and I found the result is correct for me.
>
> Could you please take a look this issue?
>
> Thanks a lot!
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/The-logic-of-Response-getAllLinks-method-is-not-good-tp5756610.html
> Sent from the cxf-dev mailing list archive at Nabble.com.
>