org.springframework.boot.autoconfigure.web.ServerProperties Java Examples

The following examples show how to use org.springframework.boot.autoconfigure.web.ServerProperties. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: H2DbProperties.java    From tx-lcn with Apache License 2.0 6 votes vote down vote up
public H2DbProperties(
        @Autowired(required = false) ConfigurableEnvironment environment,
        @Autowired(required = false) ServerProperties serverProperties) {
    String applicationName = "application";
    Integer port = 0;
    if (Objects.nonNull(environment)) {
        applicationName = environment.getProperty("spring.application.name");
    }
    if (Objects.nonNull(serverProperties)) {
        port = serverProperties.getPort();
    }
    this.filePath = System.getProperty("user.dir") +
            File.separator +
            ".txlcn" +
            File.separator +
            (StringUtils.hasText(applicationName) ? applicationName : "application") +
            "-" + port;
}
 
Example #2
Source File: RequestForwarder.java    From staffjoy with MIT License 6 votes vote down vote up
public RequestForwarder(
        ServerProperties serverProperties,
        FaradayProperties faradayProperties,
        HttpClientProvider httpClientProvider,
        MappingsProvider mappingsProvider,
        LoadBalancer loadBalancer,
        Optional<MeterRegistry> meterRegistry,
        ProxyingTraceInterceptor traceInterceptor,
        PostForwardResponseInterceptor postForwardResponseInterceptor
) {
    this.serverProperties = serverProperties;
    this.faradayProperties = faradayProperties;
    this.httpClientProvider = httpClientProvider;
    this.mappingsProvider = mappingsProvider;
    this.loadBalancer = loadBalancer;
    this.meterRegistry = meterRegistry;
    this.traceInterceptor = traceInterceptor;
    this.postForwardResponseInterceptor = postForwardResponseInterceptor;
}
 
Example #3
Source File: SkipPatternConfigTest.java    From java-spring-web with Apache License 2.0 6 votes vote down vote up
@Test
public void testShouldReturnEndpointsWithoutContextPath() {
  WebEndpointProperties webEndpointProperties = new WebEndpointProperties();
  ServerProperties properties = new ServerProperties();
  properties.getServlet().setContextPath("foo");

  EndpointsSupplier<ExposableWebEndpoint> endpointsSupplier = () -> {
    ExposableWebEndpoint infoEndpoint = createEndpoint("info");
    ExposableWebEndpoint healthEndpoint = createEndpoint("health");

    return Arrays.asList(infoEndpoint, healthEndpoint);
  };

  Optional<Pattern> pattern = new SkipPatternAutoConfiguration.ActuatorSkipPatternProviderConfig()
      .skipPatternForActuatorEndpointsSamePort(webEndpointProperties, endpointsSupplier)
      .pattern();

  then(pattern).isNotEmpty();
  then(pattern.get().pattern())
      .isEqualTo("/actuator/(info|info/.*|health|health/.*)");
}
 
Example #4
Source File: LightminClientProperties.java    From spring-batch-lightmin with Apache License 2.0 6 votes vote down vote up
@Autowired
public LightminClientProperties(final ManagementServerProperties managementServerProperties,
                                final ServerProperties serverProperties,
                                @Value("${spring.batch.lightmin.application-name:null}") final String name,
                                @Value("${endpoints.health.id:health}") final String healthEndpointId,
                                final WebEndpointProperties webEndpointProperties,
                                final Environment environment) {
    if (name == null || "null".equals(name)) {
        this.name = environment.getProperty("spring.application.name", "spring-boot-application");
    } else {
        this.name = name;
    }
    this.healthEndpointId = healthEndpointId;
    this.managementServerProperties = managementServerProperties;
    this.serverProperties = serverProperties;
    this.webEndpointProperties = webEndpointProperties;
}
 
Example #5
Source File: BackstopperSpringboot2ContainerErrorController.java    From backstopper with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("ConstantConditions")
public BackstopperSpringboot2ContainerErrorController(
    @NotNull ProjectApiErrors projectApiErrors,
    @NotNull UnhandledServletContainerErrorHelper unhandledServletContainerErrorHelper,
    @NotNull ServerProperties serverProperties
) {
    if (projectApiErrors == null) {
        throw new NullPointerException("ProjectApiErrors cannot be null.");
    }

    if (unhandledServletContainerErrorHelper == null) {
        throw new NullPointerException("UnhandledServletContainerErrorHelper cannot be null.");
    }

    if (serverProperties == null) {
        throw new NullPointerException("ServerProperties cannot be null.");
    }

    this.projectApiErrors = projectApiErrors;
    this.unhandledServletContainerErrorHelper = unhandledServletContainerErrorHelper;
    this.errorPath = serverProperties.getError().getPath();
}
 
Example #6
Source File: SpringBootAdminClientAutoConfiguration.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
@Bean
@Lazy(false)
@ConditionalOnMissingBean
public ApplicationFactory applicationFactory(InstanceProperties instance, ManagementServerProperties management,
		ServerProperties server, ServletContext servletContext, PathMappedEndpoints pathMappedEndpoints,
		WebEndpointProperties webEndpoint, ObjectProvider<List<MetadataContributor>> metadataContributors,
		DispatcherServletPath dispatcherServletPath) {
	return new ServletApplicationFactory(instance, management, server, servletContext, pathMappedEndpoints,
			webEndpoint,
			new CompositeMetadataContributor(metadataContributors.getIfAvailable(Collections::emptyList)),
			dispatcherServletPath);
}
 
Example #7
Source File: MappingsProvider.java    From staffjoy with MIT License 5 votes vote down vote up
public MappingsProvider(
        ServerProperties serverProperties,
        FaradayProperties faradayProperties,
        MappingsValidator mappingsValidator,
        HttpClientProvider httpClientProvider
) {
    this.serverProperties = serverProperties;
    this.faradayProperties = faradayProperties;
    this.mappingsValidator = mappingsValidator;
    this.httpClientProvider = httpClientProvider;
}
 
Example #8
Source File: DefaultEndpointLocator.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
DefaultEndpointLocator(Registration registration, ServerProperties serverProperties,
		Environment environment, ZipkinProperties zipkinProperties,
		InetUtils inetUtils) {
	this.registration = registration;
	this.serverProperties = serverProperties;
	this.environment = environment;
	this.zipkinProperties = zipkinProperties;
	this.firstNonLoopbackAddress = findFirstNonLoopbackAddress(inetUtils);
}
 
Example #9
Source File: DefaultEndpointLocatorConfigurationTest.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Test
public void portDefaultsTo8080() throws UnknownHostException {
	DefaultEndpointLocator locator = new DefaultEndpointLocator(null,
			new ServerProperties(), this.environment, new ZipkinProperties(),
			localAddress(ADDRESS1234));

	assertThat(locator.local().port()).isEqualTo(8080);
}
 
Example #10
Source File: DefaultEndpointLocatorConfigurationTest.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Test
public void portDefaultsToLocalhost() throws UnknownHostException {
	DefaultEndpointLocator locator = new DefaultEndpointLocator(null,
			new ServerProperties(), this.environment, new ZipkinProperties(),
			localAddress(ADDRESS1234));

	assertThat(locator.local().ipv4()).isEqualTo("1.2.3.4");
}
 
Example #11
Source File: DefaultErrorController.java    From beihu-boot with Apache License 2.0 5 votes vote down vote up
public DefaultErrorController(ErrorAttributes errorAttributes, ServerProperties properties) {
    super(errorAttributes == null ? new DefaultErrorAttributes() : errorAttributes);
    if (properties == null) {
        errorProperties = new ErrorProperties();
        errorProperties.setPath("/error");
    } else {
        this.errorProperties = properties.getError();
    }
}
 
Example #12
Source File: FwGatewayErrorConfigure.java    From fw-spring-cloud with Apache License 2.0 5 votes vote down vote up
public FwGatewayErrorConfigure(ServerProperties serverProperties,
                                 ResourceProperties resourceProperties,
                                 ObjectProvider<List<ViewResolver>> viewResolversProvider,
                                 ServerCodecConfigurer serverCodecConfigurer,
                                 ApplicationContext applicationContext) {
    this.serverProperties = serverProperties;
    this.applicationContext = applicationContext;
    this.resourceProperties = resourceProperties;
    this.viewResolvers = viewResolversProvider.getIfAvailable(Collections::emptyList);
    this.serverCodecConfigurer = serverCodecConfigurer;
}
 
Example #13
Source File: GatewayConfiguration.java    From open-cloud with MIT License 5 votes vote down vote up
/**
 * 路由加载器
 *
 * @return
 */
@Bean
public JdbcRouteLocator jdbcRouteLocator(ZuulProperties zuulProperties, ServerProperties serverProperties, JdbcTemplate jdbcTemplate, ApplicationEventPublisher publisher) {
    jdbcRouteLocator = new JdbcRouteLocator(serverProperties.getServlet().getContextPath(), zuulProperties, jdbcTemplate, publisher);
    log.info("JdbcRouteLocator:{}", jdbcRouteLocator);
    return jdbcRouteLocator;
}
 
Example #14
Source File: ErrorHandlerConfiguration.java    From SpringBlade with Apache License 2.0 5 votes vote down vote up
public ErrorHandlerConfiguration(ServerProperties serverProperties,
								 ResourceProperties resourceProperties,
								 ObjectProvider<List<ViewResolver>> viewResolversProvider,
								 ServerCodecConfigurer serverCodecConfigurer,
								 ApplicationContext applicationContext) {
	this.serverProperties = serverProperties;
	this.applicationContext = applicationContext;
	this.resourceProperties = resourceProperties;
	this.viewResolvers = viewResolversProvider.getIfAvailable(Collections::emptyList);
	this.serverCodecConfigurer = serverCodecConfigurer;
}
 
Example #15
Source File: CustomErrorWebFluxAutoConfiguration.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
public CustomErrorWebFluxAutoConfiguration(ServerProperties serverProperties,
                                           ResourceProperties resourceProperties,
                                           ObjectProvider<List<ViewResolver>> viewResolversProvider,
                                           ServerCodecConfigurer serverCodecConfigurer,
                                           ApplicationContext applicationContext) {
    this.serverProperties = serverProperties;
    this.applicationContext = applicationContext;
    this.resourceProperties = resourceProperties;
    this.viewResolvers = viewResolversProvider.getIfAvailable(Collections::emptyList);
    this.serverCodecConfigurer = serverCodecConfigurer;
}
 
Example #16
Source File: ErrorHandlerConfig.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
public ErrorHandlerConfig(ServerProperties serverProperties,
                                 ResourceProperties resourceProperties,
                                 ObjectProvider<List<ViewResolver>> viewResolversProvider,
                                 ServerCodecConfigurer serverCodecConfigurer,
                                 ApplicationContext applicationContext) {
    this.serverProperties = serverProperties;
    this.applicationContext = applicationContext;
    this.resourceProperties = resourceProperties;
    this.viewResolvers = viewResolversProvider.getIfAvailable(Collections::emptyList);
    this.serverCodecConfigurer = serverCodecConfigurer;
}
 
Example #17
Source File: SpringBootAdminClientAutoConfiguration.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
@Bean
@Lazy(false)
@ConditionalOnMissingBean
public ApplicationFactory applicationFactory(InstanceProperties instance, ManagementServerProperties management,
		ServerProperties server, PathMappedEndpoints pathMappedEndpoints, WebEndpointProperties webEndpoint,
		ObjectProvider<List<MetadataContributor>> metadataContributors) {
	return new DefaultApplicationFactory(instance, management, server, pathMappedEndpoints, webEndpoint,
			new CompositeMetadataContributor(metadataContributors.getIfAvailable(Collections::emptyList)));
}
 
Example #18
Source File: ExceptionAutoConfiguration.java    From SpringCloud with Apache License 2.0 5 votes vote down vote up
public ExceptionAutoConfiguration(ServerProperties serverProperties,
                                  ResourceProperties resourceProperties,
                                  ObjectProvider<List<ViewResolver>> viewResolversProvider,
                                  ServerCodecConfigurer serverCodecConfigurer,
                                  ApplicationContext applicationContext) {
    this.serverProperties = serverProperties;
    this.applicationContext = applicationContext;
    this.resourceProperties = resourceProperties;
    this.viewResolvers = viewResolversProvider
            .getIfAvailable(() -> Collections.emptyList());
    this.serverCodecConfigurer = serverCodecConfigurer;
}
 
Example #19
Source File: DynamicRouteConfiguration.java    From pig with MIT License 5 votes vote down vote up
public DynamicRouteConfiguration(Registration registration, DiscoveryClient discovery,
                                 ZuulProperties zuulProperties, ServerProperties server, RedisTemplate redisTemplate) {
    this.registration = registration;
    this.discovery = discovery;
    this.zuulProperties = zuulProperties;
    this.server = server;
    this.redisTemplate = redisTemplate;
}
 
Example #20
Source File: ServletErrorsAutoConfiguration.java    From errors-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/**
 * Registers a custom {@link ErrorController} to change the default error handling approach.
 *
 * @param errorAttributes    Will be used to enrich error responses.
 * @param serverProperties   Will be used to access error related configurations.
 * @param errorViewResolvers All possible view resolvers to render the whitelabel error page.
 * @return The custom error controller instance.
 */
@Bean
@ConditionalOnBean(WebErrorHandlers.class)
@ConditionalOnMissingBean(ErrorController.class)
public BasicErrorController customErrorController(ErrorAttributes errorAttributes,
                                             ServerProperties serverProperties,
                                             ObjectProvider<ErrorViewResolver> errorViewResolvers) {
    List<ErrorViewResolver> resolvers = errorViewResolvers.orderedStream().collect(toList());
    return new CustomServletErrorController(errorAttributes, serverProperties.getError(), resolvers);
}
 
Example #21
Source File: EnvironmentMonitorAutoConfigurationTests.java    From spring-cloud-config with Apache License 2.0 5 votes vote down vote up
@Test
public void testExtractorsCount() {
	ConfigurableApplicationContext context = new SpringApplicationBuilder(
			BusConfig.class, EnvironmentMonitorAutoConfiguration.class,
			ServletWebServerFactoryAutoConfiguration.class, ServerProperties.class,
			PropertyPlaceholderAutoConfiguration.class).properties("server.port=-1")
					.run();
	PropertyPathEndpoint endpoint = context.getBean(PropertyPathEndpoint.class);
	assertThat(((Collection<?>) ReflectionTestUtils.getField(
			ReflectionTestUtils.getField(endpoint, "extractor"), "extractors"))
					.size()).isEqualTo(7);
	context.close();
}
 
Example #22
Source File: CloudFoundryApplicationFactory.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
public CloudFoundryApplicationFactory(InstanceProperties instance, ManagementServerProperties management,
		ServerProperties server, PathMappedEndpoints pathMappedEndpoints, WebEndpointProperties webEndpoint,
		MetadataContributor metadataContributor, CloudFoundryApplicationProperties cfApplicationProperties) {
	super(instance, management, server, pathMappedEndpoints, webEndpoint, metadataContributor);
	this.cfApplicationProperties = cfApplicationProperties;
	this.instance = instance;
}
 
Example #23
Source File: AuthorizationServerApp.java    From spring-security-oauth with MIT License 5 votes vote down vote up
@Bean
ApplicationListener<ApplicationReadyEvent> onApplicationReadyEventListener(ServerProperties serverProperties,
		KeycloakServerProperties keycloakServerProperties) {

	return (evt) -> {

		Integer port = serverProperties.getPort();
		String keycloakContextPath = keycloakServerProperties.getContextPath();

		LOG.info("Embedded Keycloak started: http://localhost:{}{} to use keycloak", port, keycloakContextPath);
	};
}
 
Example #24
Source File: JWTAuthorizationServerApp.java    From spring-security-oauth with MIT License 5 votes vote down vote up
@Bean
ApplicationListener<ApplicationReadyEvent> onApplicationReadyEventListener(ServerProperties serverProperties, KeycloakServerProperties keycloakServerProperties) {

    return (evt) -> {

        Integer port = serverProperties.getPort();
        String keycloakContextPath = keycloakServerProperties.getContextPath();

        LOG.info("Embedded Keycloak started: http://localhost:{}{} to use keycloak", port, keycloakContextPath);
    };
}
 
Example #25
Source File: ExceptionAutoConfiguration.java    From JetfireCloud with Apache License 2.0 5 votes vote down vote up
public ExceptionAutoConfiguration(ServerProperties serverProperties,
                                  ResourceProperties resourceProperties,
                                  ObjectProvider<List<ViewResolver>> viewResolversProvider,
                                  ServerCodecConfigurer serverCodecConfigurer,
                                  ApplicationContext applicationContext) {
    this.serverProperties = serverProperties;
    this.applicationContext = applicationContext;
    this.resourceProperties = resourceProperties;
    this.viewResolvers = viewResolversProvider
            .getIfAvailable(() -> Collections.emptyList());
    this.serverCodecConfigurer = serverCodecConfigurer;
}
 
Example #26
Source File: AuthorizationServerApp.java    From spring-security-oauth with MIT License 5 votes vote down vote up
@Bean
ApplicationListener<ApplicationReadyEvent> onApplicationReadyEventListener(ServerProperties serverProperties,
		KeycloakServerProperties keycloakServerProperties) {

	return (evt) -> {

		Integer port = serverProperties.getPort();
		String keycloakContextPath = keycloakServerProperties.getContextPath();

		LOG.info("Embedded Keycloak started: http://localhost:{}{} to use keycloak", port, keycloakContextPath);
	};
}
 
Example #27
Source File: SkipPatternProviderConfigTest.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Test
public void should_return_empty_when_no_endpoints() {
	EndpointsSupplier<ExposableWebEndpoint> endpointsSupplier = Collections::emptyList;
	Optional<Pattern> pattern = new SkipPatternConfiguration.ActuatorSkipPatternProviderConfig()
			.skipPatternForActuatorEndpointsSamePort(new ServerProperties(),
					new WebEndpointProperties(), endpointsSupplier)
			.skipPattern();

	then(pattern).isEmpty();
}
 
Example #28
Source File: SampleController.java    From wingtips with Apache License 2.0 5 votes vote down vote up
@Autowired
public SampleController(ServerProperties serverProps, Environment environment) {
    this.serverPort = serverProps.getPort();
    String userIdHeaderKeysFromEnv = environment.getProperty("wingtips.user-id-header-keys");
    this.userIdHeaderKeys = (userIdHeaderKeysFromEnv == null)
                            ? null
                            : Arrays.asList(userIdHeaderKeysFromEnv.split(","));
}
 
Example #29
Source File: EnvironmentMonitorAutoConfigurationTests.java    From spring-cloud-config with Apache License 2.0 5 votes vote down vote up
@Test
public void testCanAddCustomPropertyPathNotificationExtractor() {
	ConfigurableApplicationContext context = new SpringApplicationBuilder(
			BusConfig.class, CustomPropertyPathNotificationExtractorConfig.class,
			EnvironmentMonitorAutoConfiguration.class,
			ServletWebServerFactoryAutoConfiguration.class, ServerProperties.class,
			PropertyPlaceholderAutoConfiguration.class).properties("server.port=-1")
					.run();
	PropertyPathEndpoint endpoint = context.getBean(PropertyPathEndpoint.class);
	assertThat(((Collection<?>) ReflectionTestUtils.getField(
			ReflectionTestUtils.getField(endpoint, "extractor"), "extractors"))
					.size()).isEqualTo(8);
	context.close();
}
 
Example #30
Source File: BackstopperSpringboot1ContainerErrorControllerTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Before
public void beforeMethod() {
    projectApiErrorsMock = mock(ProjectApiErrors.class);
    unhandledContainerErrorHelperMock = mock(UnhandledServletContainerErrorHelper.class);
    servletRequestMock = mock(ServletRequest.class);
    serverPropertiesMock = mock(ServerProperties.class);
    errorPropertiesMock = mock(ErrorProperties.class);
    errorPath = UUID.randomUUID().toString();

    doReturn(errorPropertiesMock).when(serverPropertiesMock).getError();
    doReturn(errorPath).when(errorPropertiesMock).getPath();
}