From 578ad0d6bc408edf9e6c875156054374f5fd8337 Mon Sep 17 00:00:00 2001 From: Thomas <> Date: Mon, 22 Mar 2021 18:40:26 +0100 Subject: change to EGIZ codestyle --- .../server/transaction/TransactionContext.java | 287 +++++++++++---------- 1 file changed, 151 insertions(+), 136 deletions(-) (limited to 'moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/server/transaction/TransactionContext.java') 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 TransactionContext object. - * - * @param transactionID A unique ID for this TransactionContext. + * + * @param transactionID A unique ID for this + * TransactionContext. * @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 TransactionContext object. - * - * @param transactionID A unique ID for this TransactionContext. + * + * @param transactionID A unique ID for this + * TransactionContext. * @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. null - * otherwise. + * configured in the web server and has been used by the client. The 0th + * element of the array contains the client certificate. + * null 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 ConfigurationProvider 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, null 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); } } -- cgit v1.2.3