Search in sources :

Example 1 with JettyMessageConsumer

use of com.adaptris.core.http.jetty.JettyMessageConsumer in project interlok by adaptris.

the class StandardHttpProducerTest method testProduce_WithUsernamePassword.

@Test
public void testProduce_WithUsernamePassword() throws Exception {
    String threadName = Thread.currentThread().getName();
    Thread.currentThread().setName(getName());
    ConfigurableSecurityHandler csh = new ConfigurableSecurityHandler();
    HashLoginServiceFactory hsl = new HashLoginServiceFactory("InterlokJetty", PROPERTIES.getProperty(HttpConsumerTest.JETTY_USER_REALM));
    csh.setLoginService(hsl);
    SecurityConstraint securityConstraint = new SecurityConstraint();
    securityConstraint.setMustAuthenticate(true);
    securityConstraint.setRoles("user");
    csh.setSecurityConstraints(Arrays.asList(securityConstraint));
    HttpConnection jc = HttpHelper.createConnection();
    jc.setSecurityHandler(csh);
    MockMessageProducer mockProducer = new MockMessageProducer();
    JettyMessageConsumer consumer = JettyHelper.createConsumer(HttpHelper.URL_TO_POST_TO);
    Channel channel = JettyHelper.createChannel(jc, consumer, mockProducer);
    HttpAuthenticator auth = getAuthenticator(getName(), getName());
    StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(channel));
    stdHttp.setIgnoreServerResponseCode(false);
    stdHttp.registerConnection(new NullConnection());
    stdHttp.setAuthenticator(auth);
    try {
        start(channel);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(TEXT);
        start(stdHttp);
        AdaptrisMessage reply = stdHttp.request(msg);
        waitForMessages(mockProducer, 1);
        assertEquals(TEXT, mockProducer.getMessages().get(0).getContent());
    } finally {
        stop(stdHttp);
        HttpHelper.stopChannelAndRelease(channel);
        Thread.currentThread().setName(threadName);
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) HttpConnection(com.adaptris.core.http.jetty.HttpConnection) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) ConfigurableSecurityHandler(com.adaptris.core.http.jetty.ConfigurableSecurityHandler) JettyMessageConsumer(com.adaptris.core.http.jetty.JettyMessageConsumer) HttpAuthenticator(com.adaptris.core.http.auth.HttpAuthenticator) NullConnection(com.adaptris.core.NullConnection) SecurityConstraint(com.adaptris.core.http.jetty.SecurityConstraint) HashLoginServiceFactory(com.adaptris.core.http.jetty.HashLoginServiceFactory) HttpConsumerTest(com.adaptris.core.http.jetty.HttpConsumerTest) Test(org.junit.Test)

Example 2 with JettyMessageConsumer

use of com.adaptris.core.http.jetty.JettyMessageConsumer in project interlok by adaptris.

the class StandardHttpProducerTest method testRequest_DeleteMethod_AlwaysSendPayload.

@Test
public void testRequest_DeleteMethod_AlwaysSendPayload() throws Exception {
    MockMessageProducer mock = new MockMessageProducer();
    HttpConnection jc = HttpHelper.createConnection();
    JettyMessageConsumer mc = createConsumer(HttpHelper.URL_TO_POST_TO);
    Channel c = createChannel(jc, createWorkflow(mc, mock, new ServiceList()));
    StandardWorkflow workflow = (StandardWorkflow) c.getWorkflowList().get(0);
    workflow.getServiceCollection().add(new StandaloneProducer(new StandardResponseProducer(HttpStatus.OK_200)));
    StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(c));
    ;
    stdHttp.setMethodProvider(new ConfiguredRequestMethodProvider(RequestMethodProvider.RequestMethod.DELETE));
    stdHttp.setRequestBody(new PayloadStreamInputParameter());
    stdHttp.setAlwaysSendPayload(true);
    StandaloneRequestor producer = new StandaloneRequestor(stdHttp);
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage(ALT_TEXT);
    try {
        start(c);
        start(producer);
        producer.doService(msg);
        waitForMessages(mock, 1);
    } finally {
        stop(c);
        stop(producer);
    }
    assertEquals(1, mock.messageCount());
    AdaptrisMessage m2 = mock.getMessages().get(0);
    assertEquals("DELETE", m2.getMetadataValue(CoreConstants.HTTP_METHOD));
    assertEquals(ALT_TEXT, m2.getContent());
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) StandardWorkflow(com.adaptris.core.StandardWorkflow) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) HttpConnection(com.adaptris.core.http.jetty.HttpConnection) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) StandaloneRequestor(com.adaptris.core.StandaloneRequestor) StandardResponseProducer(com.adaptris.core.http.jetty.StandardResponseProducer) JettyMessageConsumer(com.adaptris.core.http.jetty.JettyMessageConsumer) StandaloneProducer(com.adaptris.core.StandaloneProducer) ConfiguredRequestMethodProvider(com.adaptris.core.http.client.ConfiguredRequestMethodProvider) PayloadStreamInputParameter(com.adaptris.core.common.PayloadStreamInputParameter) HttpConsumerTest(com.adaptris.core.http.jetty.HttpConsumerTest) Test(org.junit.Test)

Example 3 with JettyMessageConsumer

use of com.adaptris.core.http.jetty.JettyMessageConsumer in project interlok by adaptris.

the class StandardHttpProducerTest method testProduce_WithUsernamePassword_BadCredentials.

@Test
public void testProduce_WithUsernamePassword_BadCredentials() throws Exception {
    String threadName = Thread.currentThread().getName();
    Thread.currentThread().setName(getName());
    ConfigurableSecurityHandler csh = new ConfigurableSecurityHandler();
    HashLoginServiceFactory hsl = new HashLoginServiceFactory("InterlokJetty", PROPERTIES.getProperty(HttpConsumerTest.JETTY_USER_REALM));
    csh.setLoginService(hsl);
    SecurityConstraint securityConstraint = new SecurityConstraint();
    securityConstraint.setMustAuthenticate(true);
    securityConstraint.setRoles("user");
    csh.setSecurityConstraints(Arrays.asList(securityConstraint));
    HttpConnection jc = HttpHelper.createConnection();
    jc.setSecurityHandler(csh);
    MockMessageProducer mockProducer = new MockMessageProducer();
    JettyMessageConsumer consumer = JettyHelper.createConsumer(HttpHelper.URL_TO_POST_TO);
    Channel channel = JettyHelper.createChannel(jc, consumer, mockProducer);
    HttpAuthenticator auth = getAuthenticator(getName(), getName());
    StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(channel));
    stdHttp.setIgnoreServerResponseCode(false);
    stdHttp.registerConnection(new NullConnection());
    stdHttp.setAuthenticator(auth);
    try {
        start(channel);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(TEXT);
        start(stdHttp);
        AdaptrisMessage reply = stdHttp.request(msg);
        fail();
    } catch (ProduceException expected) {
    } finally {
        stop(stdHttp);
        HttpHelper.stopChannelAndRelease(channel);
        Thread.currentThread().setName(threadName);
    }
}
Also used : MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) HttpConnection(com.adaptris.core.http.jetty.HttpConnection) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) ConfigurableSecurityHandler(com.adaptris.core.http.jetty.ConfigurableSecurityHandler) HttpAuthenticator(com.adaptris.core.http.auth.HttpAuthenticator) SecurityConstraint(com.adaptris.core.http.jetty.SecurityConstraint) ProduceException(com.adaptris.core.ProduceException) JettyMessageConsumer(com.adaptris.core.http.jetty.JettyMessageConsumer) NullConnection(com.adaptris.core.NullConnection) HashLoginServiceFactory(com.adaptris.core.http.jetty.HashLoginServiceFactory) HttpConsumerTest(com.adaptris.core.http.jetty.HttpConsumerTest) Test(org.junit.Test)

Example 4 with JettyMessageConsumer

use of com.adaptris.core.http.jetty.JettyMessageConsumer in project interlok by adaptris.

the class StandardHttpProducerTest method testRequest_GetMethod_NonZeroBytes.

@Test
public void testRequest_GetMethod_NonZeroBytes() throws Exception {
    MockMessageProducer mock = new MockMessageProducer();
    HttpConnection jc = HttpHelper.createConnection();
    JettyMessageConsumer mc = createConsumer(HttpHelper.URL_TO_POST_TO);
    Channel c = createChannel(jc, createWorkflow(mc, mock, new ServiceList()));
    StandardWorkflow workflow = (StandardWorkflow) c.getWorkflowList().get(0);
    workflow.getServiceCollection().add(new StandaloneProducer(new StandardResponseProducer(HttpStatus.OK_200)));
    StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(c));
    ;
    stdHttp.setMethodProvider(new ConfiguredRequestMethodProvider(RequestMethodProvider.RequestMethod.GET));
    StandaloneRequestor producer = new StandaloneRequestor(stdHttp);
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage(ALT_TEXT);
    try {
        start(c);
        start(producer);
        producer.doService(msg);
        waitForMessages(mock, 1);
    } finally {
        stop(c);
        stop(producer);
    }
    assertEquals(1, mock.messageCount());
    AdaptrisMessage m2 = mock.getMessages().get(0);
    assertEquals("GET", m2.getMetadataValue(CoreConstants.HTTP_METHOD));
    assertEquals(0, m2.getSize());
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) StandardWorkflow(com.adaptris.core.StandardWorkflow) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) HttpConnection(com.adaptris.core.http.jetty.HttpConnection) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) StandaloneRequestor(com.adaptris.core.StandaloneRequestor) StandardResponseProducer(com.adaptris.core.http.jetty.StandardResponseProducer) JettyMessageConsumer(com.adaptris.core.http.jetty.JettyMessageConsumer) StandaloneProducer(com.adaptris.core.StandaloneProducer) ConfiguredRequestMethodProvider(com.adaptris.core.http.client.ConfiguredRequestMethodProvider) HttpConsumerTest(com.adaptris.core.http.jetty.HttpConsumerTest) Test(org.junit.Test)

Example 5 with JettyMessageConsumer

use of com.adaptris.core.http.jetty.JettyMessageConsumer in project interlok by adaptris.

the class StandardHttpProducerTest method testRequest_GetMethod_NonZeroBytes_WithErrorResponse.

@Test
public void testRequest_GetMethod_NonZeroBytes_WithErrorResponse() throws Exception {
    MockMessageProducer mock = new MockMessageProducer();
    HttpConnection jc = HttpHelper.createConnection();
    JettyMessageConsumer mc = createConsumer(HttpHelper.URL_TO_POST_TO);
    ServiceList services = new ServiceList();
    services.add(new PayloadFromTemplateService().withTemplate(TEXT));
    services.add(new StandaloneProducer(new StandardResponseProducer(HttpStatus.UNAUTHORIZED_401)));
    Channel c = createChannel(jc, createWorkflow(mc, mock, services));
    StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(c));
    ;
    stdHttp.setMethodProvider(new ConfiguredRequestMethodProvider(RequestMethodProvider.RequestMethod.GET));
    stdHttp.setIgnoreServerResponseCode(true);
    stdHttp.setResponseHeaderHandler(new ResponseHeadersAsMetadata("HTTP_"));
    StandaloneRequestor producer = new StandaloneRequestor(stdHttp);
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage(ALT_TEXT);
    try {
        start(c);
        start(producer);
        // msg will now contain the response!
        producer.doService(msg);
        waitForMessages(mock, 1);
    } finally {
        stop(c);
        stop(producer);
    }
    assertEquals(1, mock.messageCount());
    AdaptrisMessage m2 = mock.getMessages().get(0);
    assertEquals("GET", m2.getMetadataValue(CoreConstants.HTTP_METHOD));
    assertEquals(TEXT, msg.getContent());
    assertEquals("401", msg.getMetadataValue(CoreConstants.HTTP_PRODUCER_RESPONSE_CODE));
    assertNotNull(msg.getMetadata("HTTP_Server"));
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) HttpConnection(com.adaptris.core.http.jetty.HttpConnection) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) StandaloneRequestor(com.adaptris.core.StandaloneRequestor) StandardResponseProducer(com.adaptris.core.http.jetty.StandardResponseProducer) JettyMessageConsumer(com.adaptris.core.http.jetty.JettyMessageConsumer) PayloadFromTemplateService(com.adaptris.core.services.metadata.PayloadFromTemplateService) StandaloneProducer(com.adaptris.core.StandaloneProducer) ConfiguredRequestMethodProvider(com.adaptris.core.http.client.ConfiguredRequestMethodProvider) HttpConsumerTest(com.adaptris.core.http.jetty.HttpConsumerTest) Test(org.junit.Test)

Aggregations

JettyMessageConsumer (com.adaptris.core.http.jetty.JettyMessageConsumer)29 Channel (com.adaptris.core.Channel)28 Test (org.junit.Test)26 HttpConnection (com.adaptris.core.http.jetty.HttpConnection)25 JettyHelper.createChannel (com.adaptris.core.http.jetty.JettyHelper.createChannel)25 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)23 HttpConsumerTest (com.adaptris.core.http.jetty.HttpConsumerTest)23 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)23 ServiceList (com.adaptris.core.ServiceList)20 StandaloneProducer (com.adaptris.core.StandaloneProducer)20 StandardResponseProducer (com.adaptris.core.http.jetty.StandardResponseProducer)20 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)18 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)12 PayloadFromTemplateService (com.adaptris.core.services.metadata.PayloadFromTemplateService)12 ConfiguredRequestMethodProvider (com.adaptris.core.http.client.ConfiguredRequestMethodProvider)11 StandardWorkflow (com.adaptris.core.StandardWorkflow)10 ConfigurableSecurityHandler (com.adaptris.core.http.jetty.ConfigurableSecurityHandler)5 HashLoginServiceFactory (com.adaptris.core.http.jetty.HashLoginServiceFactory)5 SecurityConstraint (com.adaptris.core.http.jetty.SecurityConstraint)5 NullConnection (com.adaptris.core.NullConnection)4