Package org.openid4java.util

Examples of org.openid4java.util.HttpRequestOptions


    public void testIncompleteHtmlParsing() throws DiscoveryException
    {
        // stop reading from the received HTML body shortly after the Yadis tag
        HttpFetcher cache = new HttpCache();
        HttpRequestOptions requestOptions = cache.getRequestOptions();
        requestOptions.setMaxBodySize(350);
        cache.setDefaultRequestOptions(requestOptions);

        YadisResolver resolver = new YadisResolver(cache);
        YadisResult result = resolver.discover("http://localhost:" + _servletPort + "/?html=simplehtml",
            10, Collections.singleton("http://example.com/"));
View Full Code Here


    //}


    public void testXrdsSizeExceeded()
    {
        HttpRequestOptions requestOptions = new HttpRequestOptions();
        requestOptions.setMaxBodySize(10);

        HttpFetcher cache = new HttpCache();
        cache.setDefaultRequestOptions(requestOptions);

        YadisResolver resolver = new YadisResolver(cache);
View Full Code Here

            throws DiscoveryException
    {
        // initialize the results of the HTML discovery
        HtmlResult result = new HtmlResult();

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

        try
        {
            HttpResponse resp = cache.get(identifier.toString(), requestOptions);
View Full Code Here

            if (DEBUG) _log.debug(
                "Performing HTTP " + (useGet ? "GET" : "HEAD") +
                " on: " + url + " ...");

            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)
View Full Code Here

        throws DiscoveryException
    {
        // initialize the results of the HTML discovery
        HtmlResult result = new HtmlResult();

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

        try
        {
            HttpResponse resp = httpFetcher.get(identifier.toString(), requestOptions);
View Full Code Here

                if (DEBUG) _log.debug(
                    "Performing HTTP " + (useGet ? "GET" : "HEAD") +
                    " on: " + url + " ...");


                HttpRequestOptions requestOptions = _httpFetcher.getRequestOptions();
                requestOptions.setMaxRedirects(maxRedirects);
              
                if (useGet)
                {
                    if (attempt == 1)
                        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)
View Full Code Here

TOP

Related Classes of org.openid4java.util.HttpRequestOptions

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.