Search in sources :

Example 86 with Exchange

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

the class OAuth2AuthorizationServerInterceptorBase method getMockAuthRequestExchange.

public static Callable<Exchange> getMockAuthRequestExchange() throws Exception {
    return new Callable<Exchange>() {

        @Override
        public Exchange call() throws Exception {
            Exchange exc = new Request.Builder().get(mas.getLoginURL("123security", "http://localhost:2001/", "/")).buildExchange();
            exc.getRequest().getHeader().add("Cookie", oasi.getSessionManager().getCookieName() + "=" + OAuth2TestUtil.sessionId);
            return exc;
        }
    };
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Callable(java.util.concurrent.Callable)

Example 87 with Exchange

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

the class OAuth2AuthorizationServerInterceptorBase method getMockEmptyEndpointRequest.

public static Callable<Exchange> getMockEmptyEndpointRequest() throws Exception {
    return new Callable<Exchange>() {

        @Override
        public Exchange call() throws Exception {
            Exchange exc = new Request.Builder().get("/").buildExchange();
            exc.getRequest().getHeader().add("Cookie", oasi.getSessionManager().getCookieName() + "=" + OAuth2TestUtil.sessionId);
            OAuth2TestUtil.makeExchangeValid(exc);
            return exc;
        }
    };
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Callable(java.util.concurrent.Callable)

Example 88 with Exchange

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

the class OAuth2TestUtil method makeExchangeValid.

public static void makeExchangeValid(Exchange exc) throws Exception {
    exc.setOriginalRequestUri(exc.getRequest().getUri());
    exc.setRule(new NullRule());
}
Also used : NullRule(com.predic8.membrane.core.rules.NullRule)

Example 89 with Exchange

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

the class ResolverTestTriggerTest method handleRequest.

@Override
public Outcome handleRequest(Exchange exc) {
    try {
        Class<?> clazz = Class.forName("com.predic8.membrane.core.resolver.ResolverTest");
        clazz.getField("deployment").set(null, "J2EE");
        Object value = router.getResolverMap().getFileSchemaResolver();
        Object resolverMap = clazz.getField("resolverMap").get(null);
        resolverMap.getClass().getMethod("addSchemaResolver", SchemaResolver.class).invoke(resolverMap, value);
        Parameterized p = new Parameterized(clazz);
        JUnitCore c = new JUnitCore();
        Result run = c.run(Request.runner(p));
        StringBuilder sb = new StringBuilder();
        sb.append(MAGIC);
        for (Failure f : run.getFailures()) {
            sb.append(f.toString());
            StringWriter stringWriter = new StringWriter();
            f.getException().printStackTrace(new PrintWriter(stringWriter));
            sb.append(stringWriter.toString());
            sb.append("\n");
            sb.append("\n");
        }
        exc.setResponse(Response.ok().header(Header.CONTENT_TYPE, MimeType.TEXT_PLAIN_UTF8).body(sb.toString()).build());
    } catch (Throwable t) {
        LOG.error(t.getMessage(), t);
    }
    return Outcome.RETURN;
}
Also used : Parameterized(org.junit.runners.Parameterized) JUnitCore(org.junit.runner.JUnitCore) StringWriter(java.io.StringWriter) SchemaResolver(com.predic8.membrane.core.resolver.SchemaResolver) Failure(org.junit.runner.notification.Failure) Result(org.junit.runner.Result) PrintWriter(java.io.PrintWriter)

Example 90 with Exchange

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

the class AbstractExchangeSnapshot method toAbstractExchange.

public AbstractExchange toAbstractExchange() {
    Exchange exc = new Exchange(null);
    if (getRequest() != null)
        exc.setRequest(this.getRequest().toRequest());
    if (getResponse() != null)
        exc.setResponse(this.getResponse().toResponse());
    exc.setOriginalRequestUri(getOriginalRequestUri());
    exc.setTime(getTime());
    exc.setErrorMessage(getErrorMessage());
    exc.setStatus(getStatus());
    exc.setTimeReqSent(getTimeReqSent());
    exc.setTimeReqReceived(getTimeReqReceived());
    exc.setTimeResSent(getTimeResSent());
    exc.setTimeResReceived(getTimeResReceived());
    exc.setDestinations(getDestinations().stream().collect(Collectors.toList()));
    exc.setRemoteAddr(getRemoteAddr());
    exc.setRemoteAddrIp(getRemoteAddrIp());
    exc.setId(getId());
    exc.setRule(getRule());
    setServer(getServer());
    return exc;
}
Also used : AbstractExchange(com.predic8.membrane.core.exchange.AbstractExchange) Exchange(com.predic8.membrane.core.exchange.Exchange)

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