Search in sources :

Example 1 with Exchange

use of com.predic8.membrane.core.exchange.Exchange in project service-proxy by membrane.

the class AbstractExchangeStore method notifyListenersOnExchangeRemoval.

public void notifyListenersOnExchangeRemoval(AbstractExchange exchange) {
    for (IExchangesStoreListener listener : exchangesStoreListeners) {
        exchange.removeExchangeStoreListener(listener);
        listener.removeExchange(exchange);
    }
}
Also used : IExchangesStoreListener(com.predic8.membrane.core.model.IExchangesStoreListener)

Example 2 with Exchange

use of com.predic8.membrane.core.exchange.Exchange in project service-proxy by membrane.

the class AbstractExchangeStore method notifyListenersOnExchangeAdd.

public void notifyListenersOnExchangeAdd(Rule rule, AbstractExchange exchange) {
    for (IExchangesStoreListener listener : exchangesStoreListeners) {
        exchange.addExchangeStoreListener(listener);
        listener.addExchange(rule, exchange);
    }
}
Also used : IExchangesStoreListener(com.predic8.membrane.core.model.IExchangesStoreListener)

Example 3 with Exchange

use of com.predic8.membrane.core.exchange.Exchange in project service-proxy by membrane.

the class ElasticSearchExchangeStore method getExchanges.

@Override
public AbstractExchange[] getExchanges(RuleKey ruleKey) {
    int port = ruleKey.getPort();
    try {
        Exchange exc = new Request.Builder().post(getElasticSearchExchangesPath() + "_search").body("{\n" + "  \"query\": {\n" + "    \"bool\": {\n" + "      \"must\": [\n" + "        {\n" + "          \"wildcard\": {\n" + "            \"issuer\": \"" + documentPrefix + "\"\n" + "          }\n" + "        },\n" + "        {\n" + "          \"match\": {\n" + "            \"rule.port\": \"" + port + "\"\n" + "          }\n" + "        }\n" + "      ]\n" + "    }\n" + "  }\n" + "}").header("Content-Type", "application/json").buildExchange();
        exc = client.call(exc);
        List source = getSourceElementFromElasticSearchResponse(responseToMap(exc));
        AbstractExchangeSnapshot[] snapshots = mapper.readValue(mapper.writeValueAsString(source), AbstractExchangeSnapshot[].class);
        return Stream.of(snapshots).map(snapshot -> snapshot.toAbstractExchange()).collect(Collectors.toList()).toArray(new AbstractExchange[0]);
    } catch (Exception e) {
        e.printStackTrace();
        return new AbstractExchange[0];
    }
}
Also used : AbstractExchange(com.predic8.membrane.core.exchange.AbstractExchange) Exchange(com.predic8.membrane.core.exchange.Exchange) CacheBuilder(com.google.common.cache.CacheBuilder) DynamicAbstractExchangeSnapshot(com.predic8.membrane.core.exchange.snapshots.DynamicAbstractExchangeSnapshot) AbstractExchangeSnapshot(com.predic8.membrane.core.exchange.snapshots.AbstractExchangeSnapshot) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 4 with Exchange

use of com.predic8.membrane.core.exchange.Exchange in project service-proxy by membrane.

the class ElasticSearchExchangeStore method getAllExchangesAsList.

@Override
public List<AbstractExchange> getAllExchangesAsList() {
    try {
        Exchange exc = new Request.Builder().post(getElasticSearchExchangesPath() + "_search").header("Content-Type", "application/json").body("{\n" + "  \"query\": {\n" + "    \"wildcard\": {\n" + "      \"issuer\": \"" + documentPrefix + "\"\n" + "    }\n" + "  }\n" + "}").buildExchange();
        exc = client.call(exc);
        if (!exc.getResponse().isOk())
            return new ArrayList<>();
        List sources = getSourceElementFromElasticSearchResponse(responseToMap(exc));
        return (List) sources.stream().map(source -> {
            try {
                return mapper.readValue(mapper.writeValueAsString(source), AbstractExchangeSnapshot.class).toAbstractExchange();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }).collect(Collectors.toList());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : AbstractExchange(com.predic8.membrane.core.exchange.AbstractExchange) Exchange(com.predic8.membrane.core.exchange.Exchange) CacheBuilder(com.google.common.cache.CacheBuilder) IOException(java.io.IOException) DynamicAbstractExchangeSnapshot(com.predic8.membrane.core.exchange.snapshots.DynamicAbstractExchangeSnapshot) AbstractExchangeSnapshot(com.predic8.membrane.core.exchange.snapshots.AbstractExchangeSnapshot) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 5 with Exchange

use of com.predic8.membrane.core.exchange.Exchange in project service-proxy by membrane.

the class ElasticSearchExchangeStore method removeFromElasticSearchById.

private void removeFromElasticSearchById(long id) throws Exception {
    Exchange exc = new Request.Builder().delete(getElasticSearchExchangesPath() + getLocalMachineNameWithSuffix() + "-" + id).buildExchange();
    client.call(exc);
}
Also used : AbstractExchange(com.predic8.membrane.core.exchange.AbstractExchange) Exchange(com.predic8.membrane.core.exchange.Exchange) CacheBuilder(com.google.common.cache.CacheBuilder)

Aggregations

Exchange (com.predic8.membrane.core.exchange.Exchange)107 Test (org.junit.Test)39 IOException (java.io.IOException)32 Request (com.predic8.membrane.core.http.Request)25 Outcome (com.predic8.membrane.core.interceptor.Outcome)24 Response (com.predic8.membrane.core.http.Response)16 AbstractInterceptor (com.predic8.membrane.core.interceptor.AbstractInterceptor)16 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)16 HttpRouter (com.predic8.membrane.core.HttpRouter)14 Before (org.junit.Before)13 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)12 AbstractExchange (com.predic8.membrane.core.exchange.AbstractExchange)11 Header (com.predic8.membrane.core.http.Header)10 HttpClient (com.predic8.membrane.core.transport.http.HttpClient)10 CacheBuilder (com.google.common.cache.CacheBuilder)9 Rule (com.predic8.membrane.core.rules.Rule)6 URISyntaxException (java.net.URISyntaxException)6 UnknownHostException (java.net.UnknownHostException)6 ArrayList (java.util.ArrayList)6 Session (com.predic8.membrane.core.interceptor.authentication.session.SessionManager.Session)5