cil
>> Thanks Marek!
>>
>> On 8/29/12 3:03 AM, Marek Potociar wrote:
>>> The first scenario should not work.
>> So accessing within a Servlet should not work or relative URI will not work ?
> Accessing with servlet. JAX-RS does not support injection of JAX-RS artifacts to non-JAXRS components. We may want to look into that feature, esp. with the "managed" client injection, but that's the current state.
IMHO injection of JAX-RS artifacts into other components of the Java EE
7 platform would be an important usecase. This will allow a consistent
usage of JAX-RS across the platform.
>
>> Apparently within a Servlet with absolute URI is working. Is that a bug ? :-)
> Ok, I'm confused now. Can you provide a code snipped of the working scenario you have in mind?
public static final String RESOURCE_ENDPOINT =
"
http://localhost:8080/Jersey2Sample/webresources/myresource";
@Uri(RESOURCE_ENDPOINT)
WebTarget resource;
And the following code in doGet
out.println(client.target(RESOURCE_ENDPOINT).request().get(String.class));
prints the response correctly.
>
>>> The second scenario should, provided you are injecting the WebTarget into a resource and not the servlet. If that's the case, then please file a bug.
>> So injecting a WebTarget in a Servlet will not work ? Why ?
> See above.
>
>> Injecting a resource within a resource is less likely to happen than injecting a resource within a Java EE component. Anyway, I tried:
>>
>> @Path("myresource2")
>> public class MyResource2 {
>> public static final String RESOURCE_ENDPOINT = "/Jersey2Sample/webresources/myresource";
>>
>> @Uri(RESOURCE_ENDPOINT)
>> WebTarget resource;
>>
>> @GET
>> public String get() {
>> return resource.request().get(String.class) + "2";
>> }
>> }
>>
>> And now access "myresource2" is giving:
>>
>> SEVERE: InvocationException{message=org.glassfish.jersey.client.InboundJaxrsResponse_at, response=org.glassfish.jersey.client.InboundJaxrsResponse_at_480bb10c}
>> org.glassfish.jersey.internal.MappableException: InvocationException{message=org.glassfish.jersey.client.InboundJaxrsResponse_at, response=org.glassfish.jersey.client.InboundJaxrsResponse_at_480bb10c}
>> at org.glassfish.jersey.server.model.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:122)
>> at org.glassfish.jersey.server.model.AbstractJavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(AbstractJavaResourceMethodDispatcherProvider.java:219)
>> at org.glassfish.jersey.server.model.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:79)
>> at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:262)
>> at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:82)
>> at org.glassfish.jersey.process.internal.RequestInvoker$AcceptingInvoker.apply(RequestInvoker.java:241)
>> at org.glassfish.jersey.process.internal.AsyncInflectorAdapter.apply(AsyncInflectorAdapter.java:156)
>> at org.glassfish.jersey.process.internal.RequestInvoker$2.run(RequestInvoker.java:188)
>> at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:283)
>> at org.glassfish.jersey.process.internal.RequestInvoker$3.run(RequestInvoker.java:201)
>> at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
>> at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
>> at java.util.concurrent.FutureTask.run(FutureTask.java:166)
>> at com.google.common.util.concurrent.MoreExecutors$SameThreadExecutorService.execute(MoreExecutors.java:253)
>> at com.google.common.util.concurrent.AbstractListeningExecutorService.submit(AbstractListeningExecutorService.java:44)
>> at com.google.common.util.concurrent.AbstractListeningExecutorService.submit(AbstractListeningExecutorService.java:41)
>> at org.glassfish.jersey.process.internal.RequestInvoker.apply(RequestInvoker.java:197)
>> at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:752)
>> at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:309)
>>
>> What is supposed to and not supposed to work when JAX-RS 2 is used within a Java EE context ?
> The above should work and is obviously a bug if it doesn't.
OK, will file a bug.
Arun
>
> Marek
>
>> Arun
>>
>>> Thanks,
>>> Marek
>>>
>>> On Aug 29, 2012, at 2:06 AM, Arun Gupta <Arun.p.Gupta_at_oracle.COM> wrote:
>>>
>>>> With GlassFish build 51, I created a trivial resource as:
>>>>
>>>> @Path("/myresource")
>>>> public class MyResource {
>>>>
>>>> @GET
>>>> public String get() {
>>>> return "Hello World!";
>>>> }
>>>> }
>>>>
>>>> And accessed this resource within a Servlet.doGet as:
>>>>
>>>> client.target(RESOURCE_ENDPOINT).request().get(String.class)
>>>>
>>>> If RESOURCE_ENDPOINT is "http://localhost:8080/Jersey2Sample/webresources/myresource"; then it works. A relative URI does not work and throws the error:
>>>>
>>>> InvocationException{message=URI is not absolute, response=null}
>>>> at org.glassfish.jersey.client.ClientConfig$State$4$1.failure(ClientConfig.java:416)
>>>> at org.glassfish.jersey.process.internal.ResponseProcessor.notifyCallback(ResponseProcessor.java:324)
>>>> at org.glassfish.jersey.process.internal.ResponseProcessor.setResult(ResponseProcessor.java:309)
>>>> at org.glassfish.jersey.process.internal.ResponseProcessor.access$400(ResponseProcessor.java:83)
>>>> at org.glassfish.jersey.process.internal.ResponseProcessor$1.run(ResponseProcessor.java:214)
>>>> at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:283)
>>>> at org.glassfish.jersey.process.internal.ResponseProcessor.run(ResponseProcessor.java:188)
>>>> at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
>>>> at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
>>>> at java.lang.Thread.run(Thread.java:722)
>>>>
>>>> Why ?
>>>>
>>>> If the same endpoint is accessed as:
>>>>
>>>> @Uri("/webresources/myresource")
>>>> WebTarget resource;
>>>>
>>>> resource.request().get()
>>>>
>>>> then a NPE is thrown. The "resource" object is not injected.
>>>>
>>>> Is this functionality implemented and integrated ?
>>>>
>>>> Thanks,
>>>> Arun
>>>>
>>>>
>>>> --
>>>> http://twitter.com/arungupta
>>>> http://blogs.oracle.com/arungupta
>>>>
>> --
>> http://twitter.com/arungupta
>> http://blogs.oracle.com/arungupta
>>
--
http://twitter.com/arungupta
http://blogs.oracle.com/arungupta