Search in sources :

Example 51 with MessageImpl

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

the class HttpHeadersImplTest method testGetNoLanguages.

@Test
public void testGetNoLanguages() throws Exception {
    Message m = new MessageImpl();
    m.put(Message.PROTOCOL_HEADERS, Collections.emptyMap());
    HttpHeaders h = new HttpHeadersImpl(m);
    List<Locale> locales = h.getAcceptableLanguages();
    assertEquals(1, locales.size());
    assertEquals("*", locales.get(0).toString());
}
Also used : Locale(java.util.Locale) HttpHeaders(javax.ws.rs.core.HttpHeaders) Message(org.apache.cxf.message.Message) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 52 with MessageImpl

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

the class AsyncResponseImplTest method testCancelBehavesTheSameWhenInvokedMultipleTimes.

/**
 * According to the spec, subsequent calls to cancel the same AsyncResponse should
 * have the same behavior as the first call.
 */
@Test
public void testCancelBehavesTheSameWhenInvokedMultipleTimes() {
    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());
    // 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());
    // 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 53 with MessageImpl

use of org.apache.cxf.message.MessageImpl 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 54 with MessageImpl

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

the class CacheControlHeaderProviderTest method testFromComplexStringWithSemicolon.

@Test
public void testFromComplexStringWithSemicolon() {
    CacheControlHeaderProvider cp = new CacheControlHeaderProvider() {

        protected Message getCurrentMessage() {
            Message m = new MessageImpl();
            m.put(CacheControlHeaderProvider.CACHE_CONTROL_SEPARATOR_PROPERTY, ";");
            return m;
        }
    };
    CacheControl c = cp.fromString("private=\"foo\";no-cache=\"bar\";no-store;no-transform;" + "must-revalidate;proxy-revalidate;max-age=2;s-maxage=3");
    assertTrue(c.isPrivate() && c.isNoStore() && c.isMustRevalidate() && c.isProxyRevalidate() && c.isNoCache());
    assertTrue(c.isNoTransform() && c.getNoCacheFields().size() == 1 && c.getPrivateFields().size() == 1);
    assertEquals("foo", c.getPrivateFields().get(0));
    assertEquals("bar", c.getNoCacheFields().get(0));
}
Also used : Message(org.apache.cxf.message.Message) CacheControl(javax.ws.rs.core.CacheControl) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 55 with MessageImpl

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

the class CacheControlHeaderProviderTest method testInvalidSeparator.

@Test(expected = InternalServerErrorException.class)
public void testInvalidSeparator() {
    CacheControlHeaderProvider cp = new CacheControlHeaderProvider() {

        protected Message getCurrentMessage() {
            Message m = new MessageImpl();
            m.put(CacheControlHeaderProvider.CACHE_CONTROL_SEPARATOR_PROPERTY, "(e+)+");
            return m;
        }
    };
    cp.fromString("no-store");
}
Also used : Message(org.apache.cxf.message.Message) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Aggregations

MessageImpl (org.apache.cxf.message.MessageImpl)610 Message (org.apache.cxf.message.Message)291 Test (org.junit.Test)290 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)193 WrappedMessageContext (org.apache.cxf.jaxws.context.WrappedMessageContext)152 Exchange (org.apache.cxf.message.Exchange)148 StaticSTSProperties (org.apache.cxf.sts.StaticSTSProperties)137 PasswordCallbackHandler (org.apache.cxf.sts.common.PasswordCallbackHandler)115 Crypto (org.apache.wss4j.common.crypto.Crypto)113 CustomTokenPrincipal (org.apache.wss4j.common.principal.CustomTokenPrincipal)107 JAXBElement (javax.xml.bind.JAXBElement)100 RequestSecurityTokenType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenType)93 RequestSecurityTokenResponseType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenResponseType)86 STSPropertiesMBean (org.apache.cxf.sts.STSPropertiesMBean)83 Element (org.w3c.dom.Element)74 ArrayList (java.util.ArrayList)62 ServiceMBean (org.apache.cxf.sts.service.ServiceMBean)61 StaticService (org.apache.cxf.sts.service.StaticService)61 Principal (java.security.Principal)59 Endpoint (org.apache.cxf.endpoint.Endpoint)58