diff options
author | afinkbein | 2008-12-01 16:53:55 +0000 |
---|---|---|
committer | afinkbein | 2008-12-01 16:53:55 +0000 |
commit | 849a3cdf2a0eab0ce548f32a2e0a1ee3e56d8de5 (patch) | |
tree | 1c1324aefd2b9dbc9f46f4764f1ca0e71df6406a | |
parent | cacb55efac773c6822e9845d3438c8d1c5a25269 (diff) | |
download | org.eclipse.osee-849a3cdf2a0eab0ce548f32a2e0a1ee3e56d8de5.tar.gz org.eclipse.osee-849a3cdf2a0eab0ce548f32a2e0a1ee3e56d8de5.tar.xz org.eclipse.osee-849a3cdf2a0eab0ce548f32a2e0a1ee3e56d8de5.zip |
31 files changed, 2592 insertions, 0 deletions
diff --git a/0.5.0_20081201/org.eclipse.osee.framework.core.client/.classpath b/0.5.0_20081201/org.eclipse.osee.framework.core.client/.classpath new file mode 100644 index 00000000000..8a8f1668cdc --- /dev/null +++ b/0.5.0_20081201/org.eclipse.osee.framework.core.client/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/0.5.0_20081201/org.eclipse.osee.framework.core.client/.project b/0.5.0_20081201/org.eclipse.osee.framework.core.client/.project new file mode 100644 index 00000000000..db571da02b8 --- /dev/null +++ b/0.5.0_20081201/org.eclipse.osee.framework.core.client/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.osee.framework.core.client</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/0.5.0_20081201/org.eclipse.osee.framework.core.client/.settings/org.eclipse.jdt.core.prefs b/0.5.0_20081201/org.eclipse.osee.framework.core.client/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..96f5720d28b --- /dev/null +++ b/0.5.0_20081201/org.eclipse.osee.framework.core.client/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +#Wed Oct 29 10:59:05 MST 2008
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/0.5.0_20081201/org.eclipse.osee.framework.core.client/META-INF/MANIFEST.MF b/0.5.0_20081201/org.eclipse.osee.framework.core.client/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..8c55181a850 --- /dev/null +++ b/0.5.0_20081201/org.eclipse.osee.framework.core.client/META-INF/MANIFEST.MF @@ -0,0 +1,24 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Core Client Plug-in +Bundle-SymbolicName: org.eclipse.osee.framework.core.client;singleton:=true +Bundle-Version: 0.5.0.qualifier +Bundle-Activator: org.eclipse.osee.framework.core.client.CoreClientActivator +Bundle-Vendor: Boeing +Require-Bundle: org.eclipse.equinox.ds;bundle-version="1.0.0", + org.eclipse.core.runtime, + org.eclipse.osee.framework.plugin.core;bundle-version="0.4.0" +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-ActivationPolicy: lazy +Import-Package: org.eclipse.osee.framework.core.data, + org.eclipse.osee.framework.core.exception, + org.eclipse.osee.framework.db.connection, + org.eclipse.osee.framework.db.connection.exception, + org.eclipse.osee.framework.db.connection.info, + org.eclipse.osee.framework.jdk.core.db, + org.eclipse.osee.framework.jdk.core.util, + org.eclipse.osee.framework.logging +Service-Component: OSGI-INF/application.db.provider.xml +Export-Package: org.eclipse.osee.framework.core.client, + org.eclipse.osee.framework.core.client.server, + org.eclipse.osee.framework.core.client.task diff --git a/0.5.0_20081201/org.eclipse.osee.framework.core.client/OSGI-INF/application.db.provider.xml b/0.5.0_20081201/org.eclipse.osee.framework.core.client/OSGI-INF/application.db.provider.xml new file mode 100644 index 00000000000..f77f696f083 --- /dev/null +++ b/0.5.0_20081201/org.eclipse.osee.framework.core.client/OSGI-INF/application.db.provider.xml @@ -0,0 +1,7 @@ +<?xml version="1.0"?>
+<component name="client.application.db.provider">
+ <implementation class="org.eclipse.osee.framework.core.client.internal.ClientDatabaseProvider"/>
+ <service>
+ <provide interface="org.eclipse.osee.framework.db.connection.IApplicationDatabaseInfoProvider"/>
+ </service>
+</component>
\ No newline at end of file diff --git a/0.5.0_20081201/org.eclipse.osee.framework.core.client/build.properties b/0.5.0_20081201/org.eclipse.osee.framework.core.client/build.properties new file mode 100644 index 00000000000..b26fb3192e7 --- /dev/null +++ b/0.5.0_20081201/org.eclipse.osee.framework.core.client/build.properties @@ -0,0 +1,6 @@ +source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ OSGI-INF/
diff --git a/0.5.0_20081201/org.eclipse.osee.framework.core.client/plugin.xml b/0.5.0_20081201/org.eclipse.osee.framework.core.client/plugin.xml new file mode 100644 index 00000000000..4b49b1b0c8f --- /dev/null +++ b/0.5.0_20081201/org.eclipse.osee.framework.core.client/plugin.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+ <extension
+ point="org.eclipse.core.runtime.preferences">
+ <initializer
+ class="org.eclipse.osee.framework.core.client.internal.CorePreferenceInitializer">
+ </initializer>
+ </extension>
+
+</plugin>
diff --git a/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/BaseCredentialProvider.java b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/BaseCredentialProvider.java new file mode 100644 index 00000000000..4ccda7fe949 --- /dev/null +++ b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/BaseCredentialProvider.java @@ -0,0 +1,50 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.client;
+
+import java.net.InetAddress;
+import java.util.logging.Level;
+import org.eclipse.osee.framework.core.client.server.HttpServer;
+import org.eclipse.osee.framework.core.data.OseeCodeVersion;
+import org.eclipse.osee.framework.core.data.OseeCredential;
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+import org.eclipse.osee.framework.logging.OseeLog;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public abstract class BaseCredentialProvider implements ICredentialProvider {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.core.client.ICredentialProvider#getCredential()
+ */
+ @Override
+ public OseeCredential getCredential() throws OseeCoreException {
+ OseeCredential credential = new OseeCredential();
+ credential.setUserName("");
+ credential.setDomain("");
+ credential.setPassword("");
+ credential.setAuthenticationProtocol("");
+ String localAddress = HttpServer.getLocalServerAddress();
+
+ credential.setClientAddress(Strings.isValid(localAddress) ? localAddress : "Unknown",
+ HttpServer.getDefaultServicePort());
+ credential.setClientVersion(OseeCodeVersion.getVersion());
+ try {
+ credential.setClientMachineName(InetAddress.getLocalHost().getHostName());
+ } catch (Exception ex) {
+ credential.setClientMachineName("Unknown");
+ OseeLog.log(CoreClientActivator.class, Level.SEVERE, ex);
+ }
+ return credential;
+ }
+}
diff --git a/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/ClientSessionManager.java b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/ClientSessionManager.java new file mode 100644 index 00000000000..c2975e679de --- /dev/null +++ b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/ClientSessionManager.java @@ -0,0 +1,101 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.client;
+
+import org.eclipse.osee.framework.core.client.internal.InternalClientSessionManager;
+import org.eclipse.osee.framework.core.data.IOseeUser;
+import org.eclipse.osee.framework.core.data.OseeSessionGrant;
+import org.eclipse.osee.framework.core.exception.OseeAuthenticationRequiredException;
+import org.eclipse.osee.framework.db.connection.exception.OseeArgumentException;
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class ClientSessionManager {
+
+ private ClientSessionManager() {
+ }
+
+ public static final String getStatusId() {
+ return InternalClientSessionManager.STATUS_ID;
+ }
+
+ public static boolean isSessionValid() {
+ return InternalClientSessionManager.getInstance().isSessionValid();
+ }
+
+ public static void ensureSessionCreated() {
+ InternalClientSessionManager.getInstance().ensureSessionCreated();
+ }
+
+ private static OseeSessionGrant getSessionGrant() throws OseeAuthenticationRequiredException {
+ return InternalClientSessionManager.getInstance().getOseeSessionGrant();
+ }
+
+ public static OseeClientSession getSession() throws OseeAuthenticationRequiredException {
+ return InternalClientSessionManager.getInstance().getOseeSession();
+ }
+
+ public static boolean isUserCreationRequired() throws OseeAuthenticationRequiredException {
+ return getSessionGrant().isCreationRequired();
+ }
+
+ public static void clearUserCreationRequired() throws OseeAuthenticationRequiredException {
+ getSessionGrant().setCreationRequired(false);
+ }
+
+ public static IOseeUser getCurrentUserInfo() throws OseeAuthenticationRequiredException {
+ return getSessionGrant().getOseeUserInfo();
+ }
+
+ public static String getSessionId() throws OseeAuthenticationRequiredException {
+ return getSessionGrant().getSessionId();
+ }
+
+ public static String getDataStoreLoginName() throws OseeAuthenticationRequiredException {
+ return getSessionGrant().getDatabaseInfo().getDatabaseLoginName();
+ }
+
+ public static String getDataStoreName() throws OseeAuthenticationRequiredException {
+ return getSessionGrant().getDatabaseInfo().getDatabaseName();
+ }
+
+ public static boolean isProductionDataStore() throws OseeAuthenticationRequiredException {
+ return getSessionGrant().getDatabaseInfo().isProduction();
+ }
+
+ public static String getSQL(String key) throws OseeCoreException {
+ String sql = getSessionGrant().getSqlProperties().getProperty(key);
+ if (Strings.isValid(sql)) {
+ return sql;
+ }
+ throw new OseeArgumentException(String.format("Invalid sql key [%s]", key));
+ }
+
+ public static String[] getAuthenticationProtocols() {
+ return InternalClientSessionManager.getInstance().getAuthenticationProtocols();
+ }
+
+ public static void authenticateAsGuest() throws OseeCoreException {
+ InternalClientSessionManager.getInstance().authenticateAsGuest();
+ }
+
+ public static void authenticate(ICredentialProvider credentialProvider) throws OseeCoreException {
+ InternalClientSessionManager.getInstance().authenticate(credentialProvider);
+ }
+
+ public static void releaseSession() throws OseeCoreException {
+ InternalClientSessionManager.getInstance().releaseSession();
+ }
+
+}
diff --git a/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/CoreClientActivator.java b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/CoreClientActivator.java new file mode 100644 index 00000000000..bc7068acf5f --- /dev/null +++ b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/CoreClientActivator.java @@ -0,0 +1,55 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.client;
+
+import org.eclipse.osee.framework.core.client.server.HttpServer;
+import org.eclipse.osee.framework.plugin.core.OseeActivator;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class CoreClientActivator extends OseeActivator {
+
+ public static final String PLUGIN_ID = "org.eclipse.osee.framework.core.client";
+ private static CoreClientActivator plugin;
+ private BundleContext context;
+
+ public CoreClientActivator() {
+ plugin = this;
+ context = null;
+ }
+
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ this.context = context;
+ HttpServer.startServers(1);
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ super.stop(context);
+ savePluginPreferences();
+
+ HttpServer.stopServers();
+
+ ClientSessionManager.releaseSession();
+ context = null;
+ }
+
+ public static CoreClientActivator getInstance() {
+ return plugin;
+ }
+
+ public static BundleContext getBundleContext() {
+ return getInstance().context;
+ }
+}
\ No newline at end of file diff --git a/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/CorePreferences.java b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/CorePreferences.java new file mode 100644 index 00000000000..5cf3335e670 --- /dev/null +++ b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/CorePreferences.java @@ -0,0 +1,37 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.client;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import org.eclipse.core.runtime.Preferences;
+import org.eclipse.osee.framework.jdk.core.util.Network;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class CorePreferences {
+
+ private CorePreferences() {
+
+ }
+ public static final String INETADDRESS_KEY = "org.eclipse.osee.framework.core.client.preferences.InetAddressDefault";
+
+ public static InetAddress getDefaultInetAddress() throws UnknownHostException {
+ Preferences prefStore = CoreClientActivator.getInstance().getPluginPreferences();
+ String inetaddress = prefStore.getString(CorePreferences.INETADDRESS_KEY);
+ if (Strings.isValid(inetaddress)) {
+ return InetAddress.getByName(inetaddress);
+ }
+ return Network.getValidIP();
+ }
+}
diff --git a/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/GuestCredentialProvider.java b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/GuestCredentialProvider.java new file mode 100644 index 00000000000..1e2e72bdfcd --- /dev/null +++ b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/GuestCredentialProvider.java @@ -0,0 +1,31 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.client;
+
+import org.eclipse.osee.framework.core.data.OseeCredential;
+import org.eclipse.osee.framework.core.data.SystemUser;
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class GuestCredentialProvider extends BaseCredentialProvider {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.core.client.BaseCredentialProvider#getCredential()
+ */
+ @Override
+ public OseeCredential getCredential() throws OseeCoreException {
+ OseeCredential credential = super.getCredential();
+ credential.setUserName(SystemUser.Guest.getName());
+ return credential;
+ }
+}
diff --git a/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/ICredentialProvider.java b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/ICredentialProvider.java new file mode 100644 index 00000000000..e152a991e1c --- /dev/null +++ b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/ICredentialProvider.java @@ -0,0 +1,23 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.client;
+
+import org.eclipse.osee.framework.core.data.OseeCredential;
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public interface ICredentialProvider {
+
+ OseeCredential getCredential() throws OseeCoreException;
+
+}
diff --git a/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/OseeClientProperties.java b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/OseeClientProperties.java new file mode 100644 index 00000000000..a40939b7f26 --- /dev/null +++ b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/OseeClientProperties.java @@ -0,0 +1,273 @@ +/*
+ * Created on Nov 13, 2008
+ *
+ * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
+ */
+package org.eclipse.osee.framework.core.client;
+
+import java.net.URL;
+import java.util.Dictionary;
+import java.util.Properties;
+import java.util.Map.Entry;
+import java.util.logging.Level;
+import org.eclipse.osee.framework.jdk.core.util.OseeProperties;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+import org.eclipse.osee.framework.logging.OseeLog;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class OseeClientProperties extends OseeProperties {
+
+ private static final OseeClientProperties instance = new OseeClientProperties();
+
+ private static final String HEADER_TAG = "OSEE-Client-Property-Init";
+
+ private static final String OSEE_AUTHENTICATION_PROTOCOL = "osee.authentication.protocol";
+ private static final String OSEE_APPLICATION_SERVER = "osee.application.server";
+ private static final String OSEE_ARBITRATION_SERVER = "osee.arbitration.server";
+
+ private static final String OSEE_LOCAL_APPLICATION_SERVER = "osee.local.application.server";
+ private static final String OSEE_LOCAL_HTTP_WORKER_PORT = "osee.local.http.worker.port";
+ private static final String OSEE_USAGE_LOG = "osee.record.activity";
+
+ // Database Initialization Properties
+ private static final String OSEE_IMPORT_DURING_DB_INIT = "osee.import.on.db.init";
+ private static final String OSEE_IMPORT_FROM_DB_SERVICE = "osee.import.from.connection.id.on.db.init";
+ private static final String OSEE_USE_FILE_SPECIFIED_SCHEMAS = "osee.file.specified.schema.names.on.db.init";
+ private static final String OSEE_PROMPT_ON_DB_INIT = "osee.prompt.on.db.init";
+ private static final String OSEE_CHOICE_ON_DB_INIT = "osee.choice.on.db.init";
+ private enum InitializerFlag {
+ overwrite_settings, client_defaults;
+
+ public static InitializerFlag fromString(String value) {
+ InitializerFlag toReturn = client_defaults;
+ if (Strings.isValid(value)) {
+ value = value.toLowerCase();
+ for (InitializerFlag flag : InitializerFlag.values()) {
+ if (flag.name().equals(value)) {
+ toReturn = flag;
+ break;
+ }
+ }
+ }
+ return toReturn;
+ }
+ }
+
+ private final Properties defaultProperties;
+ private final Properties overwriteProperties;
+
+ private OseeClientProperties() {
+ super();
+ this.defaultProperties = new Properties();
+ this.overwriteProperties = new Properties();
+ initialize();
+ }
+
+ /**
+ * Retrieves where table data should be imported from during OSEE database initialization. The default is to use the
+ * database connection id specified in the schema.xml files.
+ *
+ * @return the connection id to use as a source of the data to be imported.
+ */
+ public static String getTableImportSource() {
+ return getProperty(OSEE_IMPORT_FROM_DB_SERVICE);
+ }
+
+ /**
+ * Retrieves whether OSEE database initialization should use the schema names specified in the schema.xml files
+ * instead of using the connection schema. Using the connection specified schema is the default behavior.
+ *
+ * @return <b>true</b> if the file specified schemas should be used.
+ */
+ public static boolean useSchemasSpecifiedInDbConfigFiles() {
+ return Boolean.valueOf(getProperty(OSEE_USE_FILE_SPECIFIED_SCHEMAS));
+ }
+
+ /**
+ * @return whether to interactively prompt the user during database initialization for init choice
+ */
+ public static boolean promptOnDbInit() {
+ return Boolean.valueOf(getProperty(OSEE_PROMPT_ON_DB_INIT, "true"));
+ }
+
+ /**
+ * @return the predefined database initialization choice
+ */
+ public static String getChoiceOnDbInit() {
+ return getProperty(OSEE_CHOICE_ON_DB_INIT);
+ }
+
+ /**
+ * Retrieves whether OSEE database initialization should import database data as part of its tasks.
+ *
+ * @return <b>true</b> if database initialization should import database data as part of its tasks.
+ */
+ public static boolean isOseeImportAllowed() {
+ return Boolean.valueOf(getProperty(OSEE_IMPORT_DURING_DB_INIT));
+ }
+
+ /**
+ * Gets whether local application server launch is required
+ *
+ * @return <b>true</b> if local application server launch is required. <b>false</b> if local application server
+ * launch is not required.
+ */
+ public static boolean isLocalApplicationServerRequired() {
+ return Boolean.valueOf(getProperty(OSEE_LOCAL_APPLICATION_SERVER));
+ }
+
+ /**
+ * Retrieves settings for user activity logging. The default is true.
+ *
+ * @return <b>true</b> if user activity should be logged
+ */
+ public static boolean isActivityLoggingEnabled() {
+ return Boolean.valueOf(getProperty(OSEE_USAGE_LOG, "true"));
+ }
+
+ /**
+ * Retrieves the specified port to use for the local HTTP server
+ *
+ * @return port to use
+ */
+ public static String getLocalHttpWorkerPort() {
+ return getProperty(OSEE_LOCAL_HTTP_WORKER_PORT);
+ }
+
+ /**
+ * Authentication Protocol to use
+ *
+ * @return client/server authentication protocol.
+ */
+ public static String getAuthenticationProtocol() {
+ return getProperty(OSEE_AUTHENTICATION_PROTOCOL);
+ }
+
+ /**
+ * <pre>
+ * Sets the application server address and port to use. This system property sets the URL used to reference
+ * the application server. Arbitration is bypassed.
+ * </pre>
+ *
+ * <b>Format: </b> <code>http://address:port</code>
+ *
+ * @param application server URL to use instead going through the arbitration server
+ */
+ public static void setOseeApplicationServer(String value) {
+ System.setProperty(OSEE_APPLICATION_SERVER, value);
+ }
+
+ /**
+ * <pre>
+ * Retrieves the application server address and port to use. When specified, this system property sets the URL used to reference
+ * the application server. Arbitration is bypassed.
+ * </pre>
+ *
+ * <b>Format: </b> <code>http://address:port</code>
+ *
+ * @return application server URL to use instead going through the arbitration server
+ */
+ public static String getOseeApplicationServer() {
+ return getProperty(OSEE_APPLICATION_SERVER);
+ }
+
+ /**
+ * <pre>
+ * Retrieves the arbitration server address and port to use. This system property must be specified for the system to
+ * gain access to OSEE data. If the application server property is set then that address takes precedence and
+ * arbitration is bypassed.
+ * </pre>
+ *
+ * <b>Format: </b> <code>http://address:port</code>
+ *
+ * @return default arbitration server URL to set preferences.
+ */
+ public static String getOseeArbitrationServer() {
+ return getProperty(OSEE_ARBITRATION_SERVER);
+ }
+
+ private static String getProperty(String name) {
+ return getProperty(name, "");
+ }
+
+ private static String getProperty(String name, String defaultValue) {
+ String toReturn = null;
+ if (instance.overwriteProperties.containsKey(name)) {
+ toReturn = instance.overwriteProperties.getProperty(name);
+ } else if (instance.defaultProperties.containsKey(name)) {
+ toReturn = System.getProperty(name, instance.defaultProperties.getProperty(name));
+ } else {
+ toReturn = System.getProperty(name, defaultValue);
+ }
+ return toReturn;
+ }
+
+ /**
+ * A string representation of all the property setting specified by this class
+ *
+ * @return settings for all properties specified by this class
+ */
+ public static String getAllSettings() {
+ return instance.toString();
+ }
+
+ public void initialize() {
+ BundleContext context = CoreClientActivator.getBundleContext();
+ for (Bundle bundle : context.getBundles()) {
+ Dictionary<?, ?> header = bundle.getHeaders();
+ if (header != null) {
+ String data = (String) header.get(HEADER_TAG);
+ if (Strings.isValid(data)) {
+ String[] entries = data.split(",");
+ for (String entry : entries) {
+ int index = entry.indexOf(';');
+ if (index != -1) {
+ String resourcePath = entry.substring(0, index);
+ String flagString = entry.substring(index + 1, entry.length());
+ processInitializer(bundle, resourcePath, InitializerFlag.fromString(flagString));
+ } else {
+ processInitializer(bundle, entry, InitializerFlag.client_defaults);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private void processInitializer(Bundle bundle, String resourcePath, InitializerFlag flag) {
+ URL url = bundle.getResource(resourcePath);
+ if (url != null) {
+ Properties properties = new Properties();
+ try {
+ properties.loadFromXML(url.openStream());
+ } catch (Exception ex) {
+ OseeLog.log(CoreClientActivator.class, Level.SEVERE, ex.toString(), ex);
+ }
+ if (!properties.isEmpty()) {
+ OseeLog.log(CoreClientActivator.class, Level.INFO, String.format("Initializing properties [%s]", flag));
+
+ Properties itemToSet = null;
+ switch (flag) {
+ case client_defaults:
+ itemToSet = defaultProperties;
+ break;
+ case overwrite_settings:
+ itemToSet = overwriteProperties;
+ // Set System properties. Also cache the values to prevent application overwrites.
+ for (Entry<Object, Object> entry : properties.entrySet()) {
+ System.setProperty((String) entry.getKey(), (String) entry.getValue());
+ }
+ break;
+ }
+
+ if (itemToSet != null) {
+ itemToSet.putAll(properties);
+ }
+ }
+ }
+ }
+}
diff --git a/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/OseeClientSession.java b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/OseeClientSession.java new file mode 100644 index 00000000000..0021351ed7b --- /dev/null +++ b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/OseeClientSession.java @@ -0,0 +1,83 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.client;
+
+import java.io.Serializable;
+
+/**
+ * @author Donald G. Dunne
+ */
+public class OseeClientSession implements Serializable {
+
+ private static final long serialVersionUID = 6322394150666846304L;
+
+ private String id;
+ private String machineName;
+ private String userId;
+ private String machineIp;
+ private String clientVersion;
+ private int port;
+
+ public OseeClientSession(String id, String machineName, String userId, String machineIp, int port, String clientVersion) {
+ this.id = id;
+ this.machineName = machineName;
+ this.machineIp = machineIp;
+ this.userId = userId;
+ this.clientVersion = clientVersion;
+ this.port = port;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("Session:[%s] User Id:[%s] Version:[%s] Machine Name:[%s] Ip:[%s] Port:[%s]", id, userId,
+ clientVersion, machineName, machineIp, port);
+ }
+
+ public int getPort() {
+ return port;
+ }
+
+ /**
+ * @return the client version
+ */
+ public String getVersion() {
+ return clientVersion;
+ }
+
+ /**
+ * @return the id
+ */
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * @return the machineName
+ */
+ public String getMachineName() {
+ return machineName;
+ }
+
+ /**
+ * @return the userId
+ */
+ public String getUserId() {
+ return userId;
+ }
+
+ /**
+ * @return the machineIp
+ */
+ public String getMachineIp() {
+ return machineIp;
+ }
+
+}
diff --git a/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/ClientDatabaseProvider.java b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/ClientDatabaseProvider.java new file mode 100644 index 00000000000..9c1732d6ed3 --- /dev/null +++ b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/ClientDatabaseProvider.java @@ -0,0 +1,52 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.client.internal;
+
+import java.util.logging.Level;
+import org.eclipse.osee.framework.core.exception.OseeAuthenticationRequiredException;
+import org.eclipse.osee.framework.db.connection.IApplicationDatabaseInfoProvider;
+import org.eclipse.osee.framework.db.connection.IDatabaseInfo;
+import org.eclipse.osee.framework.logging.BaseStatus;
+import org.eclipse.osee.framework.logging.OseeLog;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class ClientDatabaseProvider implements IApplicationDatabaseInfoProvider {
+
+ private static final String NAME = "Client Data Source";
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.db.connection.IApplicationDatabaseInfoProvider#getDatabaseInfo()
+ */
+ @Override
+ public IDatabaseInfo getDatabaseInfo() throws OseeAuthenticationRequiredException {
+ IDatabaseInfo databaseInfo = null;
+ try {
+ databaseInfo = InternalClientSessionManager.getInstance().getDatabaseInfo();
+ OseeLog.reportStatus(new BaseStatus(NAME, Level.INFO, "%s [%s as %s]", databaseInfo.getDriver(),
+ databaseInfo.getDatabaseName(), databaseInfo.getDatabaseLoginName()));
+ } catch (OseeAuthenticationRequiredException ex) {
+ OseeLog.reportStatus(new BaseStatus(NAME, Level.SEVERE, ex, "Error obtaining database connection."));
+ throw ex;
+ }
+ return databaseInfo;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.db.connection.IApplicationDatabaseInfoProvider#getPriority()
+ */
+ @Override
+ public int getPriority() {
+ return -1;
+ }
+
+}
diff --git a/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/CorePreferenceInitializer.java b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/CorePreferenceInitializer.java new file mode 100644 index 00000000000..225e076a633 --- /dev/null +++ b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/CorePreferenceInitializer.java @@ -0,0 +1,47 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.osee.framework.core.client.internal;
+
+import java.net.UnknownHostException;
+import java.util.logging.Level;
+import org.eclipse.core.runtime.Preferences;
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.osee.framework.core.client.CoreClientActivator;
+import org.eclipse.osee.framework.core.client.CorePreferences;
+import org.eclipse.osee.framework.jdk.core.util.Network;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+import org.eclipse.osee.framework.logging.OseeLog;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class CorePreferenceInitializer extends AbstractPreferenceInitializer {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
+ */
+ public void initializeDefaultPreferences() {
+ Preferences store = CoreClientActivator.getInstance().getPluginPreferences();
+ try {
+ String defaultNetworkValue = Network.getValidIP().getHostAddress();
+ store.setDefault(CorePreferences.INETADDRESS_KEY, defaultNetworkValue);
+ String value = store.getString(CorePreferences.INETADDRESS_KEY);
+ if (!Strings.isValid(value)) {
+ store.setValue(CorePreferences.INETADDRESS_KEY, store.getDefaultString(CorePreferences.INETADDRESS_KEY));
+ }
+ } catch (UnknownHostException ex) {
+ OseeLog.log(CoreClientActivator.class, Level.SEVERE, "Error initializing default inet address key", ex);
+ }
+ }
+}
diff --git a/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/InternalClientSessionManager.java b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/InternalClientSessionManager.java new file mode 100644 index 00000000000..fc6fa7724a9 --- /dev/null +++ b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/InternalClientSessionManager.java @@ -0,0 +1,246 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.client.internal;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.InetAddress;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import org.eclipse.osee.framework.core.client.BaseCredentialProvider;
+import org.eclipse.osee.framework.core.client.CoreClientActivator;
+import org.eclipse.osee.framework.core.client.GuestCredentialProvider;
+import org.eclipse.osee.framework.core.client.ICredentialProvider;
+import org.eclipse.osee.framework.core.client.OseeClientSession;
+import org.eclipse.osee.framework.core.client.OseeClientProperties;
+import org.eclipse.osee.framework.core.client.server.HttpServer;
+import org.eclipse.osee.framework.core.client.server.HttpUrlBuilder;
+import org.eclipse.osee.framework.core.data.OseeClientInfo;
+import org.eclipse.osee.framework.core.data.OseeCodeVersion;
+import org.eclipse.osee.framework.core.data.OseeCredential;
+import org.eclipse.osee.framework.core.data.OseeServerContext;
+import org.eclipse.osee.framework.core.data.OseeSessionGrant;
+import org.eclipse.osee.framework.core.exception.OseeAuthenticationException;
+import org.eclipse.osee.framework.core.exception.OseeAuthenticationRequiredException;
+import org.eclipse.osee.framework.db.connection.IDatabaseInfo;
+import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
+import org.eclipse.osee.framework.db.connection.exception.OseeDataStoreException;
+import org.eclipse.osee.framework.db.connection.exception.OseeWrappedException;
+import org.eclipse.osee.framework.jdk.core.util.HttpProcessor;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+import org.eclipse.osee.framework.jdk.core.util.HttpProcessor.AcquireResult;
+import org.eclipse.osee.framework.logging.BaseStatus;
+import org.eclipse.osee.framework.logging.OseeLog;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class InternalClientSessionManager {
+ public static final String STATUS_ID = "Session Manager";
+ private static final InternalClientSessionManager instance = new InternalClientSessionManager();
+
+ private final OseeClientInfo clientInfo;
+ private OseeSessionGrant oseeSessionGrant;
+ private OseeClientSession oseeSession;
+
+ private InternalClientSessionManager() {
+ clearData();
+ this.clientInfo = new OseeClientInfo();
+ clientInfo.setClientAddress(HttpServer.getLocalServerAddress(), HttpServer.getDefaultServicePort());
+ clientInfo.setClientVersion(OseeCodeVersion.getVersion());
+ try {
+ clientInfo.setClientMachineName(InetAddress.getLocalHost().getHostName());
+ } catch (Exception ex) {
+ clientInfo.setClientMachineName(clientInfo.getClientAddress());
+ }
+ }
+
+ public static InternalClientSessionManager getInstance() {
+ return instance;
+ }
+
+ public boolean isSessionValid() {
+ return oseeSession != null;
+ }
+
+ public IDatabaseInfo getDatabaseInfo() throws OseeAuthenticationRequiredException {
+ return getOseeSessionGrant().getDatabaseInfo();
+ }
+
+ public OseeSessionGrant getOseeSessionGrant() throws OseeAuthenticationRequiredException {
+ ensureSessionCreated();
+ if (isSessionValid()) {
+ return oseeSessionGrant;
+ }
+ throw new OseeAuthenticationRequiredException("Session is invalid - authentication is required");
+ }
+
+ public OseeClientSession getOseeSession() throws OseeAuthenticationRequiredException {
+ ensureSessionCreated();
+ if (isSessionValid()) {
+ return oseeSession;
+ }
+ throw new OseeAuthenticationRequiredException("Session is invalid - authentication is required");
+ }
+
+ public void authenticateAsGuest() throws OseeCoreException {
+ authenticate(new GuestCredentialProvider());
+ }
+
+ public synchronized OseeClientSession authenticate(ICredentialProvider credentialProvider) throws OseeCoreException {
+ if (!isSessionValid()) {
+ try {
+ OseeCredential credential = credentialProvider.getCredential();
+ clearData();
+ oseeSessionGrant = internalAcquireSession(credential);
+ oseeSession =
+ new OseeClientSession(oseeSessionGrant.getSessionId(), clientInfo.getClientMachineName(),
+ oseeSessionGrant.getOseeUserInfo().getUserID(), clientInfo.getClientAddress(),
+ clientInfo.getPort(), clientInfo.getVersion());
+ } catch (OseeCoreException ex) {
+ OseeLog.reportStatus(new BaseStatus(STATUS_ID, Level.SEVERE, ex));
+ throw ex;
+ }
+ OseeLog.reportStatus(new BaseStatus(STATUS_ID, Level.INFO, "%s", oseeSession));
+ }
+ return oseeSession;
+ }
+
+ public void ensureSessionCreated() {
+ if (!isSessionValid()) {
+ try {
+ authenticate(new BaseCredentialProvider() {
+ public OseeCredential getCredential() throws OseeCoreException {
+ OseeCredential credential = super.getCredential();
+ credential.setUserName(System.getProperty("user.name"));
+ credential.setDomain("");
+ credential.setPassword("");
+ credential.setAuthenticationProtocol(OseeClientProperties.getAuthenticationProtocol());
+ return credential;
+ }
+ });
+ } catch (Exception ex) {
+ OseeLog.log(CoreClientActivator.class, Level.SEVERE, ex);
+ try {
+ authenticateAsGuest();
+ } catch (Exception ex1) {
+ OseeLog.log(CoreClientActivator.class, Level.SEVERE, ex1);
+ }
+ }
+ }
+ }
+
+ public void releaseSession() throws OseeCoreException {
+ if (isSessionValid()) {
+ internalReleaseSession(getOseeSessionGrant().getSessionId());
+ }
+ }
+
+ private void internalReleaseSession(String sessionId) throws OseeDataStoreException {
+ Map<String, String> parameters = new HashMap<String, String>();
+ parameters.put("operation", "release");
+ parameters.put("sessionId", sessionId);
+ try {
+ String url =
+ HttpUrlBuilder.getInstance().getOsgiServletServiceUrl(OseeServerContext.SESSION_CONTEXT, parameters);
+ String reponse = HttpProcessor.post(new URL(url));
+ OseeLog.log(CoreClientActivator.class, Level.INFO, reponse);
+ oseeSession = null;
+ oseeSessionGrant = null;
+ } catch (Exception ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ public String[] getAuthenticationProtocols() {
+ List<String> toReturn = new ArrayList<String>();
+ try {
+ Map<String, String> parameters = new HashMap<String, String>();
+ String url =
+ HttpUrlBuilder.getInstance().getOsgiServletServiceUrl(OseeServerContext.SESSION_CONTEXT, parameters);
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ AcquireResult result = HttpProcessor.acquire(new URL(url), outputStream);
+ if (result.getCode() == HttpURLConnection.HTTP_OK) {
+ String protocols = outputStream.toString("UTF-8");
+ if (Strings.isValid(protocols)) {
+ String[] results = protocols.split("[\\[\\]\\s,]+");
+ for (String entry : results) {
+ if (Strings.isValid(entry)) {
+ toReturn.add(entry);
+ }
+ }
+ }
+ }
+ } catch (Exception ex) {
+ OseeLog.log(CoreClientActivator.class, Level.SEVERE, ex);
+ }
+ return toReturn.toArray(new String[toReturn.size()]);
+ }
+
+ private void clearData() {
+ this.oseeSession = null;
+ this.oseeSessionGrant = null;
+ }
+
+ private OseeSessionGrant internalAcquireSession(OseeCredential credential) throws OseeCoreException {
+ OseeSessionGrant session = null;
+ Map<String, String> parameters = new HashMap<String, String>();
+ parameters.put("operation", "create");
+ String url = null;
+ try {
+ url = HttpUrlBuilder.getInstance().getOsgiServletServiceUrl(OseeServerContext.SESSION_CONTEXT, parameters);
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ AcquireResult result =
+ HttpProcessor.post(new URL(url), asInputStream(credential), "text/xml", "UTF-8", outputStream);
+ if (result.getCode() == HttpURLConnection.HTTP_ACCEPTED) {
+ session = fromEncryptedBytes(outputStream.toByteArray());
+ }
+ } catch (IOException ex) {
+ throw new OseeAuthenticationException(url, ex);
+ }
+ return session;
+ }
+
+ private static ByteArrayInputStream asInputStream(OseeCredential credential) throws OseeWrappedException {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ credential.write(outputStream);
+
+ //TODO ENCRYPT DATA
+
+ return new ByteArrayInputStream(outputStream.toByteArray());
+ }
+
+ private static OseeSessionGrant fromEncryptedBytes(byte[] rawData) throws OseeWrappedException {
+ OseeSessionGrant session = null;
+ InputStream inputStream = null;
+ try {
+ //TODO DECRYPT DATA
+ inputStream = new ByteArrayInputStream(rawData);
+ session = OseeSessionGrant.fromXml(inputStream);
+ } finally {
+ if (inputStream != null) {
+ try {
+ inputStream.close();
+ } catch (IOException ex) {
+ throw new OseeWrappedException(ex);
+ }
+ }
+ }
+ return session;
+ }
+}
diff --git a/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/OseeApplicationServer.java b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/OseeApplicationServer.java new file mode 100644 index 00000000000..03f4e84bf56 --- /dev/null +++ b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/internal/OseeApplicationServer.java @@ -0,0 +1,167 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.client.internal;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.sql.Timestamp;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.eclipse.osee.framework.core.client.CoreClientActivator;
+import org.eclipse.osee.framework.core.client.OseeClientProperties;
+import org.eclipse.osee.framework.core.client.server.HttpUrlBuilder;
+import org.eclipse.osee.framework.core.data.OseeCodeVersion;
+import org.eclipse.osee.framework.core.data.OseeServerContext;
+import org.eclipse.osee.framework.core.data.OseeServerInfo;
+import org.eclipse.osee.framework.core.exception.OseeArbitrationServerException;
+import org.eclipse.osee.framework.db.connection.exception.OseeDataStoreException;
+import org.eclipse.osee.framework.jdk.core.util.HttpProcessor;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+import org.eclipse.osee.framework.jdk.core.util.HttpProcessor.AcquireResult;
+import org.eclipse.osee.framework.logging.BaseStatus;
+import org.eclipse.osee.framework.logging.OseeLog;
+
+/**
+ * @author Andrew M. Finkbeiner
+ */
+public class OseeApplicationServer {
+
+ private static String oseeServer = null;
+ private static boolean isServerAlive = false;
+ private static OseeServerInfo serverInfo = null;
+ private static final String ArbitrationService = "Arbitration Server";
+ private static final String ApplicationServer = "Application Server";
+
+ private OseeApplicationServer() {
+ }
+
+ public static String getOseeApplicationServer() throws OseeArbitrationServerException {
+ checkAndUpdateStatus();
+ if (Strings.isValid(oseeServer) != true) {
+ throw new OseeArbitrationServerException("Invalid resource server address");
+ }
+ return oseeServer;
+ }
+
+ public static boolean isApplicationServerAlive() {
+ checkAndUpdateStatus();
+ return isServerAlive;
+ }
+
+ private static void checkAndUpdateStatus() {
+ isServerAlive = false;
+ if (serverInfo == null) {
+ String overrideValue = OseeClientProperties.getOseeApplicationServer();
+ if (Strings.isValid(overrideValue)) {
+ serverInfo = fromString(overrideValue);
+ } else {
+ serverInfo = getOseeServerAddress();
+ }
+ if (serverInfo != null) {
+ oseeServer = String.format("http://%s:%s/", serverInfo.getServerAddress(), serverInfo.getPort());
+ }
+ }
+ DateFormat format = new SimpleDateFormat("MM/dd/yyyy hh:mm a");
+ if (oseeServer == null) {
+ OseeLog.reportStatus(new BaseStatus(ApplicationServer, Level.SEVERE, "Application server address was null"));
+ } else {
+ isServerAlive = checkStatus();
+ if (isServerAlive) {
+ OseeLog.reportStatus(new BaseStatus(ApplicationServer, Level.INFO, "%s [%s] Running Since: %s", oseeServer,
+ serverInfo.getVersion(), format.format(serverInfo.getDateStarted())));
+ }
+ }
+ }
+
+ private static boolean checkStatus() {
+ boolean canConnect = false;
+ HttpURLConnection connection = null;
+ try {
+ URL url = new URL(oseeServer);
+ connection = (HttpURLConnection) url.openConnection();
+ connection.connect();
+ canConnect = true;
+ } catch (Exception ex) {
+ OseeLog.reportStatus(new BaseStatus(ApplicationServer, Level.SEVERE, ex));
+ } finally {
+ if (connection != null) {
+ connection.disconnect();
+ }
+ }
+ return canConnect;
+ }
+
+ public static OseeServerInfo fromString(String value) {
+ Pattern pattern = Pattern.compile("http://(.*):(\\d+)");
+ Matcher matcher = pattern.matcher(value);
+ if (matcher.find()) {
+ String address = matcher.group(1);
+ int port = Integer.valueOf(matcher.group(2));
+ return new OseeServerInfo("OVERRIDE", address, port, "OVERRIDE", new Timestamp(new Date().getTime()), true);
+ }
+ return null;
+ }
+
+ private static OseeServerInfo getOseeServerAddress() {
+ OseeServerInfo oseeServerInfo = null;
+ ByteArrayOutputStream outputStream = null;
+ InputStream inputStream = null;
+ try {
+ Map<String, String> parameters = new HashMap<String, String>();
+ parameters.put("version", OseeCodeVersion.getVersion());
+ String url =
+ HttpUrlBuilder.getInstance().getOsgiArbitrationServiceUrl(OseeServerContext.LOOKUP_CONTEXT, parameters);
+
+ outputStream = new ByteArrayOutputStream();
+ AcquireResult result = HttpProcessor.acquire(new URL(url), outputStream);
+ try {
+ OseeLog.reportStatus(new BaseStatus(ArbitrationService, Level.INFO, "%s",
+ HttpUrlBuilder.getInstance().getArbitrationServerPrefix()));
+ } catch (OseeDataStoreException ex) {
+ OseeLog.log(CoreClientActivator.class, Level.SEVERE, ex);
+ }
+ if (result.getCode() == HttpURLConnection.HTTP_OK) {
+ inputStream = new ByteArrayInputStream(outputStream.toByteArray());
+ oseeServerInfo = OseeServerInfo.fromXml(inputStream);
+ }
+ } catch (Exception ex) {
+ OseeLog.log(CoreClientActivator.class, Level.SEVERE, ex);
+ OseeLog.reportStatus(new BaseStatus(ArbitrationService, Level.SEVERE, ex,
+ "Error requesting application server for version [%s]", OseeCodeVersion.getVersion()));
+ } finally {
+ if (inputStream != null) {
+ try {
+ inputStream.close();
+ } catch (IOException ex) {
+ OseeLog.log(CoreClientActivator.class, Level.SEVERE, ex);
+ }
+ }
+ if (outputStream != null) {
+ try {
+ outputStream.close();
+ } catch (IOException ex) {
+ OseeLog.log(CoreClientActivator.class, Level.SEVERE, ex);
+ }
+ }
+ }
+ return oseeServerInfo;
+ }
+}
diff --git a/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/server/HttpGetMethod.java b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/server/HttpGetMethod.java new file mode 100644 index 00000000000..260ed1fbc2e --- /dev/null +++ b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/server/HttpGetMethod.java @@ -0,0 +1,40 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.client.server;
+
+import java.util.List;
+import org.eclipse.osee.framework.plugin.core.util.ExtensionDefinedObjects;
+
+/**
+ * @author Roberto E. Escobar
+ */
+final class HttpGetMethod implements IHttpMethod {
+
+ private static ExtensionDefinedObjects<IHttpServerRequest> extensionObjects = null;
+
+ protected HttpGetMethod() {
+ }
+
+ public void processRequest(HttpRequest httpRequest, HttpResponse httpResponse) {
+ String requestType = httpRequest.getUrlRequest();
+ if (extensionObjects == null) {
+ extensionObjects =
+ new ExtensionDefinedObjects<IHttpServerRequest>(
+ "org.eclipse.osee.framework.skynet.core.HttpServerRequest", "IHttpServerRequest", "classname");
+ }
+ List<IHttpServerRequest> httpServerRequests = extensionObjects.getObjects();
+ for (IHttpServerRequest request : httpServerRequests) {
+ if (request.getRequestType().equals(requestType)) {
+ request.processRequest(httpRequest, httpResponse);
+ }
+ }
+ }
+}
diff --git a/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/server/HttpRequest.java b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/server/HttpRequest.java new file mode 100644 index 00000000000..9e62cf5a5a2 --- /dev/null +++ b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/server/HttpRequest.java @@ -0,0 +1,227 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.core.client.server; + +import java.io.BufferedInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.net.InetAddress; +import java.net.Socket; +import java.net.URLDecoder; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.logging.Level; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.eclipse.osee.framework.core.client.CoreClientActivator; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.framework.logging.OseeLog; + +/** + * @author Roberto E. Escobar + */ +public class HttpRequest { + + public enum HttpMethod { + GET, POST, PUT, DELETE, RESOURCE_GET, INVALID; + } + private Map<String, String> parameterMap; + private String rawRequest; + private String urlRequest; + private Map<String, String> httpHeader; + private String httpProtocol; + private InputStream inputStream; + private HttpMethod httpMethod; + private InetAddress remoteAddress; + private int remotePort; + private Socket socket; + + protected HttpRequest(Socket socket) throws Exception { + this.socket = socket; + this.parameterMap = new HashMap<String, String>(); + this.rawRequest = ""; + this.urlRequest = ""; + this.httpHeader = new HashMap<String, String>(); + this.httpMethod = HttpMethod.INVALID; + + this.inputStream = new BufferedInputStream(socket.getInputStream()); + this.remoteAddress = socket.getInetAddress(); + this.remotePort = socket.getPort(); + initialize(); + } + + private void initialize() throws Exception { + InputStream inputStream = getInputStream(); + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + int value = -1; + char lastChar = 0; + char currChar = 0; + while ((value = inputStream.read()) != -1) { + currChar = (char) value; + if (currChar != '\n' && currChar != '\r') { + buffer.write((byte) value); + } + + if (lastChar == '\r' && currChar == '\n') { + String toProcess = buffer.toString("ISO-8859-1"); + buffer.reset(); + if (Strings.isValid(toProcess)) { + if (toProcess.contains("HTTP")) { + parseRequest(toProcess); + } else { + parseHeader(toProcess); + } + + } else { + break; + } + } + lastChar = currChar; + } + } + + private void parseHeader(String line) throws Exception { + Matcher matcher = Pattern.compile("(.*?):\\s*(.*)").matcher(line); + if (matcher.matches()) { + httpHeader.put(matcher.group(1), matcher.group(2)); + } + } + + public String getParameter(String key) { + String toReturn = parameterMap.get(key); + return Strings.isValid(toReturn) ? toReturn : ""; + } + + public Set<String> getParameterKeys() { + return parameterMap.keySet(); + } + + public String getParametersAsString() { + return parameterMap.toString(); + } + + public InputStream getInputStream() { + return inputStream; + } + + public HttpMethod getMethod() { + return httpMethod; + } + + public InetAddress getOriginatingAddress() { + return remoteAddress; + } + + public int getOriginatingPort() { + return remotePort; + } + + public String getHttpHeaderEntry(String key) { + String toReturn = httpHeader.get(key); + return Strings.isValid(toReturn) ? toReturn : ""; + } + + public Set<String> getHttpHeaderKeys() { + return httpHeader.keySet(); + } + + public String getHttpProtocol() { + return httpProtocol; + } + + public String getUrlRequest() { + return urlRequest; + } + + public String getRawRequest() { + return rawRequest; + } + + public Socket getSocket() { + return socket; + } + + private void parseRequest(String entry) throws Exception { + this.rawRequest = entry; + OseeLog.log(CoreClientActivator.class, Level.INFO, "HttpRequest *" + rawRequest + "*"); + String[] entries = rawRequest.split("\\s"); + if (entries.length > 0 && entries.length < 4) { + httpMethod = HttpMethod.valueOf(entries[0].trim()); + httpProtocol = entries[2].trim(); + + String request = entries[1].trim(); + boolean wasOldStyle = parseOldSchoolStyleLinks(request); + if (wasOldStyle == false) { + parseNewStyleRequests(request); + } + } + } + + /** + * Process new style requests are of the following format: + * http://127.0.0.1:<port>/<ProcessType>?key1=value1&key2=value2...&key3=value3 + * + * @param entry + * @throws Exception + */ + private void parseNewStyleRequests(String request) throws Exception { + String noHostStr = request.replaceFirst("^http:\\/\\/(.*?)\\/", "/"); + Matcher matcher = Pattern.compile("/(.*?)\\?(.*)").matcher(noHostStr); + if (matcher.matches()) { + urlRequest = matcher.group(1); + + if (!Strings.isValid(urlRequest)) { + throw new IllegalArgumentException("Unknown requestType \"" + rawRequest + "\""); + } + String data = matcher.group(2); + Matcher dataMatcher = Pattern.compile("([^&]*?)=([^&]*)").matcher(data); + while (dataMatcher.find()) { + parameterMap.put(dataMatcher.group(1), URLDecoder.decode(dataMatcher.group(2), "UTF-8")); + } + } else { + if (httpMethod.equals(HttpMethod.GET)) { + httpMethod = HttpMethod.RESOURCE_GET; + } + urlRequest = request; + } + } + + /** + * Process old format: http://127.0.0.1:<port>/get/guid/<guid>/<ats,Define> TODO old format should be removed once + * all legacy references are change to new format + * + * @param entry + * @return + * @throws Exception + */ + private boolean parseOldSchoolStyleLinks(String entry) throws Exception { + boolean handled = false; + Matcher oldMatcher = Pattern.compile("/(.*?)/guid/(.*?)/(.*)").matcher(entry); + if (oldMatcher.find()) { + handled = true; + String guid = oldMatcher.group(2); + if (oldMatcher.groupCount() > 2) { + String processType = oldMatcher.group(3); + if (processType.equals("ats")) { + parameterMap.put("guid", guid); + urlRequest = processType.toUpperCase(); + } else if (processType.equals("Define") || processType.equals("")) { + parameterMap.put("guid", guid); + urlRequest = "Define"; + } else { + throw new IllegalArgumentException("Unnable to parse old style link: \"" + rawRequest + "\""); + } + } + } + return handled; + } +} diff --git a/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/server/HttpRequestHandler.java b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/server/HttpRequestHandler.java new file mode 100644 index 00000000000..f0d552fa99c --- /dev/null +++ b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/server/HttpRequestHandler.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ + +package org.eclipse.osee.framework.core.client.server; + +import java.io.IOException; +import java.net.Socket; +import java.util.HashMap; +import java.util.Map; +import java.util.logging.Level; +import org.eclipse.osee.framework.core.client.CoreClientActivator; +import org.eclipse.osee.framework.core.client.server.HttpRequest.HttpMethod; +import org.eclipse.osee.framework.logging.OseeLog; + +/** + * @author Roberto E. Escobar + */ +public class HttpRequestHandler implements Runnable { + + private static Map<HttpMethod, IHttpMethod> httpMethodHandlers; + static { + httpMethodHandlers = new HashMap<HttpMethod, IHttpMethod>(); + httpMethodHandlers.put(HttpMethod.RESOURCE_GET, HttpResourceRequest.getInstance()); + httpMethodHandlers.put(HttpMethod.GET, new HttpGetMethod()); + } + private Socket socket; + + public HttpRequestHandler(Socket socket) throws Exception { + this.socket = socket; + } + + public void run() { + try { + processRequest(); + } catch (Exception ex) { + OseeLog.log(CoreClientActivator.class, Level.SEVERE, "Error Processing Request: ", ex); + } + } + + private void processRequest() throws Exception { + HttpRequest httpRequest = null; + HttpResponse httpResponse = null; + try { + httpRequest = new HttpRequest(socket); + httpResponse = new HttpResponse(socket); + + try { + processRequest(httpRequest, httpResponse); + } catch (Exception ex) { + httpResponse.outputStandardError(400, "Exception in processing Request ", ex); + } + } finally { + // Close streams and socket. + if (httpResponse != null && httpResponse.getOutputStream() != null) { + httpResponse.getOutputStream().close(); + } + if (httpRequest != null && httpRequest.getInputStream() != null) { + httpRequest.getInputStream().close(); + } + + if (socket != null && !socket.isClosed()) { + socket.close(); + } + } + } + + private void processRequest(HttpRequest httpRequest, HttpResponse httpResponse) throws IOException { + IHttpMethod httpMethod = httpMethodHandlers.get(httpRequest.getMethod()); + if (httpMethod != null) { + httpMethod.processRequest(httpRequest, httpResponse); + } else { + httpResponse.sendResponseHeaders(405, 0); + } + } +} diff --git a/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/server/HttpResourceRequest.java b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/server/HttpResourceRequest.java new file mode 100644 index 00000000000..a16779fd1e4 --- /dev/null +++ b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/server/HttpResourceRequest.java @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.core.client.server; + +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintStream; +import java.net.URL; +import java.util.List; +import java.util.logging.Level; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.Platform; +import org.eclipse.osee.framework.core.client.CoreClientActivator; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.framework.logging.OseeLog; +import org.eclipse.osee.framework.plugin.core.util.ExtensionPoints; +import org.osgi.framework.Bundle; + +/** + * @author Roberto E. Escobar + */ +public class HttpResourceRequest implements IHttpMethod { + + private static HttpResourceRequest instance = new HttpResourceRequest(); + + private HttpResourceRequest() { + } + + public static HttpResourceRequest getInstance() { + return instance; + } + + public void processRequest(HttpRequest httpRequest, HttpResponse httpResponse) { + String urlRequest = httpRequest.getUrlRequest(); + URL url = findResource(urlRequest); + if (url != null) { + sendResource(url, httpResponse.getOutputStream()); + } else { + httpResponse.outputStandardError(400, "Invalid Request: *" + urlRequest + "*"); + } + } + + private void sendResource(URL url, OutputStream outputStream) { + BufferedInputStream bis = null; + try { + bis = new BufferedInputStream(url.openStream()); + PrintStream ps = new PrintStream(outputStream, true, "UTF-8"); + byte[] buffer = new byte[1024]; + int count; + while ((count = bis.read(buffer)) != -1) { + ps.write(buffer, 0, count); + } + } catch (IOException ex) { + OseeLog.log(CoreClientActivator.class, Level.SEVERE, "Error sending requested resource", ex); + } finally { + try { + bis.close(); + } catch (IOException ex) { + OseeLog.log(CoreClientActivator.class, Level.SEVERE, "Error closing stream", ex); + } + } + } + + private URL findResource(String urlRequested) { + URL resource = null; + if (Strings.isValid(urlRequested) && urlRequested.endsWith("/") != true) { + if (resource == null) { + List<IConfigurationElement> elements = + ExtensionPoints.getExtensionElements("org.eclipse.osee.framework.skynet.core.WebPage", + "WebPageFolder"); + for (IConfigurationElement element : elements) { + String resourceName = element.getAttribute("Path"); + String bundleName = element.getContributor().getName(); + + if (Strings.isValid(bundleName) && Strings.isValid(resourceName)) { + try { + Bundle bundle = Platform.getBundle(bundleName); + URL url = bundle.getEntry(resourceName + urlRequested); + if (url != null) { + resource = FileLocator.resolve(url); + break; + } + } catch (Exception ex) { + throw new IllegalArgumentException(String.format("Unable to Load: [%s.%s]", bundleName, + resourceName)); + } + } + } + } + } + return resource; + } +} diff --git a/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/server/HttpResponse.java b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/server/HttpResponse.java new file mode 100644 index 00000000000..b31e18b0e78 --- /dev/null +++ b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/server/HttpResponse.java @@ -0,0 +1,252 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.core.client.server; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintStream; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.net.Socket; +import java.util.Date; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Set; +import java.util.logging.Level; +import org.eclipse.osee.framework.core.client.CoreClientActivator; +import org.eclipse.osee.framework.jdk.core.util.AHTML; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.framework.logging.OseeLog; + +/** + * @author Roberto E. Escobar + */ +public class HttpResponse { + private static final String ENTRY_SEPARATOR = "\r\n"; + private static final String FIELD_VALUE_SEPARATOR = ": "; + private static final String STATUS_LINE = "HTTP/1.1 "; + private static final String SERVER_ENTRY = "Server: SkynetHttpServer"; + private static final String DATE_ENTRY = "Date"; + private static final String CONTENT_LENGTH = "Content-Length"; + private static final String CONTENT_ENCODING = "Content-Encoding"; + private static final String CONTENT_TYPE = "Content-Type"; + private static final String CONTENT_DISPOSITION = "Content-Disposition"; + + private static Map<Integer, String> codes; + static { + HttpResponse.codes = new HashMap<Integer, String>(); + codes.put(100, StatusCodes.STATUS_100); + codes.put(101, StatusCodes.STATUS_101); + codes.put(200, StatusCodes.STATUS_200); + codes.put(201, StatusCodes.STATUS_201); + codes.put(202, StatusCodes.STATUS_202); + codes.put(203, StatusCodes.STATUS_203); + codes.put(204, StatusCodes.STATUS_204); + codes.put(205, StatusCodes.STATUS_205); + codes.put(206, StatusCodes.STATUS_206); + codes.put(300, StatusCodes.STATUS_300); + codes.put(301, StatusCodes.STATUS_301); + codes.put(302, StatusCodes.STATUS_302); + codes.put(303, StatusCodes.STATUS_303); + codes.put(304, StatusCodes.STATUS_304); + codes.put(305, StatusCodes.STATUS_305); + codes.put(307, StatusCodes.STATUS_307); + codes.put(401, StatusCodes.STATUS_401); + codes.put(402, StatusCodes.STATUS_402); + codes.put(403, StatusCodes.STATUS_403); + codes.put(404, StatusCodes.STATUS_404); + codes.put(405, StatusCodes.STATUS_405); + codes.put(406, StatusCodes.STATUS_406); + codes.put(407, StatusCodes.STATUS_407); + codes.put(408, StatusCodes.STATUS_408); + codes.put(409, StatusCodes.STATUS_409); + codes.put(410, StatusCodes.STATUS_410); + codes.put(411, StatusCodes.STATUS_411); + codes.put(412, StatusCodes.STATUS_412); + codes.put(413, StatusCodes.STATUS_413); + codes.put(414, StatusCodes.STATUS_414); + codes.put(415, StatusCodes.STATUS_415); + codes.put(416, StatusCodes.STATUS_416); + codes.put(417, StatusCodes.STATUS_417); + codes.put(500, StatusCodes.STATUS_500); + codes.put(501, StatusCodes.STATUS_501); + codes.put(502, StatusCodes.STATUS_502); + codes.put(503, StatusCodes.STATUS_503); + codes.put(504, StatusCodes.STATUS_504); + codes.put(505, StatusCodes.STATUS_505); + codes.put(400, StatusCodes.STATUS_400); + } + + private Map<String, String> responseHeaderMap; + private PrintStream printStream; + private OutputStream outputStream; + private Socket socket; + + protected HttpResponse(Socket socket) throws Exception { + this.socket = socket; + this.outputStream = socket.getOutputStream(); + this.responseHeaderMap = new LinkedHashMap<String, String>(); + this.printStream = new PrintStream(outputStream, true, "UTF-8"); + } + + public OutputStream getOutputStream() { + return outputStream; + } + + public PrintStream getPrintStream() { + return printStream; + } + + public void setContentEncoding(String encoding) { + setReponseHeader(CONTENT_ENCODING, encoding); + } + + public void setContentType(String contentType) { + setReponseHeader(CONTENT_TYPE, contentType); + } + + public void setContentDisposition(String disposition) { + setReponseHeader(CONTENT_DISPOSITION, disposition); + } + + public void setReponseHeader(String field, String value) { + responseHeaderMap.put(field, value); + } + + public String getResponseHeaderField(String field) { + String toReturn = responseHeaderMap.get(field); + return Strings.isValid(toReturn) ? toReturn : ""; + } + + public Set<String> getResponseHeaderFields() { + return responseHeaderMap.keySet(); + } + + public static String getStatus(int value) { + return codes.get(value); + } + + public String getResponseHeader(int errorCode, long responseLength) { + StringBuffer buffer = new StringBuffer(); + buffer.append(STATUS_LINE); + buffer.append(getStatus(errorCode)); + buffer.append(ENTRY_SEPARATOR); + + buffer.append(SERVER_ENTRY); + buffer.append(ENTRY_SEPARATOR); + + buffer.append(DATE_ENTRY); + buffer.append(FIELD_VALUE_SEPARATOR); + buffer.append(new Date().toString()); + buffer.append(ENTRY_SEPARATOR); + + Set<String> fields = responseHeaderMap.keySet(); + for (String field : fields) { + String values = responseHeaderMap.get(field); + buffer.append(field); + buffer.append(FIELD_VALUE_SEPARATOR); + buffer.append(values); + buffer.append(ENTRY_SEPARATOR); + } + buffer.append(ENTRY_SEPARATOR); + return buffer.toString(); + } + + public void sendResponseHeaders(int errorCode, long responseLength) throws IOException { + setReponseHeader(CONTENT_LENGTH, Long.toString(responseLength)); + byte[] header = getResponseHeader(errorCode, responseLength).getBytes(); + sendInputStream(new ByteArrayInputStream(header)); + } + + public void sendBody(InputStream inputStream) throws IOException { + sendInputStream(inputStream); + } + + private void sendInputStream(InputStream inputStream) throws IOException { + byte[] buf = new byte[10000]; + int count = -1; + while ((count = inputStream.read(buf)) != -1) { + outputStream.write(buf, 0, count); + } + inputStream.close(); + } + + public void outputStandardError(int errorCode, String message, Throwable ex) { + StringWriter sw = new StringWriter(); + if (ex != null) { + ex.printStackTrace(new PrintWriter(sw)); + } + outputStandardError(errorCode, message + sw.toString()); + } + + public void outputStandardError(int errorCode, String reason) { + String errorStr = getStatus(errorCode); + String reasonStr = (reason != null ? "Reason: " + reason : ""); + String html = + AHTML.simplePage("<h1>Error " + errorStr + "</h1><h2>OSEE was unable to handle the request.</h2>" + reasonStr + "<form><input type=button onClick='window.opener=self;window.close()' value='Close'></form>"); + OseeLog.log(CoreClientActivator.class, Level.SEVERE, "HttpServer Request failed. " + reasonStr); + try { + printStream.println(html); + } catch (Exception ex) { + OseeLog.log(CoreClientActivator.class, Level.SEVERE, "Error sending error string", ex); + } + } + + public Socket getSocket() { + return socket; + } + + private final class StatusCodes { + private static final String STATUS_100 = "100 Continue"; + private static final String STATUS_101 = "101 Switching Protocols"; + private static final String STATUS_200 = "200 OK"; + private static final String STATUS_201 = "201 Created"; + private static final String STATUS_202 = "202 Accepted"; + private static final String STATUS_203 = "203 Non-Authoritative Information"; + private static final String STATUS_204 = "204 No Content"; + private static final String STATUS_205 = "205 Reset Content"; + private static final String STATUS_206 = "206 Partial Content"; + private static final String STATUS_300 = "300 Multiple Choices"; + private static final String STATUS_301 = "301 Moved Permanently"; + private static final String STATUS_302 = "302 Found"; + private static final String STATUS_303 = "303 See Other"; + private static final String STATUS_304 = "304 Not Modified"; + private static final String STATUS_305 = "305 Use Proxy"; + private static final String STATUS_307 = "307 Temporary Redirect"; + private static final String STATUS_400 = "400 Bad Request"; + private static final String STATUS_401 = "401 Unauthorized"; + private static final String STATUS_402 = "402 Payment Required"; + private static final String STATUS_403 = "403 Forbidden"; + private static final String STATUS_404 = "404 Not Found"; + private static final String STATUS_405 = "405 Method Not Allowed"; + private static final String STATUS_406 = "406 Not Acceptable"; + private static final String STATUS_407 = "407 Proxy Authentication Required"; + private static final String STATUS_408 = "408 Request Time-out"; + private static final String STATUS_409 = "409 Conflict"; + private static final String STATUS_410 = "410 Gone"; + private static final String STATUS_411 = "411 Length Required"; + private static final String STATUS_412 = "412 Precondition Failed"; + private static final String STATUS_413 = "413 Request Entity Too Large"; + private static final String STATUS_414 = "414 Request-URI Too Large"; + private static final String STATUS_415 = "415 Unsupported Media Type"; + private static final String STATUS_416 = "416 Requested range not satisfiable"; + private static final String STATUS_417 = "417 Expectation Failed"; + private static final String STATUS_500 = "500 Internal Server Error"; + private static final String STATUS_501 = "501 Not Implemented"; + private static final String STATUS_502 = "502 Bad Gateway"; + private static final String STATUS_503 = "503 Service Unavailable"; + private static final String STATUS_504 = "504 Gateway Time-out"; + private static final String STATUS_505 = "505 HTTP Version not supported"; + } +} diff --git a/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/server/HttpServer.java b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/server/HttpServer.java new file mode 100644 index 00000000000..14bec2d46c3 --- /dev/null +++ b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/server/HttpServer.java @@ -0,0 +1,252 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ + +package org.eclipse.osee.framework.core.client.server; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.SocketTimeoutException; +import java.net.UnknownHostException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.logging.Level; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.osee.framework.core.client.CoreClientActivator; +import org.eclipse.osee.framework.core.client.CorePreferences; +import org.eclipse.osee.framework.core.client.OseeClientProperties; +import org.eclipse.osee.framework.core.data.OseeCodeVersion; +import org.eclipse.osee.framework.jdk.core.util.Strings; +import org.eclipse.osee.framework.logging.OseeLog; +import org.eclipse.osee.framework.plugin.core.util.ExtensionPoints; + +public class HttpServer implements Runnable { + private static final int DEFAULT_HTTP_PRODUCTION_PORT = 8010; + private static final int DEFAULT_HTTP_DEVELOPMENT_PORT = 8011; + protected static final String DEFAULT_SERVICE_NAME = "osee.http.server"; + + private static String serverAddress; + private static boolean isRemoteServer = false; + private static boolean neverRun = true; + private final int port; + private boolean listenFlag; + private ServerSocket listenSocket; + private String serviceName; + private ExecutorService executorService; + + private static final Map<String, HttpServer> availableServers = new HashMap<String, HttpServer>(); + + public static void remoteServerStartup() { + startServers(10); + isRemoteServer = true; + } + + public static String getLocalServerAddress() { + if (serverAddress == null) { + if (isRemoteServer) { + try { + InetAddress address = InetAddress.getLocalHost(); + serverAddress = address.getHostAddress(); + } catch (UnknownHostException ex) { + try { + serverAddress = CorePreferences.getDefaultInetAddress().getHostAddress(); + } catch (UnknownHostException ex1) { + OseeLog.log(CoreClientActivator.class, Level.SEVERE, ex1.toString(), ex1); + } + } + } else { + try { + serverAddress = CorePreferences.getDefaultInetAddress().getHostAddress(); + } catch (UnknownHostException ex) { + OseeLog.log(CoreClientActivator.class, Level.SEVERE, ex); + } + } + } + return serverAddress; + } + + public static int getPortByServiceName(String serviceName) { + int toReturn = -1; + HttpServer server = availableServers.get(serviceName); + if (server != null) { + toReturn = server.getPort(); + } + return toReturn; + } + + public static int getDefaultServicePort() { + return getPortByServiceName(HttpServer.DEFAULT_SERVICE_NAME); + } + + /** + * Starts HTTP Servers listening on a port for particularly formmated requests. A server will be started for each + * org.eclipse.osee.framework.skynet.core.HttpServerPort extension point defined. If no such extension point is + * defined, then skynet will use the osee.http.port system property. Finally if a port has still not been specified, + * the DEFAULT_HTTP_SERVER_PORT will be used. + * + * @param maxThreads TODO + */ + public static void startServers(int maxThreads) { + if (neverRun) { + neverRun = false; + Map<String, Integer> serversToRun = determineRequestedPorts(); + for (String key : serversToRun.keySet()) { + int port = serversToRun.get(key); + HttpServer server = new HttpServer(key, port, maxThreads); + availableServers.put(key, server); + Thread thread = new Thread(server); + thread.setName(String.format("%s:%s", key, port)); + thread.start(); + } + } + } + + public HttpServer(String serviceName, int port, int poolSize) { + this.listenFlag = true; + this.serviceName = serviceName; + this.port = port; + this.executorService = Executors.newFixedThreadPool(poolSize); + // new ServerKiller(this); + } + + /** + * Shuts down the HTTP Server + */ + public void haltServer() { + listenFlag = false; + } + + public static void stopServers() { + for (HttpServer server : HttpServer.availableServers.values()) { + server.haltServer(); + } + } + + private String getServiceName() { + return serviceName; + } + + private int getPort() { + return port; + } + + private String createNameForConnection(Socket incoming) { + return String.format("%s:%s - Worker - %s:%s", getServiceName(), getPort(), incoming.getInetAddress(), + incoming.getPort()); + } + + /** + * Not to be called directly. Use the constructor. + */ + public void run() { + try { + // Establish the listen socket. + listenSocket = new ServerSocket(getPort()); + OseeLog.log(CoreClientActivator.class, Level.INFO, String.format("Starting HttpServer on port: [%s]", + getPort())); + + // Process HTTP service requests in an infinite loop. + while (listenFlag) { + // Listen for a TCP connection request. + listenSocket.setSoTimeout(10000); + try { + Socket incoming = listenSocket.accept(); + try { + final HttpRequestHandler handler = new HttpRequestHandler(incoming); + final String threadName = createNameForConnection(incoming); + + // Process the request in a new thread + this.executorService.execute(new Runnable() { + public void run() { + Thread thread = Thread.currentThread(); + String oldName = thread.getName(); + thread.setName(threadName); + try { + handler.run(); + } finally { + thread.setName(oldName); + } + } + }); + } catch (Exception ex) { + OseeLog.log(CoreClientActivator.class, Level.SEVERE, "Error processing request.", ex); + } + } catch (SocketTimeoutException ex) { + /* + * this catch statement is hit every 10 seconds since that is the timeout value that + * has been set which allows the loop to check if the server should keep running (so + * don't log the exception) + */ + } + } + } catch (IOException ex) { + OseeLog.log(CoreClientActivator.class, Level.WARNING, "Unable to start HttpServer, socket may be busy", ex); + } + } + + private static Map<String, Integer> determineRequestedPorts() { + Map<String, Integer> ports = new HashMap<String, Integer>(); + List<IConfigurationElement> elements = + ExtensionPoints.getExtensionElements("org.eclipse.osee.framework.skynet.core.HttpServerPort", + "HttpServerPort"); + for (IConfigurationElement element : elements) { + String serviceName = element.getAttribute("serviceName"); + try { + String portAttribute = "productionPort"; + if (OseeCodeVersion.isDevelopment()) { + portAttribute = "developmentPort"; + } + Integer port = new Integer(element.getAttribute(portAttribute)); + + // If a serviceName is not provided, we assume extension point is + // attempting to override the default service. + if (true != Strings.isValid(serviceName)) { + OseeLog.log(CoreClientActivator.class, Level.INFO, String.format( + "Contributor [%s] overriding [%s]. Using port [%s]", element.getContributor().getName(), + DEFAULT_SERVICE_NAME, port)); + serviceName = DEFAULT_SERVICE_NAME; + } + ports.put(serviceName, port); + } catch (NumberFormatException ex) { + OseeLog.log(CoreClientActivator.class, Level.WARNING, String.format("Invalid Port for: [%s][%s]", + element.getName(), serviceName), ex); + } + } + String value = OseeClientProperties.getLocalHttpWorkerPort(); + int portToUse = 0; + if (Strings.isValid(value)) { + try { + portToUse = Integer.valueOf(value); + } catch (Exception ex) { + portToUse = 0; + } + } + + if (ports.containsKey(DEFAULT_SERVICE_NAME) == false || portToUse != 0) { + // User Specified Port take Precedence + if (portToUse == 0) { + portToUse = + false != OseeCodeVersion.isDevelopment() ? DEFAULT_HTTP_DEVELOPMENT_PORT : DEFAULT_HTTP_PRODUCTION_PORT; + } + ports.put(DEFAULT_SERVICE_NAME, portToUse); + + if (DEFAULT_HTTP_PRODUCTION_PORT != portToUse) { + OseeLog.log(CoreClientActivator.class, Level.INFO, String.format( + "HttpServer port override. Using port [%s]", portToUse)); + } + } + return ports; + } +} diff --git a/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/server/HttpUrlBuilder.java b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/server/HttpUrlBuilder.java new file mode 100644 index 00000000000..2ec414b96df --- /dev/null +++ b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/server/HttpUrlBuilder.java @@ -0,0 +1,123 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.osee.framework.core.client.server;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.Map;
+import java.util.logging.Level;
+import org.eclipse.osee.framework.core.client.CoreClientActivator;
+import org.eclipse.osee.framework.core.client.OseeClientProperties;
+import org.eclipse.osee.framework.core.client.internal.OseeApplicationServer;
+import org.eclipse.osee.framework.core.exception.OseeArbitrationServerException;
+import org.eclipse.osee.framework.db.connection.exception.OseeDataStoreException;
+import org.eclipse.osee.framework.logging.OseeLog;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class HttpUrlBuilder {
+ private static final String urlPrefixFormat = "http://%s:%s/";
+ private static HttpUrlBuilder instance = null;
+
+ private HttpUrlBuilder() {
+ }
+
+ public static HttpUrlBuilder getInstance() {
+ if (instance == null) {
+ instance = new HttpUrlBuilder();
+ }
+ return instance;
+ }
+
+ private String encode(String value) throws UnsupportedEncodingException {
+ return URLEncoder.encode(value, "UTF-8");
+ }
+
+ public String getParametersAsEncodedUrl(Map<String, String> keyValues) throws UnsupportedEncodingException {
+ StringBuilder sb = new StringBuilder();
+ for (String key : keyValues.keySet()) {
+ sb.append(encode(key));
+ sb.append("=");
+ sb.append(encode(keyValues.get(key)));
+ sb.append("&");
+ }
+ if (sb.length() - 1 >= 0) {
+ // Delete the last unnecessary '&'
+ sb.deleteCharAt(sb.length() - 1);
+ }
+ return sb.toString();
+ }
+
+ public String getLocalServerPrefix(String serviceName) {
+ int port = HttpServer.getPortByServiceName(serviceName);
+ if (port == -1) {
+ throw new IllegalStateException(
+ "Http Server was not launched by this workbench - Ensure port was set correctly");
+ }
+ return String.format(urlPrefixFormat, HttpServer.getLocalServerAddress(), port);
+ }
+
+ private String buildUrl(String prefix, String context, String parameters) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(prefix);
+ sb.append(context);
+ sb.append("?");
+ sb.append(parameters);
+ return sb.toString();
+ }
+
+ public String getUrlForLocalSkynetHttpServer(String context, Map<String, String> parameters) {
+ try {
+ return buildUrl(getSkynetHttpLocalServerPrefix(), context, getParametersAsEncodedUrl(parameters));
+ } catch (UnsupportedEncodingException ex) {
+ OseeLog.log(CoreClientActivator.class, Level.SEVERE, ex);
+ }
+ return null;
+ }
+
+ public String getSkynetHttpLocalServerPrefix() {
+ return getLocalServerPrefix(HttpServer.DEFAULT_SERVICE_NAME);
+ }
+
+ public String getApplicationServerPrefix() throws OseeDataStoreException, OseeArbitrationServerException {
+ String address = OseeApplicationServer.getOseeApplicationServer();
+ if (address.endsWith("/") != true) {
+ address += "/";
+ }
+ return address;
+ }
+
+ public String getArbitrationServerPrefix() throws OseeDataStoreException {
+ String address = OseeClientProperties.getOseeArbitrationServer();
+ if (address.endsWith("/") != true) {
+ address += "/";
+ }
+ return address;
+ }
+
+ public String getOsgiServletServiceUrl(String context, Map<String, String> parameters) throws OseeDataStoreException {
+ try {
+ return buildUrl(getApplicationServerPrefix(), context, getParametersAsEncodedUrl(parameters));
+ } catch (UnsupportedEncodingException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+
+ public String getOsgiArbitrationServiceUrl(String context, Map<String, String> parameters) throws OseeDataStoreException {
+ try {
+ return buildUrl(getArbitrationServerPrefix(), context, getParametersAsEncodedUrl(parameters));
+ } catch (UnsupportedEncodingException ex) {
+ throw new OseeDataStoreException(ex);
+ }
+ }
+}
diff --git a/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/server/IHttpMethod.java b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/server/IHttpMethod.java new file mode 100644 index 00000000000..e9814b4da3c --- /dev/null +++ b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/server/IHttpMethod.java @@ -0,0 +1,23 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.client.server;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public interface IHttpMethod {
+
+ /**
+ * @param httpRequest The HttpRequest object
+ * @param httpResponse The HttpResponse object
+ */
+ public void processRequest(HttpRequest httpRequest, HttpResponse httpResponse);
+}
diff --git a/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/server/IHttpServerRequest.java b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/server/IHttpServerRequest.java new file mode 100644 index 00000000000..02ebc62303b --- /dev/null +++ b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/server/IHttpServerRequest.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.framework.core.client.server; + +/** + * @author Donald G. Dunne + */ +public interface IHttpServerRequest extends IHttpMethod { + + /** + * @return single word request type for use in URL and in determining requestor + */ + public String getRequestType(); + + /** + * @param httpRequest The HttpRequest object + * @param httpResponse The HttpResponse object + */ + public void processRequest(HttpRequest httpRequest, HttpResponse httpResponse); + +} diff --git a/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/task/ProgressMonitorTask.java b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/task/ProgressMonitorTask.java new file mode 100644 index 00000000000..29fa93a34aa --- /dev/null +++ b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/task/ProgressMonitorTask.java @@ -0,0 +1,61 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.client.task;
+
+import java.sql.Statement;
+import java.util.concurrent.TimeUnit;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class ProgressMonitorTask extends ScheduledTask {
+ private final IProgressMonitor monitor;
+ private final Statement statement;
+
+ private ProgressMonitorTask(IProgressMonitor monitor, Statement statement, String name) {
+ super(name);
+ this.monitor = monitor;
+ this.statement = statement;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.framework.core.client.task.ScheduledTask#innerRun()
+ */
+ @Override
+ protected void innerRun() throws Exception {
+ if (monitor != null) {
+ if (monitor.isCanceled()) {
+ if (statement != null) {
+ statement.cancel();
+ }
+ unscheduleTask();
+ }
+ } else {
+ unscheduleTask();
+ }
+ }
+
+ private void unscheduleTask() {
+ Thread stopThread = new Thread() {
+ public void run() {
+ Scheduler.cancelTask(ProgressMonitorTask.this);
+ }
+ };
+ stopThread.start();
+ }
+
+ public static ScheduledTask monitor(String name, IProgressMonitor monitor, Statement statement, long millis) {
+ ProgressMonitorTask task = new ProgressMonitorTask(monitor, statement, name);
+ Scheduler.scheduleAtFixedRate(task, 0, millis, TimeUnit.MILLISECONDS);
+ return task;
+ }
+}
\ No newline at end of file diff --git a/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/task/ScheduledTask.java b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/task/ScheduledTask.java new file mode 100644 index 00000000000..c2b461d1ddb --- /dev/null +++ b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/task/ScheduledTask.java @@ -0,0 +1,50 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.client.task;
+
+import java.util.concurrent.ScheduledFuture;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public abstract class ScheduledTask implements Runnable {
+ private final String name;
+ private ScheduledFuture<ScheduledTask> futureTask;
+
+ protected ScheduledTask(String name) {
+ this.name = name;
+ this.futureTask = null;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public final void run() {
+ try {
+ innerRun();
+ } catch (Throwable th) {
+ th.printStackTrace();
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ void setScheduledFuture(ScheduledFuture<?> futureTask) {
+ this.futureTask = (ScheduledFuture<ScheduledTask>) futureTask;
+ }
+
+ protected ScheduledFuture<ScheduledTask> getFutureTask() {
+ return futureTask;
+ }
+
+ protected abstract void innerRun() throws Exception;
+
+}
diff --git a/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/task/Scheduler.java b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/task/Scheduler.java new file mode 100644 index 00000000000..f8201f4e5e1 --- /dev/null +++ b/0.5.0_20081201/org.eclipse.osee.framework.core.client/src/org/eclipse/osee/framework/core/client/task/Scheduler.java @@ -0,0 +1,94 @@ +/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.client.task;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class Scheduler {
+
+ private static final InternalScheduler scheduler = new InternalScheduler();
+
+ private Scheduler() {
+ }
+
+ public static void scheduleAtFixedRate(ScheduledTask command, long initialDelay, long period, TimeUnit unit) {
+ scheduler.scheduleAtFixedRate(command, initialDelay, period, unit);
+ }
+
+ public static void scheduleWithFixedDelay(ScheduledTask command, long initialDelay, long delay, TimeUnit unit) {
+ scheduler.scheduleWithFixedDelay(command, initialDelay, delay, unit);
+ }
+
+ public static void cancelTask(ScheduledTask command) {
+ scheduler.cancelTask(command);
+ }
+
+ public static void shutdown() {
+ scheduler.shutdown();
+ }
+
+ private static final class InternalScheduler {
+ private final Map<Runnable, ScheduledFuture<?>> futures;
+ private final ScheduledExecutorService executor;
+
+ public InternalScheduler() {
+ futures = Collections.synchronizedMap(new HashMap<Runnable, ScheduledFuture<?>>());
+ executor = Executors.newSingleThreadScheduledExecutor(new SchedulerThreadFactory());
+ }
+
+ public void scheduleAtFixedRate(ScheduledTask command, long initialDelay, long period, TimeUnit unit) {
+ ScheduledFuture<?> futureTask = executor.scheduleAtFixedRate(command, initialDelay, period, unit);
+ futures.put(command, futureTask);
+ command.setScheduledFuture(futureTask);
+ }
+
+ public void scheduleWithFixedDelay(ScheduledTask command, long initialDelay, long delay, TimeUnit unit) {
+ ScheduledFuture<?> futureTask = executor.scheduleWithFixedDelay(command, initialDelay, delay, unit);
+ futures.put(command, futureTask);
+ command.setScheduledFuture(futureTask);
+ }
+
+ public void cancelTask(ScheduledTask command) {
+ ScheduledFuture<?> future = futures.get(command);
+ if (future != null) {
+ if (future.cancel(true)) {
+ futures.remove(command);
+ }
+ }
+ }
+
+ public void shutdown() {
+ executor.shutdownNow();
+ }
+ }
+
+ private static final class SchedulerThreadFactory implements ThreadFactory {
+
+ /* (non-Javadoc)
+ * @see java.util.concurrent.ThreadFactory#newThread(java.lang.Runnable)
+ */
+ @Override
+ public Thread newThread(Runnable runnable) {
+ return new Thread(((ScheduledTask) runnable).getName());
+ }
+
+ }
+}
|