Package com.sun.jersey.api.core

Examples of com.sun.jersey.api.core.HttpRequestContext


                        extractor.getName(), extractor.getDefaultStringValue());
            }
        }

        private Form getForm(HttpContext context) {
            final HttpRequestContext r = context.getRequest();
            if (r.getMethod().equals("GET"))
                return null;

            if (!MediaTypes.typeEquals(MediaType.APPLICATION_FORM_URLENCODED_TYPE, r.getMediaType()))
                return null;

            final Form form = r.getFormParameters();
            context.getProperties().put(FormDispatchProvider.FORM_PROPERTY, form);
            return form;
        }
View Full Code Here


    public boolean accept(CharSequence path, Object resource, UriRuleContext context) {       
        // If the path is not empty then do not accept
        if (path.length() > 0) return false;
       
        final HttpRequestContext request = context.getRequest();
        final HttpResponseContext response = context.getResponse();
       
        // Get the list of resource methods for the HTTP method
        List<ResourceMethod> methods = map.get(request.getMethod());
        if (methods == null) {
            // No resource methods are found
            response.setResponse(Responses.methodNotAllowed().
                    header("Allow", allow).build());
            // Allow any further matching rules to be processed
            return false;
        }

        // Get the list of matching methods
        List<MediaType> accept = (priorityMediaTypes == null)
                ? request.getAcceptableMediaTypes()
                : request.getAcceptableMediaTypes(priorityMediaTypes);

        final Matcher m = new Matcher();
        final MatchStatus s = m.match(methods, request.getMediaType(), accept);

        if (s == MatchStatus.MATCH) {
            // If there is a match choose the first method
            final ResourceMethod method = m.rmSelected;
View Full Code Here

   
    public ViewableRule() {
    }
   
    public final boolean accept(CharSequence path, Object resource, UriRuleContext context) {
        final HttpRequestContext request = context.getRequest();
        // Only accept GET requests
        if (!request.getMethod().equals("GET"))
            return false;
       
        // Obtain the template path
        final String templatePath = (path.length() > 0) ?
            context.getMatchResult().group(1) :
View Full Code Here

    public final boolean accept(CharSequence path, Object resource, UriRuleContext context) {
        UriRuleProbeProvider.ruleAccept(ViewableRule.class.getSimpleName(), path,
                resource);

        final HttpRequestContext request = context.getRequest();
        // Only accept GET requests and internal matching requests
        if (request.getMethod().equals("GET") ||
                request.getMethod().equals(WebApplicationContext.HTTP_METHOD_MATCH_RESOURCE)) {
            // Obtain the template path
            final String templatePath = (path.length() > 0) ?
                context.getMatchResult().group(1) :
                "";

            // Resolve the viewable
            Viewable v = new Viewable(templatePath, resource);
            ResolvedViewable rv = tc.resolveViewable(v);
            if (rv == null) {
                return false;
            }

            // If an internal match resource request then always return true
            if (request.getMethod().equals(WebApplicationContext.HTTP_METHOD_MATCH_RESOURCE)) {
                return true;
            }

            if (context.isTracingEnabled()) {
                context.trace(String.format("accept implicit view: \"%s\" -> %s, %s",
View Full Code Here

                        extractor.getName(), extractor.getDefaultStringValue());
            }
        }

        private Form getForm(HttpContext context) {
            final HttpRequestContext r = context.getRequest();
            if (r.getMethod().equals("GET"))
                return null;

            if (!MediaTypes.typeEquals(MediaType.APPLICATION_FORM_URLENCODED_TYPE, r.getMediaType()))
                return null;

            final Form form = r.getFormParameters();
            context.getProperties().put(FormDispatchProvider.FORM_PROPERTY, form);
            return form;
        }
View Full Code Here

                resource);
       
        // If the path is not empty then do not accept
        if (path.length() > 0) return false;

        final HttpRequestContext request = context.getRequest();

        // If an internal match resource request then always return true
        if (request.getMethod().equals(WebApplicationContext.HTTP_METHOD_MATCH_RESOURCE)) {
            return true;
        }
       
        if (context.isTracingEnabled()) {
            final String currentPath = context.getUriInfo().getMatchedURIs().get(0);
            if (isSubResource) {
                final String prevPath = context.getUriInfo().getMatchedURIs().get(1);
                context.trace(String.format("accept sub-resource methods: \"%s\" : \"%s\", %s -> %s",
                        prevPath,
                        currentPath.substring(prevPath.length()),
                        context.getRequest().getMethod(),
                        ReflectionHelper.objectToString(resource)));
            } else {
                context.trace(String.format("accept resource methods: \"%s\", %s -> %s",
                        currentPath,
                        context.getRequest().getMethod(),
                        ReflectionHelper.objectToString(resource)));
            }
        }

        final HttpResponseContext response = context.getResponse();
       
        // Get the list of resource methods for the HTTP method
        ResourceMethodListPair methods = map.get(request.getMethod());
        if (methods == null) {
            // No resource methods are found
            response.setResponse(Responses.methodNotAllowed().
                    header("Allow", allow).build());
            // Allow any further matching rules to be processed
            return false;
        }

        // Get the list of matching methods
        List<MediaType> accept = getSpecificAcceptableMediaTypes(
                request.getAcceptableMediaTypes(),
                methods.priorityMediaTypes);

        final Matcher m = new Matcher();
        final MatchStatus s = m.match(methods, request.getMediaType(), accept);

        if (s == MatchStatus.MATCH) {
            // If there is a match choose the first method
            final ResourceMethod method = m.rmSelected;
View Full Code Here

      assertThat(provider.getInjectedType(), is(sameInstance((Type) Locale.class)));
    }
   
    @Test
    public void itInjectsTheFirstAcceptableLanguageFromTheRequest() throws Exception {
      final HttpRequestContext request = mock(HttpRequestContext.class);
      when(request.getAcceptableLanguages()).thenReturn(ImmutableList.of(Locale.CANADA, Locale.GERMANY));
     
      final HttpContext context = mock(HttpContext.class);
      when(context.getRequest()).thenReturn(request);
     
      assertThat(provider.getValue(context), is(Locale.CANADA));
View Full Code Here

      assertThat(provider.getValue(context), is(Locale.CANADA));
    }
   
    @Test
    public void itInjectsTheDefaultLocaleIfNoLanguagesAreGiven() throws Exception {
      final HttpRequestContext request = mock(HttpRequestContext.class);
      when(request.getAcceptableLanguages()).thenReturn(ImmutableList.<Locale>of());
     
      final HttpContext context = mock(HttpContext.class);
      when(context.getRequest()).thenReturn(request);
     
      assertThat(provider.getValue(context), is(Locale.getDefault()));
View Full Code Here

      assertThat(provider.getValue(context), is(Locale.getDefault()));
    }
   
    @Test
    public void itInjectsTheDefaultLocaleIfAllLanguagesAreAcceptable() throws Exception {
      final HttpRequestContext request = mock(HttpRequestContext.class);
      when(request.getAcceptableLanguages()).thenReturn(ImmutableList.of(new Locale("*")));
     
      final HttpContext context = mock(HttpContext.class);
      when(context.getRequest()).thenReturn(request);
     
      assertThat(provider.getValue(context), is(Locale.getDefault()));
View Full Code Here

      assertThat(provider.getValue(context), is(Locale.getDefault()));
    }
   
    @Test
    public void itInjectsTheDefaultLocaleIfTheAcceptLanguagesHeaderIsMalformed() throws Exception {
      final HttpRequestContext request = mock(HttpRequestContext.class);
      when(request.getAcceptableLanguages()).thenThrow(new WebApplicationException(400));
     
      final HttpContext context = mock(HttpContext.class);
      when(context.getRequest()).thenReturn(request);
     
      assertThat(provider.getValue(context), is(Locale.getDefault()));
View Full Code Here

TOP

Related Classes of com.sun.jersey.api.core.HttpRequestContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.