summaryrefslogtreecommitdiff
path: root/bkucommon/src
diff options
context:
space:
mode:
Diffstat (limited to 'bkucommon/src')
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrl.java148
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnection.java118
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/binding/DataUrlConnectionImpl.java6
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/binding/HTTPBindingProcessor.java2
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/binding/LegacyDataUrlConnectionImpl.java9
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/conf/Configurator.java16
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/GetStatusCommand.java26
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/GetStatusResult.java26
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLCommandFactory.java608
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CardChannelInfoboxImpl.java2
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/GetStatusCommandImpl.java79
-rw-r--r--bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/GetStatusResultImpl.java52
-rw-r--r--bkucommon/src/test/java/at/gv/egiz/bku/binding/HttpBindingProcessorTest.java598
13 files changed, 951 insertions, 739 deletions
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 <em>citizen-card-environment/1.2 BKU2 1.0</em>.
- * The form-parameter ResponseType is set to <em>HTTP-Security-Layer-RESPONSE</em>.
- * 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 <em>citizen-card-environment/1.2 BKU2 1.0</em>.
+ * The form-parameter ResponseType is set to <em>HTTP-Security-Layer-RESPONSE</em>.
+ * 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<String, String>();
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<String, String> responseHttpHeaders = new HashMap<String, String>();
Map<String, List<String>> httpHeaders = connection.getHeaderFields();
@@ -212,12 +212,13 @@ public class LegacyDataUrlConnectionImpl implements DataUrlConnectionSPI {
this.url = url;
requestHttpHeaders = new HashMap<String, String>();
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,
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/conf/Configurator.java b/bkucommon/src/main/java/at/gv/egiz/bku/conf/Configurator.java
index 7f180ad0..a6c70d2c 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/conf/Configurator.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/conf/Configurator.java
@@ -46,6 +46,7 @@ import at.gv.egiz.bku.slexceptions.SLRuntimeException;
import at.gv.egiz.bku.utils.urldereferencer.URLDereferencer;
public abstract class Configurator {
+
private Log log = LogFactory.getLog(Configurator.class);
protected Properties properties;
@@ -202,22 +203,22 @@ public abstract class Configurator {
}
public void configureVersion() {
- if (properties.getProperty(DataUrlConnection.USER_AGENT_PROPERTY_KEY) == null) {
+ if (properties.getProperty(DataUrlConnection.USERAGENT_CONFIG_P) == null) {
Properties p = new Properties();
try {
InputStream is = getManifest();
if (is != null) {
p.load(getManifest());
String version = p.getProperty("Implementation-Build");
- properties.setProperty(DataUrlConnection.USER_AGENT_PROPERTY_KEY,
- "citizen-card-environment/1.2 MOCCA " + version);
+ properties.setProperty(DataUrlConnection.USERAGENT_CONFIG_P,
+ DataUrlConnection.USERAGENT_BASE + version);
log.debug("Setting user agent to: "
+ properties
- .getProperty(DataUrlConnection.USER_AGENT_PROPERTY_KEY));
+ .getProperty(DataUrlConnection.USERAGENT_CONFIG_P));
} else {
log.warn("Cannot read manifest");
- properties.setProperty(DataUrlConnection.USER_AGENT_PROPERTY_KEY,
- "citizen-card-environment/1.2 MOCCA UNKNOWN");
+ properties.setProperty(DataUrlConnection.USERAGENT_CONFIG_P,
+ DataUrlConnection.USERAGENT_DEFAULT);
}
} catch (IOException e) {
log.error(e);
@@ -254,6 +255,7 @@ public abstract class Configurator {
log.error("Cannot load CA certificates", e1);
}
String disableAll = getProperty("SSL.disableAllChecks");
+ String disableHostnameVerification = getProperty("SSL.disableHostnameVerification");
try {
KeyManager[] km = null;
SSLContext sslCtx = SSLContext
@@ -275,7 +277,7 @@ public abstract class Configurator {
} catch (Exception e) {
log.error("Cannot configure SSL", e);
}
- if ((disableAll != null) && (Boolean.parseBoolean(disableAll))) {
+ if ((disableAll != null && Boolean.parseBoolean(disableAll)) || (disableHostnameVerification != null && Boolean.parseBoolean(disableHostnameVerification))) {
log.warn("---------------------------------");
log.warn(" Disabling Hostname Verification ");
log.warn("---------------------------------");
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/GetStatusCommand.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/GetStatusCommand.java
new file mode 100644
index 00000000..19099b63
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/GetStatusCommand.java
@@ -0,0 +1,26 @@
+/*
+ * 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.slcommands;
+
+/**
+ *
+ * @author Clemens Orthacker <clemens.orthacker@iaik.tugraz.at>
+ */
+public interface GetStatusCommand extends SLCommand {
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/GetStatusResult.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/GetStatusResult.java
new file mode 100644
index 00000000..c5518f51
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/GetStatusResult.java
@@ -0,0 +1,26 @@
+/*
+ * 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.slcommands;
+
+/**
+ *
+ * @author Clemens Orthacker <clemens.orthacker@iaik.tugraz.at>
+ */
+public interface GetStatusResult extends SLResult {
+
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLCommandFactory.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLCommandFactory.java
index bec2b253..1ef94e81 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLCommandFactory.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/SLCommandFactory.java
@@ -14,10 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package at.gv.egiz.bku.slcommands;
-
+package at.gv.egiz.bku.slcommands;
+
import java.io.IOException;
-import java.io.Reader;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
@@ -42,7 +41,6 @@ import org.apache.commons.logging.LogFactory;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
-import at.buergerkarte.namespaces.cardchannel.ObjectFactory;
import at.gv.egiz.bku.slexceptions.SLCommandException;
import at.gv.egiz.bku.slexceptions.SLExceptionMessages;
import at.gv.egiz.bku.slexceptions.SLRequestException;
@@ -50,38 +48,38 @@ import at.gv.egiz.bku.slexceptions.SLRuntimeException;
import at.gv.egiz.bku.utils.DebugReader;
import at.gv.egiz.slbinding.RedirectEventFilter;
import at.gv.egiz.slbinding.RedirectUnmarshallerListener;
-
-public class SLCommandFactory {
-
- /**
- * Schema files required for Security Layer command validation.
- */
- public static final String[] SCHEMA_FILES = new String[]{
- "at/gv/egiz/bku/slcommands/schema/xml.xsd",
- "at/gv/egiz/bku/slcommands/schema/xmldsig-core-schema.xsd",
- "at/gv/egiz/bku/slcommands/schema/Core-1.2.xsd"
- };
- /**
- * Logging facility.
- */
- static Log log = LogFactory.getLog(SLCommandFactory.class);
- /**
- * The instance returned by {@link #getInstance()}.
- */
- private static SLCommandFactory instance;
- /**
- * Schema for Security Layer command validation.
- */
- private Schema slSchema;
- /**
- * The JAXBContext.
- */
- private JAXBContext jaxbContext;
- /**
- * The map of <namespaceURI>:<localName> to implementation class of the
- * corresponding {@link SLCommand}.
- */
- private Map<String, Class<? extends SLCommand>> slRequestTypeMap = new HashMap<String, Class<? extends SLCommand>>();
+
+public class SLCommandFactory {
+
+ /**
+ * Schema files required for Security Layer command validation.
+ */
+ public static final String[] SCHEMA_FILES = new String[]{
+ "at/gv/egiz/bku/slcommands/schema/xml.xsd",
+ "at/gv/egiz/bku/slcommands/schema/xmldsig-core-schema.xsd",
+ "at/gv/egiz/bku/slcommands/schema/Core-1.2.xsd"
+ };
+ /**
+ * Logging facility.
+ */
+ static Log log = LogFactory.getLog(SLCommandFactory.class);
+ /**
+ * The instance returned by {@link #getInstance()}.
+ */
+ private static SLCommandFactory instance;
+ /**
+ * Schema for Security Layer command validation.
+ */
+ private Schema slSchema;
+ /**
+ * The JAXBContext.
+ */
+ private JAXBContext jaxbContext;
+ /**
+ * The map of <namespaceURI>:<localName> to implementation class of the
+ * corresponding {@link SLCommand}.
+ */
+ private Map<String, Class<? extends SLCommand>> slRequestTypeMap = new HashMap<String, Class<? extends SLCommand>>();
/**
* Configures the singleton instance with command implementations
@@ -96,239 +94,239 @@ public class SLCommandFactory {
log.debug("Registering sl command implementation for :"+key+ "; implementation class: "+impl.getCanonicalName());
slRequestTypeMap.put(key, impl);
}
- }
-
- /**
- * Register an {@link SLCommand} implementation class of a Security Layer
- * command with the given <code>namespaceUri</code> and <code>localname</code>
- * .
- *
- * @param namespaceUri
- * the namespace URI of the Security Layer command
- * @param localname
- * the localname of the Security Layer command
- * @param slCommandClass
- * the implementation class, or <code>null</code> to deregister a
- * currently registered class
- */
- public void setImplClass(String namespaceUri, String localname,
- Class<? extends SLCommand> slCommandClass) {
- if (slCommandClass != null) {
- slRequestTypeMap.put(namespaceUri + ":" + localname, slCommandClass);
- } else {
- slRequestTypeMap.remove(namespaceUri + ":" + localname);
- }
- }
-
- /**
- * Returns the implementation class of an {@link SLCommand} with the given
- * <code>name</code>, or <code>null</code> if no such class is registered.
- *
- * @param name
- * the <code>QName</code> of the Security Layer command
- * @return the implementation class, or <code>null</code> if no class is
- * registered for the given <code>name</code>
- */
- public Class<? extends SLCommand> getImplClass(QName name) {
- String namespaceURI = name.getNamespaceURI();
- String localPart = name.getLocalPart();
- return slRequestTypeMap.get(namespaceURI + ":" + localPart);
- }
-
- /**
- * Sets the schema to validate Security Layer commands with.
- *
- * @param slSchema the schema to validate Security Layer commands with
- */
- public void setSLSchema(Schema slSchema) {
- this.slSchema = slSchema;
- }
-
- /**
- * @return the jaxbContext
- */
- public JAXBContext getJaxbContext() {
- ensureJaxbContext();
- return jaxbContext;
- }
-
- /**
- * @param jaxbContext the jaxbContext to set
- */
- public void setJaxbContext(JAXBContext jaxbContext) {
- this.jaxbContext = jaxbContext;
- }
-
- /**
- * Initialize the JAXBContext.
- */
- private synchronized void ensureJaxbContext() {
- if (jaxbContext == null) {
- try {
- String slPkg = at.buergerkarte.namespaces.securitylayer._1.ObjectFactory.class.getPackage().getName();
+ }
+
+ /**
+ * Register an {@link SLCommand} implementation class of a Security Layer
+ * command with the given <code>namespaceUri</code> and <code>localname</code>
+ * .
+ *
+ * @param namespaceUri
+ * the namespace URI of the Security Layer command
+ * @param localname
+ * the localname of the Security Layer command
+ * @param slCommandClass
+ * the implementation class, or <code>null</code> to deregister a
+ * currently registered class
+ */
+ public void setImplClass(String namespaceUri, String localname,
+ Class<? extends SLCommand> slCommandClass) {
+ if (slCommandClass != null) {
+ slRequestTypeMap.put(namespaceUri + ":" + localname, slCommandClass);
+ } else {
+ slRequestTypeMap.remove(namespaceUri + ":" + localname);
+ }
+ }
+
+ /**
+ * Returns the implementation class of an {@link SLCommand} with the given
+ * <code>name</code>, or <code>null</code> if no such class is registered.
+ *
+ * @param name
+ * the <code>QName</code> of the Security Layer command
+ * @return the implementation class, or <code>null</code> if no class is
+ * registered for the given <code>name</code>
+ */
+ public Class<? extends SLCommand> getImplClass(QName name) {
+ String namespaceURI = name.getNamespaceURI();
+ String localPart = name.getLocalPart();
+ return slRequestTypeMap.get(namespaceURI + ":" + localPart);
+ }
+
+ /**
+ * Sets the schema to validate Security Layer commands with.
+ *
+ * @param slSchema the schema to validate Security Layer commands with
+ */
+ public void setSLSchema(Schema slSchema) {
+ this.slSchema = slSchema;
+ }
+
+ /**
+ * @return the jaxbContext
+ */
+ public JAXBContext getJaxbContext() {
+ ensureJaxbContext();
+ return jaxbContext;
+ }
+
+ /**
+ * @param jaxbContext the jaxbContext to set
+ */
+ public void setJaxbContext(JAXBContext jaxbContext) {
+ this.jaxbContext = jaxbContext;
+ }
+
+ /**
+ * Initialize the JAXBContext.
+ */
+ private synchronized void ensureJaxbContext() {
+ if (jaxbContext == null) {
+ try {
+ String slPkg = at.buergerkarte.namespaces.securitylayer._1.ObjectFactory.class.getPackage().getName();
String xmldsigPkg = org.w3._2000._09.xmldsig_.ObjectFactory.class.getPackage().getName();
String cardChannelPkg = at.buergerkarte.namespaces.cardchannel.ObjectFactory.class.getPackage().getName();
- setJaxbContext(JAXBContext.newInstance(slPkg + ":" + xmldsigPkg + ":" + cardChannelPkg));
- } catch (JAXBException e) {
- log.error("Failed to setup JAXBContext security layer request.", e);
- throw new SLRuntimeException(e);
- }
- }
- }
-
- /**
- * Initialize the security layer schema.
- */
- private synchronized void ensureSchema() {
- if (slSchema == null) {
- try {
- SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
- ClassLoader cl = SLCommandFactory.class.getClassLoader();
- Source[] sources = new Source[SCHEMA_FILES.length];
- for (int i = 0; i < SCHEMA_FILES.length; i++) {
- String schemaFile = SCHEMA_FILES[i];
- URL schemaURL = cl.getResource(schemaFile);
- if (schemaURL == null) {
- throw new SLRuntimeException("Failed to load schema file " + schemaFile + ".");
- }
- log.debug("Schema location: " + schemaURL);
- sources[i] = new StreamSource(schemaURL.openStream());
- }
- Schema schema = schemaFactory.newSchema(sources);
- log.debug("Schema successfully created.");
- setSLSchema(schema);
- } catch (SAXException e) {
- log.error("Failed to load security layer schema.", e);
- throw new SLRuntimeException("Failed to load security layer schema.", e);
- } catch (IOException e) {
- log.error("Failed to load security layer schema.", e);
- throw new SLRuntimeException("Failed to load security layer schema.", e);
- }
-
- }
- }
-
- /**
- * Get an instance of the <code>SLCommandFactory</code>.
- */
- public synchronized static SLCommandFactory getInstance() {
- if (instance == null) {
- instance = new SLCommandFactory();
- instance.ensureJaxbContext();
- instance.ensureSchema();
- }
- return instance;
- }
-
- /**
- * Private constructor used by {@link #getInstance()}.
- */
- private SLCommandFactory() {
- }
-
- /**
- * Unmarshalls from the given <code>source</code>.
- *
- * @see Unmarshaller#unmarshal(Source)
- *
- * <em>Note:</em>Could replace JAXB's unmarshal-time validation engine (see commented code), however,
- * we need a redirect filter.
- *
- * @param source
- * the source to unmarshal from
- * @return the object returned by {@link Unmarshaller#unmarshal(Source)}
- * @throws SLRequestException
- * if unmarshalling fails
- * @throws SLRuntimeException
- * if an unexpected error occurs configuring the unmarshaller or if
- * unmarshalling fails with an unexpected error
- */
- protected Object unmarshal(Source source) throws SLRuntimeException,
- SLRequestException {
-
- Object object;
- try {
-
-// ValidatorHandler validator = slSchema.newValidatorHandler();
-// validator.getContentHandler();
-//
-// SAXParserFactory spf = SAXParserFactory.newInstance();
-// spf.setNamespaceAware(true);
-// XMLReader saxReader = spf.newSAXParser().getXMLReader();
-// //TODO extend validator to implement redirectContentHandler (validate+redirect)
-// saxReader.setContentHandler(validator);
-// //TODO get a InputSource
-// SAXSource saxSource = new SAXSource(saxReader, source);
-//
-// Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
-// //turn off duplicate jaxb validation
-// unmarshaller.setSchema(null);
-// unmarshaller.setListener(listener);
-// unmarshaller.unmarshal(saxSource);
-
-
- XMLInputFactory inputFactory = XMLInputFactory.newInstance();
- XMLEventReader eventReader = inputFactory.createXMLEventReader(source);
- RedirectEventFilter redirectEventFilter = new RedirectEventFilter();
- XMLEventReader filteredReader = inputFactory.createFilteredReader(eventReader, redirectEventFilter);
-
- Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
- unmarshaller.setListener(new RedirectUnmarshallerListener(redirectEventFilter));
- if (slSchema != null) {
- unmarshaller.setSchema(slSchema);
- }
- log.trace("Before unmarshal().");
- object = unmarshaller.unmarshal(filteredReader);
- log.trace("After unmarshal().");
- } catch (UnmarshalException e) {
- if (log.isDebugEnabled()) {
- log.debug("Failed to unmarshall security layer request.", e);
- } else {
- log.info("Failed to unmarshall security layer request." + e.getMessage());
- }
- Throwable cause = e.getCause();
- if (cause instanceof SAXParseException) {
- throw new SLRequestException(3000,
- SLExceptionMessages.EC3000_UNCLASSIFIED, new Object[]{cause.getMessage()});
- } else {
- throw new SLRequestException(3000,
- SLExceptionMessages.EC3000_UNCLASSIFIED, new Object[]{e});
- }
- } catch (JAXBException e) {
- // unexpected error
- log.error("Failed to unmarshall security layer request.", e);
- throw new SLRuntimeException(e);
- } catch (XMLStreamException e) {
- // unexpected error
- log.error("Failed to unmarshall security layer request.", e);
- throw new SLRuntimeException(e);
- }
-
- return object;
-
- }
-
- /**
- * Creates a new <code>SLCommand</code> from the given <code>source</code> and
- * <code>context</code>.
- *
- * @param source
- * the <code>Source</code> to unmarshall from
- * @param context
- * the context for the created <code>SLCommand</code>
- * @return the <code>SLCommand</code> unmarshalled from the given
- * <code>source</code>
- * @throws SLRequestException
- * if unmarshalling fails
- * @throws SLCommandException
- * if command ist not supported
- * @throws SLRuntimeException
- * if an unexpected error occurs configuring the unmarshaller, if
- * unmarshalling fails with an unexpected error or if the
- * corresponding <code>SLCommand</code> could not be instantiated
- */
- @SuppressWarnings("unchecked")
- public SLCommand createSLCommand(Source source, SLCommandContext context)
+ setJaxbContext(JAXBContext.newInstance(slPkg + ":" + xmldsigPkg + ":" + cardChannelPkg));
+ } catch (JAXBException e) {
+ log.error("Failed to setup JAXBContext security layer request.", e);
+ throw new SLRuntimeException(e);
+ }
+ }
+ }
+
+ /**
+ * Initialize the security layer schema.
+ */
+ private synchronized void ensureSchema() {
+ if (slSchema == null) {
+ try {
+ SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ ClassLoader cl = SLCommandFactory.class.getClassLoader();
+ Source[] sources = new Source[SCHEMA_FILES.length];
+ for (int i = 0; i < SCHEMA_FILES.length; i++) {
+ String schemaFile = SCHEMA_FILES[i];
+ URL schemaURL = cl.getResource(schemaFile);
+ if (schemaURL == null) {
+ throw new SLRuntimeException("Failed to load schema file " + schemaFile + ".");
+ }
+ log.debug("Schema location: " + schemaURL);
+ sources[i] = new StreamSource(schemaURL.openStream());
+ }
+ Schema schema = schemaFactory.newSchema(sources);
+ log.debug("Schema successfully created.");
+ setSLSchema(schema);
+ } catch (SAXException e) {
+ log.error("Failed to load security layer schema.", e);
+ throw new SLRuntimeException("Failed to load security layer schema.", e);
+ } catch (IOException e) {
+ log.error("Failed to load security layer schema.", e);
+ throw new SLRuntimeException("Failed to load security layer schema.", e);
+ }
+
+ }
+ }
+
+ /**
+ * Get an instance of the <code>SLCommandFactory</code>.
+ */
+ public synchronized static SLCommandFactory getInstance() {
+ if (instance == null) {
+ instance = new SLCommandFactory();
+ instance.ensureJaxbContext();
+ instance.ensureSchema();
+ }
+ return instance;
+ }
+
+ /**
+ * Private constructor used by {@link #getInstance()}.
+ */
+ private SLCommandFactory() {
+ }
+
+ /**
+ * Unmarshalls from the given <code>source</code>.
+ *
+ * @see Unmarshaller#unmarshal(Source)
+ *
+ * <em>Note:</em>Could replace JAXB's unmarshal-time validation engine (see commented code), however,
+ * we need a redirect filter.
+ *
+ * @param source
+ * the source to unmarshal from
+ * @return the object returned by {@link Unmarshaller#unmarshal(Source)}
+ * @throws SLRequestException
+ * if unmarshalling fails
+ * @throws SLRuntimeException
+ * if an unexpected error occurs configuring the unmarshaller or if
+ * unmarshalling fails with an unexpected error
+ */
+ protected Object unmarshal(Source source) throws SLRuntimeException,
+ SLRequestException {
+
+ Object object;
+ try {
+
+// ValidatorHandler validator = slSchema.newValidatorHandler();
+// validator.getContentHandler();
+//
+// SAXParserFactory spf = SAXParserFactory.newInstance();
+// spf.setNamespaceAware(true);
+// XMLReader saxReader = spf.newSAXParser().getXMLReader();
+// //TODO extend validator to implement redirectContentHandler (validate+redirect)
+// saxReader.setContentHandler(validator);
+// //TODO get a InputSource
+// SAXSource saxSource = new SAXSource(saxReader, source);
+//
+// Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
+// //turn off duplicate jaxb validation
+// unmarshaller.setSchema(null);
+// unmarshaller.setListener(listener);
+// unmarshaller.unmarshal(saxSource);
+
+
+ XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+ XMLEventReader eventReader = inputFactory.createXMLEventReader(source);
+ RedirectEventFilter redirectEventFilter = new RedirectEventFilter();
+ XMLEventReader filteredReader = inputFactory.createFilteredReader(eventReader, redirectEventFilter);
+
+ Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
+ unmarshaller.setListener(new RedirectUnmarshallerListener(redirectEventFilter));
+ if (slSchema != null) {
+ unmarshaller.setSchema(slSchema);
+ }
+ log.trace("Before unmarshal().");
+ object = unmarshaller.unmarshal(filteredReader);
+ log.trace("After unmarshal().");
+ } catch (UnmarshalException e) {
+ if (log.isDebugEnabled()) {
+ log.debug("Failed to unmarshall security layer request.", e);
+ } else {
+ log.info("Failed to unmarshall security layer request." + e.getMessage());
+ }
+ Throwable cause = e.getCause();
+ if (cause instanceof SAXParseException) {
+ throw new SLRequestException(3000,
+ SLExceptionMessages.EC3000_UNCLASSIFIED, new Object[]{cause.getMessage()});
+ } else {
+ throw new SLRequestException(3000,
+ SLExceptionMessages.EC3000_UNCLASSIFIED, new Object[]{e});
+ }
+ } catch (JAXBException e) {
+ // unexpected error
+ log.error("Failed to unmarshall security layer request.", e);
+ throw new SLRuntimeException(e);
+ } catch (XMLStreamException e) {
+ // unexpected error
+ log.error("Failed to unmarshall security layer request.", e);
+ throw new SLRuntimeException(e);
+ }
+
+ return object;
+
+ }
+
+ /**
+ * Creates a new <code>SLCommand</code> from the given <code>source</code> and
+ * <code>context</code>.
+ *
+ * @param source
+ * the <code>Source</code> to unmarshall from
+ * @param context
+ * the context for the created <code>SLCommand</code>
+ * @return the <code>SLCommand</code> unmarshalled from the given
+ * <code>source</code>
+ * @throws SLRequestException
+ * if unmarshalling fails
+ * @throws SLCommandException
+ * if command ist not supported
+ * @throws SLRuntimeException
+ * if an unexpected error occurs configuring the unmarshaller, if
+ * unmarshalling fails with an unexpected error or if the
+ * corresponding <code>SLCommand</code> could not be instantiated
+ */
+ @SuppressWarnings("unchecked")
+ public SLCommand createSLCommand(Source source, SLCommandContext context)
throws SLCommandException, SLRuntimeException, SLRequestException {
DebugReader dr = null;
@@ -338,8 +336,8 @@ public class SLCommandFactory {
dr = new DebugReader(streamSource.getReader(), "SLCommand unmarshalled from:\n");
streamSource.setReader(dr);
}
- }
-
+ }
+
Object object;
try {
object = unmarshal(source);
@@ -351,44 +349,44 @@ public class SLCommandFactory {
}
}
- if (!(object instanceof JAXBElement)) {
- // invalid request
+ if (!(object instanceof JAXBElement)) {
+ // invalid request
log.info("Invalid security layer request. " + object.toString());
- throw new SLRequestException(3002, SLExceptionMessages.EC3002_INVALID,
- new Object[]{object.toString()});
- }
-
- QName qName = ((JAXBElement) object).getName();
- Class<? extends SLCommand> implClass = getImplClass(qName);
- if (implClass == null) {
- // command not supported
- log.info("Unsupported command received: " + qName.toString());
- throw new SLCommandException(4011,
- SLExceptionMessages.EC4011_NOTIMPLEMENTED, new Object[]{qName.toString()});
- }
+ throw new SLRequestException(3002, SLExceptionMessages.EC3002_INVALID,
+ new Object[]{object.toString()});
+ }
+ QName qName = ((JAXBElement) object).getName();
+ Class<? extends SLCommand> implClass = getImplClass(qName);
+ if (implClass == null) {
+ // command not supported
+ log.info("Unsupported command received: " + qName.toString());
+ throw new SLCommandException(4011,
+ SLExceptionMessages.EC4011_NOTIMPLEMENTED, new Object[]{qName.toString()});
+ }
+
+
-
- // try to instantiate
- SLCommand slCommand;
- try {
- slCommand = implClass.newInstance();
- log.debug("SLCommand " + slCommand.getName() + " created.");
- } catch (InstantiationException e) {
- // unexpected error
- log.error("Failed to instantiate security layer command implementation.",
- e);
- throw new SLRuntimeException(e);
- } catch (IllegalAccessException e) {
- // unexpected error
- log.error("Failed to instantiate security layer command implementation.",
- e);
- throw new SLRuntimeException(e);
- }
+ // try to instantiate
+ SLCommand slCommand;
+ try {
+ slCommand = implClass.newInstance();
+ log.debug("SLCommand " + slCommand.getName() + " created.");
+ } catch (InstantiationException e) {
+ // unexpected error
+ log.error("Failed to instantiate security layer command implementation.",
+ e);
+ throw new SLRuntimeException(e);
+ } catch (IllegalAccessException e) {
+ // unexpected error
+ log.error("Failed to instantiate security layer command implementation.",
+ e);
+ throw new SLRuntimeException(e);
+ }
+
+ slCommand.init(context, (JAXBElement) object);
+
+ return slCommand;
- slCommand.init(context, (JAXBElement) object);
-
- return slCommand;
-
- }
+ }
} \ No newline at end of file
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CardChannelInfoboxImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CardChannelInfoboxImpl.java
index 4b1cc779..19b84ac7 100644
--- a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CardChannelInfoboxImpl.java
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/CardChannelInfoboxImpl.java
@@ -118,7 +118,7 @@ public class CardChannelInfoboxImpl extends AbstractBinaryFileInfobox {
ByteArrayOutputStream redirectedStream = ((at.gv.egiz.slbinding.impl.XMLContentType) content).getRedirectedStream();
if (redirectedStream != null) {
-
+
if (log.isDebugEnabled()) {
StringBuilder sb = new StringBuilder();
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/GetStatusCommandImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/GetStatusCommandImpl.java
new file mode 100644
index 00000000..46bfe18b
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/GetStatusCommandImpl.java
@@ -0,0 +1,79 @@
+/*
+ * 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.slcommands.impl;
+
+import at.buergerkarte.namespaces.securitylayer._1.GetStatusRequestType;
+import at.gv.egiz.bku.slcommands.GetStatusCommand;
+import at.gv.egiz.bku.slcommands.SLCommandContext;
+import at.gv.egiz.bku.slcommands.SLResult;
+import at.gv.egiz.bku.slexceptions.SLCommandException;
+import at.gv.egiz.bku.slexceptions.SLException;
+import at.gv.egiz.stal.ErrorResponse;
+import at.gv.egiz.stal.STAL;
+import at.gv.egiz.stal.STALResponse;
+import at.gv.egiz.stal.StatusRequest;
+import at.gv.egiz.stal.StatusResponse;
+import java.util.Collections;
+import java.util.List;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ *
+ * @author Clemens Orthacker <clemens.orthacker@iaik.tugraz.at>
+ */
+public class GetStatusCommandImpl extends SLCommandImpl<GetStatusRequestType> implements GetStatusCommand {
+
+ protected static Log log = LogFactory.getLog(GetStatusCommandImpl.class);
+
+ @Override
+ public String getName() {
+ return "GetStatusRequest";
+ }
+
+ @Override
+ public SLResult execute() {
+
+ //ignore maxDelay and TokenStatus
+// GetStatusRequestType req = getRequestValue();
+
+ log.debug("execute GetStatusRequest");
+
+ StatusRequest stalRequest = new StatusRequest();
+
+ STAL stal = cmdCtx.getSTAL();
+
+ List<STALResponse> responses = stal.handleRequest(Collections.singletonList(stalRequest));
+
+ if (responses != null && responses.size() == 1) {
+ STALResponse stalResponse = responses.get(0);
+ if (stalResponse instanceof StatusResponse) {
+ boolean ready = ((StatusResponse) stalResponse).isCardReady();
+ log.trace("received status response cardReady: " + ready);
+ return new GetStatusResultImpl(ready);
+ } else if (stalResponse instanceof ErrorResponse) {
+ log.debug("received error response");
+ SLCommandException ex = new SLCommandException(((ErrorResponse) stalResponse).getErrorCode());
+ return new ErrorResultImpl(ex, cmdCtx.getLocale());
+ }
+ }
+ log.error("received unexpected responses");
+ return new ErrorResultImpl(new SLCommandException(4000), cmdCtx.getLocale());
+
+ }
+}
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/GetStatusResultImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/GetStatusResultImpl.java
new file mode 100644
index 00000000..fddd3b0b
--- /dev/null
+++ b/bkucommon/src/main/java/at/gv/egiz/bku/slcommands/impl/GetStatusResultImpl.java
@@ -0,0 +1,52 @@
+/*
+ * 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.slcommands.impl;
+
+import at.buergerkarte.namespaces.securitylayer._1.GetStatusResponseType;
+import at.buergerkarte.namespaces.securitylayer._1.ObjectFactory;
+import at.buergerkarte.namespaces.securitylayer._1.TokenStatusType;
+import at.gv.egiz.bku.slcommands.GetStatusResult;
+import javax.xml.bind.JAXBElement;
+import javax.xml.transform.Result;
+import javax.xml.transform.Templates;
+
+/**
+ *
+ * @author Clemens Orthacker <clemens.orthacker@iaik.tugraz.at>
+ */
+public class GetStatusResultImpl extends SLResultImpl implements GetStatusResult {
+
+ protected ObjectFactory of;
+ protected GetStatusResponseType responseType;
+
+ public GetStatusResultImpl(boolean ready) {
+ of = new ObjectFactory();
+ responseType = of.createGetStatusResponseType();
+ if (ready) {
+ responseType.setTokenStatus(TokenStatusType.READY);
+ } else {
+ responseType.setTokenStatus(TokenStatusType.REMOVED);
+ }
+
+ }
+
+ @Override
+ public void writeTo(Result result, Templates templates) {
+ JAXBElement<GetStatusResponseType> response = of.createGetStatusResponse(responseType);
+ writeTo(response, result, templates);
+ }
+}
diff --git a/bkucommon/src/test/java/at/gv/egiz/bku/binding/HttpBindingProcessorTest.java b/bkucommon/src/test/java/at/gv/egiz/bku/binding/HttpBindingProcessorTest.java
index 58941401..2130e7f1 100644
--- a/bkucommon/src/test/java/at/gv/egiz/bku/binding/HttpBindingProcessorTest.java
+++ b/bkucommon/src/test/java/at/gv/egiz/bku/binding/HttpBindingProcessorTest.java
@@ -14,75 +14,75 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package at.gv.egiz.bku.binding;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.junit.Before;
+package at.gv.egiz.bku.binding;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Before;
import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
-
-import at.gv.egiz.bku.binding.MultiTestDataUrlConnection.DataSourceProvider;
-import at.gv.egiz.bku.utils.StreamUtil;
-
-public class HttpBindingProcessorTest {
-
- public static class TestDataSource implements DataSourceProvider {
-
- private List<Integer> responseCodes = new ArrayList<Integer>();
- private List<String> content = new ArrayList<String>();
- private List<Map<String, String>> responseHeaders = new ArrayList<Map<String, String>>();
- private int counter = -1;
-
- public void resetCounter() {
- counter = -1;
- }
-
- public void addResponse(int responseCode, String content,
- Map<String, String> headerMap) {
- responseCodes.add(new Integer(responseCode));
- this.content.add(content);
- this.responseHeaders.add(headerMap);
- }
-
- @Override
- public int getResponseCode() {
- return responseCodes.get(counter);
- }
-
- @Override
- public String getResponseContent() {
- return content.get(counter);
- }
-
- @Override
- public Map<String, String> getResponseHeaders() {
- return responseHeaders.get(counter);
- }
-
- @Override
- public void nextEvent() {
- if (++counter >= responseCodes.size()) {
- counter = 0;
- }
- }
- }
-
- protected BindingProcessorManager manager;
- protected HTTPBindingProcessor bindingProcessor;
- protected Map<String, String> serverHeaderMap;
- protected Map<String, String> clientHeaderMap;
- protected TestDataUrlConnection server;
+
+import at.gv.egiz.bku.binding.MultiTestDataUrlConnection.DataSourceProvider;
+import at.gv.egiz.bku.utils.StreamUtil;
+
+public class HttpBindingProcessorTest {
+
+ public static class TestDataSource implements DataSourceProvider {
+
+ private List<Integer> responseCodes = new ArrayList<Integer>();
+ private List<String> content = new ArrayList<String>();
+ private List<Map<String, String>> responseHeaders = new ArrayList<Map<String, String>>();
+ private int counter = -1;
+
+ public void resetCounter() {
+ counter = -1;
+ }
+
+ public void addResponse(int responseCode, String content,
+ Map<String, String> headerMap) {
+ responseCodes.add(new Integer(responseCode));
+ this.content.add(content);
+ this.responseHeaders.add(headerMap);
+ }
+
+ @Override
+ public int getResponseCode() {
+ return responseCodes.get(counter);
+ }
+
+ @Override
+ public String getResponseContent() {
+ return content.get(counter);
+ }
+
+ @Override
+ public Map<String, String> getResponseHeaders() {
+ return responseHeaders.get(counter);
+ }
+
+ @Override
+ public void nextEvent() {
+ if (++counter >= responseCodes.size()) {
+ counter = 0;
+ }
+ }
+ }
+
+ protected BindingProcessorManager manager;
+ protected HTTPBindingProcessor bindingProcessor;
+ protected Map<String, String> serverHeaderMap;
+ protected Map<String, String> clientHeaderMap;
+ protected TestDataUrlConnection server;
protected static ApplicationContext appCtx;
@@ -91,236 +91,236 @@ public class HttpBindingProcessorTest {
appCtx = new ClassPathXmlApplicationContext("at/gv/egiz/bku/slcommands/testApplicationContext.xml");
}
-
- @Before
- public void setUp() throws IOException {
- server = new TestDataUrlConnection();
- DataUrl.setDataUrlConnectionClass(server);
- serverHeaderMap = new HashMap<String, String>();
- serverHeaderMap.put("Content-Type", HttpUtil.TXT_XML);
- server.setResponseCode(200);
- server.setResponseContent("<ok/>");
- server.setResponseHeaders(serverHeaderMap);
- manager = new BindingProcessorManagerImpl(new DummyStalFactory(),
- new SLCommandInvokerImpl());
- bindingProcessor = (HTTPBindingProcessor) manager.createBindingProcessor(
- "http://www.iaik.at", null);
- clientHeaderMap = new HashMap<String, String>();
- clientHeaderMap.put("Content-Type",
- "application/x-www-form-urlencoded;charset=utf8");
- bindingProcessor.setHTTPHeaders(clientHeaderMap);
- }
-
- protected String resultAsString(String encoding) throws IOException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- bindingProcessor.writeResultTo(baos, encoding);
- return new String(baos.toByteArray(), encoding);
- }
-
- @Test
- public void testWithoutDataUrlWithoutStylesheet() throws IOException {
- RequestFactory rf = new RequestFactory();
- rf.addForm("Haßnsi", "Wüurzel");
- bindingProcessor.consumeRequestStream(rf.getURLencoded());
- bindingProcessor.run();
- assertEquals(HttpUtil.TXT_XML, bindingProcessor.getResultContentType());
- assertTrue(resultAsString("UTF-8").indexOf("NullOperationResponse") != -1);
- assertEquals(200, bindingProcessor.getResponseCode());
- assertEquals(0, bindingProcessor.getResponseHeaders().size());
- }
-
- @Test
- public void testWithoutDataUrlWithStylesheet() throws IOException {
- RequestFactory rf = new RequestFactory();
- rf.addForm("Hansi", "Wurzel");
- rf.addFormAsResource("Styleshit", "at/gv/egiz/bku/binding/stylesheet.xslt");
- rf.addForm(RequestFactory.STYLESHEETURL, "formdata:Styleshit");
- bindingProcessor.consumeRequestStream(rf.getURLencoded());
- bindingProcessor.run();
- assertEquals(HttpUtil.TXT_HTML, bindingProcessor.getResultContentType());
- assertTrue(resultAsString("UTF-8").indexOf("NullKommaJosef") != -1);
- assertEquals(200, bindingProcessor.getResponseCode());
- assertEquals(0, bindingProcessor.getResponseHeaders().size());
- }
-
- @Test
- public void testWithDataUrl301WithStylesheet() throws IOException {
- RequestFactory rf = new RequestFactory();
- rf.addForm(RequestFactory.DATAURL, "http://localhost:8080");
- bindingProcessor.consumeRequestStream(rf.getURLencoded());
- server.setResponseCode(301);
- rf = new RequestFactory();
- rf.addFormAsResource("Styleshit", "at/gv/egiz/bku/binding/stylesheet.xslt");
- rf.addForm(RequestFactory.STYLESHEETURL, "formdata:Styleshit");
- server.setResponseContent(rf.getURLencodedAsString());
- bindingProcessor.run();
- assertEquals(HttpUtil.TXT_XML, bindingProcessor.getResultContentType());
- assertTrue(resultAsString("UTF-8").indexOf("NullOperationRequest") != -1);
- assertEquals(301, bindingProcessor.getResponseCode());
- assertTrue(bindingProcessor.getResponseHeaders().size() > 0);
- }
-
- @Test
- public void testWithDataUrl302WithStylesheet() throws IOException {
- RequestFactory rf = new RequestFactory();
- rf.addForm(RequestFactory.DATAURL, "http://localhost:8080");
- bindingProcessor.consumeRequestStream(rf.getURLencoded());
- server.setResponseCode(302);
- rf = new RequestFactory();
- rf.addFormAsResource("Styleshit", "at/gv/egiz/bku/binding/stylesheet.xslt");
- rf.addForm(RequestFactory.STYLESHEETURL, "formdata:Styleshit");
- server.setResponseContent(rf.getURLencodedAsString());
- bindingProcessor.run();
- assertEquals(HttpUtil.TXT_XML, bindingProcessor.getResultContentType());
- assertTrue(resultAsString("UTF-8").indexOf("NullOperationRequest") != -1);
- assertEquals(302, bindingProcessor.getResponseCode());
- assertTrue(bindingProcessor.getResponseHeaders().size() > 0);
- }
-
- @Test
- public void testWithDataUrl303WithStylesheet() throws IOException {
- RequestFactory rf = new RequestFactory();
- rf.addForm(RequestFactory.DATAURL, "http://localhost:8080");
- bindingProcessor.consumeRequestStream(rf.getURLencoded());
- server.setResponseCode(303);
- rf = new RequestFactory();
- rf.addFormAsResource("Styleshit", "at/gv/egiz/bku/binding/stylesheet.xslt");
- rf.addForm(RequestFactory.STYLESHEETURL, "formdata:Styleshit");
- server.setResponseContent(rf.getURLencodedAsString());
- bindingProcessor.run();
- assertEquals(HttpUtil.TXT_XML, bindingProcessor.getResultContentType());
- assertTrue(resultAsString("UTF-8").indexOf("NullOperationRequest") != -1);
- assertEquals(303, bindingProcessor.getResponseCode());
- assertTrue(bindingProcessor.getResponseHeaders().size() > 0);
- }
-
- @Test
- public void testWithDataUrl306WithStylesheet() throws IOException {
- RequestFactory rf = new RequestFactory();
- rf.addForm(RequestFactory.DATAURL, "http://localhost:8080");
- bindingProcessor.consumeRequestStream(rf.getURLencoded());
- server.setResponseCode(306);
- rf = new RequestFactory();
- rf.addFormAsResource("Styleshit", "at/gv/egiz/bku/binding/stylesheet.xslt");
- rf.addForm(RequestFactory.STYLESHEETURL, "formdata:Styleshit");
- server.setResponseContent(rf.getURLencodedAsString());
- bindingProcessor.run();
- assertEquals(HttpUtil.TXT_XML, bindingProcessor.getResultContentType());
- assertTrue(resultAsString("UTF-8").indexOf("ErrorResponse") != -1);
- assertEquals(200, bindingProcessor.getResponseCode());
- assertTrue(bindingProcessor.getResponseHeaders().size() == 0);
- }
-
- @Test
- public void testWithDataUrl307NonXML() throws IOException {
- RequestFactory rf = new RequestFactory();
- rf.addForm(RequestFactory.DATAURL, "http://localhost:8080");
- bindingProcessor.consumeRequestStream(rf.getURLencoded());
- server.setResponseCode(307);
- serverHeaderMap.put("Content-Type", HttpUtil.TXT_PLAIN);
- server.setResponseHeaders(serverHeaderMap);
- rf = new RequestFactory();
- rf.addFormAsResource("Styleshit", "at/gv/egiz/bku/binding/stylesheet.xslt");
- rf.addForm(RequestFactory.STYLESHEETURL, "formdata:Styleshit");
- server.setResponseContent(rf.getURLencodedAsString());
- bindingProcessor.run();
- assertEquals(HttpUtil.TXT_PLAIN, bindingProcessor.getResultContentType());
- assertTrue(resultAsString("UTF-8").indexOf("NullOperationRequest") != -1);
- assertEquals(307, bindingProcessor.getResponseCode());
- assertTrue(bindingProcessor.getResponseHeaders().size() > 0);
- }
-
- @Test
- public void testWithInvalidDataUrl307XML() throws IOException {
- RequestFactory rf = new RequestFactory();
- rf.addForm(RequestFactory.DATAURL, "http://localhost:8080");
- bindingProcessor.consumeRequestStream(rf.getURLencoded());
- server.setResponseCode(307);
- serverHeaderMap.put("Content-Type", HttpUtil.TXT_XML);
- serverHeaderMap.put("Location", "noUrl");
- server.setResponseHeaders(serverHeaderMap);
- rf = new RequestFactory();
- server.setResponseContent(rf.getNullOperationXML());
- bindingProcessor.run();
- assertEquals(HttpUtil.TXT_XML, bindingProcessor.getResultContentType());
- assertTrue(resultAsString("UTF-8").indexOf("ErrorResponse") != -1);
- assertEquals(200, bindingProcessor.getResponseCode());
- assertTrue(bindingProcessor.getResponseHeaders().size() == 0);
- }
-
- @Test
- public void testWithValidDataUrl307XML() throws IOException, InterruptedException {
- server = new MultiTestDataUrlConnection();
- DataUrl.setDataUrlConnectionClass(server);
- TestDataSource tds = new TestDataSource();
- ((MultiTestDataUrlConnection)server).setDataSource(tds);
-
- // first server response with 307 xml and location
- RequestFactory rf = new RequestFactory();
- serverHeaderMap = new HashMap<String, String>();
- serverHeaderMap.put("Location", "http://localhost:8080");
- serverHeaderMap.put("Content-Type", HttpUtil.TXT_XML);
- tds.addResponse(307, rf.getNullOperationXML(), serverHeaderMap);
-
- // 2nd response with 200 text/plain and != <ok/>
- String testString = "CheckMe";
- serverHeaderMap = new HashMap<String, String>();
- serverHeaderMap.put("Content-Type", HttpUtil.TXT_PLAIN);
- String testHeader ="DummyHeader";
- String testHeaderVal ="DummyHeaderVal";
- serverHeaderMap.put(testHeader, testHeaderVal);
- tds.addResponse(200, testString, serverHeaderMap);
-
- rf = new RequestFactory();
- rf.addForm(RequestFactory.DATAURL, "http://localhost:8080");
- bindingProcessor.consumeRequestStream(rf.getURLencoded());
- bindingProcessor.run();
-
- assertTrue(bindingProcessor.getResponseHeaders().size()>0);
- assertEquals(testHeaderVal, bindingProcessor.getResponseHeaders().get(testHeader));
- assertEquals(200,bindingProcessor.getResponseCode());
- assertEquals(HttpUtil.TXT_PLAIN, bindingProcessor.getResultContentType());
- assertEquals(testString ,resultAsString("UTF-8"));
- }
-
- @Test
- public void testWithValidDataUrl200Urlencoded() throws IOException {
- RequestFactory rf = new RequestFactory();
- rf = new RequestFactory();
- rf.addForm(RequestFactory.DATAURL, "http://localhost:8080");
- bindingProcessor.consumeRequestStream(rf.getURLencoded());
- server.setResponseCode(200);
- rf = new RequestFactory();
- rf.addFormAsResource("Styleshit", "at/gv/egiz/bku/binding/stylesheet.xslt");
- serverHeaderMap.put("Content-Type", HttpUtil.APPLICATION_URL_ENCODED);
- server.setResponseHeaders(serverHeaderMap);
- server.setResponseContent(rf.getURLencodedAsString());
- bindingProcessor.run();
- assertTrue(bindingProcessor.getResponseHeaders().size()==0);
- assertEquals(200,bindingProcessor.getResponseCode());
- assertEquals(HttpUtil.TXT_XML, bindingProcessor.getResultContentType());
- assertTrue(resultAsString("UTF-8").indexOf("NullOperationResponse") != -1);
- }
-
- @Test
- public void testWithValidDataUrl200UrlencodedAndStylesheet() throws IOException {
- RequestFactory rf = new RequestFactory();
- rf = new RequestFactory();
- rf.addForm(RequestFactory.DATAURL, "http://localhost:8080");
- bindingProcessor.consumeRequestStream(rf.getURLencoded());
- server.setResponseCode(200);
- rf = new RequestFactory();
- rf.addFormAsResource("Styleshit", "at/gv/egiz/bku/binding/stylesheet.xslt");
- rf.addForm(RequestFactory.STYLESHEETURL, "formdata:Styleshit");
- serverHeaderMap.put("Content-Type", HttpUtil.APPLICATION_URL_ENCODED);
- server.setResponseHeaders(serverHeaderMap);
- server.setResponseContent(rf.getURLencodedAsString());
- bindingProcessor.run();
- assertTrue(bindingProcessor.getResponseHeaders().size()==0);
- assertEquals(200,bindingProcessor.getResponseCode());
- assertEquals(HttpUtil.TXT_HTML, bindingProcessor.getResultContentType());
- assertTrue(resultAsString("UTF-8").indexOf("NullKommaJosef") != -1);
- }
-
-
-}
+
+ @Before
+ public void setUp() throws IOException {
+ server = new TestDataUrlConnection();
+ DataUrl.setDataUrlConnectionImpl(server);
+ serverHeaderMap = new HashMap<String, String>();
+ serverHeaderMap.put("Content-Type", HttpUtil.TXT_XML);
+ server.setResponseCode(200);
+ server.setResponseContent("<ok/>");
+ server.setResponseHeaders(serverHeaderMap);
+ manager = new BindingProcessorManagerImpl(new DummyStalFactory(),
+ new SLCommandInvokerImpl());
+ bindingProcessor = (HTTPBindingProcessor) manager.createBindingProcessor(
+ "http://www.iaik.at", null);
+ clientHeaderMap = new HashMap<String, String>();
+ clientHeaderMap.put("Content-Type",
+ "application/x-www-form-urlencoded;charset=utf8");
+ bindingProcessor.setHTTPHeaders(clientHeaderMap);
+ }
+
+ protected String resultAsString(String encoding) throws IOException {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ bindingProcessor.writeResultTo(baos, encoding);
+ return new String(baos.toByteArray(), encoding);
+ }
+
+ @Test
+ public void testWithoutDataUrlWithoutStylesheet() throws IOException {
+ RequestFactory rf = new RequestFactory();
+ rf.addForm("Haßnsi", "Wüurzel");
+ bindingProcessor.consumeRequestStream(rf.getURLencoded());
+ bindingProcessor.run();
+ assertEquals(HttpUtil.TXT_XML, bindingProcessor.getResultContentType());
+ assertTrue(resultAsString("UTF-8").indexOf("NullOperationResponse") != -1);
+ assertEquals(200, bindingProcessor.getResponseCode());
+ assertEquals(0, bindingProcessor.getResponseHeaders().size());
+ }
+
+ @Test
+ public void testWithoutDataUrlWithStylesheet() throws IOException {
+ RequestFactory rf = new RequestFactory();
+ rf.addForm("Hansi", "Wurzel");
+ rf.addFormAsResource("Styleshit", "at/gv/egiz/bku/binding/stylesheet.xslt");
+ rf.addForm(RequestFactory.STYLESHEETURL, "formdata:Styleshit");
+ bindingProcessor.consumeRequestStream(rf.getURLencoded());
+ bindingProcessor.run();
+ assertEquals(HttpUtil.TXT_HTML, bindingProcessor.getResultContentType());
+ assertTrue(resultAsString("UTF-8").indexOf("NullKommaJosef") != -1);
+ assertEquals(200, bindingProcessor.getResponseCode());
+ assertEquals(0, bindingProcessor.getResponseHeaders().size());
+ }
+
+ @Test
+ public void testWithDataUrl301WithStylesheet() throws IOException {
+ RequestFactory rf = new RequestFactory();
+ rf.addForm(RequestFactory.DATAURL, "http://localhost:8080");
+ bindingProcessor.consumeRequestStream(rf.getURLencoded());
+ server.setResponseCode(301);
+ rf = new RequestFactory();
+ rf.addFormAsResource("Styleshit", "at/gv/egiz/bku/binding/stylesheet.xslt");
+ rf.addForm(RequestFactory.STYLESHEETURL, "formdata:Styleshit");
+ server.setResponseContent(rf.getURLencodedAsString());
+ bindingProcessor.run();
+ assertEquals(HttpUtil.TXT_XML, bindingProcessor.getResultContentType());
+ assertTrue(resultAsString("UTF-8").indexOf("NullOperationRequest") != -1);
+ assertEquals(301, bindingProcessor.getResponseCode());
+ assertTrue(bindingProcessor.getResponseHeaders().size() > 0);
+ }
+
+ @Test
+ public void testWithDataUrl302WithStylesheet() throws IOException {
+ RequestFactory rf = new RequestFactory();
+ rf.addForm(RequestFactory.DATAURL, "http://localhost:8080");
+ bindingProcessor.consumeRequestStream(rf.getURLencoded());
+ server.setResponseCode(302);
+ rf = new RequestFactory();
+ rf.addFormAsResource("Styleshit", "at/gv/egiz/bku/binding/stylesheet.xslt");
+ rf.addForm(RequestFactory.STYLESHEETURL, "formdata:Styleshit");
+ server.setResponseContent(rf.getURLencodedAsString());
+ bindingProcessor.run();
+ assertEquals(HttpUtil.TXT_XML, bindingProcessor.getResultContentType());
+ assertTrue(resultAsString("UTF-8").indexOf("NullOperationRequest") != -1);
+ assertEquals(302, bindingProcessor.getResponseCode());
+ assertTrue(bindingProcessor.getResponseHeaders().size() > 0);
+ }
+
+ @Test
+ public void testWithDataUrl303WithStylesheet() throws IOException {
+ RequestFactory rf = new RequestFactory();
+ rf.addForm(RequestFactory.DATAURL, "http://localhost:8080");
+ bindingProcessor.consumeRequestStream(rf.getURLencoded());
+ server.setResponseCode(303);
+ rf = new RequestFactory();
+ rf.addFormAsResource("Styleshit", "at/gv/egiz/bku/binding/stylesheet.xslt");
+ rf.addForm(RequestFactory.STYLESHEETURL, "formdata:Styleshit");
+ server.setResponseContent(rf.getURLencodedAsString());
+ bindingProcessor.run();
+ assertEquals(HttpUtil.TXT_XML, bindingProcessor.getResultContentType());
+ assertTrue(resultAsString("UTF-8").indexOf("NullOperationRequest") != -1);
+ assertEquals(303, bindingProcessor.getResponseCode());
+ assertTrue(bindingProcessor.getResponseHeaders().size() > 0);
+ }
+
+ @Test
+ public void testWithDataUrl306WithStylesheet() throws IOException {
+ RequestFactory rf = new RequestFactory();
+ rf.addForm(RequestFactory.DATAURL, "http://localhost:8080");
+ bindingProcessor.consumeRequestStream(rf.getURLencoded());
+ server.setResponseCode(306);
+ rf = new RequestFactory();
+ rf.addFormAsResource("Styleshit", "at/gv/egiz/bku/binding/stylesheet.xslt");
+ rf.addForm(RequestFactory.STYLESHEETURL, "formdata:Styleshit");
+ server.setResponseContent(rf.getURLencodedAsString());
+ bindingProcessor.run();
+ assertEquals(HttpUtil.TXT_XML, bindingProcessor.getResultContentType());
+ assertTrue(resultAsString("UTF-8").indexOf("ErrorResponse") != -1);
+ assertEquals(200, bindingProcessor.getResponseCode());
+ assertTrue(bindingProcessor.getResponseHeaders().size() == 0);
+ }
+
+ @Test
+ public void testWithDataUrl307NonXML() throws IOException {
+ RequestFactory rf = new RequestFactory();
+ rf.addForm(RequestFactory.DATAURL, "http://localhost:8080");
+ bindingProcessor.consumeRequestStream(rf.getURLencoded());
+ server.setResponseCode(307);
+ serverHeaderMap.put("Content-Type", HttpUtil.TXT_PLAIN);
+ server.setResponseHeaders(serverHeaderMap);
+ rf = new RequestFactory();
+ rf.addFormAsResource("Styleshit", "at/gv/egiz/bku/binding/stylesheet.xslt");
+ rf.addForm(RequestFactory.STYLESHEETURL, "formdata:Styleshit");
+ server.setResponseContent(rf.getURLencodedAsString());
+ bindingProcessor.run();
+ assertEquals(HttpUtil.TXT_PLAIN, bindingProcessor.getResultContentType());
+ assertTrue(resultAsString("UTF-8").indexOf("NullOperationRequest") != -1);
+ assertEquals(307, bindingProcessor.getResponseCode());
+ assertTrue(bindingProcessor.getResponseHeaders().size() > 0);
+ }
+
+ @Test
+ public void testWithInvalidDataUrl307XML() throws IOException {
+ RequestFactory rf = new RequestFactory();
+ rf.addForm(RequestFactory.DATAURL, "http://localhost:8080");
+ bindingProcessor.consumeRequestStream(rf.getURLencoded());
+ server.setResponseCode(307);
+ serverHeaderMap.put("Content-Type", HttpUtil.TXT_XML);
+ serverHeaderMap.put("Location", "noUrl");
+ server.setResponseHeaders(serverHeaderMap);
+ rf = new RequestFactory();
+ server.setResponseContent(rf.getNullOperationXML());
+ bindingProcessor.run();
+ assertEquals(HttpUtil.TXT_XML, bindingProcessor.getResultContentType());
+ assertTrue(resultAsString("UTF-8").indexOf("ErrorResponse") != -1);
+ assertEquals(200, bindingProcessor.getResponseCode());
+ assertTrue(bindingProcessor.getResponseHeaders().size() == 0);
+ }
+
+ @Test
+ public void testWithValidDataUrl307XML() throws IOException, InterruptedException {
+ server = new MultiTestDataUrlConnection();
+ DataUrl.setDataUrlConnectionImpl(server);
+ TestDataSource tds = new TestDataSource();
+ ((MultiTestDataUrlConnection)server).setDataSource(tds);
+
+ // first server response with 307 xml and location
+ RequestFactory rf = new RequestFactory();
+ serverHeaderMap = new HashMap<String, String>();
+ serverHeaderMap.put("Location", "http://localhost:8080");
+ serverHeaderMap.put("Content-Type", HttpUtil.TXT_XML);
+ tds.addResponse(307, rf.getNullOperationXML(), serverHeaderMap);
+
+ // 2nd response with 200 text/plain and != <ok/>
+ String testString = "CheckMe";
+ serverHeaderMap = new HashMap<String, String>();
+ serverHeaderMap.put("Content-Type", HttpUtil.TXT_PLAIN);
+ String testHeader ="DummyHeader";
+ String testHeaderVal ="DummyHeaderVal";
+ serverHeaderMap.put(testHeader, testHeaderVal);
+ tds.addResponse(200, testString, serverHeaderMap);
+
+ rf = new RequestFactory();
+ rf.addForm(RequestFactory.DATAURL, "http://localhost:8080");
+ bindingProcessor.consumeRequestStream(rf.getURLencoded());
+ bindingProcessor.run();
+
+ assertTrue(bindingProcessor.getResponseHeaders().size()>0);
+ assertEquals(testHeaderVal, bindingProcessor.getResponseHeaders().get(testHeader));
+ assertEquals(200,bindingProcessor.getResponseCode());
+ assertEquals(HttpUtil.TXT_PLAIN, bindingProcessor.getResultContentType());
+ assertEquals(testString ,resultAsString("UTF-8"));
+ }
+
+ @Test
+ public void testWithValidDataUrl200Urlencoded() throws IOException {
+ RequestFactory rf = new RequestFactory();
+ rf = new RequestFactory();
+ rf.addForm(RequestFactory.DATAURL, "http://localhost:8080");
+ bindingProcessor.consumeRequestStream(rf.getURLencoded());
+ server.setResponseCode(200);
+ rf = new RequestFactory();
+ rf.addFormAsResource("Styleshit", "at/gv/egiz/bku/binding/stylesheet.xslt");
+ serverHeaderMap.put("Content-Type", HttpUtil.APPLICATION_URL_ENCODED);
+ server.setResponseHeaders(serverHeaderMap);
+ server.setResponseContent(rf.getURLencodedAsString());
+ bindingProcessor.run();
+ assertTrue(bindingProcessor.getResponseHeaders().size()==0);
+ assertEquals(200,bindingProcessor.getResponseCode());
+ assertEquals(HttpUtil.TXT_XML, bindingProcessor.getResultContentType());
+ assertTrue(resultAsString("UTF-8").indexOf("NullOperationResponse") != -1);
+ }
+
+ @Test
+ public void testWithValidDataUrl200UrlencodedAndStylesheet() throws IOException {
+ RequestFactory rf = new RequestFactory();
+ rf = new RequestFactory();
+ rf.addForm(RequestFactory.DATAURL, "http://localhost:8080");
+ bindingProcessor.consumeRequestStream(rf.getURLencoded());
+ server.setResponseCode(200);
+ rf = new RequestFactory();
+ rf.addFormAsResource("Styleshit", "at/gv/egiz/bku/binding/stylesheet.xslt");
+ rf.addForm(RequestFactory.STYLESHEETURL, "formdata:Styleshit");
+ serverHeaderMap.put("Content-Type", HttpUtil.APPLICATION_URL_ENCODED);
+ server.setResponseHeaders(serverHeaderMap);
+ server.setResponseContent(rf.getURLencodedAsString());
+ bindingProcessor.run();
+ assertTrue(bindingProcessor.getResponseHeaders().size()==0);
+ assertEquals(200,bindingProcessor.getResponseCode());
+ assertEquals(HttpUtil.TXT_HTML, bindingProcessor.getResultContentType());
+ assertTrue(resultAsString("UTF-8").indexOf("NullKommaJosef") != -1);
+ }
+
+
+}