Merge branch 'Feature/Add_Rest_Api_with_Java_client' of https://github.com/bsinno/hawkbit.git into Feature/Add_Rest_Api_with_Java_client
Conflicts: examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiExampleClient.java Signed-off-by: Jonathan Philip Knoblauch <JonathanPhilip.Knoblauch@bosch-si.com>
This commit is contained in:
@@ -1,27 +1,27 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||||
*
|
*
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.ddi.client;
|
package org.eclipse.hawkbit.ddi.client;
|
||||||
|
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
|
|
||||||
import feign.RequestInterceptor;
|
import feign.RequestInterceptor;
|
||||||
import feign.RequestTemplate;
|
import feign.RequestTemplate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class DdiAcceptedRequestInterceptor implements RequestInterceptor {
|
public class DdiAcceptedRequestInterceptor implements RequestInterceptor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(final RequestTemplate template) {
|
public void apply(final RequestTemplate template) {
|
||||||
template.header("Accept", MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_OCTET_STREAM_VALUE,
|
template.header("Accept", MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_OCTET_STREAM_VALUE,
|
||||||
MediaType.TEXT_PLAIN_VALUE);
|
MediaType.TEXT_PLAIN_VALUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
package org.eclipse.hawkbit.ddi.client;
|
package org.eclipse.hawkbit.ddi.client;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
|
import org.eclipse.hawkbit.ddi.client.authenctication.AuthenticationInterceptor;
|
||||||
import org.eclipse.hawkbit.ddi.client.resource.RootControllerResourceClient;
|
import org.eclipse.hawkbit.ddi.client.resource.RootControllerResourceClient;
|
||||||
import org.eclipse.hawkbit.feign.core.client.ApplicationJsonRequestHeaderInterceptor;
|
import org.eclipse.hawkbit.feign.core.client.ApplicationJsonRequestHeaderInterceptor;
|
||||||
import org.eclipse.hawkbit.feign.core.client.IgnoreMultipleConsumersProducersSpringMvcContract;
|
import org.eclipse.hawkbit.feign.core.client.IgnoreMultipleConsumersProducersSpringMvcContract;
|
||||||
@@ -31,10 +32,20 @@ public class DdiDefaultFeignClient {
|
|||||||
private final String tenant;
|
private final String tenant;
|
||||||
|
|
||||||
public DdiDefaultFeignClient(final String baseUrl, final String tenant) {
|
public DdiDefaultFeignClient(final String baseUrl, final String tenant) {
|
||||||
|
this(baseUrl, tenant, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DdiDefaultFeignClient(final String baseUrl, final String tenant,
|
||||||
|
final AuthenticationInterceptor authenticationInterceptor) {
|
||||||
feignBuilder = Feign.builder().contract(new IgnoreMultipleConsumersProducersSpringMvcContract())
|
feignBuilder = Feign.builder().contract(new IgnoreMultipleConsumersProducersSpringMvcContract())
|
||||||
.requestInterceptor(new ApplicationJsonRequestHeaderInterceptor())
|
.requestInterceptor(new ApplicationJsonRequestHeaderInterceptor())
|
||||||
.requestInterceptor(new DdiAcceptedRequestInterceptor()).logLevel(Level.FULL)
|
.requestInterceptor(new DdiAcceptedRequestInterceptor()).logLevel(Level.FULL)
|
||||||
.logger(new Logger.ErrorLogger()).encoder(new JacksonEncoder()).decoder(new DdiDecoder());
|
.logger(new Logger.ErrorLogger()).encoder(new JacksonEncoder()).decoder(new DdiDecoder());
|
||||||
|
|
||||||
|
if (authenticationInterceptor != null) {
|
||||||
|
feignBuilder.requestInterceptor(authenticationInterceptor);
|
||||||
|
}
|
||||||
|
|
||||||
Validate.notNull(baseUrl, "A baseUrl has to be set");
|
Validate.notNull(baseUrl, "A baseUrl has to be set");
|
||||||
Validate.notNull(tenant, "A tenant has to be set");
|
Validate.notNull(tenant, "A tenant has to be set");
|
||||||
this.baseUrl = baseUrl;
|
this.baseUrl = baseUrl;
|
||||||
|
|||||||
@@ -12,10 +12,12 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.LocalTime;
|
import java.time.LocalTime;
|
||||||
|
import java.time.temporal.ChronoField;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.eclipse.hawkbit.ddi.client.authenctication.AuthenticationInterceptor;
|
||||||
import org.eclipse.hawkbit.ddi.client.resource.RootControllerResourceClient;
|
import org.eclipse.hawkbit.ddi.client.resource.RootControllerResourceClient;
|
||||||
import org.eclipse.hawkbit.ddi.client.strategy.PersistenceStrategy;
|
import org.eclipse.hawkbit.ddi.client.strategy.PersistenceStrategy;
|
||||||
import org.eclipse.hawkbit.ddi.json.model.DdiActionFeedback;
|
import org.eclipse.hawkbit.ddi.json.model.DdiActionFeedback;
|
||||||
@@ -45,10 +47,10 @@ public class DdiExampleClient implements Runnable {
|
|||||||
private final RootControllerResourceClient rootControllerResourceClient;
|
private final RootControllerResourceClient rootControllerResourceClient;
|
||||||
private final PersistenceStrategy persistenceStrategy;
|
private final PersistenceStrategy persistenceStrategy;
|
||||||
private DdiClientStatus clientStatus;
|
private DdiClientStatus clientStatus;
|
||||||
private final DdiDefaultFeignClient sdiDefaultFeignClient;
|
|
||||||
private FinalResult finalResultOfCurrentUpdate;
|
private FinalResult finalResultOfCurrentUpdate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for the DDI example client.
|
* Constructor for the DDI example client.
|
||||||
*
|
*
|
||||||
* @param baseUrl
|
* @param baseUrl
|
||||||
@@ -62,19 +64,34 @@ public class DdiExampleClient implements Runnable {
|
|||||||
*/
|
*/
|
||||||
public DdiExampleClient(final String baseUrl, final String controllerId, final String tenant,
|
public DdiExampleClient(final String baseUrl, final String controllerId, final String tenant,
|
||||||
final PersistenceStrategy persistenceStrategy) {
|
final PersistenceStrategy persistenceStrategy) {
|
||||||
this.controllerId = controllerId;
|
this(baseUrl, controllerId, tenant, persistenceStrategy, null);
|
||||||
sdiDefaultFeignClient = new DdiDefaultFeignClient(baseUrl, tenant);
|
}
|
||||||
|
|
||||||
this.rootControllerResourceClient = sdiDefaultFeignClient.getRootControllerResourceClient();
|
/**
|
||||||
|
* Constructor for the DDI example client.
|
||||||
|
*
|
||||||
|
* @param baseUrl
|
||||||
|
* the base url of the hawkBit server
|
||||||
|
* @param controllerId
|
||||||
|
* the controller id that will be simulated
|
||||||
|
* @param tenant
|
||||||
|
* the tenant
|
||||||
|
* @param persistenceStrategy
|
||||||
|
* the persistence strategy for downloading artifacts
|
||||||
|
* @param authenticationInterceptor
|
||||||
|
* the authentication intercepter to authenticate the DDI client,
|
||||||
|
* might be {@code null}
|
||||||
|
*/
|
||||||
|
public DdiExampleClient(final String baseUrl, final String controllerId, final String tenant,
|
||||||
|
final PersistenceStrategy persistenceStrategy, final AuthenticationInterceptor authenticationInterceptor) {
|
||||||
|
this.controllerId = controllerId;
|
||||||
|
this.rootControllerResourceClient = new DdiDefaultFeignClient(baseUrl, tenant, authenticationInterceptor)
|
||||||
|
.getRootControllerResourceClient();
|
||||||
this.actionIdOfLastInstalltion = null;
|
this.actionIdOfLastInstalltion = null;
|
||||||
this.persistenceStrategy = persistenceStrategy;
|
this.persistenceStrategy = persistenceStrategy;
|
||||||
this.clientStatus = DdiClientStatus.DOWN;
|
this.clientStatus = DdiClientStatus.DOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DdiDefaultFeignClient getSdiDefaultFeignClient() {
|
|
||||||
return sdiDefaultFeignClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
clientStatus = DdiClientStatus.UP;
|
clientStatus = DdiClientStatus.UP;
|
||||||
@@ -84,7 +101,7 @@ public class DdiExampleClient implements Runnable {
|
|||||||
response = rootControllerResourceClient.getControllerBase(controllerId);
|
response = rootControllerResourceClient.getControllerBase(controllerId);
|
||||||
final String pollingTimeFormReponse = response.getBody().getConfig().getPolling().getSleep();
|
final String pollingTimeFormReponse = response.getBody().getConfig().getPolling().getSleep();
|
||||||
final LocalTime localtime = LocalTime.parse(pollingTimeFormReponse);
|
final LocalTime localtime = LocalTime.parse(pollingTimeFormReponse);
|
||||||
final long pollingIntervalInMillis = localtime.toNanoOfDay();
|
final long pollingIntervalInMillis = localtime.getLong(ChronoField.MILLI_OF_DAY);
|
||||||
final Link controllerDeploymentBaseLink = response.getBody().getLink("deploymentBase");
|
final Link controllerDeploymentBaseLink = response.getBody().getLink("deploymentBase");
|
||||||
if (controllerDeploymentBaseLink != null) {
|
if (controllerDeploymentBaseLink != null) {
|
||||||
final Long actionId = getActionIdOutOfLink(controllerDeploymentBaseLink);
|
final Long actionId = getActionIdOutOfLink(controllerDeploymentBaseLink);
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*/
|
||||||
|
package org.eclipse.hawkbit.ddi.client.authenctication;
|
||||||
|
|
||||||
|
import feign.RequestInterceptor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An DdiClient authentication intercepter to provide credential information
|
||||||
|
* e.g. in http-headers.
|
||||||
|
*/
|
||||||
|
public interface AuthenticationInterceptor extends RequestInterceptor {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*/
|
||||||
|
package org.eclipse.hawkbit.ddi.client.authenctication;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A factory to create {@link AuthenticationInterceptor}s.
|
||||||
|
*/
|
||||||
|
public class AuthenticationInterceptorFactory {
|
||||||
|
|
||||||
|
private AuthenticationInterceptorFactory() {
|
||||||
|
// factory class no public constructor
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link AuthenticationInterceptor} to authenticate a
|
||||||
|
* Ddi-Client via a target-security-token HTTP authorization header.
|
||||||
|
*
|
||||||
|
* @param targetSecurityToken
|
||||||
|
* the target-security-token to be added to the HTTP
|
||||||
|
* 'TargetToken' authorization header
|
||||||
|
* @return the authentication interceptor which can be used to authenticate
|
||||||
|
* an Ddi-Client
|
||||||
|
*/
|
||||||
|
public static AuthenticationInterceptor createTargetSecurityAuthenticator(final String targetSecurityToken) {
|
||||||
|
return new TargetSecurityTokenAuthenticationInterceptor(targetSecurityToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*/
|
||||||
|
package org.eclipse.hawkbit.ddi.client.authenctication;
|
||||||
|
|
||||||
|
import com.google.common.net.HttpHeaders;
|
||||||
|
|
||||||
|
import feign.RequestTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of the {@link AuthenticationInterceptor} to add a given
|
||||||
|
* target-security-token to the HTTP authorization header.
|
||||||
|
*/
|
||||||
|
class TargetSecurityTokenAuthenticationInterceptor implements AuthenticationInterceptor {
|
||||||
|
|
||||||
|
private final String targetSecurityToken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param targetSecurityToken
|
||||||
|
* the security token to add to the authorization header
|
||||||
|
*/
|
||||||
|
TargetSecurityTokenAuthenticationInterceptor(final String targetSecurityToken) {
|
||||||
|
this.targetSecurityToken = targetSecurityToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(final RequestTemplate template) {
|
||||||
|
template.header(HttpHeaders.AUTHORIZATION, "TargetToken " + targetSecurityToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package org.eclipse.hawkbit.example.ddi.client;
|
package org.eclipse.hawkbit.example.ddi.client;
|
||||||
|
|
||||||
|
import org.eclipse.hawkbit.ddi.client.DdiExampleClient;
|
||||||
|
import org.eclipse.hawkbit.ddi.client.strategy.SaveArtifactsStrategy;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -9,14 +11,12 @@ public class AppTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void AppTest() {
|
public void AppTest() {
|
||||||
// final DdiExampleClient ddiClient = new
|
final DdiExampleClient ddiClient = new DdiExampleClient("http://localhost:8080/", "Einstein15", "DEFAULT",
|
||||||
// DdiExampleClient("http://localhost:8080/", "Einstein1", "DEFAULT",
|
new SaveArtifactsStrategy());
|
||||||
// 2000,
|
final Thread thread = new Thread(ddiClient);
|
||||||
// new SaveArtifactsStrategy());
|
thread.run();
|
||||||
// final Thread thread = new Thread(ddiClient);
|
|
||||||
// thread.run();
|
System.out.println("next steps........................");
|
||||||
//
|
|
||||||
// System.out.println("next steps........................");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,47 +1,47 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.eclipse.hawkbit</groupId>
|
<groupId>org.eclipse.hawkbit</groupId>
|
||||||
<artifactId>hawkbit-examples-parent</artifactId>
|
<artifactId>hawkbit-examples-parent</artifactId>
|
||||||
<version>0.2.0-SNAPSHOT</version>
|
<version>0.2.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>hawkbit-example-feign-core-client</artifactId>
|
<artifactId>hawkbit-example-feign-core-client</artifactId>
|
||||||
<name>hawkbit-example-feign-core-client</name>
|
<name>hawkbit-example-feign-core-client</name>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>spring-cloud-netflix</artifactId>
|
<artifactId>spring-cloud-netflix</artifactId>
|
||||||
<version>1.0.7.RELEASE</version>
|
<version>1.0.7.RELEASE</version>
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.netflix.feign</groupId>
|
<groupId>com.netflix.feign</groupId>
|
||||||
<artifactId>feign-core</artifactId>
|
<artifactId>feign-core</artifactId>
|
||||||
<!-- need to overwrite for the interface inheritance feature of feign-core -->
|
<!-- need to overwrite for the interface inheritance feature of feign-core -->
|
||||||
<!-- <version>8.16.0</version> -->
|
<!-- <version>8.16.0</version> -->
|
||||||
<version>8.14.2</version>
|
<version>8.14.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.netflix.feign</groupId>
|
<groupId>com.netflix.feign</groupId>
|
||||||
<artifactId>feign-jackson</artifactId>
|
<artifactId>feign-jackson</artifactId>
|
||||||
<version>8.14.2</version>
|
<version>8.14.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-feign</artifactId>
|
<artifactId>spring-cloud-starter-feign</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -1,28 +1,28 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||||
*
|
*
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.feign.core.client;
|
package org.eclipse.hawkbit.feign.core.client;
|
||||||
|
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
|
|
||||||
import feign.RequestInterceptor;
|
import feign.RequestInterceptor;
|
||||||
import feign.RequestTemplate;
|
import feign.RequestTemplate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An feign request interceptor to set the defined {@code Accept} and
|
* An feign request interceptor to set the defined {@code Accept} and
|
||||||
* {@code Content-Type} headers for each request to {@code application/json}.
|
* {@code Content-Type} headers for each request to {@code application/json}.
|
||||||
*/
|
*/
|
||||||
public class ApplicationJsonRequestHeaderInterceptor implements RequestInterceptor {
|
public class ApplicationJsonRequestHeaderInterceptor implements RequestInterceptor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(final RequestTemplate template) {
|
public void apply(final RequestTemplate template) {
|
||||||
template.header("Accept", MediaType.APPLICATION_JSON_VALUE);
|
template.header("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||||
template.header("Content-Type", MediaType.APPLICATION_JSON_VALUE);
|
template.header("Content-Type", MediaType.APPLICATION_JSON_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,32 +1,32 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||||
*
|
*
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.feign.core.client;
|
package org.eclipse.hawkbit.feign.core.client;
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
import feign.Contract;
|
import feign.Contract;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
public class FeignClientConfiguration {
|
public class FeignClientConfiguration {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ApplicationJsonRequestHeaderInterceptor jsonHeaderInterceptor() {
|
public ApplicationJsonRequestHeaderInterceptor jsonHeaderInterceptor() {
|
||||||
return new ApplicationJsonRequestHeaderInterceptor();
|
return new ApplicationJsonRequestHeaderInterceptor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public Contract feignContract() {
|
public Contract feignContract() {
|
||||||
return new IgnoreMultipleConsumersProducersSpringMvcContract();
|
return new IgnoreMultipleConsumersProducersSpringMvcContract();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,43 +1,43 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||||
*
|
*
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.feign.core.client;
|
package org.eclipse.hawkbit.feign.core.client;
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.cloud.netflix.feign.support.SpringMvcContract;
|
import org.springframework.cloud.netflix.feign.support.SpringMvcContract;
|
||||||
|
|
||||||
import feign.MethodMetadata;
|
import feign.MethodMetadata;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Own implementation of the {@link SpringMvcContract} which catches the
|
* Own implementation of the {@link SpringMvcContract} which catches the
|
||||||
* {@link IllegalStateException} which occurs due multiple produces and consumes
|
* {@link IllegalStateException} which occurs due multiple produces and consumes
|
||||||
* values in the request-mapping
|
* values in the request-mapping
|
||||||
* annoation.https://github.com/spring-cloud/spring-cloud-netflix/issues/808
|
* annoation.https://github.com/spring-cloud/spring-cloud-netflix/issues/808
|
||||||
*/
|
*/
|
||||||
public class IgnoreMultipleConsumersProducersSpringMvcContract extends SpringMvcContract {
|
public class IgnoreMultipleConsumersProducersSpringMvcContract extends SpringMvcContract {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory
|
private static final Logger LOGGER = LoggerFactory
|
||||||
.getLogger(IgnoreMultipleConsumersProducersSpringMvcContract.class);
|
.getLogger(IgnoreMultipleConsumersProducersSpringMvcContract.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void processAnnotationOnMethod(final MethodMetadata data, final Annotation methodAnnotation,
|
protected void processAnnotationOnMethod(final MethodMetadata data, final Annotation methodAnnotation,
|
||||||
final Method method) {
|
final Method method) {
|
||||||
try {
|
try {
|
||||||
super.processAnnotationOnMethod(data, methodAnnotation, method);
|
super.processAnnotationOnMethod(data, methodAnnotation, method);
|
||||||
} catch (final IllegalStateException e) {
|
} catch (final IllegalStateException e) {
|
||||||
// ignore illegalstateexception here because it's thrown because of
|
// ignore illegalstateexception here because it's thrown because of
|
||||||
// multiple consumers and produces, see
|
// multiple consumers and produces, see
|
||||||
// https://github.com/spring-cloud/spring-cloud-netflix/issues/808
|
// https://github.com/spring-cloud/spring-cloud-netflix/issues/808
|
||||||
LOGGER.trace(e.getMessage(), e);
|
LOGGER.trace(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user