diff --git a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiAcceptedRequestInterceptor.java b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiAcceptedRequestInterceptor.java index 962ffd7a6..3e82618c0 100644 --- a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiAcceptedRequestInterceptor.java +++ b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiAcceptedRequestInterceptor.java @@ -1,27 +1,27 @@ -/** - * 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; - -import org.springframework.http.MediaType; - -import feign.RequestInterceptor; -import feign.RequestTemplate; - -/** - * - * - */ -public class DdiAcceptedRequestInterceptor implements RequestInterceptor { - - @Override - public void apply(final RequestTemplate template) { - template.header("Accept", MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_OCTET_STREAM_VALUE, - MediaType.TEXT_PLAIN_VALUE); - } -} +/** + * 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; + +import org.springframework.http.MediaType; + +import feign.RequestInterceptor; +import feign.RequestTemplate; + +/** + * + * + */ +public class DdiAcceptedRequestInterceptor implements RequestInterceptor { + + @Override + public void apply(final RequestTemplate template) { + template.header("Accept", MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_OCTET_STREAM_VALUE, + MediaType.TEXT_PLAIN_VALUE); + } +} diff --git a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiDefaultFeignClient.java b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiDefaultFeignClient.java index c9af1cb09..d156e8eb5 100644 --- a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiDefaultFeignClient.java +++ b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiDefaultFeignClient.java @@ -9,6 +9,7 @@ package org.eclipse.hawkbit.ddi.client; 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.feign.core.client.ApplicationJsonRequestHeaderInterceptor; import org.eclipse.hawkbit.feign.core.client.IgnoreMultipleConsumersProducersSpringMvcContract; @@ -31,10 +32,20 @@ public class DdiDefaultFeignClient { private 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()) .requestInterceptor(new ApplicationJsonRequestHeaderInterceptor()) .requestInterceptor(new DdiAcceptedRequestInterceptor()).logLevel(Level.FULL) .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(tenant, "A tenant has to be set"); this.baseUrl = baseUrl; diff --git a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiExampleClient.java b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiExampleClient.java index ad9f086bb..5945fef5d 100644 --- a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiExampleClient.java +++ b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/DdiExampleClient.java @@ -12,11 +12,14 @@ import java.io.IOException; import java.io.InputStream; import java.time.LocalDateTime; import java.time.LocalTime; +import java.time.temporal.ChronoField; import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; -import org.eclipse.hawkbit.ddi.client.strategy.PersistenceStrategy; +import org.eclipse.hawkbit.ddi.client.authenctication.AuthenticationInterceptor; +import org.eclipse.hawkbit.ddi.client.resource.RootControllerResourceClient; +import org.eclipse.hawkbit.ddi.client.strategy.ArtifactsPersistenceStrategy; import org.eclipse.hawkbit.ddi.json.model.DdiActionFeedback; import org.eclipse.hawkbit.ddi.json.model.DdiArtifact; import org.eclipse.hawkbit.ddi.json.model.DdiChunk; @@ -41,9 +44,11 @@ public class DdiExampleClient implements Runnable { private final String controllerId; private Long actionIdOfLastInstalltion; - private final DdiDefaultFeignClient ddiDefaultFeignClient; - private final PersistenceStrategy persistenceStrategy; - private STATUS clientStatus; + private final RootControllerResourceClient rootControllerResourceClient; + private final ArtifactsPersistenceStrategy persistenceStrategy; + private DdiClientStatus clientStatus; + + private FinalResult finalResultOfCurrentUpdate; /** * Constructor for the DDI example client. @@ -58,35 +63,56 @@ public class DdiExampleClient implements Runnable { * the persistence strategy for downloading artifacts */ public DdiExampleClient(final String baseUrl, final String controllerId, final String tenant, - final PersistenceStrategy persistenceStrategy) { + final ArtifactsPersistenceStrategy persistenceStrategy) { + this(baseUrl, controllerId, tenant, persistenceStrategy, null); + } + + /** + * 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 ArtifactsPersistenceStrategy persistenceStrategy, final AuthenticationInterceptor authenticationInterceptor) { this.controllerId = controllerId; - this.ddiDefaultFeignClient = new DdiDefaultFeignClient(baseUrl, tenant); + this.rootControllerResourceClient = new DdiDefaultFeignClient(baseUrl, tenant, authenticationInterceptor) + .getRootControllerResourceClient(); this.actionIdOfLastInstalltion = null; this.persistenceStrategy = persistenceStrategy; - this.clientStatus = STATUS.DOWN; + this.clientStatus = DdiClientStatus.DOWN; } @Override public void run() { - clientStatus = STATUS.UP; + clientStatus = DdiClientStatus.UP; ResponseEntity response; - while (clientStatus == STATUS.UP) { + while (clientStatus == DdiClientStatus.UP) { LOGGER.info(" Controller {} polling from hawkBit server", controllerId); - response = ddiDefaultFeignClient.getRootControllerResourceClient().getControllerBase(controllerId); - final String pollingTime = response.getBody().getConfig().getPolling().getSleep(); - final LocalTime localtime = LocalTime.parse(pollingTime); - final long pollingIntervalInMillis = localtime.toNanoOfDay(); + response = rootControllerResourceClient.getControllerBase(controllerId); + final String pollingTimeFormReponse = response.getBody().getConfig().getPolling().getSleep(); + final LocalTime localtime = LocalTime.parse(pollingTimeFormReponse); + final long pollingIntervalInMillis = localtime.getLong(ChronoField.MILLI_OF_DAY); final Link controllerDeploymentBaseLink = response.getBody().getLink("deploymentBase"); - if (controllerDeploymentBaseLink != null) { final Long actionId = getActionIdOutOfLink(controllerDeploymentBaseLink); final Integer resource = getResourceOutOfLink(controllerDeploymentBaseLink); if (actionId != actionIdOfLastInstalltion) { + finalResultOfCurrentUpdate = FinalResult.NONE; startDownload(actionId, resource); + finishUpdateProcess(actionId); actionIdOfLastInstalltion = actionId; } } - try { Thread.sleep(pollingIntervalInMillis); } catch (final InterruptedException e) { @@ -99,66 +125,81 @@ public class DdiExampleClient implements Runnable { * Stop the DDI example client */ public void stop() { - clientStatus = STATUS.DOWN; + clientStatus = DdiClientStatus.DOWN; } private void startDownload(final Long actionId, final Integer resource) { - - final ResponseEntity respone = ddiDefaultFeignClient.getRootControllerResourceClient() + final ResponseEntity respone = rootControllerResourceClient .getControllerBasedeploymentAction(controllerId, Long.valueOf(actionId), Integer.valueOf(resource)); final DdiDeploymentBase ddiDeploymentBase = respone.getBody(); final List chunks = ddiDeploymentBase.getDeployment().getChunks(); for (final DdiChunk chunk : chunks) { final List artifactList = chunk.getArtifacts(); - final Link downloadLink = ddiDeploymentBase.getDeployment().getChunks().get(0).getArtifacts().get(0) - .getLink("download-http"); - final String[] downloadLinkSep = downloadLink.getHref().split(Pattern.quote("/")); - final Long softwareModuleId = Long.valueOf(downloadLinkSep[8]); - for (final DdiArtifact ddiArtifact : artifactList) { - downloadArtifact(actionId, softwareModuleId, ddiArtifact.getFilename()); + if (artifactList.isEmpty()) { + sendFeedBackMessage(actionId, ExecutionStatus.PROCEEDING, FinalResult.NONE, + "No artifacts to download for softwaremodule " + chunk.getName()); + } else { + for (final DdiArtifact ddiArtifact : artifactList) { + if (finalResultOfCurrentUpdate != FinalResult.FAILURE) { + downloadArtifact(actionId, ddiArtifact); + } + } } + } } - private void downloadArtifact(final Long actionId, final Long softwareModuleId, final String artifact) { + private void downloadArtifact(final Long actionId, final DdiArtifact ddiArtifact) { + + final String artifact = ddiArtifact.getFilename(); + final Link downloadLink = ddiArtifact.getLink("download-http"); + final String[] downloadLinkSep = downloadLink.getHref().split(Pattern.quote("/")); + final Long softwareModuleId = Long.valueOf(downloadLinkSep[8]); sendFeedBackMessage(actionId, ExecutionStatus.PROCEEDING, FinalResult.NONE, "Starting download of artifact " + artifact); LOGGER.info("Starting download of artifact " + artifact); - final ResponseEntity responseDownloadArtifact = ddiDefaultFeignClient - .getRootControllerResourceClient().downloadArtifact(controllerId, softwareModuleId, artifact); + final ResponseEntity responseDownloadArtifact = rootControllerResourceClient + .downloadArtifact(controllerId, softwareModuleId, artifact); final HttpStatus statsuCode = responseDownloadArtifact.getStatusCode(); LOGGER.info("Finished download with stataus {}", statsuCode); try { persistenceStrategy.handleInputStream(responseDownloadArtifact.getBody(), artifact); + sendFeedBackMessage(actionId, ExecutionStatus.PROCEEDING, FinalResult.NONE, + "Downloaded artifact " + artifact); } catch (final IOException e) { - sendFeedBackMessage(actionId, ExecutionStatus.CLOSED, FinalResult.FAILURE, - "Downloaded of artifact " + artifact + " failed"); - return; + sendFeedBackMessage(actionId, ExecutionStatus.PROCEEDING, FinalResult.NONE, + "Downloaded of artifact " + artifact + "failed"); + finalResultOfCurrentUpdate = FinalResult.FAILURE; } - sendFeedBackMessage(actionId, ExecutionStatus.PROCEEDING, FinalResult.NONE, "Downloaded artifact " + artifact); - simulateSuccessfulInstallation(actionId); } private void sendFeedBackMessage(final Long actionId, final ExecutionStatus executionStatus, final FinalResult finalResult, final String message) { - final DdiResult result = new DdiResult(finalResult, null); final List details = new ArrayList<>(); details.add(message); final DdiStatus ddiStatus = new DdiStatus(executionStatus, result, details); final String time = String.valueOf(LocalDateTime.now()); final DdiActionFeedback feedback = new DdiActionFeedback(actionId, time, ddiStatus); - ddiDefaultFeignClient.getRootControllerResourceClient().postBasedeploymentActionFeedback(feedback, controllerId, - actionId); + rootControllerResourceClient.postBasedeploymentActionFeedback(feedback, controllerId, actionId); LOGGER.info("Sent feedback message to HaktBit"); } - private void simulateSuccessfulInstallation(final Long actionId) { - sendFeedBackMessage(actionId, ExecutionStatus.CLOSED, FinalResult.SUCESS, "Simulated installation successful"); + private void finishUpdateProcess(final Long actionId) { + + if (finalResultOfCurrentUpdate == FinalResult.FAILURE) { + sendFeedBackMessage(actionId, ExecutionStatus.CLOSED, FinalResult.FAILURE, "Error during update process"); + } + + if (finalResultOfCurrentUpdate == FinalResult.NONE) { + sendFeedBackMessage(actionId, ExecutionStatus.CLOSED, FinalResult.SUCESS, + "Simulated installation successful"); + } + } private Long getActionIdOutOfLink(final Link controllerDeploymentBaseLink) { @@ -180,8 +221,8 @@ public class DdiExampleClient implements Runnable { /** * Enum for DDI running status. */ - public enum STATUS { - + public enum DdiClientStatus { UP, DOWN; } + } diff --git a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/authenctication/AuthenticationInterceptor.java b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/authenctication/AuthenticationInterceptor.java new file mode 100644 index 000000000..f1a746c1b --- /dev/null +++ b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/authenctication/AuthenticationInterceptor.java @@ -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 { + +} diff --git a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/authenctication/AuthenticationInterceptorFactory.java b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/authenctication/AuthenticationInterceptorFactory.java new file mode 100644 index 000000000..5d2fb6706 --- /dev/null +++ b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/authenctication/AuthenticationInterceptorFactory.java @@ -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); + } + +} diff --git a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/authenctication/TargetSecurityTokenAuthenticationInterceptor.java b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/authenctication/TargetSecurityTokenAuthenticationInterceptor.java new file mode 100644 index 000000000..93559dd6d --- /dev/null +++ b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/authenctication/TargetSecurityTokenAuthenticationInterceptor.java @@ -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); + } +} diff --git a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/PersistenceStrategy.java b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/ArtifactsPersistenceStrategy.java similarity index 94% rename from examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/PersistenceStrategy.java rename to examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/ArtifactsPersistenceStrategy.java index e5a3a60d0..347b01bcc 100644 --- a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/PersistenceStrategy.java +++ b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/ArtifactsPersistenceStrategy.java @@ -14,7 +14,7 @@ import java.io.InputStream; /** * Interface of persistence strategy. */ -public interface PersistenceStrategy { +public interface ArtifactsPersistenceStrategy { /** * Method handling the artifact download. diff --git a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/DoNotSaveArtifactsStrategy.java b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/DoNotSaveArtifacts.java similarity index 72% rename from examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/DoNotSaveArtifactsStrategy.java rename to examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/DoNotSaveArtifacts.java index 80743c99e..7e5d72c4a 100644 --- a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/DoNotSaveArtifactsStrategy.java +++ b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/DoNotSaveArtifacts.java @@ -12,14 +12,17 @@ import java.io.IOException; import java.io.InputStream; /** - * Implementation of {@link PersistenceStrategy} for not downloading any + * Implementation of {@link ArtifactsPersistenceStrategy} for not downloading any * artifacts. */ -public class DoNotSaveArtifactsStrategy implements PersistenceStrategy { +public class DoNotSaveArtifacts implements ArtifactsPersistenceStrategy { @Override public void handleInputStream(final InputStream in, final String artifactName) throws IOException { - // do nothing + + while (in.read() != -1) { + ; + } } } diff --git a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/SaveArtifactsStrategy.java b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/SaveArtifactsToLocalTempDirectories.java similarity index 79% rename from examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/SaveArtifactsStrategy.java rename to examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/SaveArtifactsToLocalTempDirectories.java index 2ae7987cb..11ac5698b 100644 --- a/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/SaveArtifactsStrategy.java +++ b/examples/hawkbit-example-ddi-client/src/main/java/org/eclipse/hawkbit/ddi/client/strategy/SaveArtifactsToLocalTempDirectories.java @@ -18,15 +18,15 @@ import com.google.common.io.ByteStreams; import com.google.common.io.Files; /** - * Implementation of {@link PersistenceStrategy} for downloading artifacts to + * Implementation of {@link ArtifactsPersistenceStrategy} for downloading artifacts to * the temp directory. */ -public class SaveArtifactsStrategy implements PersistenceStrategy { +public class SaveArtifactsToLocalTempDirectories implements ArtifactsPersistenceStrategy { @Override public void handleInputStream(final InputStream in, final String artifactName) throws IOException { final File tempDir = Files.createTempDir(); - final File file = new File(tempDir + "\\" + artifactName); + final File file = new File(tempDir, artifactName); final OutputStream out = new FileOutputStream(file); ByteStreams.copy(in, out); } diff --git a/examples/hawkbit-example-ddi-client/src/test/java/org/eclipse/hawkbit/example/ddi/client/AppTest.java b/examples/hawkbit-example-ddi-client/src/test/java/org/eclipse/hawkbit/example/ddi/client/AppTest.java index 09f82fa6d..13eaa66d3 100644 --- a/examples/hawkbit-example-ddi-client/src/test/java/org/eclipse/hawkbit/example/ddi/client/AppTest.java +++ b/examples/hawkbit-example-ddi-client/src/test/java/org/eclipse/hawkbit/example/ddi/client/AppTest.java @@ -1,5 +1,7 @@ package org.eclipse.hawkbit.example.ddi.client; +import org.eclipse.hawkbit.ddi.client.DdiExampleClient; +import org.eclipse.hawkbit.ddi.client.strategy.SaveArtifactsToLocalTempDirectories; import org.junit.Test; /** @@ -9,14 +11,12 @@ public class AppTest { @Test public void AppTest() { - // final DdiExampleClient ddiClient = new - // DdiExampleClient("http://localhost:8080/", "Einstein1", "DEFAULT", - // 2000, - // new SaveArtifactsStrategy()); - // final Thread thread = new Thread(ddiClient); - // thread.run(); - // - // System.out.println("next steps........................"); + final DdiExampleClient ddiClient = new DdiExampleClient("http://localhost:8080/", "Einstein17", "DEFAULT", + new SaveArtifactsToLocalTempDirectories()); + final Thread thread = new Thread(ddiClient); + thread.run(); + + System.out.println("next steps........................"); } } diff --git a/examples/hawkbit-example-feign-core-client/pom.xml b/examples/hawkbit-example-feign-core-client/pom.xml index e9981829c..91f6c53c1 100644 --- a/examples/hawkbit-example-feign-core-client/pom.xml +++ b/examples/hawkbit-example-feign-core-client/pom.xml @@ -1,47 +1,47 @@ - - 4.0.0 - - org.eclipse.hawkbit - hawkbit-examples-parent - 0.2.0-SNAPSHOT - - - hawkbit-example-feign-core-client - hawkbit-example-feign-core-client - - - - - org.springframework.cloud - spring-cloud-netflix - 1.0.7.RELEASE - pom - import - - - - - - - com.netflix.feign - feign-core - - - 8.14.2 - - - com.netflix.feign - feign-jackson - 8.14.2 - - - com.fasterxml.jackson.core - jackson-databind - - - org.springframework.cloud - spring-cloud-starter-feign - - - + + 4.0.0 + + org.eclipse.hawkbit + hawkbit-examples-parent + 0.2.0-SNAPSHOT + + + hawkbit-example-feign-core-client + hawkbit-example-feign-core-client + + + + + org.springframework.cloud + spring-cloud-netflix + 1.0.7.RELEASE + pom + import + + + + + + + com.netflix.feign + feign-core + + + 8.14.2 + + + com.netflix.feign + feign-jackson + 8.14.2 + + + com.fasterxml.jackson.core + jackson-databind + + + org.springframework.cloud + spring-cloud-starter-feign + + + diff --git a/examples/hawkbit-example-feign-core-client/src/main/java/org/eclipse/hawkbit/feign/core/client/ApplicationJsonRequestHeaderInterceptor.java b/examples/hawkbit-example-feign-core-client/src/main/java/org/eclipse/hawkbit/feign/core/client/ApplicationJsonRequestHeaderInterceptor.java index ac1353fa1..e7faca3b7 100644 --- a/examples/hawkbit-example-feign-core-client/src/main/java/org/eclipse/hawkbit/feign/core/client/ApplicationJsonRequestHeaderInterceptor.java +++ b/examples/hawkbit-example-feign-core-client/src/main/java/org/eclipse/hawkbit/feign/core/client/ApplicationJsonRequestHeaderInterceptor.java @@ -1,28 +1,28 @@ -/** - * 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.feign.core.client; - -import org.springframework.http.MediaType; - -import feign.RequestInterceptor; -import feign.RequestTemplate; - -/** - * An feign request interceptor to set the defined {@code Accept} and - * {@code Content-Type} headers for each request to {@code application/json}. - */ -public class ApplicationJsonRequestHeaderInterceptor implements RequestInterceptor { - - @Override - public void apply(final RequestTemplate template) { - template.header("Accept", MediaType.APPLICATION_JSON_VALUE); - template.header("Content-Type", MediaType.APPLICATION_JSON_VALUE); - } - -} +/** + * 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.feign.core.client; + +import org.springframework.http.MediaType; + +import feign.RequestInterceptor; +import feign.RequestTemplate; + +/** + * An feign request interceptor to set the defined {@code Accept} and + * {@code Content-Type} headers for each request to {@code application/json}. + */ +public class ApplicationJsonRequestHeaderInterceptor implements RequestInterceptor { + + @Override + public void apply(final RequestTemplate template) { + template.header("Accept", MediaType.APPLICATION_JSON_VALUE); + template.header("Content-Type", MediaType.APPLICATION_JSON_VALUE); + } + +} diff --git a/examples/hawkbit-example-feign-core-client/src/main/java/org/eclipse/hawkbit/feign/core/client/FeignClientConfiguration.java b/examples/hawkbit-example-feign-core-client/src/main/java/org/eclipse/hawkbit/feign/core/client/FeignClientConfiguration.java index 83bee36b1..dc926cdbf 100644 --- a/examples/hawkbit-example-feign-core-client/src/main/java/org/eclipse/hawkbit/feign/core/client/FeignClientConfiguration.java +++ b/examples/hawkbit-example-feign-core-client/src/main/java/org/eclipse/hawkbit/feign/core/client/FeignClientConfiguration.java @@ -1,32 +1,32 @@ -/** - * 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.feign.core.client; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import feign.Contract; - -/** - * - * - */ -@Configuration -public class FeignClientConfiguration { - - @Bean - public ApplicationJsonRequestHeaderInterceptor jsonHeaderInterceptor() { - return new ApplicationJsonRequestHeaderInterceptor(); - } - - @Bean - public Contract feignContract() { - return new IgnoreMultipleConsumersProducersSpringMvcContract(); - } -} +/** + * 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.feign.core.client; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import feign.Contract; + +/** + * + * + */ +@Configuration +public class FeignClientConfiguration { + + @Bean + public ApplicationJsonRequestHeaderInterceptor jsonHeaderInterceptor() { + return new ApplicationJsonRequestHeaderInterceptor(); + } + + @Bean + public Contract feignContract() { + return new IgnoreMultipleConsumersProducersSpringMvcContract(); + } +} diff --git a/examples/hawkbit-example-feign-core-client/src/main/java/org/eclipse/hawkbit/feign/core/client/IgnoreMultipleConsumersProducersSpringMvcContract.java b/examples/hawkbit-example-feign-core-client/src/main/java/org/eclipse/hawkbit/feign/core/client/IgnoreMultipleConsumersProducersSpringMvcContract.java index e7d8890b1..b04143cdf 100644 --- a/examples/hawkbit-example-feign-core-client/src/main/java/org/eclipse/hawkbit/feign/core/client/IgnoreMultipleConsumersProducersSpringMvcContract.java +++ b/examples/hawkbit-example-feign-core-client/src/main/java/org/eclipse/hawkbit/feign/core/client/IgnoreMultipleConsumersProducersSpringMvcContract.java @@ -1,43 +1,43 @@ -/** - * 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.feign.core.client; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.cloud.netflix.feign.support.SpringMvcContract; - -import feign.MethodMetadata; - -/** - * Own implementation of the {@link SpringMvcContract} which catches the - * {@link IllegalStateException} which occurs due multiple produces and consumes - * values in the request-mapping - * annoation.https://github.com/spring-cloud/spring-cloud-netflix/issues/808 - */ -public class IgnoreMultipleConsumersProducersSpringMvcContract extends SpringMvcContract { - - private static final Logger LOGGER = LoggerFactory - .getLogger(IgnoreMultipleConsumersProducersSpringMvcContract.class); - - @Override - protected void processAnnotationOnMethod(final MethodMetadata data, final Annotation methodAnnotation, - final Method method) { - try { - super.processAnnotationOnMethod(data, methodAnnotation, method); - } catch (final IllegalStateException e) { - // ignore illegalstateexception here because it's thrown because of - // multiple consumers and produces, see - // https://github.com/spring-cloud/spring-cloud-netflix/issues/808 - LOGGER.trace(e.getMessage(), e); - } - } -} +/** + * 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.feign.core.client; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.cloud.netflix.feign.support.SpringMvcContract; + +import feign.MethodMetadata; + +/** + * Own implementation of the {@link SpringMvcContract} which catches the + * {@link IllegalStateException} which occurs due multiple produces and consumes + * values in the request-mapping + * annoation.https://github.com/spring-cloud/spring-cloud-netflix/issues/808 + */ +public class IgnoreMultipleConsumersProducersSpringMvcContract extends SpringMvcContract { + + private static final Logger LOGGER = LoggerFactory + .getLogger(IgnoreMultipleConsumersProducersSpringMvcContract.class); + + @Override + protected void processAnnotationOnMethod(final MethodMetadata data, final Annotation methodAnnotation, + final Method method) { + try { + super.processAnnotationOnMethod(data, methodAnnotation, method); + } catch (final IllegalStateException e) { + // ignore illegalstateexception here because it's thrown because of + // multiple consumers and produces, see + // https://github.com/spring-cloud/spring-cloud-netflix/issues/808 + LOGGER.trace(e.getMessage(), e); + } + } +} diff --git a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtTargetClientResource.java b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtTargetClientResource.java index 5d043afe2..19f78a12f 100644 --- a/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtTargetClientResource.java +++ b/examples/hawkbit-mgmt-api-client/src/main/java/org/eclipse/hawkbit/mgmt/client/resource/MgmtTargetClientResource.java @@ -17,5 +17,5 @@ import org.springframework.cloud.netflix.feign.FeignClient; @FeignClient(url = "${hawkbit.url:localhost:8080}/" + MgmtTargetClientResource.PATH) public interface MgmtTargetClientResource extends MgmtTargetRestApi { - static String PATH = "/rest/v1/targets"; + static String PATH = "rest/v1/targets"; }