Skip to content

request new token ,release previous request #36

@huangtaoz

Description

@huangtaoz

method: HttpConnection.send(HttpUriRequest request, boolean failedAuth)
old:

private HttpResponse send(HttpUriRequest request, boolean failedAuth) {
        try {
            injectHeaders(request);
            HttpResponse response = client.execute(request);

            /**
             * If the request failed because of authentication, and it
             * wasn't a request to the SSO service, then the most likely
             * cause is an expired SSO token. In this case we need to
             * request a new token, and try the original request again, but
             * only once. It if fails again, we just return the failed
             * response.
             */
            if (response.getStatusLine().getStatusCode() == 401 && !failedAuth) {
                ssoToken = null;
                authenticate();
                response = send(request, true);
            }

            if (response.getFirstHeader("content-type") != null) {
                checkContentType(XML_CONTENT_TYPE_RE, "XML", response.getFirstHeader("content-type").getValue());
            }
            return response;
        }
        catch (Exception e) {
            throw new Error("Failed to send request", e);
        }
    }


private HttpResponse send(HttpUriRequest request, boolean failedAuth) {
    try {
        injectHeaders(request);
        HttpResponse response = client.execute(request);

        /**
         * If the request failed because of authentication, and it
         * wasn't a request to the SSO service, then the most likely
         * cause is an expired SSO token. In this case we need to
         * request a new token, and try the original request again, but
         * only once. It if fails again, we just return the failed
         * response.
         */
        if (response.getStatusLine().getStatusCode() == 401 && !failedAuth) {
            HttpEntity entity = response.getEntity();
            if (null != entity) {
                entity.getContent().close();
            }
            ssoToken = null;
            authenticate();
            response = send(request, true);
        }

        if (response.getFirstHeader("content-type") != null) {
            checkContentType(XML_CONTENT_TYPE_RE, "XML", response.getFirstHeader("content-type").getValue());
        }
        return response;
    }
    catch (Exception e) {
        throw new Error("Failed to send request", e);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions