Skip to content

Commit

Permalink
project: remove siesta-server dependency
Browse files Browse the repository at this point in the history
Initialize Resteasy using GuiceResteasyBootstrapServletContextListener
  • Loading branch information
ibodrov committed Nov 16, 2023
1 parent cf819a2 commit 5a01781
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 106 deletions.
14 changes: 2 additions & 12 deletions server/impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,8 @@
<artifactId>siesta-api</artifactId>
</dependency>
<dependency>
<groupId>io.takari.siesta</groupId>
<artifactId>siesta-server</artifactId>
<exclusions>
<exclusion>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</exclusion>
</exclusions>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-guice</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
import com.walmartlabs.concord.server.boot.*;
import com.walmartlabs.concord.server.boot.filters.*;
import com.walmartlabs.concord.server.boot.servlets.FormServletHolder;
import com.walmartlabs.concord.server.boot.servlets.SiestaServletHolder;
import com.walmartlabs.concord.server.boot.servlets.ResteasyServletHolder;
import com.walmartlabs.concord.server.boot.statics.StaticResourcesConfigurator;
import com.walmartlabs.concord.server.boot.validation.ValidationModule;
import com.walmartlabs.concord.server.websocket.ConcordWebSocketServlet;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.web.mgt.WebSecurityManager;
Expand All @@ -37,14 +38,14 @@

import static com.google.inject.Scopes.SINGLETON;
import static com.google.inject.multibindings.Multibinder.newSetBinder;
import static com.walmartlabs.concord.server.Utils.bindServletFilter;
import static com.walmartlabs.concord.server.Utils.bindServletHolder;
import static com.walmartlabs.concord.server.Utils.*;

public class ApiServerModule implements Module {

@Override
public void configure(Binder binder) {
// Jetty

binder.bind(HttpServer.class).in(SINGLETON);

// Filter
Expand All @@ -67,7 +68,7 @@ public void configure(Binder binder) {
// ServletHolder

bindServletHolder(binder, FormServletHolder.class);
bindServletHolder(binder, SiestaServletHolder.class);
bindServletHolder(binder, ResteasyServletHolder.class);

// RequestErrorHandler

Expand All @@ -77,7 +78,7 @@ public void configure(Binder binder) {

newSetBinder(binder, ContextHandlerConfigurator.class).addBinding().to(StaticResourcesConfigurator.class);

// shiro
// Shiro

newSetBinder(binder, ServletContextListener.class).addBinding().to(ShiroListener.class).in(SINGLETON);
newSetBinder(binder, FilterChainConfigurator.class).addBinding().to(ConcordFilterChainConfigurator.class).in(SINGLETON);
Expand All @@ -87,7 +88,11 @@ public void configure(Binder binder) {
binder.bind(SecurityManager.class).to(ConcordSecurityManager.class);
binder.bind(WebSecurityManager.class).to(ConcordSecurityManager.class);

// TODO get rid of RestModule, add all internal modules directly here
binder.install(new RestModule());
binder.install(new ValidationModule());

// JAX-RS resources

newSetBinder(binder, ServletContextListener.class).addBinding().to(ResteasyListener.class).in(SINGLETON);
bindJaxRsResource(binder, ServerResource.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Singleton
@Path("/api/v1/server")
public class ServerResource implements Resource {

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.walmartlabs.concord.server.boot;

/*-
* *****
* Concord
* -----
* Copyright (C) 2017 - 2023 Walmart Inc.
* -----
* Licensed 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.
* =====
*/

import com.google.inject.Inject;
import com.google.inject.Injector;
import org.jboss.resteasy.plugins.guice.GuiceResteasyBootstrapServletContextListener;
import org.jboss.resteasy.spi.ResteasyProviderFactory;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.lang.reflect.Field;

@WebListener
public class ResteasyListener implements ServletContextListener {

private final GuiceResteasyBootstrapServletContextListener delegate;

@Inject
public ResteasyListener(Injector injector) {
this.delegate = new GuiceResteasyBootstrapServletContextListener();
try {
Field field = GuiceResteasyBootstrapServletContextListener.class.getDeclaredField("parentInjector");
field.setAccessible(true);
field.set(delegate, injector);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}

@Override
public void contextInitialized(ServletContextEvent sce) {
delegate.contextInitialized(sce);
}

@Override
public void contextDestroyed(ServletContextEvent sce) {
delegate.contextDestroyed(sce);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* *****
* Concord
* -----
* Copyright (C) 2017 - 2020 Walmart Inc.
* Copyright (C) 2017 - 2023 Walmart Inc.
* -----
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,25 +21,17 @@
*/

import org.eclipse.jetty.servlet.ServletHolder;
import org.sonatype.siesta.server.SiestaServlet;
import org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher;

import javax.inject.Inject;
import javax.servlet.annotation.WebServlet;

/**
* Binds {@link SiestaServlet} to Concord's API paths.
*/
@WebServlet({
"/api/*",
"/events/github/*"
})
public class SiestaServletHolder extends ServletHolder {

@Inject
public SiestaServletHolder(SiestaServlet siestaServlet) {
super(siestaServlet);
public class ResteasyServletHolder extends ServletHolder {

// necessary to support multiple API roots
setInitParameter("resteasy.servlet.mapping.prefix", "/");
public ResteasyServletHolder() {
super(HttpServletDispatcher.class);
}
}
14 changes: 0 additions & 14 deletions server/plugins/noderoster/impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,6 @@
<groupId>io.takari.siesta</groupId>
<artifactId>siesta-api</artifactId>
</dependency>
<dependency>
<groupId>io.takari.siesta</groupId>
<artifactId>siesta-server</artifactId>
<exclusions>
<exclusion>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
Expand Down
23 changes: 0 additions & 23 deletions targetplatform/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -603,29 +603,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.takari.siesta</groupId>
<artifactId>siesta-server</artifactId>
<version>${siesta.version}</version>
<exclusions>
<exclusion>
<groupId>org.sonatype.sisu</groupId>
<artifactId>sisu-guice</artifactId>
</exclusion>
<exclusion>
<groupId>org.sonatype.sisu.inject</groupId>
<artifactId>guice-servlet</artifactId>
</exclusion>
<exclusion>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.el</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
Expand Down

0 comments on commit 5a01781

Please sign in to comment.