From: Robert Varga Date: Fri, 13 Apr 2018 15:08:40 +0000 (+0200) Subject: Add web/servlet-api and jersey2 implementation X-Git-Tag: release/fluorine~37 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=1f41c70c0fb1dce125292056afc56cc7847c488a;p=aaa.git Add web/servlet-api and jersey2 implementation web/servlet-api provides implementation-agnostic entrypoints for creating Clients and HttpServlets. web/servlet-jersey2 provides an implementation based on jersey-2.25.1. This split allows us to have applications independent of the implementation. Change-Id: I77d92fb8764aa28817d5dcac9f8450dc42017429 Signed-off-by: Robert Varga --- diff --git a/artifacts/pom.xml b/artifacts/pom.xml index 15f429313..77573fd78 100644 --- a/artifacts/pom.xml +++ b/artifacts/pom.xml @@ -107,6 +107,27 @@ ${project.version} + + ${project.groupId}.web + web-api + ${project.version} + + + ${project.groupId}.web + web-osgi-impl + ${project.version} + + + ${project.groupId}.web + servlet-api + ${project.version} + + + ${project.groupId}.web + servlet-jersey2 + ${project.version} + + ${project.groupId} features-aaa diff --git a/features/odl-aaa-web/pom.xml b/features/odl-aaa-web/pom.xml index 76e044dc0..6fd090bec 100644 --- a/features/odl-aaa-web/pom.xml +++ b/features/odl-aaa-web/pom.xml @@ -23,6 +23,25 @@ ODL :: aaa :: ${project.artifactId} + + + + ${project.groupId} + aaa-artifacts + ${project.version} + pom + import + + + org.glassfish.jersey + jersey-bom + 2.25.1 + pom + import + + + + org.opendaylight.odlparent @@ -39,8 +58,18 @@ ${project.groupId}.web web-osgi-impl - ${project.version} + + + ${project.groupId}.web + servlet-jersey2 + + + org.glassfish.jersey.bundles.repackaged + jersey-guava + 2.25.1 + + org.opendaylight.odlparent odl-karaf-feat-jetty diff --git a/web/pom.xml b/web/pom.xml index a578ae3bc..6926961ae 100644 --- a/web/pom.xml +++ b/web/pom.xml @@ -27,5 +27,7 @@ api impl-osgi impl-jetty + servlet-api + servlet-jersey2 diff --git a/web/servlet-api/pom.xml b/web/servlet-api/pom.xml new file mode 100644 index 000000000..51dc303aa --- /dev/null +++ b/web/servlet-api/pom.xml @@ -0,0 +1,45 @@ + + + + 4.0.0 + + + org.opendaylight.aaa + aaa-parent + 0.8.0-SNAPSHOT + ../../parent + + + org.opendaylight.aaa.web + servlet-api + ODL :: aaa :: ${project.artifactId} + bundle + + + + com.google.guava + guava + + + javax.servlet + javax.servlet-api + + + javax.ws.rs + javax.ws.rs-api + + + + org.opendaylight.yangtools + concepts + + + + diff --git a/web/servlet-api/src/main/java/org/opendaylight/aaa/web/servlet/HttpServletBuilder.java b/web/servlet-api/src/main/java/org/opendaylight/aaa/web/servlet/HttpServletBuilder.java new file mode 100644 index 000000000..636553d98 --- /dev/null +++ b/web/servlet-api/src/main/java/org/opendaylight/aaa/web/servlet/HttpServletBuilder.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2018 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.aaa.web.servlet; + +import com.google.common.annotations.Beta; +import javax.annotation.concurrent.NotThreadSafe; +import javax.servlet.http.HttpServlet; +import javax.ws.rs.core.Application; +import javax.ws.rs.core.Configurable; +import org.opendaylight.yangtools.concepts.Builder; + +/** + * Utility methods for instantiating {@link HttpServlet}s from {@link Application}s, abstracting the servlet + * implementation from application developers. + * + * @author Robert Varga + */ +@Beta +@NotThreadSafe +public interface HttpServletBuilder extends Builder, Configurable { + +} diff --git a/web/servlet-api/src/main/java/org/opendaylight/aaa/web/servlet/ServletSupport.java b/web/servlet-api/src/main/java/org/opendaylight/aaa/web/servlet/ServletSupport.java new file mode 100644 index 000000000..946f31a55 --- /dev/null +++ b/web/servlet-api/src/main/java/org/opendaylight/aaa/web/servlet/ServletSupport.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2018 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.aaa.web.servlet; + +import com.google.common.annotations.Beta; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.core.Application; +import org.eclipse.jdt.annotation.NonNullByDefault; + +/** + * Main API entry point. An implementation of this interface is injected in the application. + * + * @author Robert Varga + */ +@Beta +@NonNullByDefault +public interface ServletSupport { + /** + * Create a new {@link ClientBuilder}. + * + * @return A new ClientBuilder. + */ + ClientBuilder newClientBuilder(); + + /** + * Create a new {@link HttpServletBuilder} for an {@link Application}. + * + * @return A new HttpServletBuilder. + */ + HttpServletBuilder createHttpServletBuilder(Application application); +} diff --git a/web/servlet-jersey2/pom.xml b/web/servlet-jersey2/pom.xml new file mode 100644 index 000000000..9a258c5e8 --- /dev/null +++ b/web/servlet-jersey2/pom.xml @@ -0,0 +1,77 @@ + + + + 4.0.0 + + + org.opendaylight.aaa + aaa-parent + 0.8.0-SNAPSHOT + ../../parent + + + org.opendaylight.aaa.web + servlet-jersey2 + ODL :: aaa :: ${project.artifactId} + bundle + + + + + + org.glassfish.jersey + jersey-bom + 2.25.1 + pom + import + + + + + + + + org.opendaylight.aaa.web + servlet-api + + + org.glassfish.jersey.containers + jersey-container-servlet + + + org.glassfish.jersey.core + jersey-client + + + org.osgi + org.osgi.core + + + org.kohsuke.metainf-services + metainf-services + + + + + + + org.apache.felix + maven-bundle-plugin + true + + + {META-INF/services=${project.build.directory}/classes/META-INF/services} + org.opendaylight.aaa.web.servlet.jersey2.osgi.Activator + + + + + + diff --git a/web/servlet-jersey2/src/main/java/org/opendaylight/aaa/web/servlet/jersey2/JerseyHttpServletBuilder.java b/web/servlet-jersey2/src/main/java/org/opendaylight/aaa/web/servlet/jersey2/JerseyHttpServletBuilder.java new file mode 100644 index 000000000..1159bca81 --- /dev/null +++ b/web/servlet-jersey2/src/main/java/org/opendaylight/aaa/web/servlet/jersey2/JerseyHttpServletBuilder.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2018 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.aaa.web.servlet.jersey2; + +import java.util.Map; +import javax.servlet.http.HttpServlet; +import javax.ws.rs.core.Application; +import javax.ws.rs.core.Configuration; +import org.glassfish.jersey.server.ResourceConfig; +import org.glassfish.jersey.servlet.ServletContainer; +import org.opendaylight.aaa.web.servlet.HttpServletBuilder; + +/** + * Jersey-based implementation of {@link HttpServletBuilder}. + * + * @author Robert Varga + */ +final class JerseyHttpServletBuilder implements HttpServletBuilder { + private ResourceConfig config; + + JerseyHttpServletBuilder(final Application application) { + config = ResourceConfig.forApplication(application); + } + + @Override + public HttpServlet build() { + return new ServletContainer(config); + } + + @Override + public Configuration getConfiguration() { + return config; + } + + @Override + public HttpServletBuilder property(final String name, final Object value) { + config = config.property(name, value); + return this; + } + + @Override + public HttpServletBuilder register(final Class componentClass) { + config = config.register(componentClass); + return this; + } + + @Override + public HttpServletBuilder register(final Class componentClass, final int priority) { + config = config.register(componentClass, priority); + return this; + } + + @Override + public HttpServletBuilder register(final Class componentClass, final Class... contracts) { + config = config.register(componentClass, contracts); + return this; + } + + @Override + public HttpServletBuilder register(final Class componentClass, final Map, Integer> contracts) { + config = config.register(componentClass, contracts); + return this; + } + + @Override + public HttpServletBuilder register(final Object component) { + config = config.register(component); + return this; + } + + @Override + public HttpServletBuilder register(final Object component, final int priority) { + config = config.register(component, priority); + return this; + } + + @Override + public HttpServletBuilder register(final Object component, final Class... contracts) { + config = config.register(component, contracts); + return this; + } + + @Override + public HttpServletBuilder register(final Object component, final Map, Integer> contracts) { + config = config.register(component, contracts); + return this; + } +} diff --git a/web/servlet-jersey2/src/main/java/org/opendaylight/aaa/web/servlet/jersey2/JerseyServletSupport.java b/web/servlet-jersey2/src/main/java/org/opendaylight/aaa/web/servlet/jersey2/JerseyServletSupport.java new file mode 100644 index 000000000..3bfe50ef0 --- /dev/null +++ b/web/servlet-jersey2/src/main/java/org/opendaylight/aaa/web/servlet/jersey2/JerseyServletSupport.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.aaa.web.servlet.jersey2; + +import com.google.common.annotations.Beta; +import javax.annotation.concurrent.ThreadSafe; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.core.Application; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.glassfish.jersey.client.JerseyClientBuilder; +import org.kohsuke.MetaInfServices; +import org.opendaylight.aaa.web.servlet.HttpServletBuilder; +import org.opendaylight.aaa.web.servlet.ServletSupport; + +@Beta +@MetaInfServices +@NonNullByDefault +@ThreadSafe +public final class JerseyServletSupport implements ServletSupport { + @Override + public HttpServletBuilder createHttpServletBuilder(final Application application) { + return new JerseyHttpServletBuilder(application); + } + + @Override + public ClientBuilder newClientBuilder() { + return new JerseyClientBuilder(); + } +} diff --git a/web/servlet-jersey2/src/main/java/org/opendaylight/aaa/web/servlet/jersey2/osgi/Activator.java b/web/servlet-jersey2/src/main/java/org/opendaylight/aaa/web/servlet/jersey2/osgi/Activator.java new file mode 100644 index 000000000..fad0a7dee --- /dev/null +++ b/web/servlet-jersey2/src/main/java/org/opendaylight/aaa/web/servlet/jersey2/osgi/Activator.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2018 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.aaa.web.servlet.jersey2.osgi; + +import org.opendaylight.aaa.web.servlet.ServletSupport; +import org.opendaylight.aaa.web.servlet.jersey2.JerseyServletSupport; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; + +public class Activator implements BundleActivator { + private ServiceRegistration reg; + + @Override + public void start(final BundleContext context) { + reg = context.registerService(ServletSupport.class, new JerseyServletSupport(), null); + } + + @Override + public void stop(final BundleContext context) { + if (reg != null) { + reg.unregister(); + reg = null; + } + } +}