From f6a617e6820751fb5f941ff1019426fe2aa8ba4e Mon Sep 17 00:00:00 2001 From: "peter.danner" Date: Thu, 8 Sep 2005 07:34:48 +0000 Subject: WebDAV Enhancement des Proxy git-svn-id: https://joinup.ec.europa.eu/svn/moa-idspss/trunk@502 d688527b-c9ab-4aba-bd8d-4036d912da1d --- .../moa/id/proxy/DefaultConnectionBuilder.java | 55 +++++++++++++++------- 1 file changed, 38 insertions(+), 17 deletions(-) (limited to 'id.server/src/at/gv/egovernment/moa/id/proxy/DefaultConnectionBuilder.java') diff --git a/id.server/src/at/gv/egovernment/moa/id/proxy/DefaultConnectionBuilder.java b/id.server/src/at/gv/egovernment/moa/id/proxy/DefaultConnectionBuilder.java index 5ded393d1..6f0244870 100644 --- a/id.server/src/at/gv/egovernment/moa/id/proxy/DefaultConnectionBuilder.java +++ b/id.server/src/at/gv/egovernment/moa/id/proxy/DefaultConnectionBuilder.java @@ -6,7 +6,7 @@ import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; import java.util.Iterator; -import java.util.Map; +import java.util.Vector; import javax.net.ssl.SSLSocketFactory; import javax.servlet.http.HttpServletRequest; @@ -51,14 +51,19 @@ public class DefaultConnectionBuilder implements ConnectionBuilder { String publicURLPrefix, String realURLPrefix, SSLSocketFactory sslSocketFactory, - Map parameters) + Vector parameters) throws IOException { String requestedURL = req.getRequestURL().toString(); // check whether requested URL starts with publicURLPrefix - if (! requestedURL.startsWith(publicURLPrefix)) - throw new IOException(MOAIDMessageProvider.getInstance().getMessage( - "proxy.01", new Object[] {requestedURL, publicURLPrefix})); + + //Temporary allow http:// urls instead of the https:// in publicURLPrefix + //if (req.getSession().getAttribute("authorizationkey")==null) { + // if (! requestedURL.startsWith(publicURLPrefix)) + // throw new IOException(MOAIDMessageProvider.getInstance().getMessage( + // "proxy.01", new Object[] {requestedURL, publicURLPrefix})); + //} + // in case of GET request, append query string to requested URL; // otherwise, HttpURLConnection would perform a POST request if ("get".equalsIgnoreCase(req.getMethod()) && ! parameters.isEmpty()) { @@ -74,7 +79,7 @@ public class DefaultConnectionBuilder implements ConnectionBuilder { conn.setDoInput(true); conn.setDoOutput(true); //conn.setUseCaches(false); - conn.setAllowUserInteraction(true); + //conn.setAllowUserInteraction(true); conn.setInstanceFollowRedirects(false); if (conn instanceof HttpsURLConnection && sslSocketFactory != null) { HttpsURLConnection httpsConn = (HttpsURLConnection) conn; @@ -84,31 +89,47 @@ public class DefaultConnectionBuilder implements ConnectionBuilder { } return conn; } + + + /** + * Disconnects the HttpURLConnection if necessary. + * The implementation of the Connectionbuilder decides wether + * if this should be happen or not. + * + * @param con the HttpURLConnection which is normaly to be closed + */ + public void disconnect(HttpURLConnection conn) { + conn.disconnect(); + } + + /** * @param requestedURL * @param parameters * @return */ - private String appendQueryString(String requestedURL, Map parameters) { + private String appendQueryString(String requestedURL, Vector parameters) { String newURL = requestedURL; + String parameter[] = new String[2]; String paramValue =""; String paramName =""; - for (Iterator iter = parameters.keySet().iterator(); iter.hasNext();) { + String paramString =""; + for (Iterator iter = parameters.iterator(); iter.hasNext();) { try { - paramName = URLEncoder.encode((String) iter.next(), "UTF-8"); - paramValue = URLEncoder.encode((String) parameters.get(paramName), "UTF-8"); + parameter = (String[]) iter.next(); + //next two lines work not with OWA-SSL-Login-form + paramName = URLEncoder.encode((String) parameter[0], "UTF-8"); + paramValue = URLEncoder.encode((String) parameter[1], "UTF-8"); + } catch (UnsupportedEncodingException e) { //UTF-8 should be supported } - String paramString = paramName + "=" + paramValue; - if (newURL.indexOf("?") < 0) - newURL = newURL + "?" + paramString; - else - newURL = newURL + "&" + paramString; - } + paramString = "&" + paramName + "=" + paramValue + paramString; + } + if (paramString.length()>0) newURL = newURL + "?" + paramString.substring(1); return newURL; } - + /** * @author Stefan Knirsch * @version $Id$ -- cgit v1.2.3