Search in sources :

Example 1 with AdaptrisMessage

use of com.adaptris.core.AdaptrisMessage 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 AdaptrisMessage

use of com.adaptris.core.AdaptrisMessage in project interlok by adaptris.

the class StandardHttpProducerTest method testProduce_WithEncoder.

@Test
public void testProduce_WithEncoder() throws Exception {
    MockMessageProducer mock = new MockMessageProducer();
    Channel c = HttpHelper.createAndStartChannel(mock);
    StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(c));
    ;
    stdHttp.setEncoder(new UrlConnectionEncoder());
    StandaloneProducer producer = new StandaloneProducer(stdHttp);
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
    try {
        c.requestStart();
        start(producer);
        producer.doService(msg);
        waitForMessages(mock, 1);
    } finally {
        HttpHelper.stopChannelAndRelease(c);
        stop(producer);
    }
    assertEquals(1, mock.messageCount());
    AdaptrisMessage m2 = mock.getMessages().get(0);
    assertEquals(TEXT, m2.getContent());
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) StandaloneProducer(com.adaptris.core.StandaloneProducer) HttpConsumerTest(com.adaptris.core.http.jetty.HttpConsumerTest) Test(org.junit.Test)

Example 3 with AdaptrisMessage

use of com.adaptris.core.AdaptrisMessage in project interlok by adaptris.

the class StandardHttpProducerTest method testProduce_MetadataRequestHeaders.

@Test
public void testProduce_MetadataRequestHeaders() throws Exception {
    MockMessageProducer mock = new MockMessageProducer();
    Channel c = HttpHelper.createAndStartChannel(mock);
    StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(c));
    stdHttp.setRequestHeaderProvider(new MetadataRequestHeaders(new RegexMetadataFilter()));
    StandaloneProducer producer = new StandaloneProducer(stdHttp);
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
    msg.addMetadata(getName(), getName());
    try {
        c.requestStart();
        // INTERLOK-3329 For coverage so the prepare() warning is executed 2x
        LifecycleHelper.prepare(producer);
        start(producer);
        producer.doService(msg);
        waitForMessages(mock, 1);
    } finally {
        HttpHelper.stopChannelAndRelease(c);
        stop(producer);
    }
    assertEquals(1, mock.messageCount());
    AdaptrisMessage m2 = mock.getMessages().get(0);
    assertTrue(m2.headersContainsKey(getName()));
    assertEquals(getName(), m2.getMetadataValue(getName()));
}
Also used : RegexMetadataFilter(com.adaptris.core.metadata.RegexMetadataFilter) DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) StandaloneProducer(com.adaptris.core.StandaloneProducer) HttpConsumerTest(com.adaptris.core.http.jetty.HttpConsumerTest) Test(org.junit.Test)

Example 4 with AdaptrisMessage

use of com.adaptris.core.AdaptrisMessage 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 5 with AdaptrisMessage

use of com.adaptris.core.AdaptrisMessage in project interlok by adaptris.

the class StandardHttpProducerTest method testProduceWithAuthorizationHeader.

@Test
public void testProduceWithAuthorizationHeader() throws Exception {
    MockMessageProducer mock = new MockMessageProducer();
    Channel c = HttpHelper.createAndStartChannel(mock);
    StandardHttpProducer stdHttp = new StandardHttpProducer().withURL(HttpHelper.createURL(c));
    ;
    ConfiguredAuthorizationHeader authenticator = new ConfiguredAuthorizationHeader();
    authenticator.setHeaderValue("some value");
    stdHttp.setAuthenticator(authenticator);
    StandaloneProducer producer = new StandaloneProducer(stdHttp);
    AdaptrisMessage msg = new DefaultMessageFactory().newMessage(TEXT);
    try {
        c.requestStart();
        start(producer);
        producer.doService(msg);
        waitForMessages(mock, 1);
    } finally {
        HttpHelper.stopChannelAndRelease(c);
        stop(producer);
    }
    assertEquals(1, mock.messageCount());
    AdaptrisMessage m2 = mock.getMessages().get(0);
    assertTrue(m2.headersContainsKey(HttpConstants.AUTHORIZATION));
    assertEquals("some value", m2.getMetadataValue(HttpConstants.AUTHORIZATION));
}
Also used : DefaultMessageFactory(com.adaptris.core.DefaultMessageFactory) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) JettyHelper.createChannel(com.adaptris.core.http.jetty.JettyHelper.createChannel) Channel(com.adaptris.core.Channel) StandaloneProducer(com.adaptris.core.StandaloneProducer) HttpConsumerTest(com.adaptris.core.http.jetty.HttpConsumerTest) Test(org.junit.Test)

Aggregations

AdaptrisMessage (com.adaptris.core.AdaptrisMessage)1495 Test (org.junit.Test)1362 ServiceException (com.adaptris.core.ServiceException)171 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)158 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)156 StandaloneProducer (com.adaptris.core.StandaloneProducer)125 Channel (com.adaptris.core.Channel)122 MetadataElement (com.adaptris.core.MetadataElement)94 File (java.io.File)89 TimeInterval (com.adaptris.util.TimeInterval)77 CoreException (com.adaptris.core.CoreException)67 Session (javax.jms.Session)62 StandardWorkflow (com.adaptris.core.StandardWorkflow)57 GuidGenerator (com.adaptris.util.GuidGenerator)56 JettyHelper.createChannel (com.adaptris.core.http.jetty.JettyHelper.createChannel)50 StandaloneRequestor (com.adaptris.core.StandaloneRequestor)49 Message (javax.jms.Message)47 XPath (com.adaptris.util.text.xml.XPath)45 ServiceList (com.adaptris.core.ServiceList)43 Document (org.w3c.dom.Document)40