Search in sources :

Example 71 with ExchangeImpl

use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.

the class AsyncResponseImplTest method testCancelDateBehavesTheSameWhenInvokedMultipleTimes.

/**
 * Similar to testCancelBehavesTheSameWhenInvokedMultipleTimes, but using the cancel(Date) signature.
 */
@Test
public void testCancelDateBehavesTheSameWhenInvokedMultipleTimes() {
    HttpServletRequest req = control.createMock(HttpServletRequest.class);
    HttpServletResponse resp = control.createMock(HttpServletResponse.class);
    AsyncContext asyncCtx = control.createMock(AsyncContext.class);
    Message msg = new MessageImpl();
    msg.setExchange(new ExchangeImpl());
    msg.put(ContinuationProvider.class.getName(), new Servlet3ContinuationProvider(req, resp, msg));
    req.startAsync();
    EasyMock.expectLastCall().andReturn(asyncCtx);
    control.replay();
    AsyncResponse impl = new AsyncResponseImpl(msg);
    // cancel the AsyncResponse for the first time
    Date d = new Date(System.currentTimeMillis() + 60000);
    assertTrue("Unexpectedly returned false when canceling the first time", impl.cancel(d));
    // check the state of the AsyncResponse
    assertTrue("AsyncResponse was canceled but is reporting that it was not canceled", impl.isCancelled());
    boolean isDone = impl.isDone();
    boolean isSuspended = impl.isSuspended();
    // cancel the AsyncResponse a second time
    d = new Date(System.currentTimeMillis() + 120000);
    assertTrue("Unexpectedly returned false when canceling the second time", impl.cancel(d));
    // verify that the state is the same as before the second cancel
    assertTrue("AsyncResponse was canceled (twice) but is reporting that it was not canceled", impl.isCancelled());
    assertEquals("AsynchResponse.isDone() returned a different response after canceling a second time", isDone, impl.isDone());
    assertEquals("AsynchResponse.isSuspended() returned a different response after canceling a second time", isSuspended, impl.isSuspended());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ContinuationProvider(org.apache.cxf.continuations.ContinuationProvider) Servlet3ContinuationProvider(org.apache.cxf.transport.http.Servlet3ContinuationProvider) Message(org.apache.cxf.message.Message) Servlet3ContinuationProvider(org.apache.cxf.transport.http.Servlet3ContinuationProvider) HttpServletResponse(javax.servlet.http.HttpServletResponse) AsyncContext(javax.servlet.AsyncContext) AsyncResponse(javax.ws.rs.container.AsyncResponse) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Date(java.util.Date) Test(org.junit.Test)

Example 72 with ExchangeImpl

use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.

the class AsyncResponseImplTest method testCancelIntBehavesTheSameWhenInvokedMultipleTimes.

/**
 * Similar to testCancelBehavesTheSameWhenInvokedMultipleTimes, but using the cancel(int) signature.
 */
@Test
public void testCancelIntBehavesTheSameWhenInvokedMultipleTimes() {
    HttpServletRequest req = control.createMock(HttpServletRequest.class);
    HttpServletResponse resp = control.createMock(HttpServletResponse.class);
    AsyncContext asyncCtx = control.createMock(AsyncContext.class);
    Message msg = new MessageImpl();
    msg.setExchange(new ExchangeImpl());
    msg.put(ContinuationProvider.class.getName(), new Servlet3ContinuationProvider(req, resp, msg));
    req.startAsync();
    EasyMock.expectLastCall().andReturn(asyncCtx);
    control.replay();
    AsyncResponse impl = new AsyncResponseImpl(msg);
    // cancel the AsyncResponse for the first time
    assertTrue("Unexpectedly returned false when canceling the first time", impl.cancel(10));
    // check the state of the AsyncResponse
    assertTrue("AsyncResponse was canceled but is reporting that it was not canceled", impl.isCancelled());
    boolean isDone = impl.isDone();
    boolean isSuspended = impl.isSuspended();
    // cancel the AsyncResponse a second time
    assertTrue("Unexpectedly returned false when canceling the second time", impl.cancel(25));
    // verify that the state is the same as before the second cancel
    assertTrue("AsyncResponse was canceled (twice) but is reporting that it was not canceled", impl.isCancelled());
    assertEquals("AsynchResponse.isDone() returned a different response after canceling a second time", isDone, impl.isDone());
    assertEquals("AsynchResponse.isSuspended() returned a different response after canceling a second time", isSuspended, impl.isSuspended());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ContinuationProvider(org.apache.cxf.continuations.ContinuationProvider) Servlet3ContinuationProvider(org.apache.cxf.transport.http.Servlet3ContinuationProvider) Message(org.apache.cxf.message.Message) Servlet3ContinuationProvider(org.apache.cxf.transport.http.Servlet3ContinuationProvider) HttpServletResponse(javax.servlet.http.HttpServletResponse) AsyncContext(javax.servlet.AsyncContext) AsyncResponse(javax.ws.rs.container.AsyncResponse) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 73 with ExchangeImpl

use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.

the class HttpHeadersImplTest method testGetCookiesWithComma.

@Test
public void testGetCookiesWithComma() throws Exception {
    Message m = createMessage(createHeader(HttpHeaders.COOKIE, "a=b,c=d"));
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(m);
    ex.put(HttpHeadersImpl.COOKIE_SEPARATOR_PROPERTY, ",");
    m.setExchange(ex);
    HttpHeaders h = new HttpHeadersImpl(m);
    Map<String, Cookie> cookies = h.getCookies();
    assertEquals(2, cookies.size());
    assertEquals("b", cookies.get("a").getValue());
    assertEquals("d", cookies.get("c").getValue());
}
Also used : Exchange(org.apache.cxf.message.Exchange) Cookie(javax.ws.rs.core.Cookie) HttpHeaders(javax.ws.rs.core.HttpHeaders) Message(org.apache.cxf.message.Message) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 74 with ExchangeImpl

use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.

the class HttpHeadersImplTest method testInvalidCookieSeparator.

@Test(expected = InternalServerErrorException.class)
public void testInvalidCookieSeparator() throws Exception {
    Message m = createMessage(createHeader(HttpHeaders.COOKIE, "a=b,c=d"));
    Exchange ex = new ExchangeImpl();
    ex.setInMessage(m);
    ex.put(HttpHeadersImpl.COOKIE_SEPARATOR_PROPERTY, "(e+)+");
    m.setExchange(ex);
    HttpHeaders h = new HttpHeadersImpl(m);
    h.getCookies();
}
Also used : Exchange(org.apache.cxf.message.Exchange) HttpHeaders(javax.ws.rs.core.HttpHeaders) Message(org.apache.cxf.message.Message) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 75 with ExchangeImpl

use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.

the class AttachmentDeserializerTest method setUp.

@Before
public void setUp() throws Exception {
    msg = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    msg.setExchange(exchange);
}
Also used : Exchange(org.apache.cxf.message.Exchange) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Before(org.junit.Before)

Aggregations

ExchangeImpl (org.apache.cxf.message.ExchangeImpl)227 MessageImpl (org.apache.cxf.message.MessageImpl)189 Message (org.apache.cxf.message.Message)166 Exchange (org.apache.cxf.message.Exchange)159 Test (org.junit.Test)107 Endpoint (org.apache.cxf.endpoint.Endpoint)42 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)30 ByteArrayInputStream (java.io.ByteArrayInputStream)28 QName (javax.xml.namespace.QName)23 Bus (org.apache.cxf.Bus)23 HashMap (java.util.HashMap)22 List (java.util.List)22 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)21 ByteArrayOutputStream (java.io.ByteArrayOutputStream)20 SOAPMessage (javax.xml.soap.SOAPMessage)16 LogEvent (org.apache.cxf.ext.logging.event.LogEvent)16 ArrayList (java.util.ArrayList)15 IOException (java.io.IOException)14 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)14 Conduit (org.apache.cxf.transport.Conduit)14