Package org.restlet.data

Examples of org.restlet.data.ClientInfo


                requestHeaders.add(HttpConstants.HEADER_REFERRER, request
                        .getReferrerRef().toString());
            }

            // Add the preferences
            final ClientInfo client = request.getClientInfo();
            if (client.getAcceptedMediaTypes().size() > 0) {
                try {
                    requestHeaders.add(HttpConstants.HEADER_ACCEPT,
                            PreferenceUtils.format(client
                                    .getAcceptedMediaTypes()));
                } catch (IOException ioe) {
                    getLogger().log(Level.WARNING,
                            "Unable to format the HTTP Accept header", ioe);
                }
            } else {
                requestHeaders.add(HttpConstants.HEADER_ACCEPT, MediaType.ALL
                        .getName());
            }

            if (client.getAcceptedCharacterSets().size() > 0) {
                try {
                    requestHeaders.add(HttpConstants.HEADER_ACCEPT_CHARSET,
                            PreferenceUtils.format(client
                                    .getAcceptedCharacterSets()));
                } catch (IOException ioe) {
                    getLogger().log(Level.WARNING,
                            "Unable to format the HTTP Accept header", ioe);
                }
            }

            if (client.getAcceptedEncodings().size() > 0) {
                try {
                    requestHeaders.add(HttpConstants.HEADER_ACCEPT_ENCODING,
                            PreferenceUtils.format(client
                                    .getAcceptedEncodings()));
                } catch (IOException ioe) {
                    getLogger().log(Level.WARNING,
                            "Unable to format the HTTP Accept header", ioe);
                }
            }

            if (client.getAcceptedLanguages().size() > 0) {
                try {
                    requestHeaders.add(HttpConstants.HEADER_ACCEPT_LANGUAGE,
                            PreferenceUtils.format(client
                                    .getAcceptedLanguages()));
                } catch (IOException ioe) {
                    getLogger().log(Level.WARNING,
                            "Unable to format the HTTP Accept header", ioe);
                }
View Full Code Here


     *
     * @return The client-specific information.
     */
    @Override
    public ClientInfo getClientInfo() {
        final ClientInfo result = super.getClientInfo();

        if (!this.clientAdded) {
            // Extract the header values
            final String acceptCharset = getHttpCall().getRequestHeaders()
                    .getValues(HttpConstants.HEADER_ACCEPT_CHARSET);
            final String acceptEncoding = getHttpCall().getRequestHeaders()
                    .getValues(HttpConstants.HEADER_ACCEPT_ENCODING);
            final String acceptLanguage = getHttpCall().getRequestHeaders()
                    .getValues(HttpConstants.HEADER_ACCEPT_LANGUAGE);
            final String acceptMediaType = getHttpCall().getRequestHeaders()
                    .getValues(HttpConstants.HEADER_ACCEPT);

            // Parse the headers and update the call preferences

            // Parse the Accept* headers. If an error occurs during the parsing
            // of each header, the error is traced and we keep on with the other
            // headers.
            try {
                PreferenceUtils.parseCharacterSets(acceptCharset, result);
            } catch (Exception e) {
                this.context.getLogger().log(Level.INFO, e.getMessage());
            }
            try {
                PreferenceUtils.parseEncodings(acceptEncoding, result);
            } catch (Exception e) {
                this.context.getLogger().log(Level.INFO, e.getMessage());
            }
            try {
                PreferenceUtils.parseLanguages(acceptLanguage, result);
            } catch (Exception e) {
                this.context.getLogger().log(Level.INFO, e.getMessage());
            }
            try {
                PreferenceUtils.parseMediaTypes(acceptMediaType, result);
            } catch (Exception e) {
                this.context.getLogger().log(Level.INFO, e.getMessage());
            }

            // Set other properties
            result.setAgent(getHttpCall().getRequestHeaders().getValues(
                    HttpConstants.HEADER_USER_AGENT));
            result.setAddress(getHttpCall().getClientAddress());
            result.setPort(getHttpCall().getClientPort());

            if (this.context != null) {
                // Special handling for the non standard but common
                // "X-Forwarded-For" header.
                final boolean useForwardedForHeader = Boolean
                        .parseBoolean(this.context.getParameters()
                                .getFirstValue("useForwardedForHeader", false));
                if (useForwardedForHeader) {
                    // Lookup the "X-Forwarded-For" header supported by popular
                    // proxies and caches.
                    // This information is only safe for intermediary components
                    // within your local network.
                    // Other addresses could easily be changed by setting a fake
                    // header and should not be trusted for serious security
                    // checks.
                    final String header = getHttpCall().getRequestHeaders()
                            .getValues(HttpConstants.HEADER_X_FORWARDED_FOR);
                    if (header != null) {
                        final String[] addresses = header.split(",");
                        for (int i = addresses.length - 1; i >= 0; i--) {
                            result.getAddresses().add(addresses[i].trim());
                        }
                    }
                }
            }

View Full Code Here

        if (tunnelService.isPreferencesTunnel()
                && (method.equals(Method.GET) || method.equals(Method.HEAD))) {
            final Reference resourceRef = request.getResourceRef();

            if (resourceRef.hasExtensions()) {
                final ClientInfo clientInfo = request.getClientInfo();
                boolean encodingFound = false;
                boolean characterSetFound = false;
                boolean mediaTypeFound = false;
                boolean languageFound = false;
                String extensions = resourceRef.getExtensions();
View Full Code Here

                        .getFirstValue(languageParameter);
                final String acceptedMediaType = query
                        .getFirstValue(mediaTypeParameter);

                // Updates the client preferences
                final ClientInfo clientInfo = request.getClientInfo();
                Metadata metadata = getMetadata(acceptedCharSet);
                if (metadata instanceof CharacterSet) {
                    updateMetadata(clientInfo, metadata);
                    query.removeFirst(charSetParameter);
                    queryModified = true;
View Full Code Here

                            if (keyValue.length == 2) {
                                final String key = keyValue[0].trim();
                                final String value = keyValue[1].trim();
                                if ("acceptNew".equalsIgnoreCase(key)) {
                                    if (processAcceptHeader) {
                                        final ClientInfo clientInfo = new ClientInfo();
                                        PreferenceUtils.parseMediaTypes(value,
                                                clientInfo);
                                        request
                                                .getClientInfo()
                                                .setAcceptedMediaTypes(
                                                        clientInfo
                                                                .getAcceptedMediaTypes());
                                        break;
                                    }
                                    processAcceptHeader = true;
                                } else {
View Full Code Here

        if (tunnelService.isPreferencesTunnel()
                && (method.equals(Method.GET) || method.equals(Method.HEAD))) {
            final Reference resourceRef = request.getResourceRef();

            if (resourceRef.hasExtensions()) {
                final ClientInfo clientInfo = request.getClientInfo();
                boolean encodingFound = false;
                boolean characterSetFound = false;
                boolean mediaTypeFound = false;
                boolean languageFound = false;
                String extensions = resourceRef.getExtensions();
View Full Code Here

                        .getFirstValue(languageParameter);
                final String acceptedMediaType = query
                        .getFirstValue(mediaTypeParameter);

                // Updates the client preferences
                final ClientInfo clientInfo = request.getClientInfo();
                Metadata metadata = getMetadata(acceptedCharSet);
                if (metadata instanceof CharacterSet) {
                    updateMetadata(clientInfo, metadata);
                    query.removeFirst(charSetParameter);
                    queryModified = true;
View Full Code Here

                            if (keyValue.length == 2) {
                                final String key = keyValue[0].trim();
                                final String value = keyValue[1].trim();
                                if ("acceptNew".equalsIgnoreCase(key)) {
                                    if (processAcceptHeader) {
                                        final ClientInfo clientInfo = new ClientInfo();
                                        PreferenceUtils.parseMediaTypes(value,
                                                clientInfo);
                                        request
                                                .getClientInfo()
                                                .setAcceptedMediaTypes(
                                                        clientInfo
                                                                .getAcceptedMediaTypes());
                                        break;
                                    }
                                    processAcceptHeader = true;
                                } else {
View Full Code Here

     *
     * @return The client-specific information.
     */
  @Override
    public ClientInfo getClientInfo() {
        ClientInfo result = super.getClientInfo();

        if (!this.clientAdded) {
            // Extract the header values
            String acceptCharset = getHttpCall().getRequestHeaders().getValues(
                    HttpConstants.HEADER_ACCEPT_CHARSET);
            String acceptEncoding = getHttpCall().getRequestHeaders()
                    .getValues(HttpConstants.HEADER_ACCEPT_ENCODING);
            String acceptLanguage = getHttpCall().getRequestHeaders()
                    .getValues(HttpConstants.HEADER_ACCEPT_LANGUAGE);
            String acceptMediaType = getHttpCall().getRequestHeaders()
                    .getValues(HttpConstants.HEADER_ACCEPT);

            // Parse the headers and update the call preferences

            // Parse the Accept* headers. If an error occurs during the parsing
            // of each header, the error is traced and we keep on with the other
            // headers.
            try {
                PreferenceUtils.parseCharacterSets(acceptCharset, result);
            } catch (Exception e) {
                this.context.getLogger().log(Level.INFO, e.getMessage());
            }
            try {
                PreferenceUtils.parseEncodings(acceptEncoding, result);
            } catch (Exception e) {
                this.context.getLogger().log(Level.INFO, e.getMessage());
            }
            try {
                PreferenceUtils.parseLanguages(acceptLanguage, result);
            } catch (Exception e) {
                this.context.getLogger().log(Level.INFO, e.getMessage());
            }
            try {
                PreferenceUtils.parseMediaTypes(acceptMediaType, result);
            } catch (Exception e) {
                this.context.getLogger().log(Level.INFO, e.getMessage());
            }

            // Set other properties
            result.setAgent(getHttpCall().getRequestHeaders().getValues(
                    HttpConstants.HEADER_USER_AGENT));
            result.setAddress(getHttpCall().getClientAddress());
            result.setPort(getHttpCall().getClientPort());

            // Special handling for the non standard but common
            // "X-Forwarded-For" header.
            boolean useForwardedForHeader = Boolean.parseBoolean(this.context
                    .getParameters().getFirstValue("useForwardedForHeader",
                            false));
            if (useForwardedForHeader) {
                // Lookup the "X-Forwarded-For" header supported by popular
                // proxies and caches.
                // This information is only safe for intermediary components
                // within your local network.
                // Other addresses could easily be changed by setting a fake
                // header and should not be trusted for serious security checks.
                String header = getHttpCall().getRequestHeaders().getValues(
                        HttpConstants.HEADER_X_FORWARDED_FOR);
                if (header != null) {
                    String[] addresses = header.split(",");
                    for (int i = addresses.length - 1; i >= 0; i--) {
                        result.getAddresses().add(addresses[i].trim());
                    }
                }
            }

            this.clientAdded = true;
View Full Code Here

        String feature = (String) request.getAttributes().get("feature");

        Form form = request.getResourceRef().getQueryAsForm();
        String reqRaw = form.getFirstValue("raw");
       
        ClientInfo cliInfo = request.getClientInfo();
        String agent = null;
        if(cliInfo != null) {
            agent = cliInfo.getAgent();
        }
       
        boolean wantsRaw = (
                agent == null
                || cliInfo.getAgent().contains("Googlebot")
                || (reqRaw != null && Boolean.parseBoolean(reqRaw)) );
       
        // We only show the actual KML placemark to googlebot or users who append ?raw=true
        if ( ! wantsRaw ) {
            response.redirectSeeOther(feature+".html");
View Full Code Here

TOP

Related Classes of org.restlet.data.ClientInfo

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.