From 90f7f3ea1674e7cd5ead84247ca881ca101ba72a Mon Sep 17 00:00:00 2001 From: clemenso Date: Wed, 11 Feb 2009 20:03:29 +0000 Subject: div. changes for A-Trust Activation Support (User-Agent header, GetStatusRequest, ...) git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@296 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../main/java/at/gv/egiz/bku/binding/DataUrl.java | 148 ++++++++++++--------- .../at/gv/egiz/bku/binding/DataUrlConnection.java | 118 ++++++++-------- .../gv/egiz/bku/binding/DataUrlConnectionImpl.java | 6 +- .../gv/egiz/bku/binding/HTTPBindingProcessor.java | 2 +- .../bku/binding/LegacyDataUrlConnectionImpl.java | 9 +- 5 files changed, 156 insertions(+), 127 deletions(-) (limited to 'bkucommon/src/main/java/at/gv/egiz/bku/binding') diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrl.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrl.java index 2e2cc38a..7b682136 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrl.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrl.java @@ -1,21 +1,21 @@ /* -* Copyright 2008 Federal Chancellery Austria and -* Graz University of Technology -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -package at.gv.egiz.bku.binding; - + * Copyright 2008 Federal Chancellery Austria and + * Graz University of Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package at.gv.egiz.bku.binding; + import java.net.MalformedURLException; import java.net.URL; import java.util.Properties; @@ -27,63 +27,87 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import at.gv.egiz.bku.slexceptions.SLRuntimeException; - -/** - * Used to handle DataUrl connections as specified in the CCE's HTTP protocol binding. - * - */ -public class DataUrl { - private static DataUrlConnectionSPI defaultDataUrlConnection = new DataUrlConnectionImpl(); + +/** + * Used to handle DataUrl connections as specified in the CCE's HTTP protocol binding. + * + */ +public class DataUrl { + private static Log log = LogFactory.getLog(DataUrl.class); + private static DataUrlConnectionSPI connection; private static Properties configuration; - private static SSLSocketFactory sslSocketFactory; + private static SSLSocketFactory sslSocketFactory; private static HostnameVerifier hostNameVerifier; - - - private URL url; - - /** - * Sets the default DataUrlConnection implementation - * @param aClass must not be null - */ - public static void setDataUrlConnectionClass(DataUrlConnectionSPI dataUrlConnection) { - if (dataUrlConnection == null) { - throw new NullPointerException("Default dataurlconnection must not be set to null"); - } - defaultDataUrlConnection = dataUrlConnection; - defaultDataUrlConnection.setConfiguration(configuration); - defaultDataUrlConnection.setSSLSocketFactory(sslSocketFactory); - defaultDataUrlConnection.setHostnameVerifier(hostNameVerifier); - } - - public DataUrl(String aUrlString) throws MalformedURLException { - url = new URL(aUrlString); - } - - public DataUrlConnection openConnection() { + private URL url; + + /** + * Sets the default DataUrlConnection implementation + * @param aClass must not be null + */ + static void setDataUrlConnectionImpl(DataUrlConnectionSPI conn) { + if (conn != null) { + connection = conn; + } + } + + public DataUrl(String aUrlString) throws MalformedURLException { + url = new URL(aUrlString); + if (connection == null) { + log.debug("Using default DataURLConnection class"); + connection = new DataUrlConnectionImpl(); + } + connection.setConfiguration(configuration); + connection.setSSLSocketFactory(sslSocketFactory); + connection.setHostnameVerifier(hostNameVerifier); + } + + public DataUrlConnection openConnection() { try { - log.debug("Opening dataurl connection"); - DataUrlConnectionSPI retVal = defaultDataUrlConnection.newInstance(); - retVal.init(url); - return retVal; - } catch (Exception e) { - log.error(e); - throw new SLRuntimeException("Cannot instantiate a dataurlconnection:",e); - } + log.debug("Opening dataurl connection"); + DataUrlConnectionSPI retVal = connection.newInstance(); + retVal.init(url); + return retVal; + } catch (Exception e) { + log.error(e); + throw new SLRuntimeException("Cannot instantiate a dataurlconnection:", e); + } } - + + + /** + * set configuration for all subsequently instantiated DataURL objects + * @param props + */ public static void setConfiguration(Properties props) { configuration = props; - defaultDataUrlConnection.setConfiguration(configuration); + if (configuration != null) { + String className = configuration.getProperty(DataUrlConnection.DATAURLCONNECTION_CONFIG_P); + if (className != null) { + try { + log.info("set DataURLConnection class: " + className); + Class c = Class.forName(className); + connection = (DataUrlConnectionSPI) c.newInstance(); + } catch (Exception ex) { + log.error("failed to instantiate DataURL connection " + className, ex); + } + } + } } - + + /** + * set SSLSocketFactory for all subsequently instantiated DataURL objects + * @param socketFactory + */ public static void setSSLSocketFactory(SSLSocketFactory socketFactory) { sslSocketFactory = socketFactory; - defaultDataUrlConnection.setSSLSocketFactory(socketFactory); } + /** + * set HostnameVerifier for all subsequently instantiated DataURL objects + * @param hostNameVerifier + */ public static void setHostNameVerifier(HostnameVerifier hostNameVerifier) { DataUrl.hostNameVerifier = hostNameVerifier; - defaultDataUrlConnection.setHostnameVerifier(hostNameVerifier); - } + } } \ No newline at end of file diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnection.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnection.java index c6ffa32a..21407cc3 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnection.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnection.java @@ -14,8 +14,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package at.gv.egiz.bku.binding; - +package at.gv.egiz.bku.binding; + import java.io.IOException; import java.io.InputStream; import java.net.SocketTimeoutException; @@ -23,62 +23,66 @@ import java.net.URL; import java.security.cert.X509Certificate; import at.gv.egiz.bku.slcommands.SLResult; - -/** - * Transmit a security layer result to DataURL via HTTP POST, encoded as multipart/form-data. - * The HTTP header user-agent is set to citizen-card-environment/1.2 BKU2 1.0. - * The form-parameter ResponseType is set to HTTP-Security-Layer-RESPONSE. - * All other headers/parameters are set by the caller. - * - * @author clemens - */ -public interface DataUrlConnection { - - public static final String DEFAULT_USERAGENT = "citizen-card-environment/1.2 MOCCA Unknown"; - public static final String FORMPARAM_RESPONSETYPE = "ResponseType"; - public static final String DEFAULT_RESPONSETYPE = "HTTP-Security-Layer-RESPONSE"; - public static final String FORMPARAM_XMLRESPONSE = "XMLResponse"; - public static final String FORMPARAM_BINARYRESPONSE = "BinaryResponse"; - - public static final String XML_RESPONSE_ENCODING = "UTF-8"; - public final static String USER_AGENT_PROPERTY_KEY="UserAgent"; - +/** + * Transmit a security layer result to DataURL via HTTP POST, encoded as multipart/form-data. + * The HTTP header user-agent is set to citizen-card-environment/1.2 BKU2 1.0. + * The form-parameter ResponseType is set to HTTP-Security-Layer-RESPONSE. + * All other headers/parameters are set by the caller. + * + * @author clemens + */ +public interface DataUrlConnection { + + public final static String USERAGENT_CONFIG_P = "UserAgent"; + public static final String USERAGENT_DEFAULT = "citizen-card-environment/1.2 MOCCA/UNKNOWN"; + public static final String USERAGENT_BASE = "citizen-card-environment/1.2 MOCCA/"; + + public static final String DATAURLCONNECTION_CONFIG_P = "DataURLConnectionImplClass"; + + public static final String FORMPARAM_RESPONSETYPE = "ResponseType"; + public static final String DEFAULT_RESPONSETYPE = "HTTP-Security-Layer-RESPONSE"; + public static final String FORMPARAM_XMLRESPONSE = "XMLResponse"; + public static final String FORMPARAM_BINARYRESPONSE = "BinaryResponse"; + + public static final String XML_RESPONSE_ENCODING = "UTF-8"; + + public String getProtocol(); - public URL getUrl(); - - /** - * Set a HTTP Header. - * @param key - * @param value multiple values are assumed to have the correct formatting (comma-separated list) - */ - public void setHTTPHeader(String key, String value); - - /** - * Set a form-parameter. - * @param name - * @param data - * @param contentType may be null - * @param charSet may be null - * @param transferEncoding may be null - */ - public void setHTTPFormParameter(String name, InputStream data, String contentType, String charSet, String transferEncoding); - - /** - * @pre httpHeaders != null - * @throws java.net.SocketTimeoutException - * @throws java.io.IOException - */ - public void connect() throws SocketTimeoutException, IOException; - - public X509Certificate getServerCertificate(); - - /** - * @pre connection != null - * @throws java.io.IOException - */ - public void transmit(SLResult slResult) throws IOException; - - public DataUrlResponse getResponse() throws IOException; + public URL getUrl(); + + /** + * Set a HTTP Header. + * @param key + * @param value multiple values are assumed to have the correct formatting (comma-separated list) + */ + public void setHTTPHeader(String key, String value); + + /** + * Set a form-parameter. + * @param name + * @param data + * @param contentType may be null + * @param charSet may be null + * @param transferEncoding may be null + */ + public void setHTTPFormParameter(String name, InputStream data, String contentType, String charSet, String transferEncoding); + + /** + * @pre httpHeaders != null + * @throws java.net.SocketTimeoutException + * @throws java.io.IOException + */ + public void connect() throws SocketTimeoutException, IOException; + + public X509Certificate getServerCertificate(); + + /** + * @pre connection != null + * @throws java.io.IOException + */ + public void transmit(SLResult slResult) throws IOException; + + public DataUrlResponse getResponse() throws IOException; } \ No newline at end of file diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionImpl.java index 57d89c89..d9a9454e 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionImpl.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionImpl.java @@ -225,12 +225,12 @@ public class DataUrlConnectionImpl implements DataUrlConnectionSPI { boundary = "--" + IdFactory.getInstance().createId().toString(); requestHttpHeaders = new HashMap(); if ((config != null) - && (config.getProperty(USER_AGENT_PROPERTY_KEY) != null)) { + && (config.getProperty(USERAGENT_CONFIG_P) != null)) { requestHttpHeaders.put(HttpUtil.HTTP_HEADER_USER_AGENT, config - .getProperty(USER_AGENT_PROPERTY_KEY)); + .getProperty(USERAGENT_CONFIG_P)); } else { requestHttpHeaders - .put(HttpUtil.HTTP_HEADER_USER_AGENT, DEFAULT_USERAGENT); + .put(HttpUtil.HTTP_HEADER_USER_AGENT, USERAGENT_DEFAULT); } requestHttpHeaders.put(HttpUtil.HTTP_HEADER_CONTENT_TYPE, diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/HTTPBindingProcessor.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/HTTPBindingProcessor.java index 98b5b775..43f42331 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/HTTPBindingProcessor.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/HTTPBindingProcessor.java @@ -91,7 +91,7 @@ public class HTTPBindingProcessor extends AbstractBindingProcessor implements * Defines the maximum number of dataurl connects that are allowed within a * single SL Request processing. */ - protected static int MAX_DATAURL_HOPS = 10; + protected static int MAX_DATAURL_HOPS = 50; protected static String XML_MIME_TYPE = "text/xml"; protected static String BINARY_MIME_TYPE = "application/octet-stream"; diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/LegacyDataUrlConnectionImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/LegacyDataUrlConnectionImpl.java index 452c45e5..ef9dd199 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/LegacyDataUrlConnectionImpl.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/LegacyDataUrlConnectionImpl.java @@ -165,7 +165,7 @@ public class LegacyDataUrlConnectionImpl implements DataUrlConnectionSPI { } catch (IOException iox) { log.info(iox); } - log.trace("Reading response"); + log.trace("Reading response"); result = new DataUrlResponse(url.toString(), connection.getResponseCode(), is); Map responseHttpHeaders = new HashMap(); Map> httpHeaders = connection.getHeaderFields(); @@ -212,12 +212,13 @@ public class LegacyDataUrlConnectionImpl implements DataUrlConnectionSPI { this.url = url; requestHttpHeaders = new HashMap(); if ((config != null) - && (config.getProperty(USER_AGENT_PROPERTY_KEY) != null)) { + && (config.getProperty(USERAGENT_CONFIG_P) != null)) { + log.debug("setting User-Agent header: " + config.getProperty(USERAGENT_CONFIG_P)); requestHttpHeaders.put(HttpUtil.HTTP_HEADER_USER_AGENT, config - .getProperty(USER_AGENT_PROPERTY_KEY)); + .getProperty(USERAGENT_CONFIG_P)); } else { requestHttpHeaders - .put(HttpUtil.HTTP_HEADER_USER_AGENT, DEFAULT_USERAGENT); + .put(HttpUtil.HTTP_HEADER_USER_AGENT, USERAGENT_DEFAULT); } requestHttpHeaders.put(HttpUtil.HTTP_HEADER_CONTENT_TYPE, -- cgit v1.2.3