Package org.openid4java.util

Examples of org.openid4java.util.HttpResponse


        try
        {

            if (DEBUG) _log.debug("Performing HTTP POST on " + url);
            HttpResponse resp = _httpFetcher.post(url, request.getParameterMap());
            responseCode = resp.getStatusCode();

            String postResponse = resp.getBody();
            response.copyOf(ParameterList.createFromKeyValueForm(postResponse));

            if (DEBUG) _log.debug("Retrived response:\n" + postResponse);
        }
        catch (IOException e)
View Full Code Here


        String hxri = PROXY_URL + xri.getIdentifier() + "?" + XRDS_QUERY;
        _log.info("Performing discovery on HXRI: " + hxri);

        try
        {
            HttpResponse resp = _httpFetcher.get(hxri);
            if (resp == null || HttpStatus.SC_OK != resp.getStatusCode())
                throw new DiscoveryException("Error retrieving HXRI: " + hxri);

            Set targetTypes = DiscoveryInformation.OPENID_OP_TYPES;

            List endpoints = XRDS_PARSER.parseXrds(resp.getBody(), targetTypes);

            List results = new ArrayList();

            Iterator endpointIter = endpoints.iterator();
            while (endpointIter.hasNext())
View Full Code Here

        HttpRequestOptions requestOptions = cache.getRequestOptions();
        requestOptions.setContentType("text/html");

        try
        {
            HttpResponse resp = cache.get(identifier.toString(), requestOptions);

            if (HttpStatus.SC_OK != resp.getStatusCode())
                throw new DiscoveryException( "GET failed on " +
                    identifier.toString() +
                    " Received status code: " + resp.getStatusCode(),
                    OpenIDException.DISCOVERY_HTML_GET_ERROR);

            result.setClaimed( new UrlIdentifier(resp.getFinalUri()) );

            if (resp.getBody() == null)
                throw new DiscoveryException(
                        "No HTML data read from " + identifier.toString(),
                OpenIDException.DISCOVERY_HTML_NODATA_ERROR);

            HTML_PARSER.parseHtml(resp.getBody(), result);
        }
        catch (IOException e)
        {
            throw new DiscoveryException("Fatal transport error: ",
                    OpenIDException.DISCOVERY_HTML_GET_ERROR, e);
View Full Code Here

        String hxri = PROXY_URL + xri.getIdentifier() + "?" + XRDS_QUERY;
        _log.info("Performing discovery on HXRI: " + hxri);

        try
        {
            HttpResponse resp = cache.get(hxri);
            if (resp == null || HttpStatus.SC_OK != resp.getStatusCode())
                throw new DiscoveryException("Error retrieving HXRI: " + hxri);

            Set targetTypes = DiscoveryInformation.OPENID_OP_TYPES;

            List endpoints = XRDS_PARSER.parseXrds(resp.getBody(), targetTypes);

            List results = new ArrayList();

            Iterator endpointIter = endpoints.iterator();
            while (endpointIter.hasNext())
View Full Code Here

        throws DiscoveryException {

        cache.getRequestOptions().setMaxRedirects(maxRedirects);

        try {
            HttpResponse resp = cache.get(result.getXrdsLocation().toString());

            if (resp == null || HttpStatus.SC_OK != resp.getStatusCode())
                throw new YadisException("GET failed on " + result.getXrdsLocation(),
                        OpenIDException.YADIS_GET_ERROR);

            // update xrds location, in case redirects were followed
            result.setXrdsLocation(resp.getFinalUri(), OpenIDException.YADIS_GET_INVALID_RESPONSE);

            Header contentType = resp.getResponseHeader("content-type");
            if ( contentType != null && contentType.getValue() != null)
                result.setContentType(contentType.getValue());

            if (resp.isBodySizeExceeded())
                throw new YadisException(
                    "More than " + cache.getRequestOptions().getMaxBodySize() +
                    " bytes in HTTP response body from " + result.getXrdsLocation(),
                    OpenIDException.YADIS_XRDS_SIZE_EXCEEDED);
            result.setEndpoints(XRDS_PARSER.parseXrds(resp.getBody(), serviceTypes));

        } catch (IOException e) {
            throw new YadisException("Fatal transport error: ",
                    OpenIDException.YADIS_GET_TRANSPORT_ERROR, e);
        }
View Full Code Here

            HttpRequestOptions requestOptions = cache.getRequestOptions();
            requestOptions.setMaxRedirects(maxRedirects);
            if (useGet)
                requestOptions.addRequestHeader("Accept", YADIS_ACCEPT_HEADER);

            HttpResponse resp = useGet ?
                cache.get(url.getUrl().toString(), requestOptions) :
                cache.head(url.getUrl().toString(), requestOptions);

            Header[] locationHeaders = resp.getResponseHeaders(YADIS_XRDS_LOCATION);
            Header contentType = resp.getResponseHeader("content-type");

            if (HttpStatus.SC_OK != resp.getStatusCode())
            {
                // won't be able to recover from a GET error, throw
                if (useGet)
                    throw new YadisException("GET failed on " + url + " : " +
                        resp.getStatusCode() + ":" + resp.getStatusLine(),
                        OpenIDException.YADIS_GET_ERROR);

                // HEAD is optional, will fall-back to GET
                if (DEBUG)
                    _log.debug("Cannot retrieve " + YADIS_XRDS_LOCATION +
                        " using HEAD from " + url.getUrl().toString() +
                        "; status=" + resp.getStatusLine());
            }
            else if ((locationHeaders != null && locationHeaders.length > 1))
            {
                // fail if there are more than one YADIS_XRDS_LOCATION headers
                throw new YadisException("Found " + locationHeaders.length +
                    " " + YADIS_XRDS_LOCATION + " headers.",
                    useGet ? OpenIDException.YADIS_GET_INVALID_RESPONSE :
                        OpenIDException.YADIS_HEAD_INVALID_RESPONSE);
            }
            else if (locationHeaders != null && locationHeaders.length > 0)
            {
                // we have exactly one xrds location header
                result.setXrdsLocation(locationHeaders[0].getValue(),
                    useGet ? OpenIDException.YADIS_GET_INVALID_RESPONSE :
                        OpenIDException.YADIS_HEAD_INVALID_RESPONSE);
                result.setNormalizedUrl(resp.getFinalUri());
            }
            else if (contentType != null && contentType.getValue() != null &&
                     contentType.getValue().split(";")[0].equalsIgnoreCase(YADIS_CONTENT_TYPE) &&
                     resp.getBody() != null)
            {
                // no location, but got xrds document
                result.setNormalizedUrl(resp.getFinalUri());
                result.setContentType(contentType.getValue());
                if (resp.isBodySizeExceeded())
                    throw new YadisException(
                        "More than " + requestOptions.getMaxBodySize() +
                        " bytes in HTTP response body from " + url,
                        OpenIDException.YADIS_XRDS_SIZE_EXCEEDED);
                result.setEndpoints(XRDS_PARSER.parseXrds(resp.getBody(), serviceTypes));
            }
            else if (resp.getBody() != null)
            {
                // fall-back to html-meta, if present
                String xrdsLocation = getHtmlMeta(resp.getBody());
                if (xrdsLocation != null)
                {
                    result.setNormalizedUrl(resp.getFinalUri());
                    result.setXrdsLocation(xrdsLocation,
                        OpenIDException.YADIS_GET_INVALID_RESPONSE);
                }
            }
View Full Code Here

        try
        {

            if (DEBUG) _log.debug("Performing HTTP POST on " + url);
            HttpResponse resp = _httpFetcher.post(url, request.getParameterMap());
            responseCode = resp.getStatusCode();

            String postResponse = resp.getBody();
            response.copyOf(ParameterList.createFromKeyValueForm(postResponse));

            if (DEBUG) _log.debug("Retrived response:\n" + postResponse);
        }
        catch (IOException e)
View Full Code Here

        HttpRequestOptions requestOptions = httpFetcher.getRequestOptions();
        requestOptions.setContentType("text/html");

        try
        {
            HttpResponse resp = httpFetcher.get(identifier.toString(), requestOptions);

            if (HttpStatus.SC_OK != resp.getStatusCode())
                throw new DiscoveryException( "GET failed on " +
                    identifier.toString() +
                    " Received status code: " + resp.getStatusCode(),
                    OpenIDException.DISCOVERY_HTML_GET_ERROR);

            result.setClaimed( new UrlIdentifier(resp.getFinalUri()) );

            if (resp.getBody() == null)
                throw new DiscoveryException(
                        "No HTML data read from " + identifier.toString(),
                OpenIDException.DISCOVERY_HTML_NODATA_ERROR);

            HTML_PARSER.parseHtml(resp.getBody(), result);
        }
        catch (IOException e)
        {
            throw new DiscoveryException("Fatal transport error: ",
                    OpenIDException.DISCOVERY_HTML_GET_ERROR, e);
View Full Code Here

        throws DiscoveryException {

        _httpFetcher.getRequestOptions().setMaxRedirects(maxRedirects);

        try {
            HttpResponse resp = _httpFetcher.get(result.getXrdsLocation().toString());

            if (resp == null || HttpStatus.SC_OK != resp.getStatusCode())
                throw new YadisException("GET failed on " + result.getXrdsLocation(),
                        OpenIDException.YADIS_GET_ERROR);

            // update xrds location, in case redirects were followed
            result.setXrdsLocation(resp.getFinalUri(), OpenIDException.YADIS_GET_INVALID_RESPONSE);

            Header contentType = resp.getResponseHeader("content-type");
            if ( contentType != null && contentType.getValue() != null)
                result.setContentType(contentType.getValue());

            if (resp.isBodySizeExceeded())
                throw new YadisException(
                    "More than " + _httpFetcher.getRequestOptions().getMaxBodySize() +
                    " bytes in HTTP response body from " + result.getXrdsLocation(),
                    OpenIDException.YADIS_XRDS_SIZE_EXCEEDED);
            result.setEndpoints(XRDS_PARSER.parseXrds(resp.getBody(), serviceTypes));

        } catch (IOException e) {
            throw new YadisException("Fatal transport error: " + e.getMessage(),
                    OpenIDException.YADIS_GET_TRANSPORT_ERROR, e);
        }
View Full Code Here

                        requestOptions.addRequestHeader("Accept", YADIS_ACCEPT_HEADER);
                    else
                        requestOptions.addRequestHeader("Accept", YADIS_CONTENT_TYPE);
                }

                HttpResponse resp = useGet ?
                    _httpFetcher.get(url.getUrl().toString(), requestOptions) :
                    _httpFetcher.head(url.getUrl().toString(), requestOptions);

                Header[] locationHeaders = resp.getResponseHeaders(YADIS_XRDS_LOCATION);
                Header contentType = resp.getResponseHeader("content-type");

                if (HttpStatus.SC_OK != resp.getStatusCode())
                {
                    // won't be able to recover from a GET error, throw
                    if (useGet)
                        throw new YadisException("GET failed on " + url + " : " +
                            resp.getStatusCode(), OpenIDException.YADIS_GET_ERROR);

                    // HEAD is optional, will fall-back to GET
                    if (DEBUG)
                        _log.debug("Cannot retrieve " + YADIS_XRDS_LOCATION +
                            " using HEAD from " + url.getUrl().toString() +
                            "; status=" + resp.getStatusCode());
                }
                else if ((locationHeaders != null && locationHeaders.length > 1))
                {
                    // fail if there are more than one YADIS_XRDS_LOCATION headers
                    throw new YadisException("Found " + locationHeaders.length +
                        " " + YADIS_XRDS_LOCATION + " headers.",
                        useGet ? OpenIDException.YADIS_GET_INVALID_RESPONSE :
                            OpenIDException.YADIS_HEAD_INVALID_RESPONSE);
                }
                else if (locationHeaders != null && locationHeaders.length > 0)
                {
                    // we have exactly one xrds location header
                    result.setXrdsLocation(locationHeaders[0].getValue(),
                        useGet ? OpenIDException.YADIS_GET_INVALID_RESPONSE :
                            OpenIDException.YADIS_HEAD_INVALID_RESPONSE);
                    result.setNormalizedUrl(resp.getFinalUri());
                }
                else if (contentType != null && contentType.getValue() != null &&
                         contentType.getValue().split(";")[0].equalsIgnoreCase(YADIS_CONTENT_TYPE) &&
                         resp.getBody() != null)
                {
                    // no location, but got xrds document
                    result.setNormalizedUrl(resp.getFinalUri());
                    result.setContentType(contentType.getValue());
                    if (resp.isBodySizeExceeded())
                        throw new YadisException(
                            "More than " + requestOptions.getMaxBodySize() +
                            " bytes in HTTP response body from " + url,
                            OpenIDException.YADIS_XRDS_SIZE_EXCEEDED);
                    result.setEndpoints(XRDS_PARSER.parseXrds(resp.getBody(), serviceTypes));
                }
                else if (resp.getBody() != null)
                {
                    // fall-back to html-meta, if present
                    String xrdsLocation = getHtmlMeta(resp.getBody());
                    if (xrdsLocation != null)
                    {
                        result.setNormalizedUrl(resp.getFinalUri());
                        result.setXrdsLocation(xrdsLocation,
                            OpenIDException.YADIS_GET_INVALID_RESPONSE);
                    }
                }
View Full Code Here

TOP

Related Classes of org.openid4java.util.HttpResponse

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.