Skip to Content.
Sympa Menu

notify-dpml - svn commit: r1471 - in development/main/transit/handler/src/main/net/dpml/transit: . artifact

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: niclas AT netcompartner.com
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: svn commit: r1471 - in development/main/transit/handler/src/main/net/dpml/transit: . artifact
  • Date: Thu, 13 Jan 2005 17:06:24 +0100

Author: niclas
Date: Thu Jan 13 17:06:24 2005
New Revision: 1471

Modified:
development/main/transit/handler/src/main/net/dpml/transit/Transit.java

development/main/transit/handler/src/main/net/dpml/transit/artifact/ClassicResourceHost.java
Log:
Added a PrintWriter for Transit's internals, so that we have a chance to
troubleshoot bad configurations at users places.

Modified:
development/main/transit/handler/src/main/net/dpml/transit/Transit.java
==============================================================================
--- development/main/transit/handler/src/main/net/dpml/transit/Transit.java
(original)
+++ development/main/transit/handler/src/main/net/dpml/transit/Transit.java
Thu Jan 13 17:06:24 2005
@@ -21,8 +21,12 @@

import java.net.URI;
import java.net.URISyntaxException;
+
import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;

import net.dpml.transit.artifact.SecuredTransitContext;

@@ -36,9 +40,9 @@
import net.dpml.transit.repository.StandardLoader;

/**
- * The Transit class manages the establishment of a singleton transit
instance
- * together with a service supporting the deployment of a application plugin
and
- * access to transit monitor routers.
+ * The Transit class manages the establishment of a singleton transit
instance
+ * together with a service supporting the deployment of a application plugin
and
+ * access to transit monitor routers.
*/
public final class Transit
{
@@ -83,11 +87,23 @@
private NetworkMonitorRouter m_networkMonitor;

/**
+ * PrintWriter where operations troubleshooting messages
+ * can be written to.
+ */
+ private PrintWriter m_logWriter;
+
+ /**
* The DPML home directory. If an environment variable named DPML_HOME
- * is defined, then the assigned value will be returned, otherwise the
+ * is defined, then the assigned value will be returned, otherwise the
* DPML home directory shall default to ${user.home}/.dpml.
*/
- public static final File DPML_HOME = resolveHomeDirectory();
+ public static final File DPML_HOME;
+
+
+ static
+ {
+ DPML_HOME = resolveHomeDirectory();
+ }

/**
* Returns the singleton instance of the transit system.
@@ -110,7 +126,7 @@
public static Transit getInstance( Monitor monitor )
throws TransitException
{
- if( null == monitor )
+ if( null == monitor )
{
throw new NullPointerException( "monitor" );
}
@@ -142,9 +158,19 @@
m_repositoryMonitor = new RepositoryMonitorRouter( monitor );
m_cacheMonitor = new CacheMonitorRouter( monitor );
m_networkMonitor = new NetworkMonitorRouter( monitor );
+
+ // Setting up a permanent output troubleshooting resource
+ // for Transit.
+ File logDir = new File( DPML_HOME, "transit/logs" );
+ logDir.mkdirs();
+ File logFile = new File( logDir, "transit.log" );
+ FileOutputStream fos = new FileOutputStream( logFile );
+ OutputStreamWriter osw = new OutputStreamWriter( fos, "UTF-8" );
+ m_logWriter = new PrintWriter( osw, true );
}
catch( Throwable e )
{
+ e.printStackTrace();
final String error = "Unable to construct transit instance.";
throw new TransitException( error, e );
}
@@ -181,13 +207,13 @@
}

/**
- * Start a plugin defined by the supplied uri using the
+ * Start a plugin defined by the supplied uri using the
* command-line argumements and monitors as optional plugin constructor
- * arguments. If the supplied plugin class implements the runnable
interface,
- * the start operation will attempt to start a new thread for the plugin.
If
+ * arguments. If the supplied plugin class implements the runnable
interface,
+ * the start operation will attempt to start a new thread for the plugin.
If
* the Transit handler detects a shutdown request it will attempt to
interrupt
* the thread as part of an assigned shutdown hook.
- *
+ *
* @param uri the plugin descriptor uri
* @param args the set of constructor args
* @return the plugin instance
@@ -221,6 +247,20 @@
return object;
}

+ /** Returns the LogWriter for the Transit system.
+ * This writer should only be used to report information that
+ * should not be output to the user in the course of normal
+ * execution but can aid to determine what has gone wrong in
+ * Transit, such as configuration problems, network problems
+ * and security issues.
+ * @return a PrintWriter where troubleshooting information can
+ * be written to.
+ */
+ public PrintWriter getLogWriter()
+ {
+ return m_logWriter;
+ }
+
/**
* Create a shutdown hook that will trigger shutdown of the supplied
plugin.
* @param thread the application thread
@@ -257,7 +297,7 @@

/**
* Resolve the DPML home directory using assesment of the the ${dpml.home}
- * system propertym, the DPML_HOME environment variable and fallback to
+ * system propertym, the DPML_HOME environment variable and fallback to
* ${user.home}/.dpml.
* @return the DPML home directory
*/

Modified:
development/main/transit/handler/src/main/net/dpml/transit/artifact/ClassicResourceHost.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/artifact/ClassicResourceHost.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/artifact/ClassicResourceHost.java
Thu Jan 13 17:06:24 2005
@@ -21,6 +21,7 @@

import java.io.File;
import java.io.IOException;
+import java.io.PrintWriter;

import java.net.HttpURLConnection;
import java.net.InetAddress;
@@ -44,6 +45,7 @@
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

+import net.dpml.transit.Transit;


/** This class represents a single host where resources are stored at.
@@ -107,7 +109,7 @@
* Trusted state.
*/
private boolean m_trusted;
-
+
/**
* Timestamp policy.
*/
@@ -139,7 +141,7 @@
* @param prompt the authentication prompt/realm
* @exception UnknownHostException if the supplied base url references
an unknown host
*/
- public ClassicResourceHost(
+ public ClassicResourceHost(
URL base, String[] knownGroups, int priority, Policy downloadPolicy,
boolean enabled, boolean trusted, String username, String password,
String scheme, String prompt )
throws UnknownHostException
@@ -158,7 +160,7 @@
String group = knownGroups[ i ];
m_knownGroups.add( group );
}
-
+
String protocol = base.getProtocol();
InetAddress host = InetAddress.getByName( base.getHost() );
int port = base.getPort();
@@ -230,7 +232,9 @@
// TODO: Investigate if the cache is used properly.
if( connection == null )
{
- // Not in cache. Why not?
+ // Not in cache. Why not? ---> Garbage Collection has
occurred.
+ String message = this + " - Info: Connection no longer
in cache. Reconnecting." ;
+ Transit.getInstance().getLogWriter().println( message );
URL remote = createRemoteUrl( artifact );
connection = remote.openConnection();
connection.connect();
@@ -343,10 +347,9 @@
}
else
{
- openRemoteConnection( artifact );
+ return openRemoteConnection( artifact );
}
- return true;
- }
+ }
catch( IOException e )
{
return false;
@@ -359,6 +362,10 @@
{
return false;
}
+ catch( RuntimeException e )
+ {
+ return false;
+ }
}

/**
@@ -386,20 +393,27 @@
* @exception IOException if an IO error occurs
* @exception KeyManagementException if a key management error occurs
* @exception NoSuchAlgorithmException if no such algorithm exists?
+ * @return true if the atrifact was found and could be opened, false if
not
+ * available at this resource host.
*/
- private void openRemoteConnection( Artifact artifact )
+ private boolean openRemoteConnection( Artifact artifact )
throws IOException, KeyManagementException, NoSuchAlgorithmException
{
+ PrintWriter log = Transit.getInstance().getLogWriter();
+ log.println( this + " - opening connection: " + artifact );
URL remote = createRemoteUrl( artifact );
URLConnection conn = remote.openConnection();
if( conn instanceof HttpsURLConnection )
{
+ log.println( this + " - HTTPS connection opened." );
if( m_trusted )
{
+ log.println( this + " - Using NullTrustManager." );
HttpsURLConnection ssl = (HttpsURLConnection) conn;
TrustManager nullTrustManager = new NullTrustManager();
SSLContext ctx = SSLContext.getInstance( "SSLv3" );
ctx.init( null, new TrustManager[]{nullTrustManager}, null );
+ log.println( this + " - Setting SSLv3 socket factory." );
SSLSocketFactory factory = ctx.getSocketFactory();
ssl.setSSLSocketFactory( factory );
}
@@ -408,15 +422,26 @@
if( conn instanceof HttpURLConnection )
{
int code = ( (HttpURLConnection) conn ).getResponseCode();
- if( code != HttpURLConnection.HTTP_OK )
+ log.println( this + " - ResponseCode: " + code );
+ if( code == HttpURLConnection.HTTP_UNAUTHORIZED )
+ {
+ throw new IOException( "Unauthorized request." );
+ }
+ else if( code == HttpURLConnection.HTTP_NOT_FOUND )
+ {
+ return false;
+ }
+ else if( code != HttpURLConnection.HTTP_OK )
{
- throw new IOException( "Resource doesn't exist." );
+ throw new IOException( "Unexpected Result: " + code );
}
}
synchronized ( m_connections )
{
+ log.println( this + " - caching connection: " + conn );
m_connections.put( artifact, conn );
}
+ return true;
}

/**
@@ -444,7 +469,7 @@
}

/**
- * A null trust manager that will accept any certificate. I.e. this
+ * A null trust manager that will accept any certificate. I.e. this
* class performs NO TRUST MANAGEMENT and simply serves as a mechanism
* through which https connections can be established with the same notion
* of trust as a http connection (i.e. none).
@@ -464,7 +489,7 @@
* @exception CertificateException never thrown
*/
public void checkServerTrusted( final X509Certificate[] certs, final
String authType )
- throws CertificateException
+ throws CertificateException
{
}

@@ -475,7 +500,7 @@
* @exception CertificateException never thrown
*/
public void checkClientTrusted( final X509Certificate[] certs, final
String authType )
- throws CertificateException
+ throws CertificateException
{
}

@@ -483,7 +508,7 @@
* Null implementation.
* @return an empty certificate array
*/
- public X509Certificate[] getAcceptedIssuers()
+ public X509Certificate[] getAcceptedIssuers()
{
return EMPTY_CERTS;
}



  • svn commit: r1471 - in development/main/transit/handler/src/main/net/dpml/transit: . artifact, niclas, 01/13/2005

Archive powered by MHonArc 2.6.24.

Top of Page