Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request new token ,release previous request #36

Open
huangtaoz opened this issue Aug 7, 2023 · 0 comments
Open

request new token ,release previous request #36

huangtaoz opened this issue Aug 7, 2023 · 0 comments

Comments

@huangtaoz
Copy link

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);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant