HttpConnectionFactory.java revision cc87cf22700a4a41bf0eba0d9579db53e7cedd94
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at opensso/legal/CDDLv1.0.txt.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* $Id: SessionService.java,v 1.37 2010/02/03 03:52:54 bina Exp $
*
* Portions Copyrighted 2010-2016 ForgeRock AS.
*/
/**
* Responsible for creating HTTP connections that identify themselves, via cookies, as belonging to a session.
*
* Session-aware HttpConnection management logic extracted from SessionService class
* as part of first-pass refactoring to improve SessionService adherence to SRP.
*
* @since 13.0.0
*/
/*
* Further refactoring is warranted.
*/
public class HttpConnectionFactory {
private final Debug sessionDebug;
private final SessionServiceConfig serviceConfig;
private final SessionServerConfig serverConfig;
private final SessionCookies sessionCookies;
public HttpConnectionFactory(
this.sessionDebug = sessionDebug;
this.serviceConfig = serviceConfig;
this.serverConfig = serverConfig;
this.sessionCookies = sessionCookies;
}
/**
* Helper function used for remote invocation over HTTP It constructs
* HttpURLConnection using url and adding cookies based on sid and returns
* it to the caller. In order to complete the invocation caller is supposed
* to open input stream
*
* @param url url
* @param sid SessionID
*/
public HttpURLConnection createSessionAwareConnection(URL url, SessionID sid, String extraCookies) throws Exception {
if (!serviceConfig.isSessionFailoverEnabled()) {
return null;
}
try {
String securityCookie = AccessController.doPrivileged(new EncodeAction(securityCookieValue.toString()));
cookie.append(serviceConfig.isCookieEncodingEnabled() ? URLEncDec.encode(securityCookie) : securityCookie);
if (extraCookies != null) {
}
cookie.append(serviceConfig.isCookieEncodingEnabled() ? URLEncDec.encode(sid.toString()) : sid.toString());
}
}
if (sessionDebug.messageEnabled()) {
}
connection.setDoInput(true);
throw ex;
}
return connection;
}
}