You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@aries.apache.org by Markus Rathgeb <ma...@gmail.com> on 2019/08/13 17:36:55 UTC

Changed behaviour: JSONRequire, JaxrsExtension

I tested the usage of the Aries JAX-RS Whiteboard reference
implementation a little bit.
It works for me using v1.0.1, v1.0.2 and v1.0.3.
It stopped working for me using v1.0.4 and v1.0.5.

I added a small example to explain what's not working anymore:

I created an application:

```java
@Component(service = Application.class)
@JaxrsApplicationBase("foo")
@JaxrsName(FooApplication.APP_NAME)
public class FooApplication extends Application {

    public static final String APP_NAME = "my-foo-app";

}
```

I created a REST endpoint that produces text:

```java
@Component(service = BarText.class, scope = ServiceScope.PROTOTYPE)
@JaxrsResource
@JaxrsApplicationSelect("(osgi.jaxrs.name=" + FooApplication.APP_NAME + ")")
@Path("text")
@Produces(MediaType.TEXT_PLAIN)
public class BarText {

    @GET
    public String get() {
        return "hello world";
    }

}
```

I created a REST endpoint that produces JSON:

```java
@Component(service = BarJson.class, scope = ServiceScope.PROTOTYPE)
@JaxrsResource
@JaxrsApplicationSelect("(osgi.jaxrs.name=" + FooApplication.APP_NAME + ")")
@Path("json")
@Produces(MediaType.APPLICATION_JSON)
public class BarJson {

    @GET
    public String get() {
        return "hello world";
    }

}
```

Using the v1.0.3 I can call "http://127.0.0.1:8080/foo/text" and
"http://127.0.0.1:8080/foo/json".

Then I added `@JSONRequired` to the BarJson class.

A call to "http://127.0.0.1:8080/foo/text" still succeeded. On
"http://127.0.0.1:8080/foo/json" I got a 404.
So far, all fine.

I added a bundle that provides an JAX-RS extension, a
MessageBodyReader and a MessageBodyWriter for the media type JSON (two
separate components for the reader and writer).

```java
@Component(scope = PROTOTYPE)
@JaxrsExtension
@JaxrsMediaType(APPLICATION_JSON)
public class JohnzonMessageBodyReader<T> extends IgnorableTypes
implements MessageBodyReader<T> {
...
```

```java
@Component(scope = PROTOTYPE)
@JaxrsExtension
@JaxrsMediaType(APPLICATION_JSON)
public class JohnzonMessageBodyWriter<T> extends IgnorableTypes
implements MessageBodyWriter<T> {
```

Now, again a call to "http://127.0.0.1:8080/foo/text" succeeded and a
call to "http://127.0.0.1:8080/foo/json" succeeded.

After that I updated the Aries JAX-RS Whiteboard implementation from
1.0.3 to 1.0.5.

A call to "http://127.0.0.1:8080/foo/text" still succeeded. On
"http://127.0.0.1:8080/foo/json" I got a 404.

Is there something wrong on my extension that provides the JSON media type?

Best regards,
Markus

Re: Changed behaviour: JSONRequire, JaxrsExtension

Posted by Markus Rathgeb <ma...@gmail.com>.
I assume I can answer it myself.

I need to add
@JaxrsApplicationSelect("(osgi.jaxrs.name=*)")
to the extension, so it is available for every application and not the
default only.

===
commit cfead5b98c980fc3dde8db7881518d10af923190
Author: Carlos Sierra <cs...@apache.org>
Date:   Thu Jan 31 09:44:03 2019 +0100

    [ARIES-1884] Only register to default application by default

    Extensions without application select property should only register to
    default application, instead of registering to all available
    applications as it was coded
===

Am Di., 13. Aug. 2019 um 19:36 Uhr schrieb Markus Rathgeb <ma...@gmail.com>:
>
> I tested the usage of the Aries JAX-RS Whiteboard reference
> implementation a little bit.
> It works for me using v1.0.1, v1.0.2 and v1.0.3.
> It stopped working for me using v1.0.4 and v1.0.5.
>
> I added a small example to explain what's not working anymore:
>
> I created an application:
>
> ```java
> @Component(service = Application.class)
> @JaxrsApplicationBase("foo")
> @JaxrsName(FooApplication.APP_NAME)
> public class FooApplication extends Application {
>
>     public static final String APP_NAME = "my-foo-app";
>
> }
> ```
>
> I created a REST endpoint that produces text:
>
> ```java
> @Component(service = BarText.class, scope = ServiceScope.PROTOTYPE)
> @JaxrsResource
> @JaxrsApplicationSelect("(osgi.jaxrs.name=" + FooApplication.APP_NAME + ")")
> @Path("text")
> @Produces(MediaType.TEXT_PLAIN)
> public class BarText {
>
>     @GET
>     public String get() {
>         return "hello world";
>     }
>
> }
> ```
>
> I created a REST endpoint that produces JSON:
>
> ```java
> @Component(service = BarJson.class, scope = ServiceScope.PROTOTYPE)
> @JaxrsResource
> @JaxrsApplicationSelect("(osgi.jaxrs.name=" + FooApplication.APP_NAME + ")")
> @Path("json")
> @Produces(MediaType.APPLICATION_JSON)
> public class BarJson {
>
>     @GET
>     public String get() {
>         return "hello world";
>     }
>
> }
> ```
>
> Using the v1.0.3 I can call "http://127.0.0.1:8080/foo/text" and
> "http://127.0.0.1:8080/foo/json".
>
> Then I added `@JSONRequired` to the BarJson class.
>
> A call to "http://127.0.0.1:8080/foo/text" still succeeded. On
> "http://127.0.0.1:8080/foo/json" I got a 404.
> So far, all fine.
>
> I added a bundle that provides an JAX-RS extension, a
> MessageBodyReader and a MessageBodyWriter for the media type JSON (two
> separate components for the reader and writer).
>
> ```java
> @Component(scope = PROTOTYPE)
> @JaxrsExtension
> @JaxrsMediaType(APPLICATION_JSON)
> public class JohnzonMessageBodyReader<T> extends IgnorableTypes
> implements MessageBodyReader<T> {
> ...
> ```
>
> ```java
> @Component(scope = PROTOTYPE)
> @JaxrsExtension
> @JaxrsMediaType(APPLICATION_JSON)
> public class JohnzonMessageBodyWriter<T> extends IgnorableTypes
> implements MessageBodyWriter<T> {
> ```
>
> Now, again a call to "http://127.0.0.1:8080/foo/text" succeeded and a
> call to "http://127.0.0.1:8080/foo/json" succeeded.
>
> After that I updated the Aries JAX-RS Whiteboard implementation from
> 1.0.3 to 1.0.5.
>
> A call to "http://127.0.0.1:8080/foo/text" still succeeded. On
> "http://127.0.0.1:8080/foo/json" I got a 404.
>
> Is there something wrong on my extension that provides the JSON media type?
>
> Best regards,
> Markus