diff --git a/pom.xml b/pom.xml index 4be8cd75..f202c157 100644 --- a/pom.xml +++ b/pom.xml @@ -35,6 +35,12 @@ com.netflix.archaius archaius-core ${archaius.version} + + + commons-logging + commons-logging + + com.netflix.eureka @@ -45,6 +51,16 @@ com.netflix.eureka eureka-core ${eureka.version} + + + commons-logging + commons-logging + + + log4j + log4j + + com.netflix.feign diff --git a/spring-platform-netflix-core/pom.xml b/spring-platform-netflix-core/pom.xml index b8f27db1..0031b704 100644 --- a/spring-platform-netflix-core/pom.xml +++ b/spring-platform-netflix-core/pom.xml @@ -4,7 +4,7 @@ 4.0.0 spring-platform-netflix-core - jar + jar spring-platform-netflix-core Spring Platform Netflix Core @@ -14,7 +14,7 @@ 1.0.0.BUILD-SNAPSHOT .. - + org.springframework.boot @@ -24,68 +24,68 @@ org.springframework.boot spring-boot-starter-actuator - - com.netflix.archaius - archaius-core - true - - - com.netflix.eureka - eureka-client - true - - - com.netflix.eureka - eureka-core - true - - - net.java.dev.rome - rome - 1.0.0 - true - - - com.netflix.feign - feign-core - true - - - com.netflix.feign - feign-ribbon - - - - com.netflix.hystrix - hystrix-core - true - - - com.netflix.hystrix - hystrix-metrics-event-stream - true - - - com.netflix.hystrix - hystrix-javanica - true - - - com.netflix.ribbon - ribbon-core - true - - - com.netflix.ribbon - ribbon-eureka - true - + + com.netflix.archaius + archaius-core + true + + + com.netflix.eureka + eureka-client + true + + + com.netflix.eureka + eureka-core + true + + + net.java.dev.rome + rome + 1.0.0 + true + + + com.netflix.feign + feign-core + true + + + com.netflix.feign + feign-ribbon + + + + com.netflix.hystrix + hystrix-core + true + + + com.netflix.hystrix + hystrix-metrics-event-stream + true + + + com.netflix.hystrix + hystrix-javanica + true + + + com.netflix.ribbon + ribbon-core + true + + + com.netflix.ribbon + ribbon-eureka + true + org.projectlombok lombok + + provided org.springframework.boot diff --git a/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/archaius/ConfigurableEnvironmentConfiguration.java b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/archaius/ConfigurableEnvironmentConfiguration.java index f958db13..0e46ab5d 100644 --- a/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/archaius/ConfigurableEnvironmentConfiguration.java +++ b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/archaius/ConfigurableEnvironmentConfiguration.java @@ -1,13 +1,23 @@ package org.springframework.platform.netflix.archaius; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + import org.apache.commons.configuration.AbstractConfiguration; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.env.*; +import org.springframework.core.env.CompositePropertySource; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.EnumerablePropertySource; +import org.springframework.core.env.MutablePropertySources; +import org.springframework.core.env.PropertySource; +import org.springframework.core.env.StandardEnvironment; import org.springframework.util.ReflectionUtils; -import java.lang.reflect.Field; -import java.util.*; - /** * Created by sgibb on 6/27/14. */ diff --git a/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/circuitbreaker/CircuitBreakerConfiguration.java b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/circuitbreaker/CircuitBreakerConfiguration.java index 4488f669..618f3de8 100644 --- a/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/circuitbreaker/CircuitBreakerConfiguration.java +++ b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/circuitbreaker/CircuitBreakerConfiguration.java @@ -50,7 +50,7 @@ public class CircuitBreakerConfiguration implements ImportAware { throw new IllegalStateException("Only one TransactionManagementConfigurer may exist"); } //TODO: create CircuitBreakerConfigurer API - CircuitBreakerConfigurer configurer = configurers.iterator().next(); + // CircuitBreakerConfigurer configurer = configurers.iterator().next(); //this.txManager = configurer.annotationDrivenTransactionManager(); } } diff --git a/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/endpoint/ServletWrappingEndpoint.java b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/endpoint/ServletWrappingEndpoint.java index 0fff26af..24bd0dca 100644 --- a/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/endpoint/ServletWrappingEndpoint.java +++ b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/endpoint/ServletWrappingEndpoint.java @@ -70,7 +70,7 @@ public abstract class ServletWrappingEndpoint implements InitializingBean, } @Override - public Class getEndpointType() { + public Class> getEndpointType() { return null; } } diff --git a/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/EurekaRegistryAvailableEvent.java b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/EurekaRegistryAvailableEvent.java new file mode 100644 index 00000000..58f86a1b --- /dev/null +++ b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/EurekaRegistryAvailableEvent.java @@ -0,0 +1,36 @@ +/* + * Copyright 2013-2014 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.platform.netflix.eureka; + +import org.springframework.context.ApplicationEvent; + +import com.netflix.eureka.EurekaServerConfig; + +/** + * @author Dave Syer + * + */ +@SuppressWarnings("serial") +public class EurekaRegistryAvailableEvent extends ApplicationEvent { + + /** + * @param eurekaServerConfig + */ + public EurekaRegistryAvailableEvent(EurekaServerConfig eurekaServerConfig) { + super(eurekaServerConfig); + } + +} diff --git a/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/EurekaServerAutoConfiguration.java b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/EurekaServerAutoConfiguration.java index 53604821..187ef46e 100644 --- a/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/EurekaServerAutoConfiguration.java +++ b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/EurekaServerAutoConfiguration.java @@ -31,6 +31,7 @@ import com.netflix.blitz4j.LoggingConfiguration; import com.netflix.eureka.EurekaBootStrap; import com.netflix.eureka.EurekaServerConfig; import com.netflix.eureka.EurekaServerConfigurationManager; +import com.netflix.eureka.PeerAwareInstanceRegistry; /** * @author Dave Syer @@ -69,9 +70,12 @@ public class EurekaServerAutoConfiguration implements ServletContextAware, LoggingConfiguration.getInstance().configure(); EurekaServerConfigurationManager.getInstance() .setConfiguration(eurekaServerConfig); + PeerAwareInstanceRegistry.getInstance(); + applicationContext.publishEvent(new EurekaRegistryAvailableEvent(eurekaServerConfig)); } }.contextInitialized(new ServletContextEvent(servletContext)); running = true; + applicationContext.publishEvent(new EurekaServerStartedEvent(eurekaServerConfig)); } }).start(); } diff --git a/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/EurekaServerStartedEvent.java b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/EurekaServerStartedEvent.java new file mode 100644 index 00000000..802d9d55 --- /dev/null +++ b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/EurekaServerStartedEvent.java @@ -0,0 +1,36 @@ +/* + * Copyright 2013-2014 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.platform.netflix.eureka; + +import org.springframework.context.ApplicationEvent; + +import com.netflix.eureka.EurekaServerConfig; + +/** + * @author Dave Syer + * + */ +@SuppressWarnings("serial") +public class EurekaServerStartedEvent extends ApplicationEvent { + + /** + * @param eurekaServerConfig + */ + public EurekaServerStartedEvent(EurekaServerConfig eurekaServerConfig) { + super(eurekaServerConfig); + } + +} diff --git a/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/feign/FeignBase.java b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/feign/FeignBase.java index b2876791..f80e274d 100644 --- a/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/feign/FeignBase.java +++ b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/feign/FeignBase.java @@ -1,5 +1,12 @@ package org.springframework.platform.netflix.feign; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; + +import javax.xml.transform.Source; + import org.springframework.http.HttpHeaders; import org.springframework.http.converter.ByteArrayHttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter; @@ -14,12 +21,6 @@ import org.springframework.http.converter.xml.SourceHttpMessageConverter; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; -import javax.xml.transform.Source; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; - /** * Created by sgibb on 6/27/14. */ @@ -54,7 +55,8 @@ public class FeignBase { this.messageConverters.addAll(messageConverters); } - protected void addDefaultConverters(List> messageConverters) { + @SuppressWarnings("deprecation") + protected void addDefaultConverters(List> messageConverters) { messageConverters.add(new ByteArrayHttpMessageConverter()); messageConverters.add(new StringHttpMessageConverter()); messageConverters.add(new ResourceHttpMessageConverter()); diff --git a/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/feign/SpringDecoder.java b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/feign/SpringDecoder.java index 1fdff195..81aa51a7 100644 --- a/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/feign/SpringDecoder.java +++ b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/feign/SpringDecoder.java @@ -1,87 +1,88 @@ package org.springframework.platform.netflix.feign; -import feign.FeignException; -import feign.Response; -import feign.codec.DecodeException; -import feign.codec.Decoder; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Type; +import java.util.List; + import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.web.client.HttpMessageConverterExtractor; -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.Type; -import java.util.List; +import feign.FeignException; +import feign.Response; +import feign.codec.DecodeException; +import feign.codec.Decoder; /** * Created by sgibb on 6/26/14. */ public class SpringDecoder extends FeignBase implements Decoder { - private static final Logger logger = LoggerFactory.getLogger(SpringDecoder.class); - - public SpringDecoder() { - } - - public SpringDecoder(List> messageConverters) { - super(messageConverters); - } - - @Override - public Object decode(final Response response, Type type) throws IOException, DecodeException, FeignException { - if (type instanceof Class) { - HttpMessageConverterExtractor extractor = - new HttpMessageConverterExtractor((Class) type, getMessageConverters()); - - Object data = extractor.extractData(new FeignResponseAdapter(response)); - return data; - } - throw new DecodeException("type is not an instance of Class: "+type); - } - - private class FeignResponseAdapter implements ClientHttpResponse { - private final Response response; - - private FeignResponseAdapter(Response response) { - this.response = response; - } - - @Override - public HttpStatus getStatusCode() throws IOException { - return HttpStatus.valueOf(response.status()); - } - - @Override - public int getRawStatusCode() throws IOException { - return response.status(); - } - - @Override - public String getStatusText() throws IOException { - return response.reason(); - } - - @Override - public void close() { - try { - response.body().close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Override - public InputStream getBody() throws IOException { - return response.body().asInputStream(); - } - - @Override - public HttpHeaders getHeaders() { - return getHttpHeaders(response.headers()); - } - - } + + public SpringDecoder() { + } + + public SpringDecoder(List> messageConverters) { + super(messageConverters); + } + + @Override + public Object decode(final Response response, Type type) throws IOException, + DecodeException, FeignException { + if (type instanceof Class) { + @SuppressWarnings({ "unchecked", "rawtypes" }) + HttpMessageConverterExtractor extractor = new HttpMessageConverterExtractor( + (Class) type, getMessageConverters()); + + Object data = extractor.extractData(new FeignResponseAdapter(response)); + return data; + } + throw new DecodeException("type is not an instance of Class: " + type); + } + + private class FeignResponseAdapter implements ClientHttpResponse { + private final Response response; + + private FeignResponseAdapter(Response response) { + this.response = response; + } + + @Override + public HttpStatus getStatusCode() throws IOException { + return HttpStatus.valueOf(response.status()); + } + + @Override + public int getRawStatusCode() throws IOException { + return response.status(); + } + + @Override + public String getStatusText() throws IOException { + return response.reason(); + } + + @Override + public void close() { + try { + response.body().close(); + } + catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public InputStream getBody() throws IOException { + return response.body().asInputStream(); + } + + @Override + public HttpHeaders getHeaders() { + return getHttpHeaders(response.headers()); + } + + } } diff --git a/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/feign/SpringEncoder.java b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/feign/SpringEncoder.java index 2e0654ec..6c52bc68 100644 --- a/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/feign/SpringEncoder.java +++ b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/feign/SpringEncoder.java @@ -1,9 +1,11 @@ package org.springframework.platform.netflix.feign; import com.google.common.base.Charsets; + import feign.RequestTemplate; import feign.codec.EncodeException; import feign.codec.Encoder; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpHeaders; @@ -21,81 +23,87 @@ import java.util.List; * Created by sgibb on 6/26/14. */ public class SpringEncoder extends FeignBase implements Encoder { - private static final Logger logger = LoggerFactory.getLogger(SpringEncoder.class); - - public SpringEncoder() { - } - - public SpringEncoder(List> messageConverters) { - super(messageConverters); - } - - @Override - public void encode(Object requestBody, RequestTemplate request) throws EncodeException { - //template.body(conversionService.convert(object, String.class)); - if (requestBody != null) { - Class requestType = requestBody.getClass(); - Collection contentTypes = request.headers().get("Content-Type"); - - MediaType requestContentType = null; - if (contentTypes != null && !contentTypes.isEmpty()) { - String type = contentTypes.iterator().next(); - requestContentType = MediaType.valueOf(type); - } - - for (HttpMessageConverter messageConverter : getMessageConverters()) { - if (messageConverter.canWrite(requestType, requestContentType)) { - if (logger.isDebugEnabled()) { - if (requestContentType != null) { - logger.debug("Writing [" + requestBody + "] as \"" + requestContentType + - "\" using [" + messageConverter + "]"); - } - else { - logger.debug("Writing [" + requestBody + "] using [" + messageConverter + "]"); - } - - } - - FeignOutputMessage outputMessage = new FeignOutputMessage(request); - try { - ((HttpMessageConverter) messageConverter).write( - requestBody, requestContentType, outputMessage); - } catch (IOException e) { - throw new EncodeException("Error converting request body", e); - } - request.body(outputMessage.getOutputStream().toByteArray(), Charsets.UTF_8); //TODO: set charset - return; - } - } - String message = "Could not write request: no suitable HttpMessageConverter found for request type [" + - requestType.getName() + "]"; - if (requestContentType != null) { - message += " and content type [" + requestContentType + "]"; - } - throw new EncodeException(message); - } - } - - private class FeignOutputMessage implements HttpOutputMessage { - final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - RequestTemplate request; - - private FeignOutputMessage(RequestTemplate request) { - this.request = request; - } - - @Override - public OutputStream getBody() throws IOException { - return outputStream; - } - - @Override - public HttpHeaders getHeaders() { - return getHttpHeaders(request.headers()); - } - - public ByteArrayOutputStream getOutputStream() { - return outputStream; - } - } + private static final Logger logger = LoggerFactory.getLogger(SpringEncoder.class); + + public SpringEncoder() { + } + + public SpringEncoder(List> messageConverters) { + super(messageConverters); + } + + @Override + public void encode(Object requestBody, RequestTemplate request) + throws EncodeException { + // template.body(conversionService.convert(object, String.class)); + if (requestBody != null) { + Class requestType = requestBody.getClass(); + Collection contentTypes = request.headers().get("Content-Type"); + + MediaType requestContentType = null; + if (contentTypes != null && !contentTypes.isEmpty()) { + String type = contentTypes.iterator().next(); + requestContentType = MediaType.valueOf(type); + } + + for (HttpMessageConverter messageConverter : getMessageConverters()) { + if (messageConverter.canWrite(requestType, requestContentType)) { + if (logger.isDebugEnabled()) { + if (requestContentType != null) { + logger.debug("Writing [" + requestBody + "] as \"" + + requestContentType + "\" using [" + + messageConverter + "]"); + } + else { + logger.debug("Writing [" + requestBody + "] using [" + + messageConverter + "]"); + } + + } + + FeignOutputMessage outputMessage = new FeignOutputMessage(request); + try { + @SuppressWarnings("unchecked") + HttpMessageConverter copy = (HttpMessageConverter) messageConverter; + copy.write(requestBody, requestContentType, outputMessage); + } + catch (IOException e) { + throw new EncodeException("Error converting request body", e); + } + request.body(outputMessage.getOutputStream().toByteArray(), + Charsets.UTF_8); // TODO: set charset + return; + } + } + String message = "Could not write request: no suitable HttpMessageConverter found for request type [" + + requestType.getName() + "]"; + if (requestContentType != null) { + message += " and content type [" + requestContentType + "]"; + } + throw new EncodeException(message); + } + } + + private class FeignOutputMessage implements HttpOutputMessage { + final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + RequestTemplate request; + + private FeignOutputMessage(RequestTemplate request) { + this.request = request; + } + + @Override + public OutputStream getBody() throws IOException { + return outputStream; + } + + @Override + public HttpHeaders getHeaders() { + return getHttpHeaders(request.headers()); + } + + public ByteArrayOutputStream getOutputStream() { + return outputStream; + } + } } diff --git a/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/feign/SpringMvcContract.java b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/feign/SpringMvcContract.java index 7fedbb56..c26c8d2c 100644 --- a/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/feign/SpringMvcContract.java +++ b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/feign/SpringMvcContract.java @@ -1,15 +1,16 @@ package org.springframework.platform.netflix.feign; -import feign.Contract; -import feign.MethodMetadata; -import org.springframework.web.bind.annotation.RequestMapping; +import static feign.Util.checkState; +import static feign.Util.emptyToNull; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.Arrays; -import static feign.Util.checkState; -import static feign.Util.emptyToNull; +import org.springframework.web.bind.annotation.RequestMapping; + +import feign.Contract; +import feign.MethodMetadata; /** * Created by sgibb on 6/27/14. @@ -20,7 +21,6 @@ public class SpringMvcContract extends Contract.BaseContract { @Override protected void processAnnotationOnMethod(MethodMetadata data, Annotation methodAnnotation, Method method) { - Class annotationType = methodAnnotation.annotationType(); RequestMapping mapping = RequestMapping.class.cast(methodAnnotation); if (mapping != null) { //HTTP Method diff --git a/spring-platform-netflix-core/src/test/resources/application.yml b/spring-platform-netflix-core/src/test/resources/application.yml index 1f6f88d5..4ddb02df 100644 --- a/spring-platform-netflix-core/src/test/resources/application.yml +++ b/spring-platform-netflix-core/src/test/resources/application.yml @@ -4,6 +4,8 @@ spring: application: name: client eureka: + server: + enabled: false client: serviceUrl: defaultZone: http://localhost:8080/v2/ diff --git a/spring-platform-netflix-hystrix/pom.xml b/spring-platform-netflix-hystrix/pom.xml index 9936be5b..c05e6667 100644 --- a/spring-platform-netflix-hystrix/pom.xml +++ b/spring-platform-netflix-hystrix/pom.xml @@ -1,9 +1,7 @@ 4.0.0 - org.springframework.platform spring-platform-netflix-hystrix - 1.0.0.BUILD-SNAPSHOT war Spring Platform Netflix Hystrix http://projects.spring.io/spring-platform/ @@ -16,15 +14,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - 1.7 - 1.7 - - org.springframework.boot spring-boot-maven-plugin @@ -55,7 +44,10 @@ org.springframework.platform spring-platform-netflix-core - ${project.version} + + + org.apache.httpcomponents + httpclient org.springframework.platform