SGF-514 - Configure HttpService with annotations.
(cherry picked from commit f39912a44ca8eb588bddc11cb7606b8d409f220c) Signed-off-by: John Blum <jblum@pivotal.io>
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright 2012 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.data.gemfire.config.annotation;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
/**
|
||||
* The EnableHttpService annotation marks a Spring {@link org.springframework.context.annotation.Configuration @Configuration}
|
||||
* annotated class to configure and enable GemFire/Geode's embedded HTTP service.
|
||||
*
|
||||
* By using this annotation, this allows GemFire's embedded HTTP services, like Pulse, the Management REST API
|
||||
* and the Developer REST API to be enabled.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.gemfire.config.annotation.HttpServiceConfiguration
|
||||
* @see <a href="http://geode.docs.pivotal.io/docs/rest_apps/book_intro.html">Developing REST Applications for Apache Geode</a>
|
||||
* @since 1.9.0
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Inherited
|
||||
@Documented
|
||||
@Import(HttpServiceConfiguration.class)
|
||||
@SuppressWarnings("unused")
|
||||
public @interface EnableHttpService {
|
||||
|
||||
/**
|
||||
* If set, then the GemFire member binds the embedded HTTP service to the specified address.
|
||||
* If this property is not set but the HTTP service is enabled using {@literal http-service-port},
|
||||
* then GemFire binds the HTTP service to the member’s local address. Used by the GemFire Pulse Web application
|
||||
* and the Developer REST API service.
|
||||
*
|
||||
* Defaults to unset.
|
||||
*/
|
||||
String bindAddress() default "";
|
||||
|
||||
/**
|
||||
* If non-zero, then GemFire starts an embedded HTTP service that listens on this port. The HTTP service
|
||||
* is used to host the GemFire Pulse Web application and the development REST API service. If you are hosting
|
||||
* the Pulse web app on your own Web server and are not using the Development REST API service, then disable
|
||||
* this embedded HTTP service by setting this property to zero. Ignored if {@literal jmx-manager}
|
||||
* and {@literal start-dev-rest-api} are both set to {@literal false}.
|
||||
*
|
||||
* Defaults to {@literal 7070}.
|
||||
*/
|
||||
int port() default HttpServiceConfiguration.DEFAULT_HTTP_SERVICE_PORT;
|
||||
|
||||
/**
|
||||
* Boolean indicating whether to require authentication for HTTP service connections. If this property is not set,
|
||||
* then GemFire uses the value of {@literal cluster-ssl-require-authentication} to determine whether HTTP service
|
||||
* connections require authentication.
|
||||
*
|
||||
* To enable SSL communications for the HTTP service, use the {@link EnableSsl} annotation and set the
|
||||
* {@link EnableSsl#components()} to contain
|
||||
* {@link org.springframework.data.gemfire.config.annotation.EnableSsl.Component#HTTP}.
|
||||
*
|
||||
* Defaults to {@literal false}.
|
||||
*/
|
||||
boolean sslRequireAuthentication() default false;
|
||||
|
||||
/**
|
||||
* If set to true, then the developer REST API service will be started when cache is created.
|
||||
* The REST service can be configured using {@literal http-service-port} and {@literal http-service-bind-address}
|
||||
* GemFire System Properties.
|
||||
*
|
||||
* Defaults to {@literal false}.
|
||||
*/
|
||||
boolean startDeveloperRestApi() default false;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2012 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.data.gemfire.config.annotation;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.data.gemfire.config.annotation.support.EmbeddedServiceConfigurationSupport;
|
||||
import org.springframework.data.gemfire.util.PropertiesBuilder;
|
||||
|
||||
/**
|
||||
* The HttpServiceConfiguration class is a Spring {@link org.springframework.context.annotation.ImportBeanDefinitionRegistrar}
|
||||
* that applies additional GemFire/Geode configuration by way of GemFire/Geode System properties to configure
|
||||
* GemFire/Geode's embeded HTTP service and services.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.gemfire.config.annotation.EnableHttpService
|
||||
* @see org.springframework.data.gemfire.config.annotation.support.EmbeddedServiceConfigurationSupport
|
||||
* @see <a href="http://geode.docs.pivotal.io/docs/rest_apps/book_intro.html">Developing REST Applications for Apache Geode</a>
|
||||
* @since 1.9.0
|
||||
*/
|
||||
public class HttpServiceConfiguration extends EmbeddedServiceConfigurationSupport {
|
||||
|
||||
public static final boolean DEFAULT_HTTP_SERVICE_SSL_REQUIRE_AUTHENTICATION = false;
|
||||
public static final boolean DEFAULT_HTTP_SERVICE_START_DEVELOPER_REST_API = false;
|
||||
|
||||
public static final int DEFAULT_HTTP_SERVICE_PORT = 7070;
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
protected Class getAnnotationType() {
|
||||
return EnableHttpService.class;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
@Override
|
||||
protected Properties toGemFireProperties(Map<String, Object> annotationAttributes) {
|
||||
PropertiesBuilder gemfireProperties = PropertiesBuilder.create();
|
||||
|
||||
gemfireProperties.setProperty("http-service-bind-address", annotationAttributes.get("bindAddress"));
|
||||
|
||||
gemfireProperties.setPropertyIfNotDefault("http-service-port",
|
||||
annotationAttributes.get("port"), DEFAULT_HTTP_SERVICE_PORT);
|
||||
|
||||
gemfireProperties.setPropertyIfNotDefault("http-service-ssl-require-authentication",
|
||||
annotationAttributes.get("sslRequireAuthentication"), DEFAULT_HTTP_SERVICE_SSL_REQUIRE_AUTHENTICATION);
|
||||
|
||||
gemfireProperties.setPropertyIfNotDefault("start-dev-rest-api",
|
||||
annotationAttributes.get("startDeveloperRestApi"), DEFAULT_HTTP_SERVICE_START_DEVELOPER_REST_API);
|
||||
|
||||
return gemfireProperties.build();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user