Added new default feign client
Signed-off-by: Jonathan Philip Knoblauch <JonathanPhilip.Knoblauch@bosch-si.com>
This commit is contained in:
@@ -20,7 +20,7 @@ import feign.Contract;
|
||||
public class Application {
|
||||
|
||||
@Autowired
|
||||
private DdiClient ddiClient;
|
||||
private DdiExampleClient ddiClient;
|
||||
|
||||
public static void main(final String[] args) {
|
||||
new SpringApplicationBuilder().showBanner(false).sources(Application.class).run(args);
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2016 Bosch Software Innovations GmbH, Germany. All rights reserved.
|
||||
*/
|
||||
package org.eclipse.hawkbit.ddi.client;
|
||||
|
||||
import org.eclipse.hawkbit.ddi.client.resource.RootControllerResourceClient;
|
||||
import org.eclipse.hawkbit.ddi.json.model.DdiControllerBase;
|
||||
import org.eclipse.hawkbit.ddi.rest.api.DdiRestConstants;
|
||||
import org.springframework.cloud.netflix.feign.support.ResponseEntityDecoder;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import feign.Feign;
|
||||
import feign.Logger;
|
||||
import feign.Logger.Level;
|
||||
import feign.jackson.JacksonDecoder;
|
||||
import feign.jackson.JacksonEncoder;
|
||||
|
||||
@Component
|
||||
public class DdiClient {
|
||||
|
||||
//
|
||||
// @Autowired
|
||||
// private HttpServletResponse response;
|
||||
|
||||
private final String controllerId;
|
||||
private final String name;
|
||||
private final String description;
|
||||
private RootControllerResourceClient rootControllerResourceClient;
|
||||
private String rootControllerResourcePath;
|
||||
|
||||
public DdiClient(final String rolloutsUrl, final String controllerId, final String name, final String description,
|
||||
final String tenant) {
|
||||
super();
|
||||
this.controllerId = controllerId;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
rootControllerResourcePath = rolloutsUrl + DdiRestConstants.BASE_V1_REQUEST_MAPPING;
|
||||
rootControllerResourcePath = rootControllerResourcePath.replace("{tenant}", tenant);
|
||||
|
||||
createFeignClient();
|
||||
}
|
||||
|
||||
private void createFeignClient() {
|
||||
|
||||
// BasicAuthRequestInterceptor TODO
|
||||
|
||||
final Feign.Builder feignBuilder = Feign.builder()
|
||||
.contract(new IgnoreMultipleConsumersProducersSpringMvcContract())
|
||||
.requestInterceptor(new ApplicationJsonRequestHeaderInterceptor()).logLevel(Level.FULL)
|
||||
.logger(new Logger.ErrorLogger()).encoder(new JacksonEncoder())
|
||||
.decoder(new ResponseEntityDecoder(new JacksonDecoder()));
|
||||
// TODO implement feign client encoder to handle MultiPartFile
|
||||
// .requestInterceptor(new BasicAuthRequestInterceptor(tenant + "\\" +
|
||||
// user, password))
|
||||
|
||||
rootControllerResourceClient = feignBuilder.target(RootControllerResourceClient.class,
|
||||
rootControllerResourcePath);
|
||||
|
||||
}
|
||||
|
||||
public void startDdiClient() {
|
||||
|
||||
final ResponseEntity<DdiControllerBase> response = rootControllerResourceClient.getControllerBase("test");
|
||||
final DdiControllerBase controllerBase = response.getBody();
|
||||
|
||||
// TODO notify every 10 seconds on the rollout server
|
||||
|
||||
// TODO if new update available -> start download and installation
|
||||
// process
|
||||
// report status messages
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2016 Bosch Software Innovations GmbH, Germany. All rights reserved.
|
||||
*/
|
||||
package org.eclipse.hawkbit.ddi.client;
|
||||
|
||||
import org.eclipse.hawkbit.ddi.client.resource.RootControllerResourceClient;
|
||||
import org.springframework.cloud.netflix.feign.support.ResponseEntityDecoder;
|
||||
|
||||
import feign.Feign;
|
||||
import feign.Feign.Builder;
|
||||
import feign.Logger;
|
||||
import feign.Logger.Level;
|
||||
import feign.jackson.JacksonDecoder;
|
||||
import feign.jackson.JacksonEncoder;
|
||||
|
||||
/**
|
||||
* @author Jonathan Knoblauch
|
||||
*
|
||||
*/
|
||||
public class DdiDefaultFeignClient {
|
||||
|
||||
private RootControllerResourceClient rootControllerResourceClient;
|
||||
|
||||
private final Builder feignBuilder;
|
||||
private final String baseUrl;
|
||||
private final String tenant;
|
||||
|
||||
public DdiDefaultFeignClient(final String baseUrl, final String tenant) {
|
||||
feignBuilder = Feign.builder().contract(new IgnoreMultipleConsumersProducersSpringMvcContract())
|
||||
.requestInterceptor(new ApplicationJsonRequestHeaderInterceptor()).logLevel(Level.FULL)
|
||||
.logger(new Logger.ErrorLogger()).encoder(new JacksonEncoder())
|
||||
.decoder(new ResponseEntityDecoder(new JacksonDecoder()));
|
||||
this.baseUrl = baseUrl;
|
||||
this.tenant = tenant;
|
||||
}
|
||||
|
||||
public Builder getFeignBuilder() {
|
||||
return feignBuilder;
|
||||
}
|
||||
|
||||
public RootControllerResourceClient getRootControllerResourceClient() {
|
||||
|
||||
String rootControllerResourcePath = this.baseUrl + RootControllerResourceClient.PATH;
|
||||
rootControllerResourcePath = rootControllerResourcePath.replace("{tenant}", tenant);
|
||||
// TODO tenant null throw exception
|
||||
if (rootControllerResourceClient == null) {
|
||||
rootControllerResourceClient = feignBuilder.target(RootControllerResourceClient.class,
|
||||
rootControllerResourcePath);
|
||||
}
|
||||
return rootControllerResourceClient;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2016 Bosch Software Innovations GmbH, Germany. All rights reserved.
|
||||
*/
|
||||
package org.eclipse.hawkbit.ddi.client;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class DdiExampleClient {
|
||||
|
||||
private final String controllerId;
|
||||
private final String name;
|
||||
private final String description;
|
||||
private final String baseUrl;
|
||||
final DdiDefaultFeignClient ddiDefaultFeignClient;
|
||||
|
||||
public DdiExampleClient(final String baseUrl, final String controllerId, final String name,
|
||||
final String description, final String tenant) {
|
||||
super();
|
||||
this.controllerId = controllerId;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.baseUrl = baseUrl;
|
||||
ddiDefaultFeignClient = new DdiDefaultFeignClient(baseUrl, tenant);
|
||||
}
|
||||
|
||||
public void startDdiClient() {
|
||||
|
||||
// final ResponseEntity<DdiControllerBase> response =
|
||||
|
||||
ddiDefaultFeignClient.getRootControllerResourceClient().getControllerBase(controllerId);
|
||||
|
||||
// final DdiControllerBase controllerBase = response.getBody();
|
||||
|
||||
System.out.println("test");
|
||||
|
||||
// TODO notify every 10 seconds on the rollout server
|
||||
|
||||
// TODO if new update available -> start download and installation
|
||||
// process
|
||||
// report status messages
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.eclipse.hawkbit.example.ddi.client;
|
||||
|
||||
import org.eclipse.hawkbit.ddi.client.DdiClient;
|
||||
import org.eclipse.hawkbit.ddi.client.DdiExampleClient;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
@@ -11,7 +11,8 @@ public class AppTest {
|
||||
@Test
|
||||
public void AppTest() {
|
||||
|
||||
final DdiClient ddiClient = new DdiClient("http://localhost:8080", "mytest", "mytest", "desc", "DEFAULT");
|
||||
final DdiExampleClient ddiClient = new DdiExampleClient("http://localhost:8080/", "mytest", "mytest", "desc",
|
||||
"DEFAULT");
|
||||
ddiClient.startDdiClient();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user