com.bekioui.jaxrs.server.core.NettyServer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jaxrs-server Show documentation
Show all versions of jaxrs-server Show documentation
Provide JAX-RS server to expose your RESTful API.
/**
* Copyright (C) 2016 Mehdi Bekioui ([email protected])
*
* 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.
*/
package com.bekioui.jaxrs.server.core;
import io.swagger.jaxrs.listing.SwaggerSerializers;
import io.swagger.models.Swagger;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.function.BiPredicate;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ws.rs.Path;
import javax.ws.rs.ext.Provider;
import org.jboss.resteasy.plugins.server.netty.NettyJaxrsServer;
import org.jboss.resteasy.spi.ResteasyDeployment;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import com.bekioui.jaxrs.security.filter.AuthorizationFilter;
import com.bekioui.jaxrs.server.descriptor.DeploymentResourceDescriptor;
import com.bekioui.jaxrs.server.descriptor.ResourceDescriptor;
import com.bekioui.jaxrs.server.descriptor.SwaggerResourceDescriptor;
import com.bekioui.jaxrs.server.filter.ResteasyCorsFilter;
import com.bekioui.jaxrs.server.swagger.SwaggerResource;
import com.excilys.ebi.utils.spring.log.slf4j.InjectLogger;
@Component
public final class NettyServer {
@Value("${jaxrs.server.rootResourcePath:}")
private String rootResourcePath;
@Value("${jaxrs.server.port:8080}")
private int port;
// Default: 1024 * 1024 * 10
@Value("${jaxrs.server.maxRequestSize:10485760}")
private int maxRequestSize;
@Value("${jaxrs.server.cors.enabled:false}")
private boolean corsEnabled;
@Value("${jaxrs.server.swagger.enabled:false}")
private boolean swaggerEnabled;
@Value("${jaxrs.server.security.enabled:false}")
private boolean securityEnabled;
@InjectLogger
private Logger logger;
@Autowired
private ApplicationContext applicationContext;
@Autowired
private Supplier swaggerSupplier;
@Autowired
private List deploymentResourceDescriptors;
@Autowired(required = false)
private List swaggerResourceDescriptors;
private final BiPredicate packageBiPredicate = (p1, p2) -> p1.equals(p2) || p1.getName().startsWith(p2.getName() + ".");
private final Function