Skip to content

Commit

Permalink
Merge pull request eclipse-hawkbit#289 from bsinno/fix_mgmt_feign
Browse files Browse the repository at this point in the history
Fix Mgmt Client Netflix Feign usage
  • Loading branch information
kaizimmerm authored Sep 13, 2016
2 parents da1f91b + 17e4415 commit d59065a
Show file tree
Hide file tree
Showing 31 changed files with 103 additions and 172 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ ResponseEntity<String> start(@RequestParam(value = "name", defaultValue = "simul
gatewayToken));
}

return ResponseEntity.ok("Updated " + amount + " DMF connected targets!");
return ResponseEntity.ok("Updated " + amount + " " + protocol + " connected targets!");
}

private boolean isDmfDisabled() {
Expand Down
9 changes: 8 additions & 1 deletion examples/hawkbit-example-core-feign-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-core</artifactId>
<version>1.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-context</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.LinkedHashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.netflix.feign.support.SpringMvcContract;

import feign.MethodMetadata;
import feign.Param;

/**
* Own implementation of the {@link SpringMvcContract} which catches the
Expand All @@ -38,6 +40,10 @@ protected void processAnnotationOnMethod(final MethodMetadata data, final Annota
// multiple consumers and produces, see
// https://github.com/spring-cloud/spring-cloud-netflix/issues/808
LOGGER.trace(e.getMessage(), e);

// This line from super is mandatory to avoid that access to the
// expander causes a nullpointer.
data.indexToExpander(new LinkedHashMap<Integer, Param.Expander>());
}
}
}
12 changes: 0 additions & 12 deletions examples/hawkbit-example-ddi-feign-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,6 @@

<name>hawkBit-example :: DDI Feign Client</name>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix</artifactId>
<version>1.0.7.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.eclipse.hawkbit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
package org.eclipse.hawkbit.mgmt.client.resource;

import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetRestApi;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.springframework.cloud.netflix.feign.FeignClient;

/**
* Client binding for the DistributionSet resource of the management API.
*/
@FeignClient(url = "${hawkbit.url:localhost:8080}" + MgmtRestConstants.DISTRIBUTIONSET_V1_REQUEST_MAPPING)
@FeignClient(name = "MgmtDistributionSetClient", url = "${hawkbit.url:localhost:8080}")
public interface MgmtDistributionSetClientResource extends MgmtDistributionSetRestApi {

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
package org.eclipse.hawkbit.mgmt.client.resource;

import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTagRestApi;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.springframework.cloud.netflix.feign.FeignClient;

/**
* Client binding for the DistributionSetTag resource of the management API.
*/
@FeignClient(url = "${hawkbit.url:localhost:8080}" + MgmtRestConstants.DISTRIBUTIONSET_TAG_V1_REQUEST_MAPPING)
@FeignClient(name = "MgmtDistributionSetTagClient", url = "${hawkbit.url:localhost:8080}")
public interface MgmtDistributionSetTagClientResource extends MgmtDistributionSetTagRestApi {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
package org.eclipse.hawkbit.mgmt.client.resource;

import org.eclipse.hawkbit.mgmt.rest.api.MgmtDistributionSetTypeRestApi;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.springframework.cloud.netflix.feign.FeignClient;

/**
* Client binding for the DistributionSetType resource of the management API.
*
*/
@FeignClient(url = "${hawkbit.url:localhost:8080}" + MgmtRestConstants.DISTRIBUTIONSETTYPE_V1_REQUEST_MAPPING)
@FeignClient(name = "MgmtDistributionSetTypeClient", url = "${hawkbit.url:localhost:8080}")
public interface MgmtDistributionSetTypeClientResource extends MgmtDistributionSetTypeRestApi {

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
package org.eclipse.hawkbit.mgmt.client.resource;

import org.eclipse.hawkbit.mgmt.rest.api.MgmtDownloadArtifactRestApi;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.springframework.cloud.netflix.feign.FeignClient;

/**
* A feign-client interface declaration which allows to build a feign-client
* stub.
*/
@FeignClient(url = "${hawkbit.url:localhost:8080}" + MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING)
@FeignClient(name = "MgmtDownloadArtifactClient", url = "${hawkbit.url:localhost:8080}")
public interface MgmtDownloadArtifactClientResource extends MgmtDownloadArtifactRestApi {

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
package org.eclipse.hawkbit.mgmt.client.resource;

import org.eclipse.hawkbit.mgmt.rest.api.MgmtDownloadRestApi;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.springframework.cloud.netflix.feign.FeignClient;

/**
*
*/
@FeignClient(url = "${hawkbit.url:localhost:8080}" + MgmtRestConstants.DOWNLOAD_ID_V1_REQUEST_MAPPING_BASE)
@FeignClient(name = "MgmtDownloadClient", url = "${hawkbit.url:localhost:8080}")
public interface MgmtDownloadClientResource extends MgmtDownloadRestApi {
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
*/
package org.eclipse.hawkbit.mgmt.client.resource;

import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRolloutRestApi;
import org.springframework.cloud.netflix.feign.FeignClient;

/**
* Client binding for the Rollout resource of the management API.
*/
@FeignClient(url = "${hawkbit.url:localhost:8080}" + MgmtRestConstants.ROLLOUT_V1_REQUEST_MAPPING)
@FeignClient(name = "MgmtRolloutClient", url = "${hawkbit.url:localhost:8080}")
public interface MgmtRolloutClientResource extends MgmtRolloutRestApi {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
package org.eclipse.hawkbit.mgmt.client.resource;

import org.eclipse.hawkbit.mgmt.json.model.artifact.MgmtArtifact;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleRestApi;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.ResponseEntity;
Expand All @@ -24,7 +23,7 @@
/**
* Client binding for the SoftwareModule resource of the management API.
*/
@FeignClient(url = "${hawkbit.url:localhost:8080}" + MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING)
@FeignClient(name = "MgmtSoftwareModuleClient", url = "${hawkbit.url:localhost:8080}")
public interface MgmtSoftwareModuleClientResource extends MgmtSoftwareModuleRestApi {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
*/
package org.eclipse.hawkbit.mgmt.client.resource;

import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleTypeRestApi;
import org.springframework.cloud.netflix.feign.FeignClient;

/**
* Client binding for the SoftwareModuleType resource of the management API.
*/
@FeignClient(url = "${hawkbit.url:localhost:8080}" + MgmtRestConstants.SOFTWAREMODULETYPE_V1_REQUEST_MAPPING)
@FeignClient(name = "MgmtSoftwareModuleTypeClient", url = "${hawkbit.url:localhost:8080}")
public interface MgmtSoftwareModuleTypeClientResource extends MgmtSoftwareModuleTypeRestApi {
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
*/
package org.eclipse.hawkbit.mgmt.client.resource;

import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtSystemRestApi;
import org.springframework.cloud.netflix.feign.FeignClient;

/**
* Client binding for the {@link MgmtSystemRestApi}.
*
*/
@FeignClient(url = "${hawkbit.url:localhost:8080}" + MgmtRestConstants.SYSTEM_V1_REQUEST_MAPPING)
@FeignClient(name = "MgmtSystemClient", url = "${hawkbit.url:localhost:8080}")
public interface MgmtSystemClientResource extends MgmtSystemRestApi {
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
*/
package org.eclipse.hawkbit.mgmt.client.resource;

import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtSystemManagementRestApi;
import org.springframework.cloud.netflix.feign.FeignClient;

/**
* Client binding for the {@link MgmtSystemManagementRestApi}.
*
*/
@FeignClient(url = "${hawkbit.url:localhost:8080}" + MgmtRestConstants.SYSTEM_ADMIN_MAPPING)
@FeignClient(name = "MgmtSystemManagementClient", url = "${hawkbit.url:localhost:8080}")
public interface MgmtSystemManagementClientResource extends MgmtSystemManagementRestApi {

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
*/
package org.eclipse.hawkbit.mgmt.client.resource;

import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetRestApi;
import org.springframework.cloud.netflix.feign.FeignClient;

/**
* Client binding for the Target resource of the management API.
*/
@FeignClient(url = "${hawkbit.url:localhost:8080}" + MgmtRestConstants.TARGET_V1_REQUEST_MAPPING)
@FeignClient(name = "MgmtTargetClient", url = "${hawkbit.url:localhost:8080}")
public interface MgmtTargetClientResource extends MgmtTargetRestApi {
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
*/
package org.eclipse.hawkbit.mgmt.client.resource;

import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtTargetTagRestApi;
import org.springframework.cloud.netflix.feign.FeignClient;

/**
* Client binding for the TargetTag resource of the management API.
*/
@FeignClient(url = "${hawkbit.url:localhost:8080}" + MgmtRestConstants.TARGET_TAG_V1_REQUEST_MAPPING)
@FeignClient(name = "MgmtTargetTagClient", url = "${hawkbit.url:localhost:8080}")
public interface MgmtTargetTagClientResource extends MgmtTargetTagRestApi {
}
28 changes: 0 additions & 28 deletions examples/hawkbit-example-mgmt-simulator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,40 +42,12 @@
</plugins>
</build>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix</artifactId>
<version>1.0.7.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.eclipse.hawkbit</groupId>
<artifactId>hawkbit-example-mgmt-feign-client</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.netflix.feign</groupId>
<artifactId>feign-core</artifactId>
</dependency>
<dependency>
<groupId>com.netflix.feign</groupId>
<artifactId>feign-jackson</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<artifactId>hibernate-validator</artifactId>
<groupId>org.hibernate</groupId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
import org.eclipse.hawkbit.mgmt.client.scenarios.ConfigurableScenario;
import org.eclipse.hawkbit.mgmt.client.scenarios.CreateStartedRolloutExample;
import org.eclipse.hawkbit.mgmt.client.scenarios.upload.FeignMultipartEncoder;
import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.Banner.Mode;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand Down Expand Up @@ -49,17 +48,14 @@
@Import(FeignClientConfiguration.class)
public class Application implements CommandLineRunner {

@Autowired
private ClientConfigurationProperties configuration;

@Autowired
private ConfigurableScenario configuredScenario;

@Autowired
private CreateStartedRolloutExample gettingStartedRolloutScenario;

public static void main(final String[] args) {
new SpringApplicationBuilder().showBanner(false).sources(Application.class).run(args);
new SpringApplicationBuilder().bannerMode(Mode.OFF).sources(Application.class).run(args);
}

@Override
Expand All @@ -74,18 +70,18 @@ public void run(final String... args) throws Exception {
}

@Bean
public BasicAuthRequestInterceptor basicAuthRequestInterceptor() {
public BasicAuthRequestInterceptor basicAuthRequestInterceptor(final ClientConfigurationProperties configuration) {
return new BasicAuthRequestInterceptor(configuration.getUsername(), configuration.getPassword());
}

@Bean
public ConfigurableScenario configurableScenario(final MgmtDistributionSetClientResource distributionSetResource,
@Qualifier("mgmtSoftwareModuleClientResource") final MgmtSoftwareModuleClientResource softwareModuleResource,
@Qualifier("uploadSoftwareModule") final MgmtSoftwareModuleClientResource uploadSoftwareModule,
final MgmtSoftwareModuleClientResource softwareModuleResource,
final MgmtTargetClientResource targetResource, final MgmtRolloutClientResource rolloutResource,
final ClientConfigurationProperties clientConfigurationProperties) {
return new ConfigurableScenario(distributionSetResource, softwareModuleResource, uploadSoftwareModule,
targetResource, rolloutResource, clientConfigurationProperties);
return new ConfigurableScenario(distributionSetResource, softwareModuleResource,
uploadSoftwareModule(clientConfigurationProperties), targetResource, rolloutResource,
clientConfigurationProperties);
}

@Bean
Expand All @@ -94,23 +90,21 @@ public CreateStartedRolloutExample createStartedRolloutExample() {
}

@Bean
public Logger.Level feignLoggerLevel() {
return Logger.Level.FULL;
}

@Bean
public MgmtSoftwareModuleClientResource uploadSoftwareModule() {
public MgmtSoftwareModuleClientResource uploadSoftwareModule(final ClientConfigurationProperties configuration) {
final ObjectMapper mapper = new ObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.registerModule(new Jackson2HalModule());

return Feign.builder().contract(new IgnoreMultipleConsumersProducersSpringMvcContract())
.requestInterceptor(
new BasicAuthRequestInterceptor(configuration.getUsername(), configuration.getPassword()))
.logger(new Slf4jLogger()).encoder(new FeignMultipartEncoder())
.decoder(new ResponseEntityDecoder(new JacksonDecoder(mapper)))
.target(MgmtSoftwareModuleClientResource.class,
configuration.getUrl() + MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING);
.target(MgmtSoftwareModuleClientResource.class, configuration.getUrl());
}

@Bean
public Logger.Level feignLoggerLevel() {
return Logger.Level.FULL;
}

private static boolean containsArg(final String containsArg, final String... args) {
Expand Down
Loading

0 comments on commit d59065a

Please sign in to comment.