-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/main/java/eu/h2020/symbiote/client/feign/FeignSMClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package eu.h2020.symbiote.client.feign; | ||
|
||
import eu.h2020.symbiote.client.interfaces.SMClient; | ||
import eu.h2020.symbiote.cloud.model.internal.Subscription; | ||
import eu.h2020.symbiote.security.commons.exceptions.custom.SecurityHandlerException; | ||
import eu.h2020.symbiote.security.communication.ApacheCommonsLogger4Feign; | ||
import eu.h2020.symbiote.security.communication.payloads.AAM; | ||
import eu.h2020.symbiote.security.handler.ISecurityHandler; | ||
import feign.Feign; | ||
import feign.Headers; | ||
import feign.Logger; | ||
import feign.RequestLine; | ||
import feign.jackson.JacksonDecoder; | ||
import feign.jackson.JacksonEncoder; | ||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* symbIoTe Subscription Manager client based on Feign | ||
* | ||
* @author Vasilis Glykantzis | ||
*/ | ||
public class FeignSMClient implements SMClient { | ||
|
||
private static final Log logger = LogFactory.getLog(FeignSMClient.class); | ||
|
||
private SubscriptionManagerI smClient; | ||
|
||
/** | ||
* | ||
* @param securityHandler the security handler implementation that is going to be used | ||
* @param homePlatformId the home Platform Id | ||
*/ | ||
public FeignSMClient(ISecurityHandler securityHandler, | ||
String homePlatformId) { | ||
|
||
try { | ||
Map<String, AAM> availableAAMs = securityHandler.getAvailableAAMs(); | ||
String smBaseUrl = availableAAMs.get(homePlatformId).getAamAddress().replace("/paam", "/subscriptionManager"); | ||
|
||
this.smClient = Feign.builder() | ||
.decoder(new JacksonDecoder()) | ||
.encoder(new JacksonEncoder()) | ||
.logger(new ApacheCommonsLogger4Feign(logger)) | ||
.logLevel(Logger.Level.FULL) | ||
.client(new SymbIoTeSecurityHandlerFeignClient()) | ||
.target(SubscriptionManagerI.class, smBaseUrl); | ||
} catch (SecurityHandlerException e) { | ||
logger.error("Could not create FeignSMClient", e); | ||
} | ||
} | ||
|
||
@Override | ||
public void subscribe(Subscription subscription) { | ||
this.smClient.subscribe(subscription); | ||
} | ||
|
||
private interface SubscriptionManagerI { | ||
@RequestLine("POST /subscribe ") | ||
@Headers({"Accept: application/json", "Content-Type: application/json"}) | ||
void subscribe(Subscription subscription); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/eu/h2020/symbiote/client/interfaces/SMClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package eu.h2020.symbiote.client.interfaces; | ||
|
||
import eu.h2020.symbiote.cloud.model.internal.Subscription; | ||
|
||
/** | ||
* Interface for querying the platform Subscription Manager component | ||
* | ||
* @author Vasilis Glykantzis | ||
*/ | ||
public interface SMClient { | ||
|
||
/** | ||
* Queries the Platform Registry component with home token | ||
* | ||
* @param subscription the subscription request send to the Subscription Manager | ||
*/ | ||
void subscribe(Subscription subscription); | ||
} |