Search in sources :

Example 1 with Request

use of javax.ws.rs.core.Request in project ovirt-engine by oVirt.

the class UsageFinderTest method testAdd.

@Test
public void testAdd() {
    try {
        UriInfo uriInfo = mockUri("hosts", "00000001-0001-0001-0001-000000000011", "nics");
        Request request = mockRequest("POST");
        Fault fault = usageFinder.getUsageMessage(uriInfo, request);
        assertEquals("For correct usage, see: http://localhost:8080/ovirt-engine/apidoc#services/host_nics/methods/add", fault.getDetail());
    } catch (ClassNotFoundException | IOException | URISyntaxException e) {
        fail();
    }
}
Also used : Request(javax.ws.rs.core.Request) Fault(org.ovirt.engine.api.model.Fault) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Example 2 with Request

use of javax.ws.rs.core.Request in project ovirt-engine by oVirt.

the class UsageFinderTest method testUpdateWithNonGuidId.

@Test
public void testUpdateWithNonGuidId() {
    try {
        // LUN id.
        UriInfo uriInfo = mockUri("hosts", "00000001-0001-0001-0001-000000000011", "nics", "116");
        Request request = mockRequest("PUT");
        Fault fault = usageFinder.getUsageMessage(uriInfo, request);
        assertEquals("For correct usage, see: http://localhost:8080/ovirt-engine/apidoc#services/host_nic/methods/update", fault.getDetail());
    } catch (URISyntaxException | ClassNotFoundException | IOException e) {
        fail();
    }
}
Also used : Request(javax.ws.rs.core.Request) Fault(org.ovirt.engine.api.model.Fault) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Example 3 with Request

use of javax.ws.rs.core.Request in project tomee by apache.

the class Contexts method bind.

/**
 * Using a set ensures we don't set the thread local twice or more,
 * there may be super classes with injection points of identical types
 *
 * Also allows us to get context references from other sources such as interceptors
 *
 * @param exchange Exchange
 * @param types    Collection
 */
public static void bind(final Exchange exchange, final Collection<Class<?>> types) {
    // used in lazy mode by RESTResourceFinder if cdi beans uses @Context, === initThreadLocal
    EXCHANGE.set(exchange);
    CdiAppContextsService.pushRequestReleasable(CleanUpThreadLocal.INSTANCE);
    for (final Class<?> type : types) {
        if (Request.class.equals(type)) {
            final Request binding = JAXRSUtils.createContextValue(exchange.getInMessage(), null, Request.class);
            ThreadLocalContextManager.REQUEST.set(binding);
        } else if (UriInfo.class.equals(type)) {
            final UriInfo binding = JAXRSUtils.createContextValue(exchange.getInMessage(), null, UriInfo.class);
            ThreadLocalContextManager.URI_INFO.set(binding);
        } else if (HttpHeaders.class.equals(type)) {
            final HttpHeaders binding = JAXRSUtils.createContextValue(exchange.getInMessage(), null, HttpHeaders.class);
            ThreadLocalContextManager.HTTP_HEADERS.set(binding);
        } else if (SecurityContext.class.equals(type)) {
            final SecurityContext binding = JAXRSUtils.createContextValue(exchange.getInMessage(), null, SecurityContext.class);
            ThreadLocalContextManager.SECURITY_CONTEXT.set(binding);
        } else if (ContextResolver.class.equals(type)) {
            final ContextResolver<?> binding = JAXRSUtils.createContextValue(exchange.getInMessage(), type, ContextResolver.class);
            ThreadLocalContextManager.CONTEXT_RESOLVER.set(binding);
        } else if (Providers.class.equals(type)) {
            final Providers providers = JAXRSUtils.createContextValue(exchange.getInMessage(), null, Providers.class);
            ThreadLocalContextManager.PROVIDERS.set(providers);
        } else if (ServletRequest.class.equals(type)) {
            ServletRequest servletRequest = JAXRSUtils.createContextValue(exchange.getInMessage(), null, ServletRequest.class);
            if (servletRequest == null) {
                // probably the case with CXF
                servletRequest = JAXRSUtils.createContextValue(exchange.getInMessage(), null, HttpServletRequest.class);
            }
            ThreadLocalContextManager.SERVLET_REQUEST.set(servletRequest);
        } else if (HttpServletRequest.class.equals(type)) {
            final HttpServletRequest httpServletRequest = JAXRSUtils.createContextValue(exchange.getInMessage(), null, HttpServletRequest.class);
            ThreadLocalContextManager.HTTP_SERVLET_REQUEST.set(httpServletRequest);
        } else if (HttpServletResponse.class.equals(type)) {
            final HttpServletResponse httpServletResponse = JAXRSUtils.createContextValue(exchange.getInMessage(), null, HttpServletResponse.class);
            ThreadLocalContextManager.HTTP_SERVLET_RESPONSE.set(httpServletResponse);
        } else if (ServletConfig.class.equals(type)) {
            final ServletConfig servletConfig = JAXRSUtils.createContextValue(exchange.getInMessage(), null, ServletConfig.class);
            ThreadLocalContextManager.SERVLET_CONFIG.set(servletConfig);
        } else if (Configuration.class.equals(type)) {
            final Configuration config = JAXRSUtils.createContextValue(exchange.getInMessage(), null, Configuration.class);
            ThreadLocalContextManager.CONFIGURATION.set(config);
        } else if (ResourceInfo.class.equals(type)) {
            final ResourceInfo config = JAXRSUtils.createContextValue(exchange.getInMessage(), null, ResourceInfo.class);
            ThreadLocalContextManager.RESOURCE_INFO.set(config);
        } else if (ResourceContext.class.equals(type)) {
            final ResourceContext config = JAXRSUtils.createContextValue(exchange.getInMessage(), null, ResourceContext.class);
            ThreadLocalContextManager.RESOURCE_CONTEXT.set(config);
        } else if (Application.class.equals(type)) {
            final Application config = JAXRSUtils.createContextValue(exchange.getInMessage(), null, Application.class);
            ThreadLocalContextManager.APPLICATION.set(config);
        } else {
            final Message message = exchange.getInMessage();
            final ContextProvider<?> provider = ProviderFactory.getInstance(message).createContextProvider(type, message);
            if (provider != null) {
                final Object value = provider.createContext(message);
                Map<String, Object> map = ThreadLocalContextManager.OTHERS.get();
                if (map == null) {
                    map = new HashMap<>();
                    ThreadLocalContextManager.OTHERS.set(map);
                }
                map.put(type.getName(), value);
            }
        }
    }
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) ResourceInfo(javax.ws.rs.container.ResourceInfo) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) ResourceContext(javax.ws.rs.container.ResourceContext) Configuration(javax.ws.rs.core.Configuration) Message(org.apache.cxf.message.Message) HashMap(java.util.HashMap) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(javax.servlet.ServletRequest) Request(javax.ws.rs.core.Request) ServletConfig(javax.servlet.ServletConfig) HttpServletResponse(javax.servlet.http.HttpServletResponse) ContextProvider(org.apache.cxf.jaxrs.ext.ContextProvider) Providers(javax.ws.rs.ext.Providers) HttpServletRequest(javax.servlet.http.HttpServletRequest) SecurityContext(javax.ws.rs.core.SecurityContext) Application(javax.ws.rs.core.Application) HashMap(java.util.HashMap) Map(java.util.Map) UriInfo(javax.ws.rs.core.UriInfo)

Example 4 with Request

use of javax.ws.rs.core.Request in project cxf by apache.

the class EvaluatePreconditionsTest method testIfNoneMatchIfModified200Two.

@Test
public void testIfNoneMatchIfModified200Two() {
    // RFC 2616 / section 14.26
    // "If any of the entity tags match, the entity tag of the entity that would have been returned
    // in the response to a similar GET request (without the If-None-Match header) on that resource,
    // or if "*" is given and any current entity exists for that resource, then the server MUST NOT
    // perform the requested method, unless required to do so because the resource's modification date
    // fails to match that supplied in an If-Modified-Since header field in the request"
    service.setLastModified(DATE_NEW);
    final Request request = getRequest(HttpHeaders.IF_MODIFIED_SINCE, dateFormat.format(DATE_OLD), HttpHeaders.IF_NONE_MATCH, // ETags match,
    ETAG_NEW.toString());
    // but resource
    // has new date
    final Response response = service.perform(request);
    Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus());
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(javax.ws.rs.core.Response) Request(javax.ws.rs.core.Request) Test(org.junit.Test)

Example 5 with Request

use of javax.ws.rs.core.Request in project cxf by apache.

the class EvaluatePreconditionsTest method testIfNoneMatch200.

@Test
public void testIfNoneMatch200() {
    final Request request = getRequest(HttpHeaders.IF_NONE_MATCH, ETAG_NEW.toString());
    final Response response = service.perform(request);
    Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus());
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(javax.ws.rs.core.Response) Request(javax.ws.rs.core.Request) Test(org.junit.Test)

Aggregations

Request (javax.ws.rs.core.Request)19 Response (javax.ws.rs.core.Response)12 Test (org.junit.Test)11 HttpServletResponse (javax.servlet.http.HttpServletResponse)9 IOException (java.io.IOException)4 UriInfo (javax.ws.rs.core.UriInfo)3 URISyntaxException (java.net.URISyntaxException)2 List (java.util.List)2 EntityTag (javax.ws.rs.core.EntityTag)2 ApplicationContext (org.everrest.core.ApplicationContext)2 GenericContainerResponse (org.everrest.core.GenericContainerResponse)2 Fault (org.ovirt.engine.api.model.Fault)2 HashCode (com.google.common.hash.HashCode)1 HashFunction (com.google.common.hash.HashFunction)1 Hasher (com.google.common.hash.Hasher)1 APIError (com.liferay.apio.architect.error.APIError)1 ApioLogger (com.liferay.apio.architect.logger.ApioLogger)1 ErrorMessageMapper (com.liferay.apio.architect.message.json.ErrorMessageMapper)1 ExceptionConverterManager (com.liferay.apio.architect.wiring.osgi.manager.ExceptionConverterManager)1 ErrorMessageMapperManager (com.liferay.apio.architect.wiring.osgi.manager.message.json.ErrorMessageMapperManager)1