You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2017/07/19 12:17:54 UTC
tomee git commit: TOMEE-2099 ensure properties are wired in jaxrs
runtime
Repository: tomee
Updated Branches:
refs/heads/master bfaefb36e -> 5830c209a
TOMEE-2099 ensure properties are wired in jaxrs runtime
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/5830c209
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/5830c209
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/5830c209
Branch: refs/heads/master
Commit: 5830c209a0fc287933e3a4e61484011cef96d9f7
Parents: bfaefb3
Author: Romain Manni-Bucau <rm...@gmail.com>
Authored: Wed Jul 19 14:17:04 2017 +0200
Committer: Romain Manni-Bucau <rm...@gmail.com>
Committed: Wed Jul 19 14:17:04 2017 +0200
----------------------------------------------------------------------
.../cxf/rs/AppPropertiesPropagationTest.java | 131 +++++++++++++++++++
.../server/rest/InternalApplication.java | 7 +
2 files changed, 138 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/5830c209/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/AppPropertiesPropagationTest.java
----------------------------------------------------------------------
diff --git a/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/AppPropertiesPropagationTest.java b/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/AppPropertiesPropagationTest.java
new file mode 100644
index 0000000..3a345e2
--- /dev/null
+++ b/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/AppPropertiesPropagationTest.java
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.server.cxf.rs;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Feature;
+import javax.ws.rs.core.FeatureContext;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.testing.Classes;
+import org.apache.openejb.testing.EnableServices;
+import org.apache.openejb.testing.JaxrsProviders;
+import org.apache.openejb.testing.RandomPort;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@EnableServices("jaxrs")
+@JaxrsProviders(AppPropertiesPropagationTest.Registrator.class)
+@RunWith(ApplicationComposer.class)
+@Classes(innerClassesAsBean = true)
+public class AppPropertiesPropagationTest {
+ @RandomPort("http")
+ private int port;
+
+ @Test
+ public void checkStarIsNotAnIssue() {
+ assertEquals("yes", WebClient.create("http://localhost:" + port + "/openejb/")
+ .path("AppPropertiesPropagationTest/endpoint").get(String.class));
+ assertEquals("yes", WebClient.create("http://localhost:" + port + "/openejb/")
+ .path("AppPropertiesPropagationTest/endpoint/2").get(String.class));
+ }
+
+ @Path("endpoint")
+ public static class MyEndpoint {
+ @GET
+ public String get(@Context final Application app) {
+ return String.valueOf(app.getProperties().get("AppPropertiesPropagationTest"));
+ }
+
+ @GET
+ @Produces("AppPropertiesPropagationTest/1")
+ @Path("2")
+ public MyEndpoint provider(@Context final Application app) {
+ return this;
+ }
+ }
+
+ @Provider
+ public static class Registrator implements Feature {
+ @Override
+ public boolean configure(final FeatureContext context) {
+ context.register(new Writer(context.getConfiguration().getProperty("AppPropertiesPropagationTest")
+ .toString().getBytes(StandardCharsets.UTF_8)));
+ return true;
+ }
+ }
+
+ @Provider
+ @Produces("AppPropertiesPropagationTest/1")
+ public static class Writer implements MessageBodyWriter<MyEndpoint> {
+ private final byte[] value;
+
+ Writer(byte[] value) {
+ this.value = value;
+ }
+
+ @Override
+ public boolean isWriteable(final Class<?> type, final Type genericType,
+ final Annotation[] annotations, final MediaType mediaType) {
+ return type == MyEndpoint.class;
+ }
+
+ @Override
+ public long getSize(final MyEndpoint myEndpoint, final Class<?> type, final Type genericType,
+ final Annotation[] annotations, final MediaType mediaType) {
+ return -1;
+ }
+
+ @Override
+ public void writeTo(final MyEndpoint myEndpoint, final Class<?> type, final Type genericType,
+ final Annotation[] annotations, final MediaType mediaType,
+ final MultivaluedMap<String, Object> httpHeaders,
+ final OutputStream entityStream) throws IOException, WebApplicationException {
+ entityStream.write(value);
+ }
+ }
+
+ @ApplicationPath("/AppPropertiesPropagationTest")
+ public static class MyApp extends Application {
+ @Override
+ public Map<String, Object> getProperties() {
+ return new HashMap<String, Object>(){{
+ put("AppPropertiesPropagationTest", "yes");
+ }};
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/5830c209/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/InternalApplication.java
----------------------------------------------------------------------
diff --git a/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/InternalApplication.java b/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/InternalApplication.java
index 04a8cbd..bb1d59e 100644
--- a/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/InternalApplication.java
+++ b/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/InternalApplication.java
@@ -17,7 +17,9 @@
package org.apache.openejb.server.rest;
import javax.ws.rs.core.Application;
+import java.util.Collections;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
public class InternalApplication extends Application {
@@ -43,6 +45,11 @@ public class InternalApplication extends Application {
return singletons;
}
+ @Override
+ public Map<String, Object> getProperties() {
+ return original == null ? Collections.<String, Object>emptyMap() : original.getProperties();
+ }
+
public Application getOriginal() {
return original;
}