This is an automated email from the ASF dual-hosted git repository.
rmannibucau pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwebbeans-meecrowave.git
The following commit(s) were added to refs/heads/master by this push:
new a6db02a MEECROWAVE-225 rely on jsonb jaxrs integration even for jsonp
instances
a6db02a is described below
commit a6db02a4b0070d34ab0ccff43f6990e8069840aa
Author: Romain Manni-Bucau <[email protected]>
AuthorDate: Tue Dec 10 06:52:35 2019 +0100
MEECROWAVE-225 rely on jsonb jaxrs integration even for jsonp instances
---
.../org/apache/meecrowave/tests/sse/SSETest.java | 83 +++++++++++-----------
meecrowave-core/pom.xml | 5 --
.../org/apache/meecrowave/cxf/ConfigurableBus.java | 26 +++----
3 files changed, 55 insertions(+), 59 deletions(-)
diff --git
a/integration-tests/sse/src/test/java/org/apache/meecrowave/tests/sse/SSETest.java
b/integration-tests/sse/src/test/java/org/apache/meecrowave/tests/sse/SSETest.java
index d3547a3..3205a4f 100644
---
a/integration-tests/sse/src/test/java/org/apache/meecrowave/tests/sse/SSETest.java
+++
b/integration-tests/sse/src/test/java/org/apache/meecrowave/tests/sse/SSETest.java
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ * <p>
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ * <p>
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -30,7 +30,6 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.sse.SseEventSource;
-import org.apache.johnzon.jaxrs.JsrProvider;
import org.apache.meecrowave.Meecrowave;
import org.apache.meecrowave.junit.MeecrowaveRule;
@@ -40,45 +39,47 @@ import org.junit.Test;
import static org.junit.Assert.*;
public class SSETest {
- @ClassRule
- public static final MeecrowaveRule CONTAINER = new MeecrowaveRule(new
Meecrowave.Builder()
- .randomHttpPort()
- .excludePackages("org.atmosphere")
- //.cxfServletParam("jaxrs.scope", "singleton")
-
.includePackages(NewsService.class.getPackage().getName()), "");
+ @ClassRule
+ public static final MeecrowaveRule CONTAINER = new MeecrowaveRule(new
Meecrowave.Builder()
+ .randomHttpPort()
+ .excludePackages("org.atmosphere")
+ //.cxfServletParam("jaxrs.scope", "singleton")
+ .includePackages(NewsService.class.getPackage().getName()), "");
- public static final Client client =
ClientBuilder.newBuilder().register(JsrProvider.class).build();
+ @Test
+ public void normal() {
+ //Make sure normal JAX-RS requests function with SSE enabled
+ final Client client = ClientBuilder.newBuilder().build();
+ WebTarget base = client.target(String.format("http://localhost:%d",
CONTAINER.getConfiguration().getHttpPort()));
+ Response response = base.path("/rs/news").request().get();
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
+ JsonObject responseJson = response.readEntity(JsonObject.class);
+ assertEquals("online", responseJson.getString("news"));
+ client.close();
+ }
- @Test
- public void normal() {
- //Make sure normal JAX-RS requests function with SSE enabled
- WebTarget base =
client.target(String.format("http://localhost:%d",
CONTAINER.getConfiguration().getHttpPort()));
- Response response = base.path("/rs/news").request().get();
- assertEquals(Response.Status.OK.getStatusCode(),
response.getStatus());
- JsonObject responseJson = response.readEntity(JsonObject.class);
- assertEquals("online", responseJson.getString("news"));
- }
+ @Test
+ public void sse() throws MalformedURLException, InterruptedException {
+ final Client client = ClientBuilder.newBuilder().build();
+ WebTarget base = client.target(String.format("http://localhost:%d",
CONTAINER.getConfiguration().getHttpPort()));
+ //the /META-INF/services/javax.ws.rs.sse.SseEventSource.Builder file
is only needed until this is fixed:
+ //https://issues.apache.org/jira/browse/CXF-7633
+ //An exception is not thrown on a 404 response but that is not a
Meecrowave issue.
+ try (final SseEventSource eventSource =
SseEventSource.target(base.path("/rs/news/update")).build()) {
+ CountDownLatch cdl = new CountDownLatch(5);
+ eventSource.register(sse -> {
+ JsonObject data = sse.readData(JsonObject.class,
MediaType.APPLICATION_JSON_TYPE);
+ assertNotNull(data);
+ cdl.countDown();
+ }, e -> {
+ e.printStackTrace();
+ fail(e.getMessage());
- @Test
- public void sse() throws MalformedURLException, InterruptedException {
- WebTarget base =
client.target(String.format("http://localhost:%d",
CONTAINER.getConfiguration().getHttpPort()));
- //the /META-INF/services/javax.ws.rs.sse.SseEventSource.Builder
file is only needed until this is fixed:
- //https://issues.apache.org/jira/browse/CXF-7633
- //An exception is not thrown on a 404 response but that is not
a Meecrowave issue.
- try (final SseEventSource eventSource =
SseEventSource.target(base.path("/rs/news/update")).build()) {
- CountDownLatch cdl = new CountDownLatch(5);
- eventSource.register(sse -> {
- JsonObject data =
sse.readData(JsonObject.class, MediaType.APPLICATION_JSON_TYPE);
- assertNotNull(data);
- cdl.countDown();
- }, e -> {
- e.printStackTrace();
- fail(e.getMessage());
-
- });
- eventSource.open();
- assertTrue(cdl.await(20, TimeUnit.SECONDS));
- assertTrue(eventSource.close(5, TimeUnit.SECONDS));
- }
- }
+ });
+ eventSource.open();
+ assertTrue(cdl.await(20, TimeUnit.SECONDS));
+ assertTrue(eventSource.close(5, TimeUnit.SECONDS));
+ }
+ client.close();
+ }
}
diff --git a/meecrowave-core/pom.xml b/meecrowave-core/pom.xml
index 1ad331a..c0f6616 100644
--- a/meecrowave-core/pom.xml
+++ b/meecrowave-core/pom.xml
@@ -151,11 +151,6 @@
</dependency>
<dependency>
<groupId>org.apache.johnzon</groupId>
- <artifactId>johnzon-jaxrs</artifactId>
- <version>${johnzon.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.johnzon</groupId>
<artifactId>johnzon-jsonb</artifactId>
<version>${johnzon.version}</version>
</dependency>
diff --git
a/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/ConfigurableBus.java
b/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/ConfigurableBus.java
index 11dc8c2..2abd216 100644
---
a/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/ConfigurableBus.java
+++
b/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/ConfigurableBus.java
@@ -26,6 +26,8 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Collection;
@@ -71,9 +73,6 @@ import org.apache.cxf.endpoint.ClientLifeCycleManager;
import org.apache.johnzon.core.AbstractJsonFactory;
import org.apache.johnzon.core.JsonGeneratorFactoryImpl;
import org.apache.johnzon.core.JsonParserFactoryImpl;
-import org.apache.johnzon.jaxrs.DelegateProvider;
-import org.apache.johnzon.jaxrs.JsrMessageBodyReader;
-import org.apache.johnzon.jaxrs.JsrMessageBodyWriter;
import org.apache.johnzon.jaxrs.jsonb.jaxrs.JsonbJaxrsProvider;
import org.apache.meecrowave.configuration.Configuration;
@@ -125,8 +124,7 @@ public class ConfigurableBus extends ExtensionManagerBus {
builder.isJsonbIJson(),
builder.isJsonbPrettify(),
builder.getJsonbBinaryStrategy(),
builder.getJsonbNamingStrategy(),
builder.getJsonbOrderStrategy(),
- new DelegateJsonProvider(provider,
readerFactory, writerFactory)),
- new ConfiguredJsrProvider(readerFactory,
writerFactory))
+ new DelegateJsonProvider(provider,
readerFactory, writerFactory)))
.collect(toList());
});
@@ -192,15 +190,17 @@ public class ConfigurableBus extends ExtensionManagerBus {
protected Jsonb createJsonb() {
return jsonb;
}
- }
- @Provider
- @Produces({MediaType.APPLICATION_JSON, "application/*+json"})
- @Consumes({MediaType.APPLICATION_JSON, "application/*+json"})
- public static class ConfiguredJsrProvider extends
DelegateProvider<JsonStructure> { // TODO: probably wire the encoding in johnzon
- private ConfiguredJsrProvider(final JsonReaderFactory readerFactory,
- final JsonWriterFactory writerFactory) {
- super(new JsrMessageBodyReader(readerFactory, false), new
JsrMessageBodyWriter(writerFactory, false));
+ @Override
+ public boolean isReadable(final Class<?> type, final Type genericType,
+ final Annotation[] annotations, final
MediaType mediaType) {
+ return super.isReadable(type, genericType, annotations, mediaType)
|| JsonValue.class.isAssignableFrom(type);
+ }
+
+ @Override
+ public boolean isWriteable(final Class<?> type, final Type genericType,
+ final Annotation[] annotations, final
MediaType mediaType) {
+ return super.isWriteable(type, genericType, annotations,
mediaType) || JsonValue.class.isAssignableFrom(type);
}
}