diff options
Diffstat (limited to 'bkucommon/src/main/java')
6 files changed, 244 insertions, 136 deletions
diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/AbstractBindingProcessor.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/AbstractBindingProcessor.java index 17ce29ce..23f62134 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/AbstractBindingProcessor.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/AbstractBindingProcessor.java @@ -14,73 +14,76 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package at.gv.egiz.bku.binding;
-
-import java.io.InputStream;
-import java.util.Date;
-
-import at.gv.egiz.bku.slcommands.SLCommandInvoker;
-import at.gv.egiz.stal.STAL;
-
-public abstract class AbstractBindingProcessor implements BindingProcessor {
- protected Id id;
- protected STAL stal;
- protected SLCommandInvoker commandInvoker;
- protected long lastAccessedTime = System.currentTimeMillis();
-
- public AbstractBindingProcessor(String idString) {
- this.id = IdFactory.getInstance().createId(idString);
- }
-
- /**
- * @see java.lang.Thread#run()
- */
- public abstract void run();
-
- /**
- * The caller is advised to check the result in case an error occurred.
- *
- * @see #getResult()
- */
- public abstract void consumeRequestStream(InputStream aIs);
-
- public Id getId() {
- return id;
- }
-
- public STAL getSTAL() {
- return stal;
- }
-
- public SLCommandInvoker getCommandInvoker() {
- return commandInvoker;
- }
-
- public void updateLastAccessTime() {
- lastAccessedTime = System.currentTimeMillis();
- }
-
- public Date getLastAccessTime() {
- return new Date(lastAccessedTime);
- }
-
- /**
- * To be called after object creation.
- *
- * @param aStal
- * must not be null
- * @param aCommandInvoker
- * must not be null
- */
- public void init(STAL aStal, SLCommandInvoker aCommandInvoker) {
- if (aStal == null) {
- throw new NullPointerException("STAL must not be set to null");
- }
- if (aCommandInvoker == null) {
- throw new NullPointerException("Commandinvoker must not be set to null");
- }
- stal = aStal;
- commandInvoker = aCommandInvoker;
- Thread.currentThread().setName("BPID#"+getId().toString());
- }
+package at.gv.egiz.bku.binding; + +import at.gv.egiz.bku.conf.Configuration; +import java.io.InputStream; +import java.util.Date; + +import at.gv.egiz.bku.slcommands.SLCommandInvoker; +import at.gv.egiz.stal.STAL; + +public abstract class AbstractBindingProcessor implements BindingProcessor { + protected Id id; + protected Configuration config; + protected STAL stal; + protected SLCommandInvoker commandInvoker; + protected long lastAccessedTime = System.currentTimeMillis(); + + public AbstractBindingProcessor(String idString) { + this.id = IdFactory.getInstance().createId(idString); + } + + /** + * @see java.lang.Thread#run() + */ + public abstract void run(); + + /** + * The caller is advised to check the result in case an error occurred. + * + * @see #getResult() + */ + public abstract void consumeRequestStream(InputStream aIs); + + public Id getId() { + return id; + } + + public STAL getSTAL() { + return stal; + } + + public SLCommandInvoker getCommandInvoker() { + return commandInvoker; + } + + public void updateLastAccessTime() { + lastAccessedTime = System.currentTimeMillis(); + } + + public Date getLastAccessTime() { + return new Date(lastAccessedTime); + } + + /** + * To be called after object creation. + * + * @param aStal + * must not be null + * @param aCommandInvoker + * must not be null + */ + public void init(STAL aStal, SLCommandInvoker aCommandInvoker, Configuration conf) { + if (aStal == null) { + throw new NullPointerException("STAL must not be set to null"); + } + if (aCommandInvoker == null) { + throw new NullPointerException("Commandinvoker must not be set to null"); + } + config = conf; + stal = aStal; + commandInvoker = aCommandInvoker; + Thread.currentThread().setName("BPID#"+getId().toString()); + } }
\ No newline at end of file diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessor.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessor.java index 2569bf85..0d978992 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessor.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessor.java @@ -14,64 +14,65 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package at.gv.egiz.bku.binding;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Date;
-import java.util.Locale;
-
-import at.gv.egiz.bku.slcommands.SLCommandInvoker;
-import at.gv.egiz.stal.STAL;
-
-/**
- * Represents an single instance of a SL HTTP binding.
- *
- * @author wbauer
- *
- */
-public interface BindingProcessor extends Runnable {
-
- /**
- * The stream must be read completely within this method.
- *
- * The caller is advised to check the result in case an error occurred.
- *
- * @see #getResult()
- */
- public void consumeRequestStream(InputStream aIs);
-
- /**
- * The unique Id of this http binding instance.
- * @return
- */
- public Id getId();
-
- /**
- * The used underlying STAL instance
- * @return
- */
- public STAL getSTAL();
-
- public SLCommandInvoker getCommandInvoker();
-
- public Date getLastAccessTime();
-
- public void updateLastAccessTime();
-
- public String getResultContentType();
-
- public void writeResultTo(OutputStream os, String encoding) throws IOException;
-
- public void init(STAL aStal, SLCommandInvoker aCommandInvoker);
-
- /**
- * Sets the preferred locale for userinteraction.
- * If the locale is not set the default locale will be used.
- * @param locale must not be null.
- */
+package at.gv.egiz.bku.binding; + +import at.gv.egiz.bku.conf.Configuration; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Date; +import java.util.Locale; + +import at.gv.egiz.bku.slcommands.SLCommandInvoker; +import at.gv.egiz.stal.STAL; + +/** + * Represents an single instance of a SL HTTP binding. + * + * @author wbauer + * + */ +public interface BindingProcessor extends Runnable { + + /** + * The stream must be read completely within this method. + * + * The caller is advised to check the result in case an error occurred. + * + * @see #getResult() + */ + public void consumeRequestStream(InputStream aIs); + + /** + * The unique Id of this http binding instance. + * @return + */ + public Id getId(); + + /** + * The used underlying STAL instance + * @return + */ + public STAL getSTAL(); + + public SLCommandInvoker getCommandInvoker(); + + public Date getLastAccessTime(); + + public void updateLastAccessTime(); + + public String getResultContentType(); + + public void writeResultTo(OutputStream os, String encoding) throws IOException; + + public void init(STAL aStal, SLCommandInvoker aCommandInvoker, Configuration config); + + /** + * Sets the preferred locale for userinteraction. + * If the locale is not set the default locale will be used. + * @param locale must not be null. + */ public void setLocale(Locale locale); - public boolean isFinished();
+ public boolean isFinished(); }
\ No newline at end of file diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessorManagerImpl.java b/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessorManagerImpl.java index 144416ed..bf9a63e2 100644 --- a/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessorManagerImpl.java +++ b/bkucommon/src/main/java/at/gv/egiz/bku/binding/BindingProcessorManagerImpl.java @@ -16,6 +16,7 @@ */ package at.gv.egiz.bku.binding; +import at.gv.egiz.bku.conf.Configuration; import java.net.MalformedURLException; import java.net.URL; import java.util.Collections; @@ -49,6 +50,10 @@ public class BindingProcessorManagerImpl implements BindingProcessorManager { private static Log log = LogFactory.getLog(BindingProcessorManagerImpl.class); + /** spring injected config + * Passed to created bindingprocessors, to replace their configuration */ + protected Configuration config; + protected STALFactory stalFactory; protected SLCommandInvoker commandInvokerClass; @@ -105,7 +110,7 @@ public class BindingProcessorManagerImpl implements BindingProcessorManager { * @param ci * must not be null (prototype to generate new instances) */ - public BindingProcessorManagerImpl(STALFactory fab, SLCommandInvoker ci) { + public BindingProcessorManagerImpl(STALFactory fab, SLCommandInvoker ci, Configuration conf) { if (fab == null) { throw new NullPointerException("STALFactory must not be null"); } @@ -114,6 +119,7 @@ public class BindingProcessorManagerImpl implements BindingProcessorManager { throw new NullPointerException("SLCommandInvoker must not be null"); } commandInvokerClass = ci; + config = conf; executorService = Executors.newCachedThreadPool(); } @@ -213,7 +219,7 @@ public class BindingProcessorManagerImpl implements BindingProcessorManager { commandInvokerClass.newInstance(), url); stalFactory.setLocale(locale); STAL stal = stalFactory.createSTAL(); - bindingProcessor.init(stal, commandInvokerClass.newInstance()); + bindingProcessor.init(stal, commandInvokerClass.newInstance(), config); if (locale != null) { bindingProcessor.setLocale(locale); // stal.setLocale(locale); 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 aaeacd98..1db8c836 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 @@ -16,6 +16,7 @@ */ package at.gv.egiz.bku.binding; +import at.gv.egiz.bku.conf.Configuration; import at.gv.egiz.bku.conf.Configurator; import java.net.MalformedURLException; import java.net.URL; @@ -42,6 +43,9 @@ public class DataUrl { private static HostnameVerifier hostNameVerifier; private URL url; + /** spring injected config, to replace configuration */ + //private Configuration config; + /** * Sets the default DataUrlConnection implementation * @param aClass must not be null 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 cb11a3e6..ef603fc7 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 @@ -87,12 +87,6 @@ public class HTTPBindingProcessor extends AbstractBindingProcessor implements public final static Collection<String> XML_REQ_TRANSFER_ENCODING = Arrays .asList(new String[] { "binary" }); - /** - * Defines the maximum number of dataurl connects that are allowed within a - * single SL Request processing. - */ - protected static int MAX_DATAURL_HOPS = 80; - protected static String XML_MIME_TYPE = "text/xml"; protected static String BINARY_MIME_TYPE = "application/octet-stream"; @@ -592,7 +586,7 @@ public class HTTPBindingProcessor extends AbstractBindingProcessor implements break; case DATAURL: handleDataUrl(); - if (++hopcounter > MAX_DATAURL_HOPS) { + if (++hopcounter > config.getMaxDataUrlHops()) { log.error("Maximum number of dataurl hops reached"); bindingProcessorError = new SLBindingException(2000); currentState = State.FINISHED; diff --git a/bkucommon/src/main/java/at/gv/egiz/bku/conf/Configuration.java b/bkucommon/src/main/java/at/gv/egiz/bku/conf/Configuration.java new file mode 100644 index 00000000..f813b14d --- /dev/null +++ b/bkucommon/src/main/java/at/gv/egiz/bku/conf/Configuration.java @@ -0,0 +1,100 @@ +/* + * 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.conf; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * BKU Common Configuration + * + * Injected to BKU Common classes as defined in mocca-conf.xml + * + * Replace at.gv.egiz.bku.conf.Configurator, + * currently only few configuration options are supported. + * + * @author Clemens Orthacker <clemens.orthacker@iaik.tugraz.at> + */ +public class Configuration { + + public static final int MAX_DATAURL_HOPS_DEFAULT = 50; + public static final String IMPLEMENTATION_NAME_DEFAULT = "MOCCA"; + public static final String IMPLEMENTATION_VERSION_DEFAULT = "UNKNOWN"; + + private static final Log log = LogFactory.getLog(Configuration.class); + + private int maxDataUrlHops = -1; + private String implementationName; + private String implementationVersion; + + public void setMaxDataUrlHops(int maxDataUrlHops) { + this.maxDataUrlHops = maxDataUrlHops; + } + + /** + * Defines the maximum number of dataurl connects that are allowed within a + * single SL Request processing. + */ + public int getMaxDataUrlHops() { + if (maxDataUrlHops < 0) { + log.warn("maxDataUrlHops not configured, using default: " + MAX_DATAURL_HOPS_DEFAULT); + return MAX_DATAURL_HOPS_DEFAULT; + } + return maxDataUrlHops; + } + + /** + * @return the implementationName + */ + public String getImplementationName() { + if (implementationName == null) { + log.info("implementationName not configured, using default: " + IMPLEMENTATION_NAME_DEFAULT); + return "MOCCA"; + } + return implementationName; + } + + /** + * @param implementationName the implementationName to set + */ + public void setImplementationName(String implementationName) { + this.implementationName = implementationName; + } + + /** + * @return the implementationVersion + */ + public String getImplementationVersion() { + if (implementationName == null) { + log.info("implementationName not configured, using default: " + IMPLEMENTATION_VERSION_DEFAULT); + return IMPLEMENTATION_VERSION_DEFAULT; + } + return implementationVersion; + } + + /** + * @param implementationVersion the implementationVersion to set + */ + public void setImplementationVersion(String implementationVersion) { + this.implementationVersion = implementationVersion; + } + + + + +} |