You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2018/03/04 00:46:38 UTC

[isis] branch master updated: ISIS-1891 added jaxrs-resteasy-4 plugin

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new 29c7b80  ISIS-1891 added jaxrs-resteasy-4 plugin
29c7b80 is described below

commit 29c7b80a54a9897ff4d30934f7a6a2a93cce248c
Author: Andi Huber <ah...@apache.org>
AuthorDate: Sun Mar 4 01:46:35 2018 +0100

    ISIS-1891 added jaxrs-resteasy-4 plugin
    
    intended for JEE 8 deployment
---
 core/plugins/jaxrs-resteasy-4/pom.xml              |  6 +-
 .../jaxrs/resteasy/IsisResteasy4Plugin.java        | 34 ++++++++++
 .../conneg/RestfulObjectsJaxbWriterForXml.java     | 74 ++++++++++++++++++++++
 .../viewer/restfulobjects/server/conneg/Util.java  | 33 ++++++++++
 ...r.restfulobjects.applib.client.UriBuilderPlugin |  1 +
 ...wer.restfulobjects.server.IsisJaxrsServerPlugin |  1 +
 6 files changed, 146 insertions(+), 3 deletions(-)

diff --git a/core/plugins/jaxrs-resteasy-4/pom.xml b/core/plugins/jaxrs-resteasy-4/pom.xml
index 9e5b8a4..ca17d9f 100644
--- a/core/plugins/jaxrs-resteasy-4/pom.xml
+++ b/core/plugins/jaxrs-resteasy-4/pom.xml
@@ -67,20 +67,20 @@
 		<dependency>
 			<groupId>org.jboss.resteasy</groupId>
 			<artifactId>resteasy-jaxb-provider</artifactId>
-			<version>${resteasy3-jaxrs.version}</version>
+			<version>${resteasy4-jaxrs.version}</version>
 		</dependency>
 
 		<dependency>
 			<groupId>org.jboss.resteasy</groupId>
 			<artifactId>resteasy-jackson-provider</artifactId>
-			<version>${resteasy3-jaxrs.version}</version>
+			<version>${resteasy4-jaxrs.version}</version>
 		</dependency>
 
 		<!-- RestEasy -->
 		<dependency>
 			<groupId>org.jboss.resteasy</groupId>
 			<artifactId>resteasy-jaxrs</artifactId>
-			<version>${resteasy3-jaxrs.version}</version>
+			<version>${resteasy4-jaxrs.version}</version>
 			<exclusions>
 				<exclusion>
 					<groupId>org.jboss.spec.javax.servlet</groupId>
diff --git a/core/plugins/jaxrs-resteasy-4/src/main/java/org/apache/isis/plugins/jaxrs/resteasy/IsisResteasy4Plugin.java b/core/plugins/jaxrs-resteasy-4/src/main/java/org/apache/isis/plugins/jaxrs/resteasy/IsisResteasy4Plugin.java
new file mode 100644
index 0000000..a5f75fb
--- /dev/null
+++ b/core/plugins/jaxrs-resteasy-4/src/main/java/org/apache/isis/plugins/jaxrs/resteasy/IsisResteasy4Plugin.java
@@ -0,0 +1,34 @@
+package org.apache.isis.plugins.jaxrs.resteasy;
+
+import javax.ws.rs.core.UriBuilder;
+
+import org.apache.isis.viewer.restfulobjects.applib.client.RestfulResponse.HttpStatusCode;
+import org.apache.isis.viewer.restfulobjects.applib.client.RestfulResponse;
+import org.apache.isis.viewer.restfulobjects.applib.client.UriBuilderPlugin;
+import org.apache.isis.viewer.restfulobjects.server.IsisJaxrsServerPlugin;
+import org.apache.isis.viewer.restfulobjects.server.conneg.RestfulObjectsJaxbWriterForXml;
+import org.jboss.resteasy.specimpl.ResteasyUriBuilder;
+import org.jboss.resteasy.spi.Failure;
+
+public class IsisResteasy4Plugin implements UriBuilderPlugin, IsisJaxrsServerPlugin {
+
+	@Override
+	public UriBuilder uriTemplate(String uriTemplate) {
+		return new ResteasyUriBuilder().uriTemplate(uriTemplate);
+	}
+
+	@Override
+	public Object newRestfulObjectsJaxbWriterForXml() {
+		
+		return new RestfulObjectsJaxbWriterForXml();
+	}
+
+	@Override
+	public HttpStatusCode getFailureStatusCodeIfAny(Throwable ex) {
+		
+		return (ex instanceof Failure) 
+				? RestfulResponse.HttpStatusCode.statusFor(((Failure)ex).getErrorCode())
+				: null;
+	}
+
+}
diff --git a/core/plugins/jaxrs-resteasy-4/src/main/java/org/apache/isis/viewer/restfulobjects/server/conneg/RestfulObjectsJaxbWriterForXml.java b/core/plugins/jaxrs-resteasy-4/src/main/java/org/apache/isis/viewer/restfulobjects/server/conneg/RestfulObjectsJaxbWriterForXml.java
new file mode 100644
index 0000000..e00c78b
--- /dev/null
+++ b/core/plugins/jaxrs-resteasy-4/src/main/java/org/apache/isis/viewer/restfulobjects/server/conneg/RestfulObjectsJaxbWriterForXml.java
@@ -0,0 +1,74 @@
+/*
+ *  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.isis.viewer.restfulobjects.server.conneg;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.ext.Provider;
+import javax.xml.bind.Marshaller;
+
+import org.jboss.resteasy.plugins.providers.jaxb.JAXBXmlRootElementProvider;
+
+import org.apache.isis.applib.services.bookmark.BookmarkService;
+import org.apache.isis.core.metamodel.services.ServicesInjector;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.core.runtime.system.session.IsisSessionFactory;
+import org.apache.isis.schema.utils.jaxbadapters.PersistentEntityAdapter;
+
+@Provider
+@Produces({"application/xml", "application/*+xml", "text/*+xml"})
+public class RestfulObjectsJaxbWriterForXml extends JAXBXmlRootElementProvider {
+
+    public RestfulObjectsJaxbWriterForXml(){
+        ;
+    }
+
+    @Override protected boolean isReadWritable(
+            final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType) {
+        return super.isReadWritable(type, genericType, annotations, mediaType) && hasXRoDomainTypeParameter(mediaType);
+    }
+
+    protected boolean hasXRoDomainTypeParameter(final MediaType mediaType) {
+        return Util.hasXRoDomainTypeParameter(mediaType);
+    }
+
+    @Override
+    protected Marshaller getMarshaller(
+            final Class<?> type, final Annotation[] annotations, final MediaType mediaType) {
+        final Marshaller marshaller = super.getMarshaller(type, annotations, mediaType);
+        marshaller.setAdapter(PersistentEntityAdapter.class, new PersistentEntityAdapter() {
+            @Override
+            protected BookmarkService getBookmarkService() {
+                return getServicesInjector().lookupServiceElseFail(BookmarkService.class);
+            }
+        });
+        return marshaller;
+    }
+
+    ServicesInjector getServicesInjector() {
+        return getIsisSessionFactory().getServicesInjector();
+    }
+
+    IsisSessionFactory getIsisSessionFactory() {
+        return IsisContext.getSessionFactory();
+    }
+}
diff --git a/core/plugins/jaxrs-resteasy-4/src/main/java/org/apache/isis/viewer/restfulobjects/server/conneg/Util.java b/core/plugins/jaxrs-resteasy-4/src/main/java/org/apache/isis/viewer/restfulobjects/server/conneg/Util.java
new file mode 100644
index 0000000..e7663ad
--- /dev/null
+++ b/core/plugins/jaxrs-resteasy-4/src/main/java/org/apache/isis/viewer/restfulobjects/server/conneg/Util.java
@@ -0,0 +1,33 @@
+/*
+ *  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.isis.viewer.restfulobjects.server.conneg;
+
+import javax.ws.rs.core.MediaType;
+
+final class Util {
+
+    private Util(){
+    }
+
+    static boolean hasXRoDomainTypeParameter(final MediaType mediaType) {
+        final boolean retval = mediaType.getParameters().containsKey("x-ro-domain-type");
+        return retval;
+    }
+
+}
diff --git a/core/plugins/jaxrs-resteasy-4/src/main/resources/META-INF/services/org.apache.isis.viewer.restfulobjects.applib.client.UriBuilderPlugin b/core/plugins/jaxrs-resteasy-4/src/main/resources/META-INF/services/org.apache.isis.viewer.restfulobjects.applib.client.UriBuilderPlugin
new file mode 100644
index 0000000..634a35e
--- /dev/null
+++ b/core/plugins/jaxrs-resteasy-4/src/main/resources/META-INF/services/org.apache.isis.viewer.restfulobjects.applib.client.UriBuilderPlugin
@@ -0,0 +1 @@
+org.apache.isis.plugins.jaxrs.resteasy.IsisResteasy4Plugin
\ No newline at end of file
diff --git a/core/plugins/jaxrs-resteasy-4/src/main/resources/META-INF/services/org.apache.isis.viewer.restfulobjects.server.IsisJaxrsServerPlugin b/core/plugins/jaxrs-resteasy-4/src/main/resources/META-INF/services/org.apache.isis.viewer.restfulobjects.server.IsisJaxrsServerPlugin
new file mode 100644
index 0000000..634a35e
--- /dev/null
+++ b/core/plugins/jaxrs-resteasy-4/src/main/resources/META-INF/services/org.apache.isis.viewer.restfulobjects.server.IsisJaxrsServerPlugin
@@ -0,0 +1 @@
+org.apache.isis.plugins.jaxrs.resteasy.IsisResteasy4Plugin
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
ahuber@apache.org.