diff options
author | Thomas Lenz <thomas.lenz@egiz.gv.at> | 2021-03-24 11:08:57 +0000 |
---|---|---|
committer | Thomas Lenz <thomas.lenz@egiz.gv.at> | 2021-03-24 11:08:57 +0000 |
commit | 666d8c9f8cec7573e60a14ab039c0874f6a9ec53 (patch) | |
tree | d9b2506506cf544ea3758322fd5488c913073427 /moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/transaction | |
parent | d003a873fdeec22b1dd57d61590a12a1691ae137 (diff) | |
parent | cd65b47cc30e7119593bbb05afa48d4f896a4859 (diff) | |
download | moa-sig-666d8c9f8cec7573e60a14ab039c0874f6a9ec53.tar.gz moa-sig-666d8c9f8cec7573e60a14ab039c0874f6a9ec53.tar.bz2 moa-sig-666d8c9f8cec7573e60a14ab039c0874f6a9ec53.zip |
Merge branch 'feature/codestyle_and_gitlab_ci' into 'master'
Feature/codestyle and gitlab ci
See merge request egiz/moa-sig!1
Diffstat (limited to 'moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/transaction')
4 files changed, 176 insertions, 161 deletions
diff --git a/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/transaction/DeleteableDataSource.java b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/transaction/DeleteableDataSource.java index a5ea592..335bf68 100644 --- a/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/transaction/DeleteableDataSource.java +++ b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/transaction/DeleteableDataSource.java @@ -3,5 +3,5 @@ package at.gv.egovernment.moa.spss.server.transaction; import javax.activation.DataSource; public interface DeleteableDataSource extends DataSource { - public void delete(); + void delete(); } diff --git a/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/transaction/TransactionContext.java b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/transaction/TransactionContext.java index 4e0d9f6..5746657 100644 --- a/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/transaction/TransactionContext.java +++ b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/transaction/TransactionContext.java @@ -21,11 +21,8 @@ * that you distribute must include a readable copy of the "NOTICE" text file. */ - package at.gv.egovernment.moa.spss.server.transaction; -import iaik.xml.crypto.utils.URI; - import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; @@ -33,23 +30,23 @@ import java.io.InputStream; import java.security.cert.X509Certificate; import java.util.HashMap; import java.util.Iterator; +import java.util.Map.Entry; import java.util.Vector; import javax.activation.DataSource; -import java.util.Map.Entry; - import org.w3c.dom.Element; import at.gv.egovernment.moa.spss.MOAApplicationException; import at.gv.egovernment.moa.spss.server.config.ConfigurationProvider; import at.gv.egovernment.moaspss.logging.Logger; +import iaik.xml.crypto.utils.URI; /** * Contains information about the current request. - * + * * @author Stefan Knirsch - * @author Patrick Peck + * @author Patrick Peck */ public class TransactionContext { @@ -69,18 +66,19 @@ public class TransactionContext { private HashMap resolvedEntities = null; /** The configuration to use throughout the request. */ private ConfigurationProvider configuration = null; - + /** * Create a <code>TransactionContext</code> object. - * - * @param transactionID A unique ID for this <code>TransactionContext</code>. + * + * @param transactionID A unique ID for this + * <code>TransactionContext</code>. * @param clientCertificate The client certificate chain. - * @param configuration The MOA configuration to use for this transaction. + * @param configuration The MOA configuration to use for this transaction. */ public TransactionContext( - String transactionID, - X509Certificate[] clientCertificate, - ConfigurationProvider configuration) { + String transactionID, + X509Certificate[] clientCertificate, + ConfigurationProvider configuration) { this.transactionID = transactionID; this.clientCertificate = clientCertificate; @@ -89,18 +87,19 @@ public class TransactionContext { /** * Create a <code>TransactionContext</code> object. - * - * @param transactionID A unique ID for this <code>TransactionContext</code>. + * + * @param transactionID A unique ID for this + * <code>TransactionContext</code>. * @param clientCertificate The client certificate chain. - * @param configuration The MOA configuration to use for this transaction. - * @param attachments to use for this transaction. + * @param configuration The MOA configuration to use for this transaction. + * @param attachments to use for this transaction. */ public TransactionContext( - String transactionID, - X509Certificate[] clientCertificate, - ConfigurationProvider configuration, - Element request, - HashMap attachments) { + String transactionID, + X509Certificate[] clientCertificate, + ConfigurationProvider configuration, + Element request, + HashMap attachments) { this.transactionID = transactionID; this.clientCertificate = clientCertificate; @@ -108,14 +107,14 @@ public class TransactionContext { this.request = request; this.attachments = attachments; } - + /** * Returns the client certificate. - * + * * @return The client certificate chain, if SSL client authentication has been - * configured in the web server and has been used by the client. The 0th - * element of the array contains the client certificate. <code>null</code> - * otherwise. + * configured in the web server and has been used by the client. The 0th + * element of the array contains the client certificate. + * <code>null</code> otherwise. */ public X509Certificate[] getClientCertificate() { return clientCertificate; @@ -123,7 +122,7 @@ public class TransactionContext { /** * Returns the unique transaction ID. - * + * * @return The transaction ID. */ public String getTransactionID() { @@ -132,7 +131,7 @@ public class TransactionContext { /** * Returns the name of the request. - * + * * @return The name of the request. */ public String getRequestName() { @@ -141,7 +140,7 @@ public class TransactionContext { /** * Sets the name of the request. - * + * * @param requestName The request name to set. */ public void setRequestName(String requestName) { @@ -150,7 +149,7 @@ public class TransactionContext { /** * Sets the the request. - * + * * @param request The request to set. */ public void setRequest(Element request) { @@ -159,7 +158,7 @@ public class TransactionContext { /** * Returns the request. - * + * * @return The request. */ public Element getRequest() { @@ -168,7 +167,7 @@ public class TransactionContext { /** * Sets the the response. - * + * * @param response The response to set. */ public void setResponse(Element response) { @@ -177,23 +176,26 @@ public class TransactionContext { /** * Returns the response. - * + * * @return The response. */ public Element getResponse() { return response; } - + /** * Adds an attachment to the transactions list of SOAP attachments. - * + * * @param referenceId Identification value for the SOAP attachment. * @param contentType MIME type of the SOAP attachment. - * @param is Handle to the ManagedMemoryDataSource of the SOAP attachment. + * @param is Handle to the ManagedMemoryDataSource of the SOAP + * attachment. */ public void addAttachment(String referenceId, String contentType, DataSource is) { - if (this.attachments == null) this.attachments = new HashMap(); - Vector entry = new Vector(2); + if (this.attachments == null) { + this.attachments = new HashMap(); + } + final Vector entry = new Vector(2); entry.add(contentType); entry.add(is); this.attachments.put(referenceId, entry); @@ -201,185 +203,198 @@ public class TransactionContext { /** * Adds an attachment to the transactions list of SOAP attachments. - * + * * @param referenceId Identification value for the SOAP attachment. * @param contentType MIME type of the SOAP attachment. - * @param is Handle to the InputStream of the SOAP attachment. - * @param filename Filename of the temporary file the InputStream belongs to + * @param is Handle to the InputStream of the SOAP attachment. + * @param filename Filename of the temporary file the InputStream belongs to */ public void addAttachment(String referenceId, String contentType, InputStream is, String filename) { - if (this.attachments == null) this.attachments = new HashMap(); - Vector entry = new Vector(3); + if (this.attachments == null) { + this.attachments = new HashMap(); + } + final Vector entry = new Vector(3); entry.add(contentType); entry.add(is); entry.add(filename); this.attachments.put(referenceId, entry); } - + /** - * Returns the ManagedMemoryDataSource to a specific SOAP attachment identified by referenceId. - * + * Returns the ManagedMemoryDataSource to a specific SOAP attachment identified + * by referenceId. + * * @param referenceId Identification value for the SOAP attachment. */ public DataSource getAttachment(String referenceId) { - if (attachments==null) { + if (attachments == null) { return null; } - Vector entry = (Vector) attachments.get(referenceId); - if (entry==null) { + final Vector entry = (Vector) attachments.get(referenceId); + if (entry == null) { return null; } - Object object = entry.get(1); + final Object object = entry.get(1); if (object instanceof DataSource) { - return (DataSource) object; + return (DataSource) object; } else { - return null; + return null; } } - + /** * Returns the InputStream to a specific SOAP attachment identified by uri. - * + * * @param uri Identification value for the SOAP attachment. */ public InputStream getAttachmentInputStream(URI uri) throws MOAApplicationException { - if (attachments==null) { + if (attachments == null) { return null; } - String referenceId = uri.getPath(); - Vector entry = (Vector) attachments.get(referenceId); - if (entry==null) { + final String referenceId = uri.getPath(); + final Vector entry = (Vector) attachments.get(referenceId); + if (entry == null) { return null; } InputStream attachmentIs = null; - Object object = entry.get(1); - + final Object object = entry.get(1); + if (object instanceof DataSource) { - try { - attachmentIs = (InputStream) ( ((DataSource)object).getInputStream()); - } catch (IOException e) { - throw new MOAApplicationException("2208", new Object[] { uri }, e); - } + try { + attachmentIs = ((DataSource) object).getInputStream(); + } catch (final IOException e) { + throw new MOAApplicationException("2208", new Object[] { uri }, e); + } } else { - attachmentIs = (InputStream) object; + attachmentIs = (InputStream) object; } return attachmentIs; - //If we would return the whole mmds: return (ManagedMemoryDataSource) entry.get(1); + // If we would return the whole mmds: return (ManagedMemoryDataSource) + // entry.get(1); } - + /** - * Returns the content type to a specific SOAP attachment identified by referenceId. - * + * Returns the content type to a specific SOAP attachment identified by + * referenceId. + * * @param referenceId Identification value for the SOAP attachment. */ public String getAttachmentContentType(String referenceId) { - Vector entry = (Vector) attachments.get(referenceId); - if (entry==null) { + final Vector entry = (Vector) attachments.get(referenceId); + if (entry == null) { return null; } return (String) entry.get(0); } - + /** * Delete the temporary attachment files. */ -public void cleanAttachmentCache() { - if (null==attachments) { + public void cleanAttachmentCache() { + if (null == attachments) { return; } - Iterator iterator = attachments.entrySet().iterator(); + final Iterator iterator = attachments.entrySet().iterator(); while (iterator.hasNext()) { - Entry hmEntry = (Entry) iterator.next(); - Vector entry = (Vector)hmEntry.getValue(); - Object object = entry.get(1); + final Entry hmEntry = (Entry) iterator.next(); + final Vector entry = (Vector) hmEntry.getValue(); + final Object object = entry.get(1); if (object instanceof DataSource) { - DataSource mmds = (DataSource)object; - try { - if (mmds!=null) { - InputStream is = mmds.getInputStream(); - if (is!=null) is.close(); -// not available in Axis 1.0 to 1.1 + final DataSource mmds = (DataSource) object; + try { + if (mmds != null) { + final InputStream is = mmds.getInputStream(); + if (is != null) { + is.close(); + } +// not available in Axis 1.0 to 1.1 // File f = mmds.getDiskCacheFile(); // if (f!=null) f.delete(); - if(mmds instanceof DeleteableDataSource) { - ((DeleteableDataSource)mmds).delete(); - } - //mmds..delete(); - } - } catch (IOException e) { - // ok to do nothing here - } + if (mmds instanceof DeleteableDataSource) { + ((DeleteableDataSource) mmds).delete(); + } + // mmds..delete(); + } + } catch (final IOException e) { + // ok to do nothing here + } } else if (object instanceof InputStream) { - InputStream is = (InputStream)object; - try { - if (is!=null) is.close(); - String tempFile = (String) entry.get(2); - if (tempFile!=null){ - File f = new File(tempFile); - f.delete(); - } - } catch (IOException e) { - // ok to do nothing here - } + final InputStream is = (InputStream) object; + try { + if (is != null) { + is.close(); + } + final String tempFile = (String) entry.get(2); + if (tempFile != null) { + final File f = new File(tempFile); + f.delete(); + } + } catch (final IOException e) { + // ok to do nothing here + } } } } - + /** * Returns the <code>ConfigurationProvider</code> associated with this * transaction. - * - * @return The ConfigurationProvider associated with this transaction. + * + * @return The ConfigurationProvider associated with this transaction. */ public ConfigurationProvider getConfiguration() { return configuration; } - + /** * Search an uri content in cashed map. - * + * * @param uri The value to look for. * @return If found the cached entity, <code>null<code> otherwise. */ public Vector FindResolvedEntity(String uri) { - if (resolvedEntities==null) return null; - return (Vector) resolvedEntities.get(uri); + if (resolvedEntities == null) { + return null; + } + return (Vector) resolvedEntities.get(uri); } - + /** * Get a new InputStream of a cached entity. - * + * * @param uri The value to look for. * @return A new InputStream of the cached entity. */ public InputStream ResolveURI(String uri) { - InputStream is = null; - Vector entity = FindResolvedEntity(uri); - if (entity!=null) { - byte[] contentBytes = (byte[]) entity.get(0); - if (contentBytes!=null) { - is = new ByteArrayInputStream(contentBytes); - } - } - return is; + InputStream is = null; + final Vector entity = FindResolvedEntity(uri); + if (entity != null) { + final byte[] contentBytes = (byte[]) entity.get(0); + if (contentBytes != null) { + is = new ByteArrayInputStream(contentBytes); + } + } + return is; } /** - * Put a read entity (supplement, detached content, data object) on - * transactions entity cash, to prevent repeated reading on slower channels. - * - * @param uri A transaction-wide unique URI used as key of the entity cash - * table. + * Put a read entity (supplement, detached content, data object) on transactions + * entity cash, to prevent repeated reading on slower channels. + * + * @param uri A transaction-wide unique URI used as key of the entity + * cash table. * @param contentBytes The cached content belonging to the uri. - * @param contentType If known, the MIME-type of the cashed content. + * @param contentType If known, the MIME-type of the cashed content. */ public void PutResolvedEntity(String uri, byte[] contentBytes, String contentType) { - Logger.trace(" storing uri content of uri \"" + uri + "\" for future references"); - if (resolvedEntities==null) resolvedEntities = new HashMap(); - Vector entity = new Vector(); - entity.add(contentBytes); - entity.add(contentType); - resolvedEntities.put(uri, entity); + Logger.trace(" storing uri content of uri \"" + uri + "\" for future references"); + if (resolvedEntities == null) { + resolvedEntities = new HashMap(); + } + final Vector entity = new Vector(); + entity.add(contentBytes); + entity.add(contentType); + resolvedEntities.put(uri, entity); } } diff --git a/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/transaction/TransactionContextManager.java b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/transaction/TransactionContextManager.java index 8a45ddf..080f801 100644 --- a/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/transaction/TransactionContextManager.java +++ b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/transaction/TransactionContextManager.java @@ -21,30 +21,29 @@ * that you distribute must include a readable copy of the "NOTICE" text file. */ - package at.gv.egovernment.moa.spss.server.transaction; /** * Provides each thread with an instance of <code>TransactionContext</code>. - * + * * The single instance of the <code>TransactionContextManager</code> should be * used to access contextual information for each web service transaction, e.g. * the transaction ID, MOA configuration, client certificate, etc. - * + * * @author Stefan Knirsch * @author Patrick Peck */ public class TransactionContextManager { - /** The single instance of <code>TransactionContextManager</code> */ + /** The single instance of <code>TransactionContextManager</code> */ private static TransactionContextManager instance = null; - + /** Contains a single <code>TransactionContext</code> for each thread. */ private ThreadLocal context = null; /** * Get the single instance of <code>TransactionContextManager</code>. - * + * * @return The single instanc of <code>TransactionContextManager</code>. */ public static synchronized TransactionContextManager getInstance() { @@ -56,7 +55,7 @@ public class TransactionContextManager { /** * Creates a new <code>TransactionContextManager</code>. - * + * * Protected to disallow direct instantiation. */ protected TransactionContextManager() { @@ -65,7 +64,7 @@ public class TransactionContextManager { /** * Set the <code>TransactionContext</code> for the current thread. - * + * * @param txContext The <code>TransactionContext</code> for this thread. */ public void setTransactionContext(TransactionContext txContext) { @@ -74,10 +73,10 @@ public class TransactionContextManager { /** * Get the <code>TransactionContext</code> for the current thread. - * + * * @return The <code>TransactionContext</code> for the current thread or - * <code>null</code>, if none has been set (or if this method is being invoked - * outside the bounds of a transaction). + * <code>null</code>, if none has been set (or if this method is being + * invoked outside the bounds of a transaction). */ public TransactionContext getTransactionContext() { return (TransactionContext) context.get(); diff --git a/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/transaction/TransactionIDGenerator.java b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/transaction/TransactionIDGenerator.java index b173308..463785b 100644 --- a/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/transaction/TransactionIDGenerator.java +++ b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/transaction/TransactionIDGenerator.java @@ -21,27 +21,28 @@ * that you distribute must include a readable copy of the "NOTICE" text file. */ - package at.gv.egovernment.moa.spss.server.transaction; - /** * A generator for unique transaction IDs. - * - * <p>The transaction IDs are of the form "<base>-<counter>", where: - * <ul> + * + * <p> + * The transaction IDs are of the form "<base>-<counter>", where: + * <ul> * <li><code>base</code> is initialized with the system time when this class is * being loaded</li> * <li><code>counter</code> is incremented sequentially on each call to * <code>nextID()</code></li> * </ul> * </p> - * - * <p> Assuming that it is highly unlikely that MOA servers are started at - * exactly the same time instant, the mechanism provided by this class should - * guarantee unique transaction IDs across multiple restarts and/or instances of - * the server.</p> - * + * + * <p> + * Assuming that it is highly unlikely that MOA servers are started at exactly + * the same time instant, the mechanism provided by this class should guarantee + * unique transaction IDs across multiple restarts and/or instances of the + * server. + * </p> + * * @author Patrick Peck * @author Stefan Knirsch */ @@ -63,13 +64,13 @@ public class TransactionIDGenerator { /** * Returns the next transaction ID. - * + * * @return The next transaction ID. */ public static synchronized String nextID() { counter++; - return (base + "-" + counter); + return base + "-" + counter; } } |