Skip to content

Commit

Permalink
project: drop siesta-server dependency
Browse files Browse the repository at this point in the history
Migrate to the internal Resteasy integration.
  • Loading branch information
ibodrov committed Jan 2, 2024
1 parent 21bcaa8 commit 580131a
Show file tree
Hide file tree
Showing 74 changed files with 873 additions and 233 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ObjectMapperProvider implements Provider<ObjectMapper> {

@Override
public ObjectMapper get() {
log.info("Using concord-common's ObjectMapper...");
log.debug("Using concord-common's ObjectMapper...");

ObjectMapper mapper = new ObjectMapper()
.registerModule(new Jdk8Module())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void testValidationJsonStoreRequest() throws Exception {
fail("exception expected");
} catch (ApiException e) {
assertEquals(400, e.getCode());
assertEquals("[{\"id\":\"PARAMETER createOrUpdate.arg1.name\",\"message\":\"must match \\\"^[0-9a-zA-Z][0-9a-zA-Z_@.\\\\-~]{2,128}$\\\"\"}]", e.getResponseBody());
assertEquals("[{\"id\":\"ImmutableJsonStoreRequest.createOrUpdate.arg1.name\",\"message\":\"must match \\\"^[0-9a-zA-Z][0-9a-zA-Z_@.\\\\-~]{2,128}$\\\"\"}]", e.getResponseBody());
}
}

Expand Down
24 changes: 6 additions & 18 deletions server/impl/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -101,22 +102,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>
</dependency>
<dependency>
<groupId>io.takari.siesta</groupId>
<artifactId>siesta-jackson2</artifactId>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-guice</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
Expand Down Expand Up @@ -395,7 +382,8 @@
<resourcePackages>
<package>com.walmartlabs.concord.server</package>
</resourcePackages>
<configurationFilePath>${project.build.directory}/classes/openapi-server-config.yaml</configurationFilePath>
<configurationFilePath>${project.build.directory}/classes/openapi-server-config.yaml
</configurationFilePath>
</configuration>
<executions>
<execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* =====
*/

import org.sonatype.siesta.ValidationErrorsException;
import com.walmartlabs.concord.server.boot.validation.ValidationErrorsException;

public class ApiEntityValidationException extends ValidationErrorsException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,21 @@
import com.walmartlabs.concord.common.ObjectMapperProvider;
import com.walmartlabs.concord.server.boot.*;
import com.walmartlabs.concord.server.boot.filters.*;
import com.walmartlabs.concord.server.boot.resteasy.ResteasyModule;
import com.walmartlabs.concord.server.boot.servlets.FormServletHolder;
import com.walmartlabs.concord.server.boot.servlets.SiestaServletHolder;
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;
import org.eclipse.jetty.servlet.FilterHolder;
import org.sonatype.siesta.Component;
import org.sonatype.siesta.jackson2.ObjectMapperResolver;

import javax.servlet.ServletContextListener;
import javax.servlet.http.HttpServlet;

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 {

Expand All @@ -53,7 +51,6 @@ public void configure(Binder binder) {

binder.bind(ObjectMapper.class).toProvider(ObjectMapperProvider.class).in(SINGLETON);
binder.bind(ObjectMapper.class).annotatedWith(Names.named("siesta")).toProvider(ObjectMapperProvider.class).in(SINGLETON);
newSetBinder(binder, Component.class).addBinding().to(ObjectMapperResolver.class);

// Jetty

Expand All @@ -79,7 +76,6 @@ public void configure(Binder binder) {
// ServletHolder

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

// RequestErrorHandler

Expand All @@ -89,7 +85,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 @@ -99,7 +95,14 @@ 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());

// Resteasy

binder.install(new ResteasyModule());

// JAX-RS resources

bindJaxRsResource(binder, ServerResource.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
* =====
*/

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.inject.Binder;
import com.google.inject.Module;
import com.typesafe.config.Config;
import com.walmartlabs.concord.common.ObjectMapperProvider;
import com.walmartlabs.concord.db.DatabaseModule;
import com.walmartlabs.concord.dependencymanager.DependencyManagerConfiguration;
import com.walmartlabs.concord.server.agent.AgentModule;
Expand Down Expand Up @@ -69,6 +71,8 @@ public ConcordServerModule(Config config) {

@Override
public void configure(Binder binder) {
binder.bind(ObjectMapper.class).toProvider(ObjectMapperProvider.class);

binder.install(new ConfigurationModule(config));
binder.install(new MetricModule());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@

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;
import java.time.OffsetDateTime;

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

Expand Down Expand Up @@ -83,6 +82,13 @@ public void maintenanceMode() {
taskScheduler.stop();
}

@GET
@Path("/test")
@Produces(MediaType.APPLICATION_JSON)
public TestBean test() {
return new TestBean(OffsetDateTime.now());
}

@Named
public static class PingDao extends AbstractDao {

Expand All @@ -95,4 +101,7 @@ public void ping() {
dsl().selectOne().execute();
}
}

public record TestBean(OffsetDateTime now) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
*/

import com.google.inject.Binder;
import com.walmartlabs.concord.server.boot.resteasy.ExceptionMapperSupport;
import com.walmartlabs.concord.server.sdk.BackgroundTask;
import com.walmartlabs.concord.server.sdk.ScheduledTask;
import org.eclipse.jetty.servlet.ServletHolder;
import org.sonatype.siesta.Component;
import org.sonatype.siesta.ExceptionMapperSupport;
import org.sonatype.siesta.Resource;

import javax.servlet.Filter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
*/

import com.walmartlabs.concord.server.AgentWorkerUtils;
import com.walmartlabs.concord.server.boot.validation.ValidationErrorsException;
import com.walmartlabs.concord.server.sdk.metrics.WithTimer;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.sonatype.siesta.Resource;
import org.sonatype.siesta.ValidationErrorsException;

import javax.inject.Inject;
import javax.ws.rs.GET;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

import com.walmartlabs.concord.server.OffsetDateTimeParam;
import com.walmartlabs.concord.server.boot.validation.ValidationErrorsException;
import com.walmartlabs.concord.server.cfg.AuditConfiguration;
import com.walmartlabs.concord.server.org.OrganizationEntry;
import com.walmartlabs.concord.server.org.OrganizationManager;
Expand All @@ -40,7 +41,6 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.shiro.authz.UnauthorizedException;
import org.sonatype.siesta.Resource;
import org.sonatype.siesta.ValidationErrorsException;

import javax.inject.Inject;
import javax.ws.rs.*;
Expand Down

This file was deleted.

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

/*
* Copyright (c) 2007-2014 Sonatype, Inc. All rights reserved.
*
* This program is licensed to you under the Apache License Version 2.0,
* and you may not use this file except in compliance with the Apache License Version 2.0.
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Apache License Version 2.0 is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*
* *****
* Concord
* -----
* Copyright (C) 2017 - 2024 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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonatype.siesta.Component;

import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;

/**
* Based on the original {@link org.sonatype.siesta.ExceptionMapperSupport}.
*/
public abstract class ExceptionMapperSupport<E extends Throwable> implements ExceptionMapper<E>, Component {

protected final Logger log = LoggerFactory.getLogger(getClass());

public Response toResponse(E exception) {
if (exception == null) {
throw new NullPointerException();
}

// debug/trace log exception details
if (log.isTraceEnabled()) {
log.trace("Mapping exception: " + exception, exception);
} else {
log.debug("Mapping exception: " + exception);
}

// Prepare the response
Response response;
try {
response = convert(exception);
} catch (Exception e) {
log.warn("Failed to map exception", e);
response = Response.serverError().entity(e.getMessage()).build();
}

// Log terse (unless debug enabled) warning with fault details
Object entity = response.getEntity();
log.warn("Response: [{}] {}; mapped from: {}",
response.getStatus(),
entity == null ? "(no entity/body)" : String.format("'%s'", entity),
exception,
log.isDebugEnabled() ? exception : null
);

return response;
}

/**
* Convert the given exception into a response.
*
* @param exception The exception to convert.
*/
protected abstract Response convert(E exception);
}
Loading

0 comments on commit 580131a

Please sign in to comment.