Package javax.ws.rs.core

Examples of javax.ws.rs.core.UriInfo


        }
       
        TemplatesImpl templ =  new TemplatesImpl(templates);
        MessageContext mc = getContext();
        if (mc != null) {
            UriInfo ui = mc.getUriInfo();
            MultivaluedMap<String, String> params = ui.getPathParameters();
            for (Map.Entry<String, List<String>> entry : params.entrySet()) {
                String value = entry.getValue().get(0);
                int ind = value.indexOf(";");
                if (ind > 0) {
                    value = value.substring(0, ind);
                }
                templ.setTransformerParameter(entry.getKey(), value);
            }
           
            List<PathSegment> segments = ui.getPathSegments();
            if (segments.size() > 0) {
                setTransformParameters(templ, segments.get(segments.size() - 1).getMatrixParameters());
            }
            setTransformParameters(templ, ui.getQueryParameters());
            templ.setTransformerParameter(ABSOLUTE_PATH_PARAMETER, ui.getAbsolutePath().toString());
            templ.setTransformerParameter(RELATIVE_PATH_PARAMETER, ui.getPath());
            templ.setTransformerParameter(BASE_PATH_PARAMETER, ui.getBaseUri().toString());
            if (configuredParams != null) {
                for (Map.Entry<String, Object> entry : configuredParams.entrySet()) {
                    templ.setTransformerParameter(entry.getKey(), entry.getValue());
                }
            }
View Full Code Here


    public ResponseBuilder location(URI loc) {
        if (!loc.isAbsolute()) {
            Message currentMessage = PhaseInterceptorChain.getCurrentMessage();
            if (currentMessage != null) {
               
                UriInfo ui = new UriInfoImpl(currentMessage.getExchange().getInMessage(), null);
                loc = ui.getBaseUriBuilder()
                        .path(loc.getRawPath())
                        .replaceQuery(loc.getRawQuery())
                        .fragment(loc.getRawFragment()).buildFromEncoded();
            }
        }
View Full Code Here

        if (!"GET".equals(m.get(Message.HTTP_REQUEST_METHOD))) {
            return null;
        }

        UriInfo ui = new UriInfoImpl(m);
        if (!ui.getQueryParameters().containsKey(WADL_QUERY)) {
            return null;
        }

        if (isPrivate(m)) {
            return Response.status(401).build();
        }

        StringBuilder sbMain = new StringBuilder();
        sbMain.append("<application xmlns=\"").append(getNamespace())
              .append("\" xmlns:xs=\"").append(XmlSchemaConstants.XSD_NAMESPACE_URI).append("\"");
        StringBuilder sbGrammars = new StringBuilder();
        sbGrammars.append("<grammars>");

        StringBuilder sbResources = new StringBuilder();
        sbResources.append("<resources base=\"").append(ui.getBaseUri().toString()).append("\">");

        List<ClassResourceInfo> cris = getResourcesList(m, resource);

        Set<Class<?>> allTypes =
            ResourceUtils.getAllRequestResponseTypes(cris, useJaxbContextForQnames).keySet();
View Full Code Here

    }
   
    @Test
    public void testGetRequestURI() {
       
        UriInfo u = new UriInfoImpl(mockMessage("http://localhost:8080/baz/bar", "/foo", "n=1%202"),
                            null);

        assertEquals("Wrong request uri", "http://localhost:8080/baz/bar/foo?n=1%202",
                     u.getRequestUri().toString());
    }
View Full Code Here

    }
   
    @Test
    public void testGetRequestURIWithEncodedChars() {
       
        UriInfo u = new UriInfoImpl(mockMessage("http://localhost:8080/baz/bar", "/foo/%20bar", "n=1%202"),
                            null);

        assertEquals("Wrong request uri", "http://localhost:8080/baz/bar/foo/%20bar?n=1%202",
                     u.getRequestUri().toString());
    }
View Full Code Here

        assertTrue(customJaxbReader instanceof JAXBElementProvider);
       
        JAXBElementProvider provider = (JAXBElementProvider)customJaxbReader;
        MessageContext mc = provider.getContext();
        assertNotNull(mc);
        UriInfo ui = mc.getUriInfo();
        MultivaluedMap<String, String> queries = ui.getQueryParameters();
        assertEquals(1, queries.size());
        List<String> uriQuery = queries.get("uri");
        assertEquals(1, uriQuery.size());
        assertEquals(property, uriQuery.get(0));
       
View Full Code Here

            Class<?> type = field.getType();
            if (Request.class.equals(type)) {
                Request binding = JAXRSUtils.createContextValue(exchange.getInMessage(), null, Request.class);
                ThreadLocalContextManager.REQUEST.set(binding);
            } else if (UriInfo.class.equals(type)) {
                UriInfo binding = JAXRSUtils.createContextValue(exchange.getInMessage(), null, UriInfo.class);
                ThreadLocalContextManager.URI_INFO.set(binding);
            } else if (HttpHeaders.class.equals(type)) {
                HttpHeaders binding = JAXRSUtils.createContextValue(exchange.getInMessage(), null, HttpHeaders.class);
                ThreadLocalContextManager.HTTP_HEADERS.set(binding);
            } else if (SecurityContext.class.equals(type)) {
View Full Code Here

public class StripExtensionFilter implements ContainerRequestFilter {
    private static final Logger log = LoggerFactory.getLogger(StripExtensionFilter.class);

    @Override
    public void filter(ContainerRequestContext requestContext) throws IOException {
        UriInfo uriInfo = requestContext.getUriInfo();

        String path = uriInfo.getPath();
        if (path.endsWith(".json")) {
            if (!path.startsWith("/")) {
                path = "/" + path;
            }

            if (path.startsWith("/openstack/network/")) {
                path = path.substring(0, path.length() - 5);
                URI uri = uriInfo.getRequestUri();

                URI newUri = UriBuilder.fromUri(uri).replacePath(path).build();
                log.info("Rewriting URI: {} -> {}", uri, newUri);

                requestContext.setRequestUri(newUri);
View Full Code Here

        String userAgent = requestContext.getHeaderString("User-Agent");
        if (userAgent == null || !BROKEN_USER_AGENTS.contains(userAgent)) {
            return;
        }

        UriInfo uriInfo = requestContext.getUriInfo();
        String path = uriInfo.getPath();

        if (path.contains("v2.0/") || path.contains("v3/")) {
            // if (path.startsWith("//v2/") || path.startsWith("//v3/")) {
            // path = path.substring(1);
            // }
            if (!path.startsWith("/")) {
                path = "/" + path;
            }

            if (path.startsWith("/v2.0/") || path.startsWith("/v3/")) {
                path = "/openstack/identity" + path;

                redirect = true;
            }
        }

        if (redirect) {
            URI uri = uriInfo.getRequestUri();

            URI newUri = UriBuilder.fromUri(uri).replacePath(path).build();
            log.info("Rewriting URI: {} -> {}", uri, newUri);

            requestContext.setRequestUri(newUri);
View Full Code Here

                        final Class target = ReflectionHelper.getDeclaringClass(cc.getAccesibleObject());
                        final Class inject = (Class)t;
                        return new Injectable<Object>() {
                            @Override
                            public Object getValue() {
                                final UriInfo ui = context.getUriInfo();
                                final List l = ui.getMatchedResources();

                                final Object parent = getParent(l, target);
                                if (parent == null) return null;
                                try {
                                    return inject.cast(parent);
View Full Code Here

TOP

Related Classes of javax.ws.rs.core.UriInfo

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.