14 changed files with 350 additions and 243 deletions
@ -0,0 +1,36 @@
@@ -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); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,36 @@
@@ -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); |
||||
} |
||||
|
||||
} |
@ -1,87 +1,88 @@
@@ -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<HttpMessageConverter<?>> 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<HttpMessageConverter<?>> 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()); |
||||
} |
||||
|
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue