Search in sources :

Example 1 with Interceptor

use of com.predic8.membrane.core.interceptor.Interceptor in project service-proxy by membrane.

the class BasicAuthenticationInterceptorIntegrationTest method testHashedPassword.

@Test
public void testHashedPassword() throws Exception {
    List<User> users = new ArrayList<User>();
    User user = new User("admin", "$6$12345678$jwCsYagMo/KNcTDqnrWL25Dy3AfAT5U94abA5a/iPFO.Cx2zAkMpPxZBNKY/P/xiRrCfCFDxdBp7pvNEMoBcr0");
    users.add(user);
    BasicAuthenticationInterceptor interceptor = new BasicAuthenticationInterceptor();
    StaticUserDataProvider provider = (StaticUserDataProvider) interceptor.getUserDataProvider();
    interceptor.setUsers(users);
    User postData = new User("admin", "admin");
    try {
        provider.verify(postData.getAttributes());
    } catch (Exception e) {
        fail();
    }
}
Also used : User(com.predic8.membrane.core.interceptor.authentication.session.StaticUserDataProvider.User) ArrayList(java.util.ArrayList) StaticUserDataProvider(com.predic8.membrane.core.interceptor.authentication.session.StaticUserDataProvider) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with Interceptor

use of com.predic8.membrane.core.interceptor.Interceptor in project service-proxy by membrane.

the class WSDLInterceptorTest method setUp.

@Before
public void setUp() throws Exception {
    exc = new Exchange(new FakeHttpHandler(3011));
    exc.setRequest(MessageUtil.getGetRequest("/axis2/services/BLZService?wsdl"));
    InputStream resourceAsStream = this.getClass().getResourceAsStream("/blz-service.wsdl");
    Response okResponse = Response.ok().contentType("text/xml; charset=utf-8").body(resourceAsStream, true).build();
    exc.setResponse(okResponse);
    exc.setOriginalHostHeader("thomas-bayer.com:80");
    interceptor = new WSDLInterceptor();
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Response(com.predic8.membrane.core.http.Response) InputStream(java.io.InputStream) FakeHttpHandler(com.predic8.membrane.core.transport.http.FakeHttpHandler) Before(org.junit.Before)

Example 3 with Interceptor

use of com.predic8.membrane.core.interceptor.Interceptor in project service-proxy by membrane.

the class CustomInterceptorTest method test.

@Test
public void test() throws IOException, InterruptedException {
    File baseDir = getExampleDir("custom-interceptor");
    BufferLogger b = new BufferLogger();
    Process2 ant = new Process2.Builder().in(baseDir).executable("ant compile").withWatcher(b).start();
    try {
        int exitCode = ant.waitFor(60000);
        if (exitCode != 0)
            throw new RuntimeException("Ant exited with code " + exitCode + ": " + b.toString());
    } finally {
        ant.killScript();
    }
    FileUtils.copyDirectoryToDirectory(new File(baseDir, "build/classes"), getMembraneHome());
    Process2 sl = new Process2.Builder().in(baseDir).script("service-proxy").waitForMembrane().start();
    try {
        SubstringWaitableConsoleEvent invoked = new SubstringWaitableConsoleEvent(sl, "MyInterceptor invoked");
        getAndAssert200("http://localhost:2000/");
        assertTrue(invoked.occurred());
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) BufferLogger(com.predic8.membrane.examples.util.BufferLogger) File(java.io.File) SubstringWaitableConsoleEvent(com.predic8.membrane.examples.util.SubstringWaitableConsoleEvent) Test(org.junit.Test)

Example 4 with Interceptor

use of com.predic8.membrane.core.interceptor.Interceptor in project service-proxy by membrane.

the class GroovyTest method test.

@Test
public void test() throws IOException, InterruptedException {
    Process2 sl = new Process2.Builder().in(getExampleDir("groovy")).script("service-proxy").waitForMembrane().start();
    try {
        SubstringWaitableConsoleEvent groovyCalled = new SubstringWaitableConsoleEvent(sl, "X-Groovy header added with value :Groovy interceptor");
        getAndAssert200("http://localhost:2000/");
        assertTrue(groovyCalled.occurred());
    } finally {
        sl.killScript();
    }
}
Also used : Process2(com.predic8.membrane.examples.Process2) SubstringWaitableConsoleEvent(com.predic8.membrane.examples.util.SubstringWaitableConsoleEvent) Test(org.junit.Test)

Example 5 with Interceptor

use of com.predic8.membrane.core.interceptor.Interceptor in project service-proxy by membrane.

the class WsaEndpointRewriterInterceptorTest method testRewriterInterceptor.

@Test
public void testRewriterInterceptor() throws Exception {
    exc.setRequest(MessageUtil.getPostRequest("http://localhost:9000/SoapContext/SoapPort?wsdl"));
    InputStream input = WsaEndpointRewriterTest.class.getResourceAsStream("/interceptor/ws_addressing/body.xml");
    exc.getRequest().setBody(new Body(input));
    assertEquals(Outcome.CONTINUE, rewriter.handleRequest(exc));
    assertEquals(exc.getProperty("messageId"), "urn:uuid:62a0de08-055a-4da7-aefa-730af9dbc6b6");
}
Also used : InputStream(java.io.InputStream) Body(com.predic8.membrane.core.http.Body) Test(org.junit.Test)

Aggregations

Interceptor (com.predic8.membrane.core.interceptor.Interceptor)11 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)6 Test (org.junit.Test)6 HttpRouter (com.predic8.membrane.core.HttpRouter)5 Rule (com.predic8.membrane.core.rules.Rule)5 Before (org.junit.Before)5 Exchange (com.predic8.membrane.core.exchange.Exchange)4 ArrayList (java.util.ArrayList)4 LoadBalancingInterceptor (com.predic8.membrane.core.interceptor.balancer.LoadBalancingInterceptor)3 ResolverMap (com.predic8.membrane.core.resolver.ResolverMap)3 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)3 Response (com.predic8.membrane.core.http.Response)2 AbstractInterceptor (com.predic8.membrane.core.interceptor.AbstractInterceptor)2 DispatchingInterceptor (com.predic8.membrane.core.interceptor.DispatchingInterceptor)2 HTTPClientInterceptor (com.predic8.membrane.core.interceptor.HTTPClientInterceptor)2 RuleMatchingInterceptor (com.predic8.membrane.core.interceptor.RuleMatchingInterceptor)2 UserFeatureInterceptor (com.predic8.membrane.core.interceptor.UserFeatureInterceptor)2 AccessControlInterceptor (com.predic8.membrane.core.interceptor.acl.AccessControlInterceptor)2 User (com.predic8.membrane.core.interceptor.authentication.session.StaticUserDataProvider.User)2 RequestInterceptor (com.predic8.membrane.core.interceptor.flow.RequestInterceptor)2