throws DebugException {
URL requestURL = parametersInitializer.getRequestURL(launch);
try {
// We only support this kind of debug session initializer here:
if (parametersInitializer instanceof IWebDebugParametersInitializer) {
IWebDebugParametersInitializer webParametersInitializer = (IWebDebugParametersInitializer) parametersInitializer;
StringBuilder getParams = new StringBuilder("?"); //$NON-NLS-1$
// Initialize debug parameters (using cookies):
Hashtable<String, String> debugParameters = parametersInitializer
.getDebugParameters(launch);
if (debugParameters != null) {
Enumeration<String> k = debugParameters.keys();
while (k.hasMoreElements()) {
String key = k.nextElement();
String value = debugParameters.get(key);
getParams.append(URLEncoder.encode(key, URL_ENCODING))
.append('=')
.append(URLEncoder.encode(value, URL_ENCODING));
if (k.hasMoreElements()) {
getParams.append('&');
}
}
}
// Initialize with additional GET parameters
String requestMethod = webParametersInitializer
.getRequestMethod(launch);
if (IWebDebugParametersInitializer.GET_METHOD
.equals(requestMethod)) {
Hashtable<String, String> requestParameters = webParametersInitializer
.getRequestParameters(launch);
if (requestParameters != null) {
Enumeration<String> k = requestParameters.keys();
while (k.hasMoreElements()) {
String key = k.nextElement();
String value = requestParameters.get(key);
getParams.append('&');
getParams
.append(URLEncoder
.encode(key, URL_ENCODING))
.append('=')
.append(URLEncoder.encode(value,
URL_ENCODING));
}
}
}
requestURL = new URL(requestURL.getProtocol(),
requestURL.getHost(), requestURL.getPort(),
requestURL.getPath() + getParams.toString());
// Open the connection:
if (PHPDebugPlugin.DEBUG) {
System.out.println("Opening URL connection: " //$NON-NLS-1$
+ requestURL.toString());
}
HttpURLConnection urlConection = (HttpURLConnection) requestURL
.openConnection();
urlConection.setDoInput(true);
urlConection.setDoOutput(true);
if (requestMethod != null) {
urlConection.setRequestMethod(requestMethod);
}
// Add additional headers
Hashtable<String, String> headers = webParametersInitializer
.getRequestHeaders(launch);
if (headers != null) {
Enumeration<String> k = headers.keys();
while (k.hasMoreElements()) {
String key = k.nextElement();
String value = URLEncoder.encode(headers.get(key),
URL_ENCODING);
if (PHPDebugPlugin.DEBUG) {
System.out.println("Adding HTTP header: " + key //$NON-NLS-1$
+ "=" + value); //$NON-NLS-1$
}
urlConection.addRequestProperty(key, value);
}
}
// Set cookies
Hashtable<String, String> cookies = webParametersInitializer
.getRequestCookies(launch);
if (cookies != null) {
StringBuilder cookieBuf = new StringBuilder();
Enumeration<String> k = cookies.keys();
while (k.hasMoreElements()) {
String key = k.nextElement();
String value = cookies.get(key);
cookieBuf.append(URLEncoder.encode(key, URL_ENCODING))
.append('=')
.append(URLEncoder.encode(value, URL_ENCODING));
if (k.hasMoreElements()) {
cookieBuf.append("; "); //$NON-NLS-1$
}
}
if (PHPDebugPlugin.DEBUG) {
System.out.println("Setting cookies: " //$NON-NLS-1$
+ cookieBuf.toString());
}
urlConection.addRequestProperty("Cookie", //$NON-NLS-1$
cookieBuf.toString());
}
DataOutputStream outputStream = new DataOutputStream(
urlConection.getOutputStream());
try {
// Initialize with additional POST parameters
if (requestMethod == IWebDebugParametersInitializer.POST_METHOD) {
Hashtable<String, String> requestParameters = webParametersInitializer
.getRequestParameters(launch);
if (requestParameters != null) {
StringBuilder postParams = new StringBuilder();
Enumeration<String> k = requestParameters.keys();
while (k.hasMoreElements()) {
String key = k.nextElement();
String value = requestParameters.get(key);
postParams
.append(URLEncoder.encode(key,
URL_ENCODING))
.append('=')
.append(URLEncoder.encode(value,
URL_ENCODING));
if (k.hasMoreElements()) {
postParams.append('&');
}
}
outputStream.writeBytes(postParams.toString());
}
}
// Add raw data
String rawData = webParametersInitializer
.getRequestRawData(launch);
if (rawData != null) {
outputStream.writeBytes(rawData);
}
} finally {