Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.equinox.http/src/org')
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/Activator.java44
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/DefaultHttpContext.java45
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/ExternalMessages.properties59
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/Http.java207
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpConfiguration.java618
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpConnection.java148
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpDate.java387
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpListener.java486
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpMsg.java71
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpSecurityTracker.java42
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpServerSocket.java76
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpService.java75
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpSocket.java91
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpThread.java134
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpThreadPool.java287
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/LogMessages.properties16
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/LogTracker.java173
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/LogTrackerMsg.java27
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/Registration.java32
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/ResourceRegistration.java229
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/ResourceUnavailableException.java15
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/SSLTracker.java27
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/SecureAction.java92
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/ServletRegistration.java87
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/StaticDataReader.java228
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/Tokenizer.java113
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/URI.java127
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/mime.types44
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/HttpServletRequestImpl.java1438
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/HttpServletResponseImpl.java861
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/HttpSessionContextImpl.java53
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/HttpSessionImpl.java501
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/RequestDispatcherImpl.java294
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/ServletConfigImpl.java71
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/ServletContextImpl.java450
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/ServletInputStreamImpl.java514
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/ServletOutputStreamImpl.java139
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/ServletPrintWriter.java46
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/status.codes52
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/socket/ServerSocketInterface.java32
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/socket/SocketInterface.java73
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/socket/https/HttpsServerSocket.java156
-rw-r--r--bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/socket/https/HttpsSocket.java117
43 files changed, 0 insertions, 8777 deletions
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/Activator.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/Activator.java
deleted file mode 100644
index 7cc753132..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/Activator.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2006 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http;
-
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-
-/**
- */
-
-public class Activator implements BundleActivator {
- /*
- * ----------------------------------------------------------------------
- * BundleActivator Interface implementation
- * ----------------------------------------------------------------------
- */
-
- private Http http = null;
-
- /**
- * Required by BundleActivator Interface.
- */
- public void start(BundleContext context) throws Exception {
- http = new Http(context);
- http.start();
- }
-
- /**
- * Required by BundleActivator Interface.
- */
- public void stop(BundleContext context) throws Exception {
- http.stop();
- http.close();
- http = null;
- }
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/DefaultHttpContext.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/DefaultHttpContext.java
deleted file mode 100644
index e63e4f137..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/DefaultHttpContext.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2005 IBM Corporation.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http;
-
-import java.io.IOException;
-import java.net.URL;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.osgi.framework.Bundle;
-import org.osgi.service.http.HttpContext;
-
-public class DefaultHttpContext implements HttpContext {
-
- protected Bundle bundle;
- protected HttpSecurityTracker securityTracker;
-
- public DefaultHttpContext(Bundle bundle, HttpSecurityTracker securityTracker) {
- this.bundle = bundle;
- this.securityTracker = securityTracker;
- }
-
- /* Implementation defined behavior */
- public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) throws IOException {
- return securityTracker.handleSecurity(request, response);
- }
-
- /* Behavior defined by OSGi spec */
- public URL getResource(String name) {
- return (new SecureAction()).getBundleResource(bundle, name);
- }
-
- /* Behavior defined by OSGi spec */
- public String getMimeType(String name) {
- return null;
- }
-
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/ExternalMessages.properties b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/ExternalMessages.properties
deleted file mode 100644
index aab018df9..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/ExternalMessages.properties
+++ /dev/null
@@ -1,59 +0,0 @@
-###############################################################################
-# Copyright (c) 2005, 2006 IBM Corporation and others.
-# 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:
-# IBM Corporation - initial API and implementation
-###############################################################################
-# NLS_MESSAGEFORMAT_ALL
-
-HTTP_ALIAS_ALREADY_REGISTERED_EXCEPTION=Alias {0} is already registered
-HTTP_SERVLET_ALREADY_REGISTERED_EXCEPTION=This servlet object has already been registered under a different alias
-HTTP_SERVLET_NULL_EXCEPTION=This servlet object is null.
-HTTP_SERVLET_EXCEPTION=Servlet Exception
-HTTP_ALIAS_UNREGISTER_EXCEPTION=Alias could not be unregistered
-HTTP_ALIAS_INVALID_EXCEPTION=Invalid alias {0} alias must start with a "/" but not end with a "/"
-HTTP_RESOURCE_NAME_INVALID_EXCEPTION=Invalid resource name {0} name must not end with a "/"
-HTTP_SERVET_INIT_EXCEPTION=Servlet init exception
-HTTP_DEFAULT_MIME_TABLE_ERROR=An error occured processing the default MIME table
-HTTP_STATUS_CODES_TABLE_ERROR=An error occured processing the status codes table
-HTTP_STATUS_CODE_NOT_FOUND=Unsupported
-HTTP_ACCEPT_SOCKET_EXCEPTION=Error while waiting on port {0}
-HTTP_PORT_IN_USE_EXCEPTION=Port {0} is use
-HTTP_INVALID_VALUE_RANGE_EXCEPTION=Value must be between {0} and {1}
-HTTP_CONNECTION_EXCEPTION=Error handling connection
-HTTP_INVALID_SCHEME_EXCEPTION=The scheme {0} is not supported
-HTTP_NO_HEADER_LINE_READ_EXCEPTION=No header line was read
-HTTP_QUERYDATA_PARSE_EXCEPTION=Exception parsing query data
-HTTP_INVALID_HEADER_LINE_EXCEPTION=Invalid header line: {0}
-HTTP_HEADER_LINE_TOO_LONG_EXCEPTION=Header line was larger than buffer size: {0}
-HTTP_UNEXPECTED_IOEXCEPTION=An unexpected IOException occurred
-HTTP_UNEXPECTED_RUNTIMEEXCEPTION=An unexpected RuntimeException occurred
-HTTP_ONLY_SUPPORTS_2_1=HttpService only supports servlet 2.1 specification.
-HTTP_HOST_UNKNOWN=The host address "{0}" is unknown. Defaulting to all IP addresses.
-OSGi_Http_Service_IBM_Implementation_16=OSGi Http Service - IBM Implementation
-IBM_Http_Service_37=IBM Http Service
-Jan_1=Jan
-Feb_2=Feb
-Mar_3=Mar
-Apr_4=Apr
-May_5=May
-Jun_6=Jun
-Jul_7=Jul
-Aug_8=Aug
-Sep_9=Sep
-Oct_10=Oct
-Nov_11=Nov
-Dec_12=Dec
-Sun_13=Sun
-Mon_14=Mon
-Tue_15=Tue
-Wed_16=Wed
-Thu_17=Thu
-Fri_18=Fri
-Sat_19=Sat
-HTTP_DEFAULT_PORT_FORMAT_EXCEPTION={0} value is not an integer
-HTTP_THREAD_POOL_CREATE_NUMBER_ERROR=Failed to create thread number {0}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/Http.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/Http.java
deleted file mode 100644
index 8d14565ba..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/Http.java
+++ /dev/null
@@ -1,207 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2007 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.util.Hashtable;
-import java.util.Vector;
-import org.eclipse.equinox.http.servlet.HttpSessionImpl;
-import org.eclipse.equinox.socket.ServerSocketInterface;
-import org.eclipse.equinox.socket.https.HttpsServerSocket;
-import org.eclipse.osgi.util.NLS;
-import org.osgi.framework.BundleContext;
-import org.osgi.service.log.LogService;
-
-public class Http {
- public static final boolean DEBUG = false;
- BundleContext context;
- private LogTracker log = null;
-
- protected HttpConfiguration configuration;
-
- /** Mapping of Session ID (String) => HttpSessionImpl */
- protected Hashtable sessions;
-
- protected Vector servlets;
- protected StaticDataReader dataReader;
-
- HttpSecurityTracker securityTracker;
-
- protected Http(BundleContext context) throws Exception {
- this.context = context;
-
- initialize();
- }
-
- /**
- * Initializes fields.
- * <p>
- * Added for subclassing purposes
- */
- protected void initialize() throws Exception {
- log = new LogTracker(context, System.out);
- log.open();
-
- securityTracker = new HttpSecurityTracker(context);
-
- servlets = new Vector(15);
-
- //initialize sessions Hashtable
- sessions = new Hashtable(15);
-
- //get a MIMETypes object to compute MIMETypes
- dataReader = new StaticDataReader(this);
- }
-
- protected void start() throws Exception {
- if (Http.DEBUG) {
- logDebug("Starting Http Service bundle"); //$NON-NLS-1$
- }
-
- try {
- configuration = new HttpConfiguration(this);
- } catch (IOException e) {
- logError("Http Service failed to start -- HALTING", e); //$NON-NLS-1$
- stop();
- throw e;
- }
-
- if (Http.DEBUG) {
- logInfo("Http Service started"); //$NON-NLS-1$
- }
- }
-
- protected void stop() {
- if (Http.DEBUG) {
- logDebug("Stopping Http Service bundle"); //$NON-NLS-1$
- }
-
- if (configuration != null) {
- configuration.close();
- configuration = null;
- }
-
- if (Http.DEBUG) {
- logDebug("Http Service stopped"); //$NON-NLS-1$
- }
- }
-
- protected void close() {
-
- if (securityTracker != null) {
- securityTracker.close();
- securityTracker = null;
- }
-
- if (log != null) {
- log.close();
- log = null;
- }
- }
-
- /**
- * @param session javax.servlet.http.HttpSession
- */
- public void addSession(HttpSessionImpl session) {
- sessions.put(session.getId(), session);
- }
-
- public void removeSession(HttpSessionImpl session) {
- sessions.remove(session.getId());
- }
-
- /**
- * Returns a valid session from the cache.
- *
- * @param id ID of requested session.
- * @return Valid session object.
- */
- public HttpSessionImpl getSession(String id) {
- HttpSessionImpl session = (HttpSessionImpl) sessions.get(id);
-
- if ((session != null) && (session.isValid(true))) {
- return (session); /* session is valid */
- }
- /* session is null or invalid and has removed itself from the cache */
-
- return (null);
- }
-
- /**
- * @return MIMETypes
- */
- public String getMimeType(String name) {
- return (dataReader.computeMimeType(name));
- }
-
- /**
- * @return java.lang.String
- * @param statusCode java.lang.String
- */
- public String getStatusPhrase(int statusCode) {
- return (dataReader.computeStatusPhrase(statusCode));
- }
-
- public void logDebug(String message) {
- if (Http.DEBUG) {
- System.out.println(message);
-
- log.log(LogService.LOG_DEBUG, message);
- }
- }
-
- public void logDebug(String message, Throwable t) {
- if (Http.DEBUG) {
- System.out.println(message);
- t.printStackTrace(System.out);
-
- log.log(LogService.LOG_DEBUG, message, t);
- }
- }
-
- public void logError(String message, Throwable t) {
- if (Http.DEBUG) {
- System.out.println(message);
- t.printStackTrace(System.out);
- }
-
- log.log(LogService.LOG_ERROR, message, t);
- }
-
- public void logInfo(String message) {
- if (Http.DEBUG) {
- System.out.println(message);
- }
-
- log.log(LogService.LOG_INFO, message);
- }
-
- public void logWarning(String message, Throwable t) {
- if (Http.DEBUG) {
- System.out.println(message);
- t.printStackTrace(System.out);
- }
-
- log.log(LogService.LOG_WARNING, message, t);
- }
-
- protected ServerSocketInterface createSSLServerSocket(int port, int backlog, InetAddress address) throws IOException {
- HttpsServerSocket socket;
- try {
- socket = new HttpsServerSocket(context, port, backlog, address);
- } catch (UnsupportedOperationException ex) {
- throw new IOException(NLS.bind(HttpMsg.HTTP_INVALID_SCHEME_EXCEPTION, "https")); //$NON-NLS-1$
- }
- return (socket);
- }
-
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpConfiguration.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpConfiguration.java
deleted file mode 100644
index efffd7185..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpConfiguration.java
+++ /dev/null
@@ -1,618 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2009 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.security.*;
-import java.util.*;
-import org.eclipse.equinox.socket.ServerSocketInterface;
-import org.eclipse.osgi.util.NLS;
-import org.osgi.framework.*;
-import org.osgi.service.cm.*;
-
-/**
- * This class is the main configuration class for Http Service. It creates the
- * thread pool and the listeners and responds to configuration changes.
- */
-
-public class HttpConfiguration implements ManagedService, ManagedServiceFactory {
-
- /** default HttpListener object for 'http' protocol
- * This object is set if ConfigurationAdmin has NOT configured any
- * HttpListeners and we are not waiting to be configured.
- */
- private HttpListener defaultHttpListener;
- /** default HttpListener object for 'https' protocol
- * This object is set if ConfigurationAdmin has NOT configured any
- * HttpListeners and we are not waiting to be configured.
- */
- private HttpListener defaultHttpsListener;
- /** Hashtable of HttpListener object configured by the ConfigurationAdmin
- * Configuration PID (String) => HttpListener object
- */
- Hashtable configuredListeners;
-
- protected Http http;
-
- protected HttpThreadPool pool;
-
- protected final static String enviroKeyHttpPort = "org.osgi.service.http.port"; //$NON-NLS-1$
- protected final static String enviroKeyHttpsPort = "org.osgi.service.http.port.secure"; //$NON-NLS-1$
- protected final static String enviroKeyHttpAddress = "org.eclipse.equinox.http.address"; //$NON-NLS-1$
-
- protected final static String HTTPSERVICEPID = "org.eclipse.equinox.http.Http"; //$NON-NLS-1$
- protected ServiceRegistration managedService;
- protected final static String HTTPSERVICEFACTORYPID = "org.eclipse.equinox.http.HttpFactory"; //$NON-NLS-1$
- protected ServiceRegistration managedServiceFactory;
-
- protected final static String enviroKeyHttpMinThreads = "org.eclipse.equinox.http.minThreads"; //$NON-NLS-1$
- protected final static String enviroKeyHttpMaxThreads = "org.eclipse.equinox.http.maxThreads"; //$NON-NLS-1$
-
- protected final static String keyHttpMinThreads = "http.minThreads"; //$NON-NLS-1$
- protected final static String keyHttpMaxThreads = "http.maxThreads"; //$NON-NLS-1$
- protected final static String keyHttpThreadPriority = "http.threadPriority"; //$NON-NLS-1$
- protected final static String keyHttpAddress = "http.address"; //$NON-NLS-1$
- protected final static String keyHttpPort = "http.port"; //$NON-NLS-1$
- protected final static String keyHttpScheme = "http.scheme"; //$NON-NLS-1$
- protected final static String keyHttpTimeout = "http.timeout"; //$NON-NLS-1$
-
- protected static final int DEFAULT_MINTHREADS = 4;
- protected static final int DEFAULT_MAXTHREADS = 20;
- protected static final int DEFAULT_THREADPRIOTRITY = Thread.NORM_PRIORITY;
- protected static String DEFAULT_HTTP_ADDRESS = "ALL"; //$NON-NLS-1$
- protected static int DEFAULT_HTTP_PORT = 80;
- protected static int DEFAULT_HTTPS_PORT = 443;
- protected static final int DEFAULT_TIMEOUT = 30;
-
- /** Current minimum number of threads in the thread pool */
- private int minThreads = DEFAULT_MINTHREADS;
- /** Current maximum number of threads in the thread pool */
- private int maxThreads = DEFAULT_MAXTHREADS;
- /** Current priority of the the threads in the thread pool */
- private int threadPriority = DEFAULT_THREADPRIOTRITY;
-
- private boolean active;
-
- /**
- * Constructor - create the Http Configuration object and start it.
- */
- protected HttpConfiguration(Http http) throws IOException {
- this.http = http;
- active = true;
-
- initialize();
- }
-
- /**
- * Initializes fields.
- * <p>
- */
- protected void initialize() {
- setDefaultPorts();
- setThreadPoolSizes();
- pool = new HttpThreadPool(http, minThreads, maxThreads, threadPriority);
- configuredListeners = new Hashtable(7);
- synchronized (configuredListeners) {
- createDefaultListeners();
- }
-
- registerManagedService();
- registerManagedServiceFactory();
- }
-
- protected void registerManagedService() {
- /* Register a Managed Service to handle updates to the general configuration values */
- Hashtable properties = new Hashtable(7);
-
- properties.put(Constants.SERVICE_VENDOR, "IBM"); //$NON-NLS-1$
- properties.put(Constants.SERVICE_DESCRIPTION, HttpMsg.OSGi_Http_Service_IBM_Implementation_16);
- properties.put(Constants.SERVICE_PID, HTTPSERVICEPID);
-
- managedService = http.context.registerService(ManagedService.class.getName(), this, properties);
- }
-
- protected void registerManagedServiceFactory() {
- /* Register a Managed Service Factory to handle updates to the unique configuration values */
- Hashtable properties = new Hashtable(7);
-
- properties.put(Constants.SERVICE_VENDOR, "IBM"); //$NON-NLS-1$
- properties.put(Constants.SERVICE_DESCRIPTION, HttpMsg.OSGi_Http_Service_IBM_Implementation_16);
- properties.put(Constants.SERVICE_PID, HTTPSERVICEFACTORYPID);
-
- managedServiceFactory = http.context.registerService(ManagedServiceFactory.class.getName(), this, properties);
- }
-
- /**
- * Create default Http Listeners if requested.
- * <p>
- */
- protected void createDefaultListeners() {
- if (DEFAULT_HTTP_PORT != -1) {
- try {
- defaultHttpListener = new HttpListener(http, this, createProperties(DEFAULT_HTTP_ADDRESS, DEFAULT_HTTP_PORT, "http", 30));//$NON-NLS-1$
- } catch (IOException e) {
- http.logError(HttpMsg.HTTP_UNEXPECTED_IOEXCEPTION, e);
- http.logError(HttpMsg.HTTP_UNEXPECTED_RUNTIMEEXCEPTION, e);
- }
- }
-
- }
-
- /**
- * Close default Http Listeners if present.
- * <p>
- */
- protected void closeDefaultListeners() {
- if (defaultHttpListener != null) {
- defaultHttpListener.close();
- defaultHttpListener = null;
- }
-
- if (defaultHttpsListener != null) {
- defaultHttpsListener.close();
- defaultHttpsListener = null;
- }
- }
-
- /**
- * Create default Http Listeners if requested.
- * <p>
- */
- protected void setDefaultPorts() {
- BundleContext context = http.context;
-
- String property = context.getProperty(enviroKeyHttpPort);
- if (property != null) {
- try {
- DEFAULT_HTTP_PORT = Integer.parseInt(property);
- } catch (NumberFormatException e) {
- http.logWarning(NLS.bind(HttpMsg.HTTP_DEFAULT_PORT_FORMAT_EXCEPTION, enviroKeyHttpPort), e);
- }
- }
-
- property = context.getProperty(enviroKeyHttpsPort);
- if (property != null) {
- try {
- DEFAULT_HTTPS_PORT = Integer.parseInt(property);
- } catch (NumberFormatException e) {
- http.logWarning(NLS.bind(HttpMsg.HTTP_DEFAULT_PORT_FORMAT_EXCEPTION, enviroKeyHttpsPort), e);
- }
- }
-
- DEFAULT_HTTP_ADDRESS = context.getProperty(enviroKeyHttpAddress);
- if (DEFAULT_HTTP_ADDRESS == null) {
- DEFAULT_HTTP_ADDRESS = "ALL"; //$NON-NLS-1$
- }
- }
-
- protected void setThreadPoolSizes() {
- BundleContext context = http.context;
-
- String property = context.getProperty(enviroKeyHttpMinThreads);
- if (property != null) {
- try {
- int min = Integer.parseInt(property);
-
- if ((min < 0) || (min > 63)) {
- // Don't set the property and throw the exception to get the nice logging below.
- throw new NumberFormatException();
- }
-
- minThreads = min;
- } catch (NumberFormatException e) {
- http.logWarning(enviroKeyHttpMinThreads + " must be in the range 0-63", e); //$NON-NLS-1$
- }
- }
-
- property = context.getProperty(enviroKeyHttpMaxThreads);
- if (property != null) {
- try {
- int max = Integer.parseInt(property);
-
- if ((max < 0) || (max > 63)) {
- // Don't set the property and throw the exception to get the nice logging below.
- throw new NumberFormatException();
- }
-
- maxThreads = max;
- } catch (NumberFormatException e) {
- http.logWarning(enviroKeyHttpMaxThreads + " must be in the range 0-63", e); //$NON-NLS-1$
- }
- }
-
- }
-
- protected Dictionary createProperties(String address, int port, String scheme, int socketTimeout) {
- Hashtable properties = new Hashtable(31);
-
- properties.put(Constants.SERVICE_VENDOR, "IBM"); //$NON-NLS-1$
- properties.put(Constants.SERVICE_DESCRIPTION, HttpMsg.OSGi_Http_Service_IBM_Implementation_16);
- properties.put(Constants.SERVICE_PID, "org.eclipse.equinox.http.HttpService-" + scheme); //$NON-NLS-1$
- properties.put(keyHttpAddress, address);
- properties.put(keyHttpPort, new Integer(port));
- properties.put(keyHttpScheme, scheme);
- properties.put(keyHttpTimeout, new Integer(socketTimeout));
-
- return (properties);
- }
-
- protected ServerSocketInterface createServerSocket(String address, int port, String scheme) throws IOException {
- InetAddress netAddress = null;
- if (address != null) {
- try {
- netAddress = InetAddress.getByName(address);
- } catch (UnknownHostException uhe) {
- http.logWarning(NLS.bind(HttpMsg.HTTP_HOST_UNKNOWN, address), uhe);
- }
- }
- if ("http".equalsIgnoreCase(scheme)) //$NON-NLS-1$
- {
- try {
- ServerSocketInterface ssi = new HttpServerSocket(port, 50, netAddress);
- ssi.setAddress(address);
- return ssi;
- } catch (IOException e) {
- http.logError(NLS.bind(HttpMsg.HTTP_PORT_IN_USE_EXCEPTION, new Integer(port)), e);
-
- throw e;
- }
- }
-
- if ("https".equalsIgnoreCase(scheme)) //$NON-NLS-1$
- {
- try {
- ServerSocketInterface ssi = http.createSSLServerSocket(port, 50, netAddress);
- ssi.setAddress(address);
- return ssi;
- } catch (IOException e) {
- http.logError(NLS.bind(HttpMsg.HTTP_PORT_IN_USE_EXCEPTION, new Integer(port)), e);
-
- throw e;
- }
- }
-
- throw new IOException(NLS.bind(HttpMsg.HTTP_INVALID_SCHEME_EXCEPTION, scheme));
- }
-
- void close() {
- active = false;
-
- managedService.unregister();
-
- managedServiceFactory.unregister();
-
- if (defaultHttpListener != null) {
- defaultHttpListener.close();
- defaultHttpListener = null;
- }
-
- if (defaultHttpsListener != null) {
- defaultHttpsListener.close();
- defaultHttpsListener = null;
- }
-
- Enumeration listeners = configuredListeners.elements();
- while (listeners.hasMoreElements()) {
- HttpListener listener = (HttpListener) listeners.nextElement();
-
- listener.close();
- }
-
- pool.close();
- }
-
- /**
- * Return a descriptive name of this ManagedServiceFactory.
- *
- * @return the name for the factory, which might be localized
- */
- public String getName() {
- return HttpMsg.IBM_Http_Service_37;
- }
-
- /**
- * Create a new instance, or update the configuration of an
- * existing instance.
- *
- * If the PID of the <tt>Configuration</tt> object is new for the Managed Service Factory,
- * then create a new factory instance, using the configuration
- * <tt>properties</tt> provided. Else, update the service instance with the
- * provided <tt>properties</tt>.
- *
- * <p>If the factory instance is registered with the Framework, then
- * the configuration <tt>properties</tt> should be copied to its registry
- * properties. This is not mandatory and
- * security sensitive properties should obviously not be copied.
- *
- * <p>If this method throws any <tt>Exception</tt>, the
- * Configuration Admin service must catch it and should log it.
- *
- * <p>When the implementation of updated detects any kind of
- * error in the configuration properties, it should create a
- * new {@link ConfigurationException}which describes the problem.
- *
- * <p>The Configuration Admin service must call this method on a thread
- * other than the thread which necessitated the callback. This implies that
- * implementors of the <tt>ManagedServiceFactory</tt> class can be assured that the
- * callback will not take place during registration when they
- * execute the registration in a synchronized method.
- *
- * @param pid the PID for this configuration
- * @param properties the configuration properties
- * @throws ConfigurationException when the configuration properties are invalid
- */
- public void updated(final String pid, final Dictionary properties) throws ConfigurationException {
- if (active) {
- String address = DEFAULT_HTTP_ADDRESS;
- int port = DEFAULT_HTTP_PORT;
- String scheme = "http"; //$NON-NLS-1$
- int timeout = DEFAULT_TIMEOUT;
-
- /* Get configuration values and validate */
- String key = keyHttpPort;
- Object portProperty = properties.get(key);
- if (portProperty != null) /* if null we will just use the default */
- {
- if (!(portProperty instanceof Integer)) {
- throw new ConfigurationException(key, "not an Integer"); //$NON-NLS-1$
- }
-
- port = ((Integer) portProperty).intValue();
-
- if ((port < 0) || (port > 65535)) {
- throw new ConfigurationException(key, "must be in the range 0-65535"); //$NON-NLS-1$
- }
- }
-
- key = keyHttpScheme;
- Object schemeProperty = properties.get(key);
- if (schemeProperty != null) /* if null we will just use the default */
- {
- if (!(schemeProperty instanceof String)) {
- throw new ConfigurationException(key, "not an String"); //$NON-NLS-1$
- }
-
- scheme = (String) schemeProperty;
-
- if (!(scheme.equals("http") || scheme.equals("https"))) //$NON-NLS-1$ //$NON-NLS-2$
- {
- throw new ConfigurationException(key, "must be either http or https"); //$NON-NLS-1$
- }
- }
-
- key = keyHttpAddress;
- Object addressProperty = properties.get(key);
- if (addressProperty != null) /* if null we will just use the default */
- {
- if (!(addressProperty instanceof String)) {
- throw new ConfigurationException(key, "not an String"); //$NON-NLS-1$
- }
-
- address = (String) addressProperty;
- }
-
- key = keyHttpTimeout;
- Object timeoutProperty = properties.get(key);
- if (timeoutProperty != null) /* if null we will just use the default */
- {
- if (!(timeoutProperty instanceof Integer)) {
- throw new ConfigurationException(key, "not an Integer"); //$NON-NLS-1$
- }
-
- timeout = ((Integer) timeoutProperty).intValue();
-
- if ((timeout < 0) || (timeout > 600)) {
- throw new ConfigurationException(key, "must be in the range 0-600"); //$NON-NLS-1$
- }
- }
-
- if (schemeProperty == null) {
- if (port == DEFAULT_HTTPS_PORT) {
- scheme = "https"; //$NON-NLS-1$
- }
- } else {
- if (portProperty == null) {
- if (scheme.equals("https")) //$NON-NLS-1$
- {
- port = DEFAULT_HTTPS_PORT;
- }
- }
- }
-
- if (addressProperty == null) {
- properties.put(keyHttpAddress, address);
- }
- if (schemeProperty == null) {
- properties.put(keyHttpScheme, scheme);
- }
- if (portProperty == null) {
- properties.put(keyHttpPort, new Integer(port));
- }
- if (timeoutProperty == null) {
- properties.put(keyHttpTimeout, new Integer(timeout));
- }
-
- properties.remove("service.bundleLocation"); /* Don't want to publish this! *///$NON-NLS-1$
- properties.put(Constants.SERVICE_VENDOR, "IBM"); //$NON-NLS-1$
- properties.put(Constants.SERVICE_DESCRIPTION, HttpMsg.OSGi_Http_Service_IBM_Implementation_16);
-
- /* Configuration values have been validated */
- synchronized (configuredListeners) {
- try {
- AccessController.doPrivileged(new PrivilegedExceptionAction() {
- public Object run() throws ConfigurationException {
- if (configuredListeners.size() == 0) {
- closeDefaultListeners();
- }
-
- HttpListener listener = (HttpListener) configuredListeners.get(pid);
-
- try {
- if (listener != null) {
- listener.setProperties(properties);
- } else {
- listener = new HttpListener(http, HttpConfiguration.this, properties);
-
- configuredListeners.put(pid, listener);
- }
- } catch (IOException e) {
- http.logError(HttpMsg.HTTP_UNEXPECTED_IOEXCEPTION, e);
-
- if (configuredListeners.size() == 0) {
- createDefaultListeners();
- }
-
- throw new ConfigurationException(null, e.getMessage());
- }
-
- return null;
- }
- });
- } catch (PrivilegedActionException pae) {
- throw (ConfigurationException) pae.getException();
- }
- }
- }
- }
-
- /**
- * Remove a factory instance.
- *
- * Remove the factory instance associated with the PID. If the instance was
- * registered with the service registry, it should be unregistered.
- * <p>If this method throws any <tt>Exception</tt>, the Configuration Admin
- * service must catch it and should log it.
- * <p> The Configuration Admin service must call this method on a thread
- * other than the thread which called <tt>delete()</tt> on the corresponding
- * <tt>Configuration</tt> object.
- *
- * @param pid the PID of the service to be removed
- */
- public void deleted(final String pid) {
- if (active) {
- synchronized (configuredListeners) {
- AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
- HttpListener listener = (HttpListener) configuredListeners.remove(pid);
-
- if (listener != null) {
- listener.close();
- }
-
- if (configuredListeners.size() == 0) {
- createDefaultListeners();
- }
-
- return null;
- }
- });
- }
- }
- }
-
- /**
- * Update the configuration for a Managed Service.
- *
- * <p>When the implementation of <tt>updated(Dictionary)</tt> detects any kind of
- * error in the configuration properties, it should create a
- * new <tt>ConfigurationException</tt> which describes the problem. This
- * can allow a management system to provide useful information to
- * a human administrator.
- *
- * <p>If this method throws any other <tt>Exception</tt>, the
- * Configuration Admin service must catch it and should log it.
- * <p> The Configuration Admin service must call this method on a thread
- * other than the thread which initiated the callback. This
- * implies that implementors of Managed Service can be assured
- * that the callback will not take place during registration
- * when they execute the registration in a synchronized method.
- *
- * @param properties configuration properties, or <tt>null</tt>
- * @throws ConfigurationException when the update fails
- */
- public void updated(Dictionary properties) throws ConfigurationException {
- /* Since updated is called asynchronously, we may have stopped
- * after the decision was made to call.
- */
- if (active) {
- if (properties == null) {
- /* We have no configuration; we will just use our defaults */
- return;
- }
-
- int min = minThreads;
- int max = maxThreads;
- int priority = threadPriority;
-
- /* Get configuration values and validate */
- String key = keyHttpMinThreads;
- Object property = properties.get(key);
- if (property != null) /* if null we will just use the default */
- {
- if (!(property instanceof Integer)) {
- throw new ConfigurationException(key, "not an Integer"); //$NON-NLS-1$
- }
-
- min = ((Integer) property).intValue();
-
- if ((min < 0) || (min > 63)) {
- throw new ConfigurationException(key, "must be in the range 0-63"); //$NON-NLS-1$
- }
- }
-
- key = keyHttpMaxThreads;
- property = properties.get(key);
- if (property != null) /* if null we will just use the default */
- {
- if (!(property instanceof Integer)) {
- throw new ConfigurationException(key, "not an Integer"); //$NON-NLS-1$
- }
-
- max = ((Integer) property).intValue();
-
- if ((max < 0) || (max > 63)) {
- throw new ConfigurationException(key, "must be in the range 0-63"); //$NON-NLS-1$
- }
- }
-
- key = keyHttpThreadPriority;
- property = properties.get(key);
- if (property != null) /* if null we will just use the default */
- {
- if (!(property instanceof Integer)) {
- throw new ConfigurationException(key, "not an Integer"); //$NON-NLS-1$
- }
-
- priority = ((Integer) property).intValue();
-
- if ((priority < Thread.MIN_PRIORITY) || (priority > Thread.MAX_PRIORITY)) {
- throw new ConfigurationException(key, "must be one of the Thread defined priorities"); //$NON-NLS-1$
- }
- }
-
- /* Configuration values have been validated */
- if ((max != maxThreads) || (min != minThreads)) {
- pool.setSize(min, max);
-
- /* Get the values from the pool in case it adjusted them */
- minThreads = pool.getLowerSizeLimit();
- maxThreads = pool.getUpperSizeLimit();
- }
-
- if (priority != threadPriority) {
- pool.setPriority(priority);
- threadPriority = priority;
- }
- }
- }
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpConnection.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpConnection.java
deleted file mode 100644
index d63853047..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpConnection.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.equinox.http;
-
-import java.io.IOException;
-import java.io.InterruptedIOException;
-import java.net.SocketException;
-import javax.servlet.ServletException;
-import org.eclipse.equinox.socket.SocketInterface;
-
-/* @ThreadSafe */
-public class HttpConnection implements Runnable {
- /** Master HTTP object */
- private final Http http;
-
- /** socket that this thread is operating */
- private final SocketInterface socket;
-
- /** Listener this thread is working for */
- private final HttpListener listener;
-
- /** if true, we support Keep-Alive for the socket */
- private volatile boolean supportKeepAlive;
-
- public HttpConnection(Http http, HttpListener listenerParam, SocketInterface socketParam, int socketTimeout) {
- this.http = http;
- this.listener = listenerParam;
- this.socket = socketParam;
- boolean keepAlive;
- if (socketTimeout > 0) {
- try {
- socketParam.setSoTimeout(socketTimeout);
-
- keepAlive = true;
- } catch (SocketException e) {
- keepAlive = false;
- }
- } else {
- keepAlive = false;
- }
-
- setKeepAlive(keepAlive);
- }
-
- public void run() {
- boolean keepAlive = false;
-
- try {
- if (Http.DEBUG) {
- http.logDebug(Thread.currentThread().getName() + ": Processing request on socket: " + socket); //$NON-NLS-1$
- }
-
- socket.markInactive(); /* mark inactive: we are not actively processing a request */
-
- listener.handleConnection(socket);
-
- keepAlive = supportKeepAlive && !socket.isClosed();
- } catch (InterruptedIOException e) {
- /*
- * A read on the socket did not complete within the timeout period.
- */
- keepAlive = false;
-
- if (Http.DEBUG) {
- http.logDebug(Thread.currentThread().getName() + ": Read Timeout while processing connection on socket: " + socket, e); //$NON-NLS-1$
- }
- } catch (SocketException e) {
- /*
- * Most likely the user agent closed the socket.
- */
- keepAlive = false;
-
- if (Http.DEBUG) {
- http.logDebug(Thread.currentThread().getName() + ": Socket Exception while processing connection on socket: " + socket, e); //$NON-NLS-1$
- }
- }
- // BUGBUG Need to handle UnavailableException
- // Servlet 2.2 Section 3.3.3.2
- // BUGBUG An unhandled exception should result in flushing the response
- // buff and returning status code 500.
- // Servlet 2.3 Section 9.9.2
- catch (ServletException e) {
- /*
- * The Servlet threw a ServletException.
- */
- keepAlive = false;
-
- http.logWarning(HttpMsg.HTTP_SERVLET_EXCEPTION, e);
- } catch (IOException e) {
- /*
- * The Servlet threw an IOException.
- */
- keepAlive = false;
-
- http.logWarning(HttpMsg.HTTP_CONNECTION_EXCEPTION, e);
- } catch (Throwable t) {
- /*
- * Some exception has occurred. Log it and keep the thread working.
- */
- keepAlive = false;
-
- http.logError(HttpMsg.HTTP_CONNECTION_EXCEPTION, t);
- } finally {
- if (!keepAlive) {
- if (!socket.isClosed()) {
- try {
- if (Http.DEBUG) {
- http.logDebug(Thread.currentThread().getName() + ": Closing socket: " + socket); //$NON-NLS-1$
- }
-
- socket.close();
- } catch (IOException e) {
- // TODO: consider logging
- }
- }
- }
- }
- }
-
- public void setKeepAlive(boolean keepAlive) {
- supportKeepAlive = keepAlive;
- }
-
- public boolean isClosed() {
- return socket.isClosed();
- }
-
- public void close() throws IOException {
- socket.close();
- }
-
- public boolean isActive() {
- return socket.isActive();
- }
-
- public String toString() {
- return socket.toString();
- }
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpDate.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpDate.java
deleted file mode 100644
index 7d0184e62..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpDate.java
+++ /dev/null
@@ -1,387 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2009 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http;
-
-import java.util.*;
-
-/**
- * <b>HTTPDate</b> provides several services with regards to dates and date formatting.
- */
-public class HttpDate {
-
- protected Calendar time;
- private boolean valid = true;
-
- private static final String[] MONTH_NAMES = {HttpMsg.Jan_1, HttpMsg.Feb_2, HttpMsg.Mar_3, HttpMsg.Apr_4, HttpMsg.May_5, HttpMsg.Jun_6, HttpMsg.Jul_7, HttpMsg.Aug_8, HttpMsg.Sep_9, HttpMsg.Oct_10, HttpMsg.Nov_11, HttpMsg.Dec_12};
- private static final String[] WEEK_DAYS = {HttpMsg.Sun_13, HttpMsg.Mon_14, HttpMsg.Tue_15, HttpMsg.Wed_16, HttpMsg.Thu_17, HttpMsg.Fri_18, HttpMsg.Sat_19};
-
- private static TimeZone gmt = null;
-
- /**
- * Constructs an HTTPDate object representing the current time.
- */
- public HttpDate() { // Now...
- if (gmt == null) {
- gmt = TimeZone.getTimeZone("GMT"); //$NON-NLS-1$
- }
- time = new GregorianCalendar(gmt);
- }
-
- /**
- * Constructs an HTTPDate object from the passed long.
- * @param iTime the number of uSeconds since the epoch.
- */
- public HttpDate(long iTime) { // Raw mill seconds
- this();
- time.setTime(new Date(iTime));
- }
-
- /**
- * Constructs an HTTPDate object from an RFC compliant string.
- * @param iString the time in a formatted string.
- */
- public HttpDate(String iString) { // RFC2068 3.3.1 compliant
- this();
- if (iString.indexOf(",") > 0) //$NON-NLS-1$
- {
- if (iString.indexOf("-") > 0) //$NON-NLS-1$
- {
- parseRFC1036(iString);
- } else {
- parseRFC1123(iString);
- }
- } else { //asctime type
- parseASC(iString);
- }
- }
-
- /**
- * Constructs an HTTPDate object from the passed long.
- * @param iTime the number of uSeconds since the epoch.
- */
- public HttpDate(Date iTime) { // Raw mill seconds
- this();
- time.setTime(iTime);
- }
-
- /**
- * Returns the Date/Time time as an RFC 1123 formatted String
- */
- public static String format(long time) {
- return (new HttpDate(time).toString());
- }
-
- protected void formatDoubleDigit(StringBuffer buff, int val) {
- if (val < 10) {
- buff.append('0');
- }
-
- buff.append(val);
- }
-
- /**
- * Returns the time represented as a long. This represents the number
- * of uSeconds since the epoch.
- * @return the time represented as a long.
- */
- public long getAsLong() {
- return (time.getTime().getTime());
- }
-
- /**
- * Returns the time represented as a string.
- * @return the time represented as a string.
- */
- public String getAsString() {
- return (toString());
- }
-
- /**
- * Returns the day of the month of the internal time, starting at 1
- * @return the day of the month.
- */
- public int getDay() {
- return (time.get(Calendar.DATE));
- }
-
- /**
- * Returns the day of the week of the internal time.
- * The number is in the range of 0 to 6 where 0 represents Sunday.
- * @return the day of the week.
- */
- public int getDayOfWeek() {
- return (time.get(Calendar.DAY_OF_WEEK) - 1);
- }
-
- /**
- * Returns the hour of the day of the internal time. 24 Hour time
- * @return the hour.
- */
- public int getHour() {
- return (time.get(Calendar.HOUR_OF_DAY));
- }
-
- /**
- * Returns the minute of the hour of the internal time.
- * @return the minute.
- */
- public int getMin() {
- return (time.get(Calendar.MINUTE));
- }
-
- /**
- * Returns the month of the year of the internal time.
- * The number is in the range of 0 to 11 where 0 represents January.
- * @return the month of the year.
- */
- public int getMonth() {
- return (time.get(Calendar.MONTH));
- }
-
- /**
- * Returns the second of the minute of the internal time.
- * @return the second.
- */
- public int getSec() {
- return (time.get(Calendar.SECOND));
- }
-
- /**
- * Returns the year of the internal time.
- * @return the year.
- */
- public int getYear() {
- return (time.get(Calendar.YEAR));
- }
-
- /**
- * Checks whether or not the Date this object represents is valid.
- * It would be Invalid if the string used to construct the object was a NON
- * RFC 1123, 1036 or ASC Time conforming Date String.
- * @return true if this object represents a REAL date.
- */
- public boolean isValid() {
- return (valid);
- }
-
- protected int locateMonth(String monthString) throws NumberFormatException {
- for (int i = 0; i < 12; i++) {
- if (MONTH_NAMES[i].equals(monthString)) {
- return (i);
- }
- }
- throw new NumberFormatException("Invalid month: " + monthString); //$NON-NLS-1$
- }
-
- /**
- * Returns the current Date/Time as an RFC ASC Time formatted String
- */
- public static String now() {
- return (new HttpDate().toString());
- }
-
- protected void parseASC(String str) {
- //ASCTIMEFMT = "EEE MMM dD HH:MM:SS YYYY"
- // 012345678901234567890123
-
- int day, month, year, hour, min, sec;
-
- parsedate: try {
- /* ignore day */
-
- if (str.charAt(3) != ' ') {
- break parsedate;
- }
-
- month = locateMonth(str.substring(4, 7));
-
- if (str.charAt(7) != ' ') {
- break parsedate;
- }
-
- if (str.charAt(8) == ' ') {
- day = Integer.parseInt(str.substring(9, 10));
- } else {
- day = Integer.parseInt(str.substring(8, 10));
- }
-
- if (str.charAt(10) != ' ') {
- break parsedate;
- }
-
- hour = Integer.parseInt(str.substring(11, 13));
-
- if (str.charAt(13) != ':') {
- break parsedate;
- }
-
- min = Integer.parseInt(str.substring(14, 16));
-
- if (str.charAt(16) != ':') {
- break parsedate;
- }
-
- sec = Integer.parseInt(str.substring(17, 19));
-
- if (str.charAt(19) != ' ') {
- break parsedate;
- }
-
- year = Integer.parseInt(str.substring(20));
-
- time.set(year, month, day, hour, min, sec);
- return;
- } catch (NumberFormatException e) {
- valid = false;
- }
- }
-
- protected void parseRFC1036(String str) {
- //RFC1036DATEFMT = "EEEE, DD-MMM-YY HH:MM:SS ZZZ"
- // 0123456789012345678901
-
- int day, month, year, hour, min, sec;
- parsedate: try {
- /* skip past day */
-
- int i = str.indexOf(", "); //$NON-NLS-1$
-
- if (i == -1) {
- break parsedate;
- }
-
- str = str.substring(i + 2);
-
- day = Integer.parseInt(str.substring(0, 2));
-
- if (str.charAt(2) != '-') {
- break parsedate;
- }
-
- month = locateMonth(str.substring(3, 6));
-
- if (str.charAt(6) != '-') {
- break parsedate;
- }
-
- year = Integer.parseInt(str.substring(7, 9));
- year += (year < 70) ? 2000 : 1900; /* y2k window */
-
- if (str.charAt(9) != ' ') {
- break parsedate;
- }
-
- hour = Integer.parseInt(str.substring(10, 12));
-
- if (str.charAt(12) != ':') {
- break parsedate;
- }
-
- min = Integer.parseInt(str.substring(13, 15));
-
- if (str.charAt(15) != ':') {
- break parsedate;
- }
-
- sec = Integer.parseInt(str.substring(16, 18));
-
- if (str.charAt(18) != ' ') {
- break parsedate;
- }
-
- time.set(year, month, day, hour, min, sec);
- } catch (NumberFormatException e) {
- valid = false;
- }
- }
-
- protected void parseRFC1123(String str) {
- //RFC1123DATEFMT = "EEE, DD MMM YYYY HH:MM:SS ZZZ"
- // 01234567890123456789012345678
-
- int day, month, year, hour, min, sec;
-
- parsedate: try {
- /* ignore day */
-
- if ((str.charAt(3) != ',') || (str.charAt(4) != ' ')) {
- break parsedate;
- }
-
- day = Integer.parseInt(str.substring(5, 7));
-
- if (str.charAt(7) != ' ') {
- break parsedate;
- }
-
- month = locateMonth(str.substring(8, 11));
-
- if (str.charAt(11) != ' ') {
- break parsedate;
- }
-
- year = Integer.parseInt(str.substring(12, 16));
-
- if (str.charAt(16) != ' ') {
- break parsedate;
- }
-
- hour = Integer.parseInt(str.substring(17, 19));
-
- if (str.charAt(19) != ':') {
- break parsedate;
- }
-
- min = Integer.parseInt(str.substring(20, 22));
-
- if (str.charAt(22) != ':') {
- break parsedate;
- }
-
- sec = Integer.parseInt(str.substring(23, 25));
-
- if (str.charAt(25) != ' ') {
- break parsedate;
- }
-
- time.set(year, month, day, hour, min, sec);
- } catch (NumberFormatException e) {
- valid = false;
- }
-
- }
-
- /**
- * Returns the time represented as an RFC1123 string.
- * @return the time represented as a string.
- */
- public String toString() {
- StringBuffer buff = new StringBuffer(30);
- buff.append(WEEK_DAYS[getDayOfWeek()]);
- buff.append(", "); //$NON-NLS-1$
- formatDoubleDigit(buff, getDay());
- buff.append(' ');
- buff.append(MONTH_NAMES[getMonth()]);
- buff.append(' ');
- buff.append(getYear());
- buff.append(' ');
-
- formatDoubleDigit(buff, getHour());
- buff.append(':');
- formatDoubleDigit(buff, getMin());
- buff.append(':');
- formatDoubleDigit(buff, getSec());
- buff.append(' ');
- buff.append(time.getTimeZone().getID());
-
- return (buff.toString());
- }
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpListener.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpListener.java
deleted file mode 100644
index 954e34107..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpListener.java
+++ /dev/null
@@ -1,486 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2006 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.Socket;
-import java.util.*;
-
-import javax.servlet.Servlet;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletResponse;
-
-import org.eclipse.equinox.http.servlet.*;
-import org.eclipse.equinox.socket.ServerSocketInterface;
-import org.eclipse.equinox.socket.SocketInterface;
-import org.eclipse.osgi.util.NLS;
-import org.osgi.framework.*;
-import org.osgi.service.http.HttpContext;
-import org.osgi.service.http.NamespaceException;
-
-public class HttpListener extends Thread implements ServiceFactory {
- protected Http http;
- /** ServerSocket upon which this listener operates */
- protected volatile ServerSocketInterface serverSocket;
- /** Controlling HttpConfiguration object */
- protected HttpConfiguration configuration;
- /** if true this thread must terminate */
- protected volatile boolean running;
- protected ServiceRegistration service;
- private String httpsvcClass = "org.osgi.service.http.HttpService"; //$NON-NLS-1$
- protected Hashtable registrations;
- /** Mapping of HttpContext => ServletContextImpl */
- protected Hashtable servletContexts;
- protected int socketTimeout;
- protected Object lock = new Object();
-
- /**
- * Constructor.
- *
- */
- protected HttpListener(Http http, HttpConfiguration configuration, Dictionary properties) throws IOException {
- this.http = http;
- this.configuration = configuration;
- registrations = new Hashtable(51);
- //initialize servletContext Hashtable
- servletContexts = new Hashtable(15);
- setProperties(properties);
- start();
- }
-
- /**
- * Returns true if this thread has been closed.
- * @return boolean
- */
- public boolean isClosed() {
- return (!running);
- }
-
- /**
- * Close this thread.
- */
- public void close() {
- running = false;
- try {
- setProperties(null);
- } catch (IOException e) {
- /* this will not occur when calling with null */
- }
-
- servletContexts = null;
- }
-
- /*
- * ----------------------------------------------------------------------
- * ServiceFactory Interface implementation
- * ----------------------------------------------------------------------
- */
- public Object getService(Bundle bundle, ServiceRegistration reg) {
- return (new HttpService(this, bundle));
- }
-
- public void ungetService(Bundle bundle, ServiceRegistration reg, Object httpService) {
- ((HttpService) httpService).destroy();
- }
-
- public synchronized void setProperties(Dictionary properties) throws IOException {
- ServerSocketInterface oldServerSocket = serverSocket;
-
- if (properties != null) {
- String address = (String) properties.get(HttpConfiguration.keyHttpAddress);
- int port = ((Integer) (properties.get(HttpConfiguration.keyHttpPort))).intValue();
- String scheme = (String) properties.get(HttpConfiguration.keyHttpScheme);
- socketTimeout = ((Integer) (properties.get(HttpConfiguration.keyHttpTimeout))).intValue() * 1000;
-
- if ("ALL".equalsIgnoreCase(address)) { //$NON-NLS-1$
- address = null;
- }
-
- if ((serverSocket == null) || (port != serverSocket.getLocalPort()) || !scheme.equals(serverSocket.getScheme())) {
- serverSocket = configuration.createServerSocket(address, port, scheme);
- closeServerSocket(oldServerSocket);
- } else if ((serverSocket.getAddress() != null && !serverSocket.getAddress().equals(address)) || (serverSocket.getAddress() == null && address != null)) {
- serverSocket = null;
- closeServerSocket(oldServerSocket);
- serverSocket = configuration.createServerSocket(address, port, scheme);
- synchronized (lock) {
- lock.notify();
- }
- }
-
- properties.put(HttpConfiguration.keyHttpPort, new Integer(serverSocket.getLocalPort()));
- if (service == null) {
- service = http.context.registerService(httpsvcClass, this, properties);
- } else {
- service.setProperties(properties);
- }
- } else {
- serverSocket = null;
- closeServerSocket(oldServerSocket);
- service.unregister();
- service = null;
- }
- }
-
- protected Object getProperty(String key) {
- return service.getReference().getProperty(key);
- }
-
- private void closeServerSocket(ServerSocketInterface oldServerSocket) {
- if (oldServerSocket != null) {
- try {
- try {
- Socket phonyClient = new Socket(InetAddress.getByName(oldServerSocket.getAddress()), oldServerSocket.getLocalPort());
- phonyClient.close();
- } catch (IOException e) {
- http.logWarning(HttpMsg.HTTP_UNEXPECTED_IOEXCEPTION, e);
- }
- } finally {
- try {
- oldServerSocket.close();
- } catch (IOException e) {
- http.logWarning(HttpMsg.HTTP_UNEXPECTED_IOEXCEPTION, e);
- }
- }
-
- configuration.pool.recallThreads();
- }
- }
-
- public void run() {
- running = true;
-
- while (running) {
- SocketInterface socket = null;
-
- try {
- if (serverSocket == null) {
- if (running) {
- try {
- synchronized (lock) {
- lock.wait(5000);
- }
- } catch (InterruptedException e) {
- // ignore and check exit condition
- }
- if (serverSocket == null) {
- running = false;
- continue;
- }
- } else {
- continue;
- }
- }
- ServerSocketInterface tempServerSocket = this.serverSocket;
- socket = tempServerSocket.acceptSock();
-
- if (tempServerSocket != this.serverSocket) /* socket changed while we were waiting */
- {
- try {
- socket.close();
- } catch (IOException e) {
- // TODO: consider logging
- }
-
- socket = null;
- }
- } catch (IOException e) {
- if (serverSocket != null) {
- http.logError(NLS.bind(HttpMsg.HTTP_ACCEPT_SOCKET_EXCEPTION, new Integer(serverSocket.getLocalPort())), e);
- }
- }
-
- if (socket != null) {
- HttpThread thread = configuration.pool.getThread();
-
- if (thread != null) {
- thread.handleConnection(new HttpConnection(http, this, socket, socketTimeout));
- } else {
- try {
- socket.close();
- } catch (Exception e) {
- // TODO: consider logging
- }
- }
- }
- }
- }
-
- protected void handleConnection(SocketInterface socket) throws IOException, ServletException {
- /* Create the servlet request and response objects */
- HttpServletResponseImpl response = new HttpServletResponseImpl(socket, http);
-
- HttpServletRequestImpl request = new HttpServletRequestImpl(socket, http, response);
-
- /* After the request and response objects are successfully created,
- * we enter a try/finally block to ensure that the response is
- * always closed.
- */
- try {
- //Get the URI from socket
- String uri = request.getRequestURI();
- //Get Registration object associated with the request
- Registration registration = getRegistration(uri);
-
- while (registration != null) {
- try {
- if (registration.getHttpContext().handleSecurity(request, response)) {
- //Service Request
- registration.service(request, response);
- }
-
- return;
- } catch (ResourceUnavailableException e) {
- uri = reduceURI(uri);
-
- if (uri == null) {
- registration = null;
- } else {
- registration = getRegistration(uri);
- }
- }
- }
-
- if (registration == null) {
- if (Http.DEBUG) {
- http.logDebug("File " + request.getRequestURI() + //$NON-NLS-1$
- " not found -- No Registration object"); //$NON-NLS-1$
- }
-
- response.sendError(HttpServletResponse.SC_NOT_FOUND);
- }
- } finally {
- response.close(); /* close (and flush) the response output */
- }
- }
-
- protected ResourceRegistration registerResources(Bundle bundle, String alias, String name, HttpContext httpContext) throws NamespaceException {
- synchronized (registrations) {
- if (Http.DEBUG) {
- http.logDebug("HttpService -- Registering Resource -- Alias = " + //$NON-NLS-1$
- alias + " Name = " + name); //$NON-NLS-1$
- }
-
- checkAlias(alias);
-
- //check to see if name is valid
- if (name == null)
- throw new IllegalArgumentException(NLS.bind(HttpMsg.HTTP_RESOURCE_NAME_INVALID_EXCEPTION, name));
- int length = name.length();
- if (length > 1) { //we need to allow "/" and ""
- if (name.endsWith("/")) //$NON-NLS-1$
- {
- throw new IllegalArgumentException(NLS.bind(HttpMsg.HTTP_RESOURCE_NAME_INVALID_EXCEPTION, name));
- }
- }
-
- checkNamespace(alias);
-
- ResourceRegistration registration = new ResourceRegistration(bundle, alias, name, httpContext, http);
-
- registrations.put(alias, registration);
-
- return (registration);
- }
- }
-
- private void checkAlias(String alias) {
- if (alias == null)
- throw new IllegalArgumentException(NLS.bind(HttpMsg.HTTP_ALIAS_INVALID_EXCEPTION, alias));
- //check to see if the alias is valid
- if (!alias.equals("/")) //$NON-NLS-1$
- { //so one can register at "/"
- if (!alias.startsWith("/") || alias.endsWith("/")) //$NON-NLS-1$ //$NON-NLS-2$
- {
- throw new IllegalArgumentException(NLS.bind(HttpMsg.HTTP_ALIAS_INVALID_EXCEPTION, alias));
- }
- }
- }
-
- protected ServletRegistration registerServlet(Bundle bundle, String alias, Servlet servlet, Dictionary initparams, HttpContext httpContext) throws ServletException, NamespaceException {
- synchronized (registrations) {
- if (Http.DEBUG) {
- http.logDebug("HttpService -- Registering Servlet -- Alias = " + alias); //$NON-NLS-1$
- }
-
- checkAlias(alias);
-
- checkNamespace(alias);
-
- if (servlet == null) {
- throw new IllegalArgumentException(HttpMsg.HTTP_SERVLET_NULL_EXCEPTION);
- }
-
- if (http.servlets.contains(servlet)) {
- throw new ServletException(HttpMsg.HTTP_SERVLET_ALREADY_REGISTERED_EXCEPTION);
- }
- /* Determine the ServletContext */
- ServletContextImpl servletContext = getServletContext(httpContext);
- //Create registration object
- ServletRegistration registration = new ServletRegistration(bundle, alias, servlet, httpContext, servletContext);
-
- //call servlet's init() method
- try {
- servlet.init(new ServletConfigImpl(servletContext, initparams));
- } catch (ServletException e) {
- ungetServletContext(httpContext);
-
- throw e;
- } catch (Throwable t) {
- ungetServletContext(httpContext);
-
- throw new ServletException(HttpMsg.HTTP_SERVET_INIT_EXCEPTION, t);
- }
-
- http.servlets.addElement(servlet);
- registrations.put(alias, registration);
- return (registration);
- }
- }
-
- protected void unregister(Bundle bundle, String alias) throws IllegalArgumentException {
- synchronized (registrations) {
- Registration registration = (Registration) registrations.get(alias);
- if (registration != null) {
- //this is to prevent other bundles from unregistering a bundle's resource/servlet
- if (registration.getBundle() != bundle) {
- registration = null;
- }
- }
-
- removeRegistration(registration);
- }
- }
-
- protected HttpContext createDefaultHttpContext(Bundle bundle) {
- return (new DefaultHttpContext(bundle, http.securityTracker));
- }
-
- protected ServletContextImpl getServletContext(HttpContext httpContext) {
- /* Determine the ServletContext */
- ServletContextImpl servletContext = (ServletContextImpl) servletContexts.get(httpContext);
-
- if (servletContext == null) {
- servletContext = new ServletContextImpl(http, this, httpContext);
- servletContexts.put(httpContext, servletContext);
- }
-
- servletContext.incrUseCount();
-
- return (servletContext);
- }
-
- protected void ungetServletContext(HttpContext httpContext) {
- ServletContextImpl servletContext = (ServletContextImpl) servletContexts.get(httpContext);
-
- if (servletContext != null) {
- int useCount = servletContext.decrUseCount();
-
- if (useCount <= 0) {
- servletContexts.remove(httpContext);
- }
- }
- }
-
- protected void destroyBundle(Bundle bundle) {
- if (registrations != null) {
- if (Http.DEBUG) {
- http.logDebug("Removing bundle " + bundle + //$NON-NLS-1$
- " from HttpListener"); //$NON-NLS-1$
- }
-
- synchronized (registrations) {
- Enumeration e = registrations.elements();
-
- while (e.hasMoreElements()) {
- Registration reg = (Registration) e.nextElement();
-
- if (bundle == reg.getBundle()) {
- removeRegistration(reg);
- }
- }
- }
- }
- }
-
- private void checkNamespace(String uri) throws NamespaceException {
- if (uri == null)
- throw new IllegalArgumentException(NLS.bind(HttpMsg.HTTP_ALIAS_INVALID_EXCEPTION, uri));
- // If alias already exists in master resource table,
- // throw NamespaceException
- if (registrations.get(uri) != null) {
- throw new NamespaceException(NLS.bind(HttpMsg.HTTP_ALIAS_ALREADY_REGISTERED_EXCEPTION, uri));
- }
- }
-
- public Registration getRegistration(String uri) {
- synchronized (registrations) {
- while (uri != null) {
- Registration reg = (Registration) registrations.get(uri);
-
- if (reg != null) {
- return (reg);
- }
- uri = reduceURI(uri);
- }
- return (null);
- }
- }
-
- /**
- * Reduce the input URI per the HttpService spec.
- *
- * @param uri input URI to be reduced.
- * @return Reduced URI or null if no further reduction possible.
- */
- private String reduceURI(String uri) {
- if (uri.equals("/")) //$NON-NLS-1$
- {
- return (null);
- }
-
- int index = uri.lastIndexOf('/');
-
- if (index < 0) {
- return (null);
- }
-
- if (index == 0) {
- return ("/"); //$NON-NLS-1$
- }
-
- return (uri.substring(0, index));
- }
-
- /**
- * Must be called while holding the registrations lock
- *
- */
- private void removeRegistration(Registration registration) {
- if (registration == null) {
- throw new IllegalArgumentException(HttpMsg.HTTP_ALIAS_UNREGISTER_EXCEPTION);
- }
- registrations.remove(registration.getAlias());
- if (registration instanceof ServletRegistration) {
- Servlet servlet = ((ServletRegistration) registration).getServlet();
- http.servlets.removeElement(servlet);
- }
-
- // BUGBUG Must not call servlet.destroy while it is processing requests!
- // Servlet 2.2 Section 3.3.4
- registration.destroy();
-
- if (registration instanceof ServletRegistration) {
- ungetServletContext(registration.getHttpContext());
- }
- }
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpMsg.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpMsg.java
deleted file mode 100644
index 54bfa4aa0..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpMsg.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2006 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.equinox.http;
-
-import org.eclipse.osgi.util.NLS;
-
-public class HttpMsg extends NLS {
- private static final String BUNDLE_NAME = "org.eclipse.equinox.http.ExternalMessages"; //$NON-NLS-1$
-
- public static String HTTP_ALIAS_ALREADY_REGISTERED_EXCEPTION;
- public static String HTTP_SERVLET_ALREADY_REGISTERED_EXCEPTION;
- public static String HTTP_SERVLET_NULL_EXCEPTION;
- public static String HTTP_SERVLET_EXCEPTION;
- public static String HTTP_ALIAS_UNREGISTER_EXCEPTION;
- public static String HTTP_ALIAS_INVALID_EXCEPTION;
- public static String HTTP_RESOURCE_NAME_INVALID_EXCEPTION;
- public static String HTTP_SERVET_INIT_EXCEPTION;
- public static String HTTP_DEFAULT_MIME_TABLE_ERROR;
- public static String HTTP_STATUS_CODES_TABLE_ERROR;
- public static String HTTP_STATUS_CODE_NOT_FOUND;
- public static String HTTP_ACCEPT_SOCKET_EXCEPTION;
- public static String HTTP_PORT_IN_USE_EXCEPTION;
- public static String HTTP_INVALID_VALUE_RANGE_EXCEPTION;
- public static String HTTP_CONNECTION_EXCEPTION;
- public static String HTTP_INVALID_SCHEME_EXCEPTION;
- public static String HTTP_NO_HEADER_LINE_READ_EXCEPTION;
- public static String HTTP_QUERYDATA_PARSE_EXCEPTION;
- public static String HTTP_INVALID_HEADER_LINE_EXCEPTION;
- public static String HTTP_HEADER_LINE_TOO_LONG_EXCEPTION;
- public static String HTTP_UNEXPECTED_IOEXCEPTION;
- public static String HTTP_UNEXPECTED_RUNTIMEEXCEPTION;
- public static String HTTP_ONLY_SUPPORTS_2_1;
- public static String HTTP_HOST_UNKNOWN;
- public static String OSGi_Http_Service_IBM_Implementation_16;
- public static String IBM_Http_Service_37;
- public static String Jan_1;
- public static String Feb_2;
- public static String Mar_3;
- public static String Apr_4;
- public static String May_5;
- public static String Jun_6;
- public static String Jul_7;
- public static String Aug_8;
- public static String Sep_9;
- public static String Oct_10;
- public static String Nov_11;
- public static String Dec_12;
- public static String Sun_13;
- public static String Mon_14;
- public static String Tue_15;
- public static String Wed_16;
- public static String Thu_17;
- public static String Fri_18;
- public static String Sat_19;
- public static String HTTP_DEFAULT_PORT_FORMAT_EXCEPTION;
- public static String HTTP_THREAD_POOL_CREATE_NUMBER_ERROR;
-
- static {
- // initialize resource bundles
- NLS.initializeMessages(BUNDLE_NAME, HttpMsg.class);
- }
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpSecurityTracker.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpSecurityTracker.java
deleted file mode 100644
index d37803453..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpSecurityTracker.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2006 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http;
-
-import java.io.IOException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.service.http.HttpContext;
-import org.osgi.util.tracker.ServiceTracker;
-
-public class HttpSecurityTracker extends ServiceTracker {
-
- protected HttpSecurityTracker(BundleContext context) throws InvalidSyntaxException {
- super(context, context.createFilter("(&(objectClass=org.osgi.service.http.HttpContext)(org.eclipse.equinox.http.default.handleSecurity=*))"), null); //$NON-NLS-1$
-
- open();
- }
-
- protected boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) throws IOException {
- HttpContext service = (HttpContext) getService();
-
- if (service != null) {
- return (service.handleSecurity(request, response));
- }
-
- return (defaultHandleSecurity(request, response));
- }
-
- protected boolean defaultHandleSecurity(HttpServletRequest request, HttpServletResponse response) throws IOException {
- return (true);
- }
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpServerSocket.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpServerSocket.java
deleted file mode 100644
index d4ab9501a..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpServerSocket.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2005 IBM Corporation.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http;
-
-import java.io.IOException;
-import java.net.Socket;
-import org.eclipse.equinox.socket.ServerSocketInterface;
-import org.eclipse.equinox.socket.SocketInterface;
-
-public class HttpServerSocket extends java.net.ServerSocket implements ServerSocketInterface {
- String address = null;
-
- /**
- * HttpServerSocket constructor comment.
- * @param port int
- * @exception java.io.IOException The exception description.
- */
- public HttpServerSocket(int port) throws java.io.IOException {
- super(port);
- }
-
- /**
- * HttpServerSocket constructor comment.
- * @param port int
- * @param backlog int
- * @exception java.io.IOException The exception description.
- */
- public HttpServerSocket(int port, int backlog) throws java.io.IOException {
- super(port, backlog);
- }
-
- /**
- * HttpServerSocket constructor comment.
- * @param port int
- * @param backlog int
- * @param bindAddr java.net.InetAddress
- * @exception java.io.IOException The exception description.
- */
- public HttpServerSocket(int port, int backlog, java.net.InetAddress bindAddr) throws java.io.IOException {
- super(port, backlog, bindAddr);
- }
-
- /**
- * This method was created in VisualAge.
- */
- public Socket accept() throws IOException {
- return (Socket) acceptSock();
- }
-
- public SocketInterface acceptSock() throws IOException {
- HttpSocket socket = new HttpSocket(getScheme());
- implAccept(socket);
- return (socket);
- }
-
- public String getScheme() {
- return ("http"); //$NON-NLS-1$
- }
-
- public String getAddress() {
- return address;
- }
-
- public void setAddress(String address) {
- this.address = address;
- }
-
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpService.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpService.java
deleted file mode 100644
index 6b41e4d3d..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpService.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2006 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http;
-
-import javax.servlet.Servlet;
-import javax.servlet.ServletException;
-import org.osgi.framework.Bundle;
-import org.osgi.service.http.HttpContext;
-import org.osgi.service.http.NamespaceException;
-
-public class HttpService implements org.osgi.service.http.HttpService {
- private HttpListener listener;
- private Bundle bundle;
-
- HttpService(HttpListener listener, Bundle bundle) {
- this.listener = listener;
- this.bundle = bundle;
- }
-
- void destroy() {
- listener.destroyBundle(bundle);
- listener = null;
- bundle = null;
- }
-
- public void registerResources(String alias, String name, HttpContext httpContext) throws NamespaceException {
- HttpListener tempListener = this.listener;
-
- if (tempListener != null) {
- if (httpContext == null) {
- httpContext = createDefaultHttpContext();
- }
-
- tempListener.registerResources(bundle, alias, name, httpContext);
- }
- }
-
- public void registerServlet(String alias, Servlet servlet, java.util.Dictionary initparams, HttpContext httpContext) throws ServletException, NamespaceException, IllegalArgumentException {
- HttpListener tempListener = this.listener;
-
- if (tempListener != null) {
- if (httpContext == null) {
- httpContext = createDefaultHttpContext();
- }
-
- tempListener.registerServlet(bundle, alias, servlet, initparams, httpContext);
- }
- }
-
- public void unregister(String alias) throws IllegalArgumentException {
- HttpListener tempListener = this.listener;
-
- if (tempListener != null) {
- tempListener.unregister(bundle, alias);
- }
- }
-
- public HttpContext createDefaultHttpContext() {
- HttpListener tempListener = this.listener;
-
- if (tempListener != null) {
- return (tempListener.createDefaultHttpContext(bundle));
- }
-
- return (null);
- }
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpSocket.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpSocket.java
deleted file mode 100644
index 7def88ce8..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpSocket.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2006 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http;
-
-import java.io.*;
-import org.eclipse.equinox.socket.SocketInterface;
-
-/* @ThreadSafe */
-public class HttpSocket extends java.net.Socket implements SocketInterface {
- private InputStream in = null;
- private boolean closed = false;
- private boolean active = false;
- private final String scheme;
-
- public HttpSocket(String sheme) {
- super();
- this.scheme = sheme;
- }
-
- public synchronized void close() throws IOException {
- super.close();
- //must set closed to try after calling super.close() otherwise
- //jdk1.4 will not close the socket
- closed = true;
- }
-
- /**
- * Wrap the real socket input stream in a buffered input stream
- *
- * @return a buffered InputStream which wraps the real input stream.
- * @throws IOException
- */
- public synchronized InputStream getInputStream() throws IOException {
- if (in == null) {
- in = new BufferedInputStream(super.getInputStream());
- }
-
- return in;
- }
-
- /**
- * Return the scheme this socket is using.
- *
- * @return Either "http" or "https".
- */
- public String getScheme() {
- return scheme;
- }
-
- /**
- * Test to see if the socket has been closed.
- *
- * @return true if close has been called on this socket.
- */
- public synchronized boolean isClosed() {
- return closed;
- }
-
- /**
- * Test to see if the socket is active.
- *
- * @return true if markActive has been called.
- */
- public synchronized boolean isActive() {
- return active;
- }
-
- /**
- * Mark the socket active.
- *
- */
- public synchronized void markActive() {
- active = true;
- }
-
- /**
- * Mark the socket inactive.
- *
- */
- public synchronized void markInactive() {
- active = false;
- }
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpThread.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpThread.java
deleted file mode 100644
index 823e0830b..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpThread.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2006 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http;
-
-import java.io.IOException;
-
-/**
- * The class provide a thread for processing HTTP requests.
- */
-/* @ThreadSafe */
-public class HttpThread extends Thread {
- /** Master HTTP object */
- private final Http http;
-
- /** if true this thread must terminate */
- private volatile boolean running;
-
- /** Pool to which this thread belongs. */
- private final HttpThreadPool pool;
-
- /** connection that this thread is operating */
- private volatile HttpConnection conn;
-
- /** lock object to wait for work */
- private final Object waitLock = new Object();
-
- /**
- * HttpThread constructor.
- */
- public HttpThread(Http http, HttpThreadPool pool, String name) {
- super(pool, name);
-
- this.http = http;
- this.pool = pool;
-
- setDaemon(true); /* mark thread as daemon thread */
- }
-
- /**
- * Returns true if this thread has been closed.
- * @return boolean
- */
- public boolean isClosed() {
- return (!running);
- }
-
- /**
- * Close this thread.
- */
- public void close() {
- running = false;
-
- if (conn == null) {
- interrupt();
- } else {
- try {
- conn.close();
- } catch (IOException e) {
- // TODO: consider logging
- }
- }
- }
-
- /**
- * recall this thread.
- */
- public void recall() {
- if (Http.DEBUG) {
- http.logDebug(getName() + ": recall on socket: " + conn); //$NON-NLS-1$
- }
-
- if (conn != null) {
- conn.setKeepAlive(false); /* disable keep alive in case the connection is currently processing a request */
- if (!conn.isActive()) { /* if the connection is not processing a request, close it */
- try {
- if (Http.DEBUG) {
- http.logDebug(getName() + ": Closing socket: " + conn); //$NON-NLS-1$
- }
- conn.close();
- } catch (IOException e) {
- // TODO: consider logging
- }
- }
- }
- }
-
- /**
- * Set the connection for this thread to process. The thread must have just been
- * retreived from the thread pool.
- * @param connParam The HttpConnection to process.
- */
- public void handleConnection(HttpConnection connParam) {
- if (running) {
- this.conn = connParam;
- synchronized (waitLock) {
- waitLock.notify();
- }
- }
- }
-
- public void run() {
- running = true;
-
- while (running) {
- if (conn == null) { /* if we have no work to do, wait in the pool */
- synchronized (waitLock) {
- pool.putThread(this);
-
- try {
- waitLock.wait();
- } catch (InterruptedException e) {
- // ignore and check exit condition
- }
- }
- }
-
- if (running && (conn != null)) {
- conn.run(); /* execute the connection */
-
- if (conn.isClosed()) { /* if connection is closed */
- conn = null; /* go back to the pool and wait */
- }
- }
- }
- }
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpThreadPool.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpThreadPool.java
deleted file mode 100644
index 7c12ecf57..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/HttpThreadPool.java
+++ /dev/null
@@ -1,287 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2009 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http;
-
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.Vector;
-import org.eclipse.osgi.util.NLS;
-
-/* @ThreadSafe */
-public class HttpThreadPool extends ThreadGroup {
- /** Master HTTP object */
- final Http http;
-
- /** container to threads waiting for work */
- private final Vector idleThreads; /* @GuardedBy("this") */
- /** container to threads which are working */
- private final Vector activeThreads; /* @GuardedBy("this") */
- /** Upper bound on size of thread pool */
- private int upper; /* @GuardedBy("this") */
- /** Lower bound on size of thread pool */
- private int lower; /* @GuardedBy("this") */
- /** Priority of thread pool */
- private volatile int priority;
- /** number of threads to be terminated when they are returned to the pool */
- private int hitCount; /* @GuardedBy("this") */
- /** Thread allocation number */
- private int number; /* @GuardedBy("this") */
- /** prevent new threads from readjusting */
- private int adjusting = 0; /* @GuardedBy("this") */
-
- /**
- * Constructs and populates a new thread pool with the specified thread group
- * identifier and the specified number of threads.
- *
- */
- public HttpThreadPool(Http http, int lower, int upper, int priority) {
- super("Http Service Thread Pool"); //$NON-NLS-1$
- this.http = http;
- idleThreads = new Vector(upper);
- activeThreads = new Vector(upper);
- number = 0;
- setSize(lower, upper);
-
- setPriority(priority);
- }
-
- /**
- * Returns the lower bound on size of thread pool.
- */
- public synchronized int getLowerSizeLimit() {
- return lower;
- }
-
- /**
- * Returns the upper bound on size of thread pool.
- */
- public synchronized int getUpperSizeLimit() {
- return upper;
- }
-
- /**
- * Sets the size of thread pool.
- *
- * @param lower the lower bounds on the size
- * @param upper the upper bounds on the size
- */
- public synchronized void setSize(int lower, int upper) {
- this.lower = lower;
- this.upper = upper;
- adjustThreadCount();
- }
-
- /**
- * Must be called while synchronized on this object.
- *
- */
- /* @GuardedBy("this") */
- private void adjustThreadCount() {
- if (adjusting > 0) {
- adjusting--;
- return;
- }
- int active = activeThreads.size();
- int idle = idleThreads.size();
- int count = idle + active;
-
- if (Http.DEBUG) {
- http.logDebug("Current thread count: " + idle + " idle, " + active + " active"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- if (idle < 2) {
- count += 5;
- } else {
- if (idle > 10) {
- count -= 5;
- }
- }
-
- if (count > upper) {
- count = upper;
- }
-
- if (count < lower) {
- count = lower;
- }
-
- int delta = count - (idle + active);
- if (Http.DEBUG) {
- http.logDebug("New thread count: " + count + ", delta: " + delta); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- if (delta < 0) /* remove threads */
- {
- delta = -delta; /* invert sign */
- if (delta < idle) {
- for (int i = idle - 1; delta > 0; i--, delta--) {
- HttpThread thread = (HttpThread) idleThreads.elementAt(i);
- idleThreads.removeElementAt(i);
- thread.close();
- }
- } else {
- hitCount += delta - idle;
- for (int i = 0; i < idle; i++) {
- HttpThread thread = (HttpThread) idleThreads.elementAt(i);
- thread.close();
- }
- idleThreads.removeAllElements();
- }
- } else {
- if (delta > 0) /* add threads */
- {
- adjusting = delta; /* new threads will call this method */
- if (delta > hitCount) {
- delta -= hitCount;
- hitCount = 0;
- idleThreads.ensureCapacity(count);
- for (int i = 0; i < delta; i++) {
- number++;
- final String threadName = "HttpThread_" + number; //$NON-NLS-1$
- try {
- AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
- HttpThread thread = new HttpThread(http, HttpThreadPool.this, threadName);
- thread.start(); /* thread will add itself to the pool */
- return null;
- }
- });
- } catch (RuntimeException e) {
- /* No resources to create another thread */
- http.logError(NLS.bind(HttpMsg.HTTP_THREAD_POOL_CREATE_NUMBER_ERROR, new Integer(number)), e);
-
- number--;
-
- /* Readjust the upper bound of the thread pool */
- upper -= delta - i;
-
- break;
- }
- }
- } else {
- hitCount -= delta;
- }
- }
- }
- }
-
- /**
- * Set the priority of the threads in the thread pool.
- *
- * @param priority Thread priority.
- */
- public void setPriority(int priority) {
- if ((Thread.MIN_PRIORITY <= priority) && (priority <= Thread.MAX_PRIORITY)) {
- this.priority = priority;
- } else {
- throw new IllegalArgumentException(NLS.bind(HttpMsg.HTTP_INVALID_VALUE_RANGE_EXCEPTION, new Object[] {new Integer(Thread.MIN_PRIORITY), new Integer(Thread.MAX_PRIORITY)}));
- }
- }
-
- /**
- * Returns a thread to the thread pool and notifies the pool that
- * a thread is available.
- *
- * @param thread the thread being added/returned to the pool
- */
- public synchronized void putThread(HttpThread thread) {
- if (Http.DEBUG) {
- http.logDebug(thread.getName() + ": becoming idle"); //$NON-NLS-1$
- }
-
- activeThreads.removeElement(thread);
-
- if (hitCount > 0) {
- hitCount--;
- thread.close();
- } else {
- if (!idleThreads.contains(thread)) {
- idleThreads.addElement(thread);
- notify();
- }
- }
-
- adjustThreadCount();
- }
-
- /**
- * Gets the next available thread from the thread pool. If no thread is
- * available, this method blocks until one becomes available or the pool is
- * disposed of.
- *
- * @return the next available thread; if the pool has been (or is disposed
- * of while waiting), null is returned
- */
- public synchronized HttpThread getThread() {
- adjustThreadCount();
-
- while (upper > 0) {
- int count = idleThreads.size();
- if (count > 0) {
- int i = count - 1;
-
- HttpThread thread = (HttpThread) idleThreads.elementAt(i);
- idleThreads.removeElementAt(i);
- if (thread.getPriority() != priority) {
- thread.setPriority(priority);
- }
- activeThreads.addElement(thread);
- //new Exception((size-i)+" Threads are at work!").printStackTrace();
- if (Http.DEBUG) {
- http.logDebug(thread.getName() + ": becoming active"); //$NON-NLS-1$
- }
-
- return thread;
- }
- try {
- wait();
- } catch (InterruptedException e) {
- // ignore and check exit condition
- }
- }
-
- return null;
- }
-
- /**
- * Remove all thread from the pool.
- */
- public synchronized void close() {
- recallThreads();
-
- setSize(0, 0);
- /* Notify everyone waiting for a thread */
- notifyAll();
-
- // destroy the threadgroup, will never go away otherwise
- try {
- // Need to set it to a daemon first otherwise it will not be destroyed
- setDaemon(true);
- destroy();
- } catch (Exception e) {
- // TODO: consider logging
- }
- }
-
- /**
- * This method recalls threads that are waiting on a socket for work.
- * This is needed when Keep-Alive is in use and we need to
- * close the socket the thread is waiting on.
- *
- */
- public synchronized void recallThreads() {
- int count = activeThreads.size();
- for (int i = count - 1; i >= 0; i--) {
- HttpThread thread = (HttpThread) activeThreads.elementAt(i);
- thread.recall();
- }
- }
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/LogMessages.properties b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/LogMessages.properties
deleted file mode 100644
index 6d12a8dd8..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/LogMessages.properties
+++ /dev/null
@@ -1,16 +0,0 @@
-###############################################################################
-# Copyright (c) 2005, 2006 IBM Corporation and others.
-# 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:
-# IBM Corporation - initial API and implementation
-###############################################################################
-# NLS_MESSAGEFORMAT_ALL
-
-Unknown_Log_level=Unknown Log Level
-Info=Log Info
-Warning=Log Warning
-Error=Log Error
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/LogTracker.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/LogTracker.java
deleted file mode 100644
index ae0d24c15..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/LogTracker.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1998, 2007 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http;
-
-import java.io.PrintStream;
-import java.util.Calendar;
-import java.util.Date;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.log.LogService;
-import org.osgi.util.tracker.ServiceTracker;
-
-/**
- * LogTracker class. This class encapsulates the LogService
- * and handles all issues such as the service coming and going.
- */
-
-public class LogTracker extends ServiceTracker implements LogService {
- /** LogService interface class name */
- protected final static String clazz = "org.osgi.service.log.LogService"; //$NON-NLS-1$
-
- /** PrintStream to use if LogService is unavailable */
- private final PrintStream out;
-
- /**
- * Create new LogTracker.
- *
- * @param context BundleContext of parent bundle.
- * @param out Default PrintStream to use if LogService is unavailable.
- */
- public LogTracker(BundleContext context, PrintStream out) {
- super(context, clazz, null);
- this.out = out;
- }
-
- /*
- * ----------------------------------------------------------------------
- * LogService Interface implementation
- * ----------------------------------------------------------------------
- */
-
- public void log(int level, String message) {
- log(null, level, message, null);
- }
-
- public void log(int level, String message, Throwable exception) {
- log(null, level, message, exception);
- }
-
- public void log(ServiceReference reference, int level, String message) {
- log(reference, level, message, null);
- }
-
- public synchronized void log(ServiceReference reference, int level, String message, Throwable exception) {
- ServiceReference[] references = getServiceReferences();
-
- if (references != null) {
- int size = references.length;
-
- for (int i = 0; i < size; i++) {
- LogService service = (LogService) getService(references[i]);
- if (service != null) {
- try {
- service.log(reference, level, message, exception);
- } catch (Exception e) {
- // TODO: consider printing to System Error
- }
- }
- }
-
- return;
- }
-
- noLogService(level, message, exception, reference);
- }
-
- /**
- * The LogService is not available so we write the message to a PrintStream.
- *
- * @param level Logging level
- * @param message Log message.
- * @param throwable Log exception or null if none.
- * @param reference ServiceReference associated with message or null if none.
- */
- protected void noLogService(int level, String message, Throwable throwable, ServiceReference reference) {
- if (out != null) {
- synchronized (out) {
- // Bug #113286. If no log service present and messages are being
- // printed to stdout, prepend message with a timestamp.
- String timestamp = getDate(new Date());
- out.print(timestamp + " "); //$NON-NLS-1$
-
- switch (level) {
- case LOG_DEBUG : {
- out.print("Debug: "); //$NON-NLS-1$
-
- break;
- }
- case LOG_INFO : {
- out.print(LogTrackerMsg.Info);
-
- break;
- }
- case LOG_WARNING : {
- out.print(LogTrackerMsg.Warning);
-
- break;
- }
- case LOG_ERROR : {
- out.print(LogTrackerMsg.Error);
-
- break;
- }
- default : {
- out.print("["); //$NON-NLS-1$
- out.print(LogTrackerMsg.Unknown_Log_level);
- out.print("]: "); //$NON-NLS-1$
-
- break;
- }
- }
-
- out.println(message);
-
- if (reference != null) {
- out.println(reference);
- }
-
- if (throwable != null) {
- throwable.printStackTrace(out);
- }
- }
- }
- }
-
- // from EclipseLog to avoid using DateFormat -- see bug 149892#c10
- private String getDate(Date date) {
- Calendar c = Calendar.getInstance();
- c.setTime(date);
- StringBuffer sb = new StringBuffer();
- appendPaddedInt(c.get(Calendar.YEAR), 4, sb).append('-');
- appendPaddedInt(c.get(Calendar.MONTH) + 1, 2, sb).append('-');
- appendPaddedInt(c.get(Calendar.DAY_OF_MONTH), 2, sb).append(' ');
- appendPaddedInt(c.get(Calendar.HOUR_OF_DAY), 2, sb).append(':');
- appendPaddedInt(c.get(Calendar.MINUTE), 2, sb).append(':');
- appendPaddedInt(c.get(Calendar.SECOND), 2, sb).append('.');
- appendPaddedInt(c.get(Calendar.MILLISECOND), 3, sb);
- return sb.toString();
- }
-
- private StringBuffer appendPaddedInt(int value, int pad, StringBuffer buffer) {
- pad = pad - 1;
- if (pad == 0)
- return buffer.append(Integer.toString(value));
- int padding = (int) Math.pow(10, pad);
- if (value >= padding)
- return buffer.append(Integer.toString(value));
- while (padding > value && padding > 1) {
- buffer.append('0');
- padding = padding / 10;
- }
- buffer.append(value);
- return buffer;
- }
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/LogTrackerMsg.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/LogTrackerMsg.java
deleted file mode 100644
index ad805bb68..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/LogTrackerMsg.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 2006 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http;
-
-import org.eclipse.osgi.util.NLS;
-
-public class LogTrackerMsg extends NLS {
- private static final String BUNDLE_NAME = "org.eclipse.equinox.http.LogMessages"; //$NON-NLS-1$
-
- public static String Unknown_Log_level;
- public static String Info;
- public static String Warning;
- public static String Error;
-
- static {
- // initialize resource bundles
- NLS.initializeMessages(BUNDLE_NAME, LogTrackerMsg.class);
- }
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/Registration.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/Registration.java
deleted file mode 100644
index dfbbf3666..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/Registration.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2005 IBM Corporation.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http;
-
-import java.io.IOException;
-import javax.servlet.*;
-import org.eclipse.equinox.http.servlet.HttpServletRequestImpl;
-import org.eclipse.equinox.http.servlet.HttpServletResponseImpl;
-import org.osgi.framework.Bundle;
-import org.osgi.service.http.HttpContext;
-
-public interface Registration {
- public abstract Bundle getBundle();
-
- public abstract HttpContext getHttpContext();
-
- public abstract void destroy();
-
- public abstract String getAlias();
-
- public abstract void service(HttpServletRequestImpl req, HttpServletResponseImpl res) throws ServletException, IOException;
-
- public abstract void service(ServletRequest req, ServletResponse res) throws ServletException, IOException;
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/ResourceRegistration.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/ResourceRegistration.java
deleted file mode 100644
index 9aafa7ee9..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/ResourceRegistration.java
+++ /dev/null
@@ -1,229 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2009 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http;
-
-import java.io.*;
-import java.net.URL;
-import java.net.URLConnection;
-import javax.servlet.ServletException;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.*;
-import org.eclipse.equinox.http.servlet.HttpServletRequestImpl;
-import org.eclipse.equinox.http.servlet.HttpServletResponseImpl;
-import org.osgi.framework.Bundle;
-import org.osgi.service.http.HttpContext;
-
-/**
- This class contains methods used to send requested resources a client.
- */
-public class ResourceRegistration extends HttpServlet implements Registration {
-
- private static final long serialVersionUID = -8732464938673729607L;
- protected Bundle bundle;
- protected HttpContext httpContext;
- protected String alias;
- protected String path;
- protected Http http;
- protected SecureAction secureAction;
-
- /**
- * The constructor
- */
- protected ResourceRegistration(Bundle bundle, String alias, String path, HttpContext httpContext, Http http) {
- this.bundle = bundle;
- this.alias = alias;
- this.path = path;
- this.httpContext = httpContext;
- this.http = http;
-
- secureAction = new SecureAction();
- }
-
- public Bundle getBundle() {
- return (bundle);
- }
-
- public HttpContext getHttpContext() {
- return (httpContext);
- }
-
- /**
- * This method returns the correct MIME type of a given URI by first checking
- * the HttpContext::getMimeType and, if null, checking the httpservice's MIMETypes table.
- * @return java.lang.String
- * @param name java.lang.String
- */
- private String computeMimeType(String name, URLConnection conn) {
- String mimeType = httpContext.getMimeType(name);
- if (mimeType != null) {
- return (mimeType);
- }
-
- mimeType = conn.getContentType();
- if (mimeType != null) {
- return (mimeType);
- }
-
- return (http.getMimeType(name));
- }
-
- public void destroy() {
- alias = null;
- path = null;
- }
-
- public String getAlias() {
- return (alias);
- }
-
- /** This method is called by Http::handleConnection. It is called when a request comes in for
- * a resource registered by this registration.
- */
- public void service(HttpServletRequestImpl request, HttpServletResponseImpl response) throws ServletException, IOException {
- /* set additional data for the servlet request */
- request.init(alias, null);
-
- super.service(request, response);
- }
-
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
- String filename = getFilename(request.getRequestURI());
-
- URL url = httpContext.getResource(filename);
-
- if (url == null) {
- // We got null back from httpContext.getResource
- // In this case we want to keep looking to see if another alias matches
- throw new ResourceUnavailableException();
- }
-
- URLConnection conn = secureAction.openURL(url);
-
- long modifiedSince = request.getDateHeader("If-Modified-Since"); //$NON-NLS-1$
- if (modifiedSince >= 0) {
- long modified = conn.getLastModified();
- if ((modified > 0) && (modifiedSince >= modified)) {
- response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
- return;
- }
- }
-
- InputStream in;
- try {
- in = conn.getInputStream();
- } catch (IOException ex) {
- response.sendError(HttpServletResponse.SC_NOT_FOUND);
- return;
- }
-
- try {
- int contentlength = conn.getContentLength();
- if (contentlength >= 0) {
- response.setContentLength(contentlength);
- }
-
- String mimeType = computeMimeType(filename, conn);
- response.setContentType(mimeType);
-
- // We want to use a writer if we are sending text
- if (mimeType.startsWith("text/")) //$NON-NLS-1$
- {
- PrintWriter writer = response.getWriter();
-
- writer.flush(); /* write the headers and unbuffer the output */
-
- BufferedReader reader = new BufferedReader(new InputStreamReader(in));
-
- char buffer[] = new char[4096];
- int read;
- while ((read = reader.read(buffer, 0, buffer.length)) != -1) {
- writer.write(buffer, 0, read);
- }
- } else {
- ServletOutputStream out = response.getOutputStream();
-
- out.flush(); /* write the headers and unbuffer the output */
-
- byte buffer[] = new byte[4096];
- int read;
- while ((read = in.read(buffer, 0, buffer.length)) != -1) {
- out.write(buffer, 0, read);
- }
- }
- } finally {
- in.close();
- }
- }
-
- protected void doHead(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- String filename = getFilename(request.getRequestURI());
-
- URL url = httpContext.getResource(filename);
-
- if (url == null) {
- // We got null back from httpContext.getResource
- // In this case we want to keep looking to see if another alias matches
- throw new ResourceUnavailableException();
- }
- URLConnection conn = secureAction.openURL(url);
- int contentlength = conn.getContentLength();
- if (contentlength >= 0) {
- response.setContentLength(contentlength);
-
- String mimeType = computeMimeType(filename, conn);
- response.setContentType(mimeType);
- } else {
- super.doHead(request, response);
- }
- }
-
- protected String getFilename(String filename) {
- //If the requested URI is equal to the Registeration's alias, send the file
- //corresponding to the alias. Otherwise, we have request for a file in an
- //registered directory (the file was not directly registered itself).
- if (filename.equals(alias)) {
- filename = path;
- } else {
- // The file we re looking for is the registered resource (alias) + the rest of the
- // filename that is not part of the registered resource. For example, if we export
- // /a to /tmp and we have a request for /a/b/foo.txt, then /tmp is our directory
- // (file.toString()) and /b/foo.txt is the rest.
- // The result is that we open the file /tmp/b/foo.txt.
-
- int aliaslen = alias.length();
- int pathlen = path.length();
-
- if (pathlen == 1) /* path == "/" */
- {
- if (aliaslen > 1) /* alias != "/" */
- {
- filename = filename.substring(aliaslen);
- }
- } else /* path != "/" */
- {
- StringBuffer buf = new StringBuffer(aliaslen + pathlen);
- buf.append(path);
-
- if (aliaslen == 1) /* alias == "/" */
- {
- buf.append(filename);
- } else /* alias != "/" */
- {
- buf.append(filename.substring(aliaslen));
- }
-
- filename = buf.toString();
- }
- }
-
- return (filename);
- }
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/ResourceUnavailableException.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/ResourceUnavailableException.java
deleted file mode 100644
index a3333401c..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/ResourceUnavailableException.java
+++ /dev/null
@@ -1,15 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2006 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http;
-
-public class ResourceUnavailableException extends RuntimeException {
- private static final long serialVersionUID = 4662869318092654517L;
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/SSLTracker.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/SSLTracker.java
deleted file mode 100644
index 264e409f4..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/SSLTracker.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2005 IBM Corporation.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.util.tracker.ServiceTracker;
-
-public class SSLTracker extends ServiceTracker {
- protected static final String sslsvcClass = "com.ibm.osg.service.ssl.SSLService"; //ssl //$NON-NLS-1$
-
- protected SSLTracker(BundleContext context) {
- super(context, sslsvcClass, null);
-
- open();
- }
-
- //BUGBUG need to handle opening and closing of HTTPS port!
- // e.g. httpAcceptor.createSSLListener();
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/SecureAction.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/SecureAction.java
deleted file mode 100644
index a97dfc5a7..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/SecureAction.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2003, 2006 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.equinox.http;
-
-import java.io.IOException;
-import java.net.URL;
-import java.net.URLConnection;
-import java.security.*;
-import org.osgi.framework.Bundle;
-
-/**
- * Utility class to execute common privileged code.
- */
-public class SecureAction {
- // make sure we use the correct controlContext;
- private AccessControlContext controlContext;
-
- /**
- * Constructs a new SecureAction object. The constructed SecureAction object
- * uses the caller's AccessControlContext to perform security checks
- */
- public SecureAction() {
- // save the control context to be used.
- this.controlContext = AccessController.getContext();
- }
-
- /**
- * Gets a resource from a bundle.
- * @param bundle the bundle to get the resource from
- * @param name The name of the resource
- * @return The URL of the resource
- */
-
- public URL getBundleResource(final Bundle bundle, final String name) {
- if (System.getSecurityManager() == null)
- return bundle.getResource(name);
- return (URL) AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
- return bundle.getResource(name);
- }
- }, controlContext);
- }
-
- public URLConnection openURL(final URL url) throws IOException {
- if (System.getSecurityManager() == null)
- return open(url);
- try {
- return (URLConnection) AccessController.doPrivileged(new PrivilegedExceptionAction() {
- public Object run() throws IOException {
- return open(url);
- }
- }, controlContext);
- } catch(PrivilegedActionException ex) {
- throw (IOException) ex.getException();
- }
- }
-
- URLConnection open(final URL url)throws IOException
- {
- URLConnection connection = url.openConnection();
- connection.connect(); /* establish connection to check permissions */
- return connection;
- }
-
- /**
- * Returns a system property. Same as calling
- * System.getProperty(String,String).
- * @param property the property key.
- * @param def the default value if the property key does not exist.
- * @return the value of the property or the def value if the property
- * does not exist.
- */
- public String getProperty(final String property, final String def) {
- if (System.getSecurityManager() == null)
- return System.getProperty(property, def);
- return (String) AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
- return System.getProperty(property, def);
- }
- }, controlContext);
- }
-
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/ServletRegistration.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/ServletRegistration.java
deleted file mode 100644
index cd99c7504..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/ServletRegistration.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2005 IBM Corporation.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http;
-
-import java.io.IOException;
-import java.security.AccessControlContext;
-import java.security.AccessController;
-import javax.servlet.*;
-import org.eclipse.equinox.http.servlet.*;
-import org.osgi.framework.Bundle;
-import org.osgi.service.http.HttpContext;
-
-public class ServletRegistration implements Registration {
- protected Bundle bundle;
- protected HttpContext httpContext;
- protected String alias;
- protected Servlet servlet;
- protected ServletContextImpl servletContext;
- protected AccessControlContext accessControlContext;
-
- protected ServletRegistration(Bundle bundle, String alias, Servlet servlet, HttpContext httpContext, ServletContextImpl servletContext) {
- this.bundle = bundle;
- this.alias = alias;
- this.servlet = servlet;
- this.httpContext = httpContext;
- this.servletContext = servletContext;
- // The constructor is called on the calling bundle's thread, therefore this
- // should capture the AccessControlContext for the calling bundle.
- accessControlContext = AccessController.getContext();
- }
-
- public Bundle getBundle() {
- return (bundle);
- }
-
- public HttpContext getHttpContext() {
- return (httpContext);
- }
-
- public void destroy() {
- if (servlet != null) {
- servlet.destroy();
- }
-
- this.alias = null;
- this.servlet = null;
- }
-
- public java.lang.String getAlias() {
- return (alias);
- }
-
- /**
- * This is to provide the request dispatcher direct access to the servlet for a
- * RequestDispatcher.include call
- * @return javax.servlet.Servlet
- */
- public Servlet getServlet() {
- return (servlet);
- }
-
- public void service(HttpServletRequestImpl request, HttpServletResponseImpl response) throws ServletException, IOException {
- /* set additional data for the servlet request */
- request.init(alias, servletContext);
-
- service((ServletRequest) request, (ServletResponse) response);
- }
-
- public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
- if (servlet instanceof SingleThreadModel) {
- synchronized (this) {
- servlet.service(request, response);
- }
- } else {
- servlet.service(request, response);
- }
- }
-
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/StaticDataReader.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/StaticDataReader.java
deleted file mode 100644
index 760079fdc..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/StaticDataReader.java
+++ /dev/null
@@ -1,228 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2009 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http;
-
-import java.io.*;
-import java.util.Hashtable;
-import java.util.StringTokenizer;
-
-public class StaticDataReader {
- protected Http http;
- protected static final String defaultMimeType = "application/octet-stream"; //$NON-NLS-1$
- protected static final String defaultMimeTable = "mime.types"; //$NON-NLS-1$
- protected static final String defaultStatusCodes = "status.codes"; //$NON-NLS-1$
-
- /** file extentsions (String) => MIME type (String) */
- protected Hashtable mimeTypes;
-
- /** status code (Integer) => status phrase (String) */
- protected Hashtable statusCodes;
-
- /**
- * Construct mime table from a standard mime.types file.
- */
- public StaticDataReader(Http http) {
- this.http = http;
-
- InputStream in = getClass().getResourceAsStream(defaultMimeTable);
- mimeTypes = parseMimeTypes(in);
-
- in = getClass().getResourceAsStream(defaultStatusCodes);
- statusCodes = parseStatusCodes(in);
-
- }
-
- /**
- * Determine the mime type of a file based on the file extension.
- * This method is more convenient to use than getMIMEType because
- * takes a filename as an argument. It is also able to discern that
- * files which are directories, such as
- * http://www.ibm.com/ are assumed to be HTML, rather than appOctet.
- *
- * @param filename - the name of the file, which must
- * not be null.
- * @returns String - the mime type of the file.
- */
- public String computeMimeType(String filename) {
- int i = filename.lastIndexOf('.');
-
- if (i >= 0) {
- return (getMimeType(filename.substring(i + 1)));
- }
-
- return (getMimeType(filename));
- }
-
- /**
- * This method was created in VisualAge.
- * @return java.lang.String
- * @param statusCode int
- */
- public String computeStatusPhrase(int statusCode) {
- String statusPhrase = (String) statusCodes.get(new Integer(statusCode));
- if (statusPhrase != null) {
- return (statusPhrase);
- }
-
- return (HttpMsg.HTTP_STATUS_CODE_NOT_FOUND);
- }
-
- private String getMimeType(String extension) {
- String type = (String) mimeTypes.get(extension.toLowerCase());
-
- if (type != null) {
- return (type);
- }
-
- return (defaultMimeType);
- }
-
- /**
- * Parses the default MIME type table.
- *
- * @return Default MIME type Hashtable
- */
- private Hashtable parseMimeTypes(InputStream in) {
- Hashtable resultMimeTypes = new Hashtable();
-
- if (in != null) {
- try {
- BufferedReader rdr = new BufferedReader(new InputStreamReader(in, "ISO-8859-1")); //$NON-NLS-1$
- while (true) {
- String line = rdr.readLine();
- if (line == null) /* EOF */
- {
- break;
- }
-
- if ((line.length() != 0) && (line.charAt(0) != '#')) { // skip comments and blank lines
- StringTokenizer tokens = new StringTokenizer(line);
- String type = tokens.nextToken();
- while (tokens.hasMoreTokens()) {
- String ext = tokens.nextToken();
- resultMimeTypes.put(ext.toLowerCase(), type);
- }
- }
- }
- } catch (Exception e) {
- http.logError(HttpMsg.HTTP_DEFAULT_MIME_TABLE_ERROR, e);
- } finally {
- try {
- in.close();
- } catch (IOException e) {
- // TODO: consider logging
- }
- }
- }
-
- return (resultMimeTypes);
- }
-
- /**
- * This method was created in VisualAge.
- */
- private Hashtable parseStatusCodes(InputStream in) {
- Hashtable resultStatusCodes = new Hashtable();
-
- if (in != null) {
- try {
- BufferedReader rdr = new BufferedReader(new InputStreamReader(in, "ISO-8859-1")); //$NON-NLS-1$
- while (true) {
- String line = rdr.readLine();
- if (line == null) /* EOF */
- {
- break;
- }
-
- if ((line.length() != 0) && (line.charAt(0) != '#')) { // skip comments and blank lines
- int space = line.indexOf(' ');
- Integer status = new Integer(line.substring(0, space));
- String statusPhrase = line.substring(space + 1);
- resultStatusCodes.put(status, statusPhrase);
- }
- }
- } catch (Exception e) {
- http.logError(HttpMsg.HTTP_STATUS_CODES_TABLE_ERROR, e);
- } finally {
- try {
- in.close();
- } catch (IOException e) {
- // TODO: consider logging
- }
- }
- }
-
- return (resultStatusCodes);
- }
-
- /* TODO: Consider Removing this method
- * Read alias data and populate a Hashtable.
- * The inputstream is always closed.
- *
- * @param in InputStream from which to read alias data.
- * @return Hashtable of aliases.
- */
- /*
- private static Hashtable parseAliases(InputStream in) {
- Hashtable aliases = new Hashtable(37);
-
- if (in != null) {
- try {
- try {
- BufferedReader br = new BufferedReader(new InputStreamReader(in, "8859_1")); //$NON-NLS-1$
-
- while (true) {
- String line = br.readLine();
-
- if (line == null) // EOF
- {
- break; // done
- }
-
- Tokenizer tokenizer = new Tokenizer(line);
-
- String master = tokenizer.getString("#"); //$NON-NLS-1$
-
- if (master != null) {
- master = master.toUpperCase();
-
- aliases.put(master, master);
-
- parseloop: while (true) {
- String alias = tokenizer.getString("#"); //$NON-NLS-1$
-
- if (alias == null) {
- break parseloop;
- }
-
- aliases.put(alias.toUpperCase(), master);
- }
- }
- }
- } catch (IOException e) {
- if (Http.DEBUG) {
- e.printStackTrace();
- }
- }
- } finally {
- try {
- in.close();
- } catch (IOException ee) {
- // TODO: consider logging
- }
- }
- }
-
- return (aliases);
- }
- */
-
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/Tokenizer.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/Tokenizer.java
deleted file mode 100644
index 76dd58958..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/Tokenizer.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2005 IBM Corporation.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http;
-
-public class Tokenizer {
- private char value[];
- private int max;
- private int cursor;
-
- public Tokenizer(String value) {
- this.value = value.toCharArray();
- max = this.value.length;
- cursor = 0;
- }
-
- public char getChar() {
- int cur = cursor;
- if (cur < max) {
- cursor = cur + 1;
- return (value[cur]);
- }
- return ('\0'); /* end of value */
- }
-
- public String getString(String terminals) {
- skipWhiteSpace();
- char[] val = value;
- int cur = cursor;
-
- if (cur < max) {
- if (val[cur] == '\"') /* if a quoted string */
- {
- cur++; /* skip quote */
- char c = '\0';
- int begin = cur;
- for (; cur < max; cur++) {
- c = val[cur];
- if (c == '\"') {
- break;
- }
- }
- int count = cur - begin;
- if (c == '\"') {
- cur++;
- }
- cursor = cur;
- if (count > 0) {
- skipWhiteSpace();
- return (new String(val, begin, count));
- }
- } else /* not a quoted string; same as token */
- {
- int begin = cur;
- for (; cur < max; cur++) {
- char c = val[cur];
- if ((c == ' ') || (c == '\t') || (terminals.indexOf(c) != -1)) {
- break;
- }
- }
- cursor = cur;
- int count = cur - begin;
- if (count > 0) {
- skipWhiteSpace();
- return (new String(val, begin, count));
- }
- }
- }
- return (null);
- }
-
- public String getToken(String terminals) {
- skipWhiteSpace();
- char[] val = value;
- int cur = cursor;
-
- int begin = cur;
- for (; cur < max; cur++) {
- char c = val[cur];
- if ((c == ' ') || (c == '\t') || (terminals.indexOf(c) != -1)) {
- break;
- }
- }
- cursor = cur;
- int count = cur - begin;
- if (count > 0) {
- skipWhiteSpace();
- return (new String(val, begin, count));
- }
- return (null);
- }
-
- private void skipWhiteSpace() {
- char[] val = value;
- int cur = cursor;
-
- for (; cur < max; cur++) {
- char c = val[cur];
- if ((c == ' ') || (c == '\t')) {
- continue;
- }
- break;
- }
- cursor = cur;
- }
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/URI.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/URI.java
deleted file mode 100644
index b52dff3ba..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/URI.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2009 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http;
-
-import java.io.UnsupportedEncodingException;
-
-public class URI {
- /**
- * Takes an encoded string and decodes it
- * @param input encoded String
- * @param charset The charset to use convert escaped characters
- * @return Decoded String.
- */
- public static String decode(String input, String charset) {
- if (input == null) {
- return null;
- }
-
- return decode(input, 0, input.length(), charset);
- }
-
- /**
- * Takes an encoded string and decodes it
- * @param input encoded String (must not be null)
- * @param begin the beginning index, inclusive.
- * @param end the ending index, exclusive.
- * @param charset The charset to use convert escaped characters
- * @return Decoded String.
- */
- public static String decode(String input, int begin, int end, String charset) {
- if (input == null) {
- return (null);
- }
-
- int index = input.indexOf('%', begin);
- if ((index == -1) || (index >= end)) {
- return input.substring(begin, end).replace('+', ' ');
- }
-
- int size = end - begin;
- StringBuffer result = new StringBuffer(size);
- byte[] bytes = new byte[size];
- int length = 0;
-
- for (int i = begin; i < end; i++) {
- char c = input.charAt(i);
-
- if (c == '%') {
- if (i + 2 >= end) {
- throw new IllegalArgumentException();
- }
-
- i++;
- int digit = Character.digit(input.charAt(i), 16);
- if (digit == -1) {
- throw new IllegalArgumentException();
- }
- int value = (digit << 4);
-
- i++;
- digit = Character.digit(input.charAt(i), 16);
- if (digit == -1) {
- throw new IllegalArgumentException();
- }
- value |= digit;
-
- bytes[length] = (byte) value;
- length++;
- } else {
- if (length > 0) {
- result.append(convert(bytes, 0, length, charset));
-
- length = 0;
- }
-
- if (c == '+') {
- c = ' ';
- }
-
- result.append(c);
- }
- }
-
- if (length > 0) {
- result.append(convert(bytes, 0, length, charset));
-
- length = 0;
- }
-
- return result.toString();
- }
-
- /**
- * Convert bytes to a String using the supplied charset.
- * @param input Array of bytes to convert.
- * @param offset the beginning index, inclusive.
- * @param length number of bytes to convert.
- * @param charset The charset to use convert the bytes.
- * @return String containing converted bytes.
- */
- public static String convert(byte[] input, int offset, int length, String charset) {
- if (charset != null) {
- try {
- return new String(input, offset, length, charset);
- } catch (UnsupportedEncodingException e) {
- /* if the supplied charset is invalid,
- * fall through to use 8859_1.
- */
- }
- }
-
- try {
- return new String(input, offset, length, "ISO-8859-1"); //$NON-NLS-1$
- } catch (UnsupportedEncodingException e) {
- /* in the unlikely event 8859_1 is not present */
- return new String(input, offset, length);
- }
- }
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/mime.types b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/mime.types
deleted file mode 100644
index 764b0ae5d..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/mime.types
+++ /dev/null
@@ -1,44 +0,0 @@
-###############################################################################
-# Copyright (c) 2005 IBM Corporation.
-# 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:
-# IBM Corporation - initial API and implementation
-###############################################################################
-
-# mime.types
-# This file contains the default mapping of file extension to MIME types.
-# This file must be encoded in ISO-8859-1.
-# Extension are processed in a case insensitive manner.
-
-# MIME type Extension
-
-application/octet-stream bin dms lha lzh exe class
-application/x-gtar gtar
-application/x-javascript js
-application/x-tar tar
-application/x-tcl tcl
-application/zip zip jar jxe
-application/pdf pdf
-audio/basic au snd
-audio/midi mid midi kar
-audio/mpeg mpga mp2 mp3
-audio/x-aiff aif aiff aifc
-audio/x-wav wav
-image/gif gif
-image/png png
-image/jpeg jpeg jpg jpe
-image/vnd.map.wbmp wbmp
-model/vrml wrl vrml
-text/html html htm
-text/plain asc txt
-text/richtext rtx
-text/rtf rtf
-text/sgml sgml sgm
-text/xml xml
-text/css css
-text/vnd.map.wml wml
-video/mpeg mpeg mpg mpe
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/HttpServletRequestImpl.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/HttpServletRequestImpl.java
deleted file mode 100644
index d1520e02d..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/HttpServletRequestImpl.java
+++ /dev/null
@@ -1,1438 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2009 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http.servlet;
-
-import java.io.*;
-import java.security.Principal;
-import java.util.*;
-import javax.servlet.RequestDispatcher;
-import javax.servlet.ServletInputStream;
-import javax.servlet.http.*;
-import org.eclipse.equinox.http.*;
-import org.eclipse.equinox.socket.SocketInterface;
-import org.eclipse.osgi.util.NLS;
-import org.osgi.service.http.HttpContext;
-
-/**
- * Implementation of the HttpServletRequest interface
- *
- * Per Servlet 2.2 Section 3.3.3.3, this object need not be thread-safe.
- */
-
-public class HttpServletRequestImpl implements HttpServletRequest {
-
- protected Http http;
- protected HttpServletResponseImpl response;
- protected SocketInterface socket;
- protected ServletInputStreamImpl servletInputStream;
- protected String scheme;
- protected String authType = null;
- protected String remoteUser = null;
-
- protected int contentLength = -2;
- protected String contentType = null;
- protected String serverName = null;
-
- protected Hashtable parameters = null;
- protected Hashtable attributes = null;
- protected BufferedReader reader = null;
- protected ServletInputStream inputstream = null;
- protected Cookie[] cookies;
-
- //request-line variables
- protected String method = null;
- protected String reqURI = null; /* URI decoded */
- protected String protocol = null;
- protected String servletPath = null;
- protected String pathInfo = null; /* URI decoded */
- protected String queryString = null;
- protected String charset = null;
-
- protected Hashtable headers = null;
- protected HttpSessionImpl session;
- protected String requestedSessionId = null;
- protected ServletContextImpl servletContext;
-
- protected boolean parsedQueryData = false;
-
- public HttpServletRequestImpl(SocketInterface socket, Http http, HttpServletResponseImpl response) throws IOException {
- this.response = response;
- this.socket = socket;
- this.http = http;
- scheme = socket.getScheme();
-
- servletInputStream = new ServletInputStreamImpl(socket.getInputStream());
-
- response.setRequest(this);
-
- parseHeaders(); /* allocate headers Hashtable */
- }
-
- /**
- * Initialize additional request data.
- *
- * @param servletPathParam URI alias for this request
- * @param servletContextParam ServletContext for this request
- */
- public void init(String servletPathParam, ServletContextImpl servletContextParam) {
- // BUGBUG Need to deal with context path
- // Servlet 2.2 Section 5.4
- this.servletPath = servletPathParam;
- this.servletContext = servletContextParam;
-
- String tempPathInfo = reqURI.substring(servletPathParam.length());
- if ((tempPathInfo.length() == 0) || tempPathInfo.equals("/")) //$NON-NLS-1$
- {
- /* leave as null */
- } else {
- this.pathInfo = tempPathInfo;
- }
-
- if (authType == null) {
- Object obj = getAttribute(HttpContext.AUTHENTICATION_TYPE);
- if (obj instanceof String) {
- authType = (String) obj;
- }
- }
-
- if (remoteUser == null) {
- Object obj = getAttribute(HttpContext.REMOTE_USER);
- if (obj instanceof String) {
- remoteUser = (String) obj;
- }
- }
- }
-
- /**
- * Returns the value of the named attribute of the request, or
- * null if the attribute does not exist. This method allows
- * access to request information not already provided by the other
- * methods in this interface. Attribute names should follow the
- * same convention as package names.
- * The following predefined attributes are provided.
- *
- * <TABLE BORDER>
- * <tr>
- * <th>Attribute Name</th>
- * <th>Attribute Type</th>
- * <th>Description</th>
- * </tr>
- *
- * <tr>
- * <td VALIGN=TOP>javax.net.ssl.cipher_suite</td>
- * <td VALIGN=TOP>string</td>
- * <td>The string name of the SSL cipher suite in use, if the
- * request was made using SSL</td>
- * </tr>
- *
- * <tr>
- * <td VALIGN=TOP>javax.net.ssl.peer_certificates</td>
- * <td VALIGN=TOP>array of javax.security.cert.X509Certificate</td>
- * <td>The chain of X.509 certificates which authenticates the client.
- * This is only available when SSL is used with client
- * authentication is used.</td>
- * </tr>
- *
- * <tr>
- * <td VALIGN=TOP>javax.net.ssl.session</td>
- * <td VALIGN=TOP>javax.net.ssl.SSLSession</td>
- * <td>An SSL session object, if the request was made using SSL.</td>
- * </tr>
- *
- * </TABLE>
- *
- * <BR>
- * <P>The package (and hence attribute) names beginning with java.*,
- * and javax.* are reserved for use by Javasoft. Similarly, com.sun.*
- * is reserved for use by Sun Microsystems.
- *
- * @param name the name of the attribute whose value is required
- */
- public Object getAttribute(String name) {
- if (attributes != null) {
- return (attributes.get(name));
- }
- return (null);
- }
-
- /**
- * Returns an enumeration of attribute names contained in this request.
- */
-
- public Enumeration getAttributeNames() {
- if (attributes != null) {
- return (attributes.keys());
- }
- return (new Vector(0).elements());
- }
-
- /**
- * Gets the authentication scheme of this request. Same as the CGI
- * variable AUTH_TYPE.
- *
- * @return this request's authentication scheme, or null if none.
- */
- public String getAuthType() {
- return (authType);
- }
-
- /**
- * Returns the character set encoding for the input of this request.
- */
- public String getCharacterEncoding() {
- if (contentType == null) {
- getContentType(); /* parse the content type */
- }
-
- return (charset);
- }
-
- /**
- * Returns the size of the request entity data, or -1 if not known.
- * Same as the CGI variable CONTENT_LENGTH.
- */
- public int getContentLength() {
- if (contentLength == -2) {
- contentLength = getIntHeaderUpper("CONTENT-LENGTH"); //$NON-NLS-1$
- }
- return (contentLength);
- }
-
- /**
- * Returns the Internet Media Type of the request entity data, or
- * null if not known. Same as the CGI variable CONTENT_TYPE.
- */
-
- public String getContentType() {
- if (contentType == null) {
- contentType = getHeaderUpper("CONTENT-TYPE"); //$NON-NLS-1$
-
- if (contentType != null) {
- int index = contentType.indexOf(';', 0);
- if (index >= 0) {
- Tokenizer tokenizer = new Tokenizer(contentType);
-
- // TODO: verify next statement. It was String mimetype = tokenizer.getToken(";");
- tokenizer.getToken(";"); //$NON-NLS-1$
- tokenizer.getChar(); /* eat semicolon */
-
- parseloop: while (true) {
- String attribute = tokenizer.getToken("="); //$NON-NLS-1$
- char c = tokenizer.getChar();
-
- if (c != '=') {
- break parseloop; /* invalid content type */
- }
-
- String value = tokenizer.getString(";"); //$NON-NLS-1$
- c = tokenizer.getChar();
-
- if ("charset".equalsIgnoreCase(attribute)) //$NON-NLS-1$
- {
- charset = value;
- }
-
- if (c == '\0') {
- break parseloop;
- }
- }
- }
- }
- }
-
- return (contentType);
- }
-
- /**
- * Gets an array of cookies found in this request. If no cookies are present, an empty
- * array was returned.
- * @return the array of cookies found in this request
- */
- public Cookie[] getCookies() {
- parseCookies();
-
- return ((Cookie[]) cookies.clone());
- }
-
- /**
- * Gets the value of the requested date header field of this
- * request. If the header can't be converted to a date, the method
- * throws an IllegalArgumentException. The case of the header
- * field name is ignored.
- *
- * From HTTP/1.1 RFC 2616
- * 3.3.1 Full Date
- *
- * HTTP applications have historically allowed three different formats
- * for the representation of date/time stamps:
- *
- * Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123
- * Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
- * Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format
- *
- * The first format is preferred as an Internet standard and represents
- * a fixed-length subset of that defined by RFC 1123 [8] (an update to
- * RFC 822 [9]). The second format is in common use, but is based on the
- * obsolete RFC 850 [12] date format and lacks a four-digit year.
- * HTTP/1.1 clients and servers that parse the date value MUST accept
- * all three formats (for compatibility with HTTP/1.0), though they MUST
- * only generate the RFC 1123 format for representing HTTP-date values
- * in header fields. See section 19.3 for further information.
- *
- * Note: Recipients of date values are encouraged to be robust in
- * accepting date values that may have been sent by non-HTTP
- * applications, as is sometimes the case when retrieving or posting
- * messages via proxies/gateways to SMTP or NNTP.
- *
- * All HTTP date/time stamps MUST be represented in Greenwich Mean Time
- * (GMT), without exception. For the purposes of HTTP, GMT is exactly
- * equal to UTC (Coordinated Universal Time). This is indicated in the
- * first two formats by the inclusion of "GMT" as the three-letter
- * abbreviation for time zone, and MUST be assumed when reading the
- * asctime format. HTTP-date is case sensitive and MUST NOT include
- * additional LWS beyond that specifically included as SP in the
- * grammar.
- *
- * HTTP-date = rfc1123-date | rfc850-date | asctime-date
- * rfc1123-date = wkday "," SP date1 SP time SP "GMT"
- * rfc850-date = weekday "," SP date2 SP time SP "GMT"
- * asctime-date = wkday SP date3 SP time SP 4DIGIT
- * date1 = 2DIGIT SP month SP 4DIGIT
- * ; day month year (e.g., 02 Jun 1982)
- * date2 = 2DIGIT "-" month "-" 2DIGIT
- * ; day-month-year (e.g., 02-Jun-82)
- * date3 = month SP ( 2DIGIT | ( SP 1DIGIT ))
- * ; month day (e.g., Jun 2)
- * time = 2DIGIT ":" 2DIGIT ":" 2DIGIT
- * ; 00:00:00 - 23:59:59
- * wkday = "Mon" | "Tue" | "Wed"
- * | "Thu" | "Fri" | "Sat" | "Sun"
- * weekday = "Monday" | "Tuesday" | "Wednesday"
- * | "Thursday" | "Friday" | "Saturday" | "Sunday"
- * month = "Jan" | "Feb" | "Mar" | "Apr"
- * | "May" | "Jun" | "Jul" | "Aug"
- * | "Sep" | "Oct" | "Nov" | "Dec"
- *
- * Note: HTTP requirements for the date/time stamp format apply only
- * to their usage within the protocol stream. Clients and servers are
- * not required to use these formats for user presentation, request
- * logging, etc.
- *
- * @param name the String containing the name of the requested
- * header field
- * @return the value the requested date header field, or -1 if not
- * found.
- */
- public long getDateHeader(String name) {
- //headers are stored as strings and must be converted
- String date = getHeader(name);
-
- if (date != null) {
- HttpDate d = new HttpDate(date);
-
- if (d.isValid()) {
- return (d.getAsLong()); // Parsed OK, so get the value as a Long
- }
- throw new IllegalArgumentException();
- }
-
- return (-1);
- }
-
- /**
- * Gets the value of the requested header field of this request.
- * The case of the header field name is ignored.
- *
- * @param name the String containing the name of the requested
- * header field
- * @return the value of the requested header field, or null if not
- * known.
- */
-
- //This should be case insensitive
- public String getHeader(String name) {
- return ((String) headers.get(name.toUpperCase()));
- }
-
- /**
- * Gets the header names for this request.
- *
- * @return an enumeration of strings representing the header names
- * for this request. Some server implementations do not allow
- * headers to be accessed in this way, in which case this method
- * will return null.
- */
- public Enumeration getHeaderNames() {
- return (headers.keys());
- }
-
- protected String getHeaderUpper(String name) {
- return ((String) headers.get(name));
- }
-
- /**
- * Returns an input stream for reading binary data in the request body.
- *
- * @see #getReader()
- * @exception IllegalStateException if getReader has been
- * called on this same request.
- */
- public ServletInputStream getInputStream() {
- if (inputstream == null) {
- synchronized (this) {
- if (inputstream == null) {
- if (reader != null) {
- throw new IllegalStateException();
- }
-
- inputstream = servletInputStream.getServletInputStream(getContentLength());
- }
- }
- }
-
- return (inputstream);
- }
-
- /**
- * Gets the value of the specified integer header field of this
- * request. The case of the header field name is ignored. If the
- * header can't be converted to an integer, the method throws a
- * NumberFormatException.
- *
- * @param name the String containing the name of the requested
- * header field
- * @return the value of the requested header field, or -1 if not
- * found.
- */
-
- //This lookup is case insensitive
- public int getIntHeader(String name) {
- String value = getHeader(name);
-
- if (value != null) {
- return (Integer.parseInt(value));
- }
-
- return (-1);
- }
-
- protected int getIntHeaderUpper(String name) {
- String value = getHeaderUpper(name);
-
- if (value != null) {
- return (Integer.parseInt(value));
- }
-
- return (-1);
- }
-
- /**
- * Gets the HTTP method (for example, GET, POST, PUT) with which
- * this request was made. Same as the CGI variable REQUEST_METHOD.
- *
- * @return the HTTP method with which this request was made
- */
- public String getMethod() {
- return (method);
- }
-
- /**
- * Returns a string containing the lone value of the specified
- * parameter, or null if the parameter does not exist. For example,
- * in an HTTP servlet this method would return the value of the
- * specified query string parameter. Servlet writers should use
- * this method only when they are sure that there is only one value
- * for the parameter. If the parameter has (or could have)
- * multiple values, servlet writers should use
- * getParameterValues. If a multiple valued parameter name is
- * passed as an argument, the return value is implementation
- * dependent.
- *
- * @see #getParameterValues
- *
- * @param name the name of the parameter whose value is required.
- */
- public String getParameter(String name) {
- String[] values = getParameterValues(name);
-
- if ((values != null) && (values.length > 0)) {
- return (values[0]);
- }
-
- return (null);
- }
-
- /**
- * Returns the parameter names for this request as an enumeration
- * of strings, or an empty enumeration if there are no parameters
- * or the input stream is empty. The input stream would be empty
- * if all the data had been read from the stream returned by the
- * method getInputStream.
- */
- public Enumeration getParameterNames() {
- if (!parsedQueryData) {
- parseQueryData();
- }
-
- if (parameters != null) {
- return (parameters.keys());
- }
-
- return (new Vector(0).elements());
- }
-
- /**
- * Returns the values of the specified parameter for the request as
- * an array of strings, or null if the named parameter does not
- * exist. For example, in an HTTP servlet this method would return
- * the values of the specified query string or posted form as an
- * array of strings.
- *
- * @param name the name of the parameter whose value is required.
- * @see javax.servlet.ServletRequest#getParameter
- */
- public String[] getParameterValues(String name) {
- if (!parsedQueryData) {
- parseQueryData();
- }
-
- if (parameters != null) {
- return ((String[]) parameters.get(name));
- }
-
- return (null);
- }
-
- /**
- * Gets any optional extra path information following the servlet
- * path of this request's URI, but immediately preceding its query
- * string. Same as the CGI variable PATH_INFO.
- *
- * @return the optional path information following the servlet
- * path, but before the query string, in this request's URI; null
- * if this request's URI contains no extra path information
- */
- public String getPathInfo() {
- return (pathInfo);
- }
-
- /**
- * Gets any optional extra path information following the servlet
- * path of this request's URI, but immediately preceding its query
- * string, and translates it to a real path. Similar to the CGI
- * variable PATH_TRANSLATED
- *
- * @return extra path information translated to a real path or null
- * if no extra path information is in the request's URI
- */
- public String getPathTranslated() {
- // JSP 1.0 Section B.5
- return servletContext.getRealPath(getPathInfo());
- }
-
- /**
- * Returns the protocol and version of the request as a string of
- * the form <code>&lt;protocol&gt;/&lt;major version&gt;.&lt;minor
- * version&gt</code>. Same as the CGI variable SERVER_PROTOCOL.
- */
- public String getProtocol() {
- return (protocol);
- }
-
- /**
- * Gets any query string that is part of the HTTP request URI.
- * Same as the CGI variable QUERY_STRING.
- *
- * @return query string that is part of this request's URI, or null
- * if it contains no query string
- */
- public String getQueryString() {
- return (queryString);
- }
-
- /**
- * Returns a buffered reader for reading text in the request body.
- * This translates character set encodings as appropriate.
- *
- * @see #getInputStream()
- *
- * @exception IllegalStateException if getInputStream has been
- * called on this same request.
- */
- public BufferedReader getReader() {
- if (reader == null) {
- synchronized (this) {
- if (reader == null) {
- if (inputstream != null) {
- throw new IllegalStateException();
- }
-
- // BUGBUG Must create reader with charset getCharacterEncoding or iso-8859-1 if null.
- // Servlet 2.3 Section 4.9
- reader = new BufferedReader(new InputStreamReader(servletInputStream.getServletInputStream(getContentLength())));
- }
- }
- }
-
- return (reader);
- }
-
- /**
- * Applies alias rules to the specified virtual path and returns
- * the corresponding real path, or null if the translation can not
- * be performed for any reason. For example, an HTTP servlet would
- * resolve the path using the virtual docroot, if virtual hosting
- * is enabled, and with the default docroot otherwise. Calling
- * this method with the string "/" as an argument returns the
- * document root.
- *
- * @param path the virtual path to be translated to a real path
- * *deprecated
- */
- public String getRealPath(String path) {
- return servletContext.getRealPath(path);
- }
-
- /**
- * Returns the IP address of the agent that sent the request.
- * Same as the CGI variable REMOTE_ADDR.
- */
- public String getRemoteAddr() {
- return (socket.getInetAddress().getHostAddress());
- }
-
- /**
- * Returns the fully qualified host name of the agent that sent the
- * request. Same as the CGI variable REMOTE_HOST.
- */
- public String getRemoteHost() {
- return (socket.getInetAddress().getHostName());
- }
-
- /**
- * Gets the name of the user making this request. The user name is
- * set with HTTP authentication. Whether the user name will
- * continue to be sent with each subsequent communication is
- * browser-dependent. Same as the CGI variable REMOTE_USER.
- *
- * @return the name of the user making this request, or null if not
- * known.
- */
- public String getRemoteUser() {
- return (remoteUser);
- }
-
- /**
- * Returns the session id specified with this request. This may differ from
- * the session id in the current session if the session id given by the
- * client was invalid for whatever reason and a new session was created.
- * This method will return null if the request does not have a session
- * associated with it.
- *
- * @return the session id specified by this request, or null if the
- * request did not specify a session id
- *
- * @see #isRequestedSessionIdValid */
- public String getRequestedSessionId() {
- parseCookies(); /* allocate cookies array */
-
- if (requestedSessionId == null) {
- String sessionCookieName = HttpSessionImpl.sessionCookieName;
- int numCookies = cookies.length;
- for (int i = 0; i < numCookies; i++) {
- Cookie cookie = cookies[i];
- if (sessionCookieName.equals(cookie.getName())) {
- requestedSessionId = cookie.getValue();
- break;
- }
- }
- }
-
- return (requestedSessionId);
- }
-
- /**
- * Gets, from the first line of the HTTP request, the part of this
- * request's URI that is to the left of any query string.
- * For example,
- *
- * <blockquote>
- * <table>
- * <tr align=left><th>First line of HTTP request<th>
- * <th>Return from <code>getRequestURI</code>
- * <tr><td>POST /some/path.html HTTP/1.1<td><td>/some/path.html
- * <tr><td>GET http://foo.bar/a.html HTTP/1.0
- * <td><td>http://foo.bar/a.html
- * <tr><td>HEAD /xyz?a=b HTTP/1.1<td><td>/xyz
- * </table>
- * </blockquote>
- *
- * <p>To reconstruct a URL with a URL scheme and host, use the
- * method javax.servlet.http.HttpUtils.getRequestURL, which returns
- * a StringBuffer.
- *
- * @return this request's URI
- * @see javax.servlet.http.HttpUtils#getRequestURL
- */
- public String getRequestURI() {
- // BUGBUG this should probably be URI encoded?
- // Servlet 2.2 Section 5.4
- return (reqURI);
- }
-
- /**
- * Returns the scheme of the URL used in this request, for example
- * "http", "https", or "ftp". Different schemes have different
- * rules for constructing URLs, as noted in RFC 1738. The URL used
- * to create a request may be reconstructed using this scheme, the
- * server name and port, and additional information such as URIs.
- */
- public String getScheme() {
- return (scheme);
- }
-
- /**
- * Returns the host name of the server that received the request.
- * Same as the CGI variable SERVER_NAME.
- */
- public String getServerName() {
-
- if (serverName == null) {
- String value = getHeaderUpper("HOST"); //$NON-NLS-1$
- if (value != null) {
- int n = value.indexOf(':');
- if (n < 0) {
- serverName = value;
- } else {
- serverName = value.substring(0, n).trim();
- }
- } else {
- serverName = socket.getLocalAddress().getHostName();
- }
- }
- return serverName;
- }
-
- /**
- * Returns the port number on which this request was received.
- * Same as the CGI variable SERVER_PORT.
- */
- public int getServerPort() {
- return (socket.getLocalPort());
- }
-
- /**
- * Gets the part of this request's URI that refers to the servlet
- * being invoked. Analogous to the CGI variable SCRIPT_NAME.
- *
- * @return the servlet being invoked, as contained in this
- * request's URI
- */
- public String getServletPath() {
- return (servletPath);
- }
-
- /**
- * Returns the current valid session associated with this request.
- * A session will be created for the
- * request if there is not already a session associated with the request.
- *
- * To ensure the session is properly
- * maintained, the servlet developer must call this method before the
- * response is committed.
- *
- * @return the session associated with this request.
- */
- public HttpSession getSession() {
- return (getSession(true));
- }
-
- /**
- * Returns the current valid session associated with this request.
- * If there is not already a session associated with the request,
- * a session will be created for the request only
- * if the argument is true.
- *
- * To ensure the session is properly
- * maintained, the servlet developer must call this method before the
- * response is committed.
- *
- * If the create flag is set to false and no session
- * is associated with this request, then this method will return null.
- *
- * <p><b>Note</b>: to ensure the session is properly maintained,
- * the servlet developer must call this method (at least once)
- * before any output is written to the response.
- *
- * <p>Additionally, application-writers need to be aware that newly
- * created sessions (that is, sessions for which
- * <code>HttpSession.isNew</code> returns true) do not have any
- * application-specific state.
- *
- * @return the session associated with this request or null if
- * create was false and no valid session is associated
- * with this request.
- */
- public synchronized HttpSession getSession(boolean create) {
- if (session != null) /* if session cached in this request */
- {
- /* test to see if the session is still valid */
- if (session.isValid(false)) {
- return (session);
- }
-
- session = null; /* dereference invalid session */
- } else {
- /* Session is not cached in this request
- * Check to see if the client requested a session id.
- */
-
- String sessionId = getRequestedSessionId();
- if (sessionId != null) {
- session = http.getSession(sessionId);
-
- if (session != null) /* valid session in cache */
- {
- return (session);
- }
- }
- }
-
- // we didn't get a valid session, so create one if desired
- if (create) {
- session = new HttpSessionImpl(http);
- response.addCookie(session.getCookie());
- return (session);
- }
-
- // Nothing we did produced a valid session, and the caller
- // didn't ask us to create one.
- return (null);
- }
-
- /**
- * Checks whether the session id specified by this request came in
- * as a cookie. (The requested session may not be one returned by
- * the <code>getSession</code> method.)
- *
- * @return true if the session id specified by this request came in
- * as a cookie; false otherwise
- *
- * @see #getSession
- */
- public boolean isRequestedSessionIdFromCookie() {
- /* We always use cookies. If there is a requestedSessionId,
- * it came from a Cookie.
- */
- return (getRequestedSessionId() != null);
- }
-
- /**
- * Checks whether the session id specified by this request came in
- * as part of the URL. (The requested session may not be the one
- * returned by the <code>getSession</code> method.)
- *
- * @return true if the session id specified by the request for this
- * session came in as part of the URL; false otherwise
- *
- * @see #getSession
- *
- * @deprecated use isRequestSessionIdFromURL() instead
- */
- public boolean isRequestedSessionIdFromUrl() {
- return (isRequestedSessionIdFromURL());
- }
-
- /**
- * Checks whether the session id specified by this request came in
- * as part of the URL. (The requested session may not be the one
- * returned by the <code>getSession</code> method.)
- *
- * @return true if the session id specified by the request for this
- * session came in as part of the URL; false otherwise
- *
- * @see #getSession
- */
-
- public boolean isRequestedSessionIdFromURL() {
- /* We do not support URL rewriting. We use cookies. */
- return (false);
- }
-
- /**
- * This method checks whether this request is associated with a session
- * that is currently valid. If the session used by the request is not valid,
- * it will not be returned via the getSession method.
- *
- * @return true if the request session is valid.
- *
- * @see #getRequestedSessionId
- * @see javax.servlet.http.HttpSessionContext
- * @see #getSession
- */
- public boolean isRequestedSessionIdValid() {
- HttpSession currentSession = getSession(false); /* get current session, if any */
-
- if (currentSession != null) /* if there is a session, see if it the requested session */
- {
- return (currentSession.getId().equals(getRequestedSessionId()));
- }
-
- return (false);
- }
-
- protected synchronized void parseCookies() {
- if (cookies == null) {
- nocookies: {
- String cookieHeader = getHeaderUpper("COOKIE"); //$NON-NLS-1$
- if (cookieHeader == null) {
- break nocookies;
- }
- Vector cookieVector = new Vector(20);
- int cookieVersion = 0;
-
- //parse through cookie header for all cookies
-
- Tokenizer tokenizer = new Tokenizer(cookieHeader);
-
- String name = tokenizer.getToken("="); //$NON-NLS-1$
- char c = tokenizer.getChar();
- String value;
-
- if (name.equals("$Version")) //$NON-NLS-1$
- {
- if (c != '=') {
- if (Http.DEBUG) {
- http.logDebug("Cookie parse error", new Exception()); //$NON-NLS-1$
- }
- break nocookies;
- }
-
- value = tokenizer.getString(";,"); //$NON-NLS-1$
-
- try {
- cookieVersion = Integer.parseInt(value);
- } catch (NumberFormatException e) {
- if (Http.DEBUG) {
- http.logDebug("Cookie version error", e); //$NON-NLS-1$
- }
- }
-
- name = null;
- }
-
- parseloop: while (true) {
- if (name == null) {
- name = tokenizer.getToken("="); //$NON-NLS-1$
- c = tokenizer.getChar();
- }
-
- if (c != '=') {
- if (Http.DEBUG) {
- http.logDebug("Cookie parse error", new Exception()); //$NON-NLS-1$
- }
- break nocookies;
- }
-
- value = tokenizer.getString(";,"); //$NON-NLS-1$
- c = tokenizer.getChar();
-
- Cookie cookie;
- try {
- cookie = new Cookie(name, value);
- } catch (IllegalArgumentException e) {
- if (Http.DEBUG) {
- http.logDebug("Cookie constructor error", e); //$NON-NLS-1$
- }
- break nocookies;
- }
- cookie.setVersion(cookieVersion);
-
- cookieVector.addElement(cookie);
-
- if (c == '\0') {
- break parseloop;
- }
-
- name = tokenizer.getToken("="); //$NON-NLS-1$
- c = tokenizer.getChar();
- if (name.equals("$Path")) //$NON-NLS-1$
- {
- if (c != '=') {
- if (Http.DEBUG) {
- http.logDebug("Cookie parse error", new Exception()); //$NON-NLS-1$
- }
- break nocookies;
- }
- cookie.setPath(tokenizer.getString(";,")); //$NON-NLS-1$
-
- c = tokenizer.getChar();
- if (c == '\0') {
- break parseloop;
- }
-
- name = tokenizer.getToken("="); //$NON-NLS-1$
- c = tokenizer.getChar();
- }
-
- if (name.equals("$Domain")) //$NON-NLS-1$
- {
- if (c != '=') {
- if (Http.DEBUG) {
- http.logDebug("Cookie parse error", new Exception()); //$NON-NLS-1$
- }
- break nocookies;
- }
- cookie.setDomain(tokenizer.getString(";,")); //$NON-NLS-1$
-
- c = tokenizer.getChar();
- if (c == '\0') {
- break parseloop;
- }
-
- name = null;
- }
- }
-
- if (cookieVector.size() > 0) {
- cookies = new Cookie[cookieVector.size()];
- cookieVector.copyInto(cookies);
- return;
- }
- }
-
- cookies = new Cookie[0];
- }
- }
-
- protected void parseHeaders() throws IOException {
- headers = new Hashtable(31);
- byte[] buffer = new byte[4096];
-
- /* The first line in an http request is always the request-line. */
- String line = readHeaderLine(buffer);
-
- if (line.length() == 0) {
- throw new InterruptedIOException(HttpMsg.HTTP_NO_HEADER_LINE_READ_EXCEPTION);
- }
-
- socket.markActive(); /* indicate we are processing a request */
-
- parseRequestLine(line);
-
- /* Now we get to the headers. */
- // BUGBUG Headers can be repeated! getHeader must return the first header
- // in the request. The (2.2) getHeaders method can be used to get all
- // the headers' values.
- // Servlet 2.2 Section 5.3
- boolean firstLine = true;
- String header = null;
- StringBuffer value = new StringBuffer(256);
- while (true) {
- line = readHeaderLine(buffer);
-
- if (line.length() == 0) { //End of headers
- if (!firstLine) /* flush last line */
- {
- headers.put(header, value.toString().trim());
- }
- break;
- }
-
- // System.out.println(line);
-
- char c = line.charAt(0);
- if ((c == ' ') || (c == '\t')) /* continuation */
- {
- if (firstLine) /* if no previous line */
- {
- throw new IOException(NLS.bind(HttpMsg.HTTP_INVALID_HEADER_LINE_EXCEPTION, line));
- }
- value.append(line.substring(1));
- continue;
- }
-
- if (!firstLine) {
- headers.put(header, value.toString().trim());
- value.setLength(0); /* clear StringBuffer */
- }
-
- //use ':' as a delimeter to separate the key and the value
- int colon = line.indexOf(':', 0);
-
- // Our keys are saved as upper case so we can do case-insensitive
- // searches on them.
- header = line.substring(0, colon).toUpperCase();
- value.append(line.substring(colon + 1));
- firstLine = false;
- }//while
- }
-
- /**
- * This methods MUST only be called by one of the getParameter methods
- * Servlet 2.2 Section 5.1
- */
- protected synchronized void parseQueryData() {
- if (!parsedQueryData) {
- try {
- /* Request parameters must come from BOTH the query string
- * and the POST data. Query string must be processed before POST data.
- * Servlet 2.2 Section 5.1.
- */
-
- if (queryString != null) {
- if (parameters == null) {
- parameters = new Hashtable();
- }
-
- parseQueryString(parameters, queryString, null);
- }
-
- /* POST data must only be read if the following conditions are
- * true
- * 1. getScheme is "http" or "https"
- * 2. getMethod is "POST"
- * 3. getContextType is "application/x-www-form-urlencoded"
- * 4. servlet calls getParameter* method.
- * Servlet 2.2 Section 5.1
- */
- String content_type = getContentType();
-
- if (content_type != null) {
- int index = content_type.indexOf(';', 0);
- if (index >= 0) {
- content_type = content_type.substring(0, index).trim();
- }
- }
-
- if ("POST".equals(method) && //$NON-NLS-1$
- ("http".equals(scheme) || "https".equals(scheme)) && //$NON-NLS-1$ //$NON-NLS-2$
- "application/x-www-form-urlencoded".equals(content_type) //$NON-NLS-1$
- ) {
- int content_length = getContentLength();
- if (content_length > 0) {
- // System.out.println("Read POST data");
- /* Read the post data from the ServletInputStream */
- ServletInputStream in = getInputStream();
- byte buffer[] = new byte[content_length];
- int bytesRead = 0;
- while (bytesRead < content_length) {
- int count;
-
- try {
- count = in.read(buffer, bytesRead, content_length - bytesRead);
- } catch (IOException e) {
- throw new IllegalArgumentException();
- }
-
- if (count < 1) {
- break;
- }
-
- bytesRead += count;
- }
-
- String encoding = getCharacterEncoding();
-
- /* Must use charset getCharacterEncoding or iso-8859-1 if null.
- * Servlet 2.3 Section 4.9
- */
-
- String postData = URI.convert(buffer, 0, bytesRead, encoding);
-
- if (parameters == null) {
- parameters = new Hashtable();
- }
-
- parseQueryString(parameters, postData, encoding);
- }
- }
- } catch (Exception e) {
- //Bad query string, ignore, log and continue
- http.logError(HttpMsg.HTTP_QUERYDATA_PARSE_EXCEPTION, e);
- }
-
- parsedQueryData = true;
- }
- }
-
- /**
- * Parses a query string and builds a hashtable of key-value
- * pairs, where the values are arrays of strings. The query string
- * should have the form of a string packaged by the GET or POST
- * method. (For example, it should have its key-value pairs
- * delimited by ampersands (&) and its keys separated from its
- * values by equal signs (=).)
- *
- * <p> A key can appear one or more times in the query string.
- * Each time a key appears, its corresponding value is inserted
- * into its string array in the hash table. (So keys that appear
- * once in the query string have, in the hash table, a string array
- * of length one as their value, keys that appear twice have a
- * string array of length two, etc.)
- *
- * <p> When the keys and values are moved into the hashtable, any
- * plus signs (+) are returned to spaces and characters sent in
- * hexadecimal notation (%xx) are converted back to characters.
- *
- * @param data query string to be parsed
- * @param result a hashtable built from the parsed key-value pairs; the
- *.hashtable's values are arrays of strings
- * @exception IllegalArgumentException if the query string is
- * invalid.
- */
- protected void parseQueryString(Hashtable result, String data, String encoding) {
- if (data == null) {
- throw new IllegalArgumentException();
- }
-
- // System.out.println("Querystring: " + data);
-
- data = data.trim(); /* Strip CRLF if present */
-
- int len = data.length();
-
- if (len >= 0) {
- int begin = 0;
-
- while (true) {
- int end = data.indexOf('&', begin);
- if (end == -1) {
- end = len;
- }
-
- int equals = data.indexOf('=', begin);
-
- String key;
- String value;
- if ((equals >= end) || (equals == -1)) {
- key = URI.decode(data, begin, end, encoding);
- value = ""; //$NON-NLS-1$
- } else {
- key = URI.decode(data, begin, equals, encoding);
- value = URI.decode(data, equals + 1, end, encoding);
- }
-
- String[] values = (String[]) result.get(key);
-
- if (values == null) {
- values = new String[1];
- values[0] = value;
- result.put(key, values);
- } else {
- int length = values.length;
- String[] newvalues = new String[length + 1];
- System.arraycopy(values, 0, newvalues, 0, length);
- newvalues[length] = value;
- result.put(key, newvalues);
- }
-
- if (end == len) {
- break;
- }
-
- begin = end + 1;
- }
- }
- }
-
- /**
- * This method was created in VisualAge.
- * @param requestLine java.lang.String
- */
- protected void parseRequestLine(String requestLine) {
- if (Http.DEBUG) {
- http.logDebug("Http Request Line=\"" + requestLine + "\""); //$NON-NLS-1$ //$NON-NLS-2$
- }
- // System.out.println("Http Request Line=\"" + requestLine + "\"");
-
- int space = requestLine.indexOf(' ', 0);
- method = requestLine.substring(0, space);
-
- int nextspace = requestLine.lastIndexOf(' ');
- protocol = requestLine.substring(nextspace + 1);
-
- int query = requestLine.indexOf('?', space + 1);
-
- if ((query >= nextspace) || (query == -1)) {
- reqURI = URI.decode(requestLine, space + 1, nextspace, null);
- } else {
- reqURI = URI.decode(requestLine, space + 1, query, null);
- queryString = requestLine.substring(query + 1, nextspace);
- }
- }
-
- /**
- * This method is only used by the constructor (albiet indirectly)
- * @return java.lang.String
- */
- protected String readHeaderLine(byte[] buffer) throws IOException {
- int read = servletInputStream.readLine(buffer, 0, buffer.length);
- if (read <= 0) {
- throw new InterruptedIOException(HttpMsg.HTTP_NO_HEADER_LINE_READ_EXCEPTION);
- }
-
- // BUGBUG should use 8859_1 encoding to make string
- /* create String from byte array using 0 for high byte of chars */
- String line = URI.convert(buffer, 0, read, null);
-
- if (line.endsWith("\n")) //$NON-NLS-1$
- {
- return (line.trim()); /* trim removes trailing CRLF */
- }
-
- try {
- response.sendError(HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE);
- } finally {
- response.close();
- }
-
- throw new IOException(NLS.bind(HttpMsg.HTTP_HEADER_LINE_TOO_LONG_EXCEPTION, new Integer(buffer.length)));
- }
-
- /**
- * This method places an attribute into the request for later use by
- * other objects which will have access to this request object such as
- * nested servlets.
- *
- * @param name Attribute name
- * @param val Attribute value
- */
- public void setAttribute(String name, Object val) {
- if (attributes == null) {
- synchronized (this) {
- if (attributes == null) {
- attributes = new Hashtable(31);
- }
- }
- }
-
- if (val == null) {
- attributes.remove(name);
- } else {
- attributes.put(name, val);
- }
- }
-
- /**
- * @see javax.servlet.http.HttpServletRequest#getContextPath()
- */
- public String getContextPath() throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.http.HttpServletRequest#getHeaders(String)
- */
- public Enumeration getHeaders(String name) throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.http.HttpServletRequest#getRequestURL()
- */
- public StringBuffer getRequestURL() throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.http.HttpServletRequest#getUserPrincipal()
- */
- public Principal getUserPrincipal() throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.http.HttpServletRequest#isUserInRole(String)
- */
- public boolean isUserInRole(String role) throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.ServletRequest#getLocale()
- */
- public Locale getLocale() throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.ServletRequest#getLocales()
- */
- public Enumeration getLocales() throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.ServletRequest#getParameterMap()
- */
- public Map getParameterMap() throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.ServletRequest#getRequestDispatcher(String)
- */
- public RequestDispatcher getRequestDispatcher(String path) throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.ServletRequest#isSecure()
- */
- public boolean isSecure() throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.ServletRequest#removeAttribute(String)
- */
- public void removeAttribute(String name) throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.ServletRequest#setCharacterEncoding(String)
- */
- public void setCharacterEncoding(String env) throws UnsupportedEncodingException, UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /* For compilation only. Will not implement.
- *
- */
- public String getLocalAddr() {
- //return(socket.getInetAddress().getLocalHost().getHostAddress());
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /* For compilation only. Will not implement.
- *
- */
- public String getLocalName() {
- //return(socket.getInetAddress().getLocalHost().getHostName());
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /* For compilation only. Will not implement.
- *
- */
- public int getLocalPort() {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /* For compilation only. Will not implement.
- *
- */
- public int getRemotePort() {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/HttpServletResponseImpl.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/HttpServletResponseImpl.java
deleted file mode 100644
index 12020c016..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/HttpServletResponseImpl.java
+++ /dev/null
@@ -1,861 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2009 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http.servlet;
-
-import java.io.*;
-import java.util.*;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletResponse;
-import org.eclipse.equinox.http.*;
-import org.eclipse.equinox.socket.SocketInterface;
-
-/**
- * The implementation of the HttpServletResponse interface.
- *
- * Per Servlet 2.2 Section 3.3.3.3, this object need not be thread-safe.
- **/
-
-public class HttpServletResponseImpl implements HttpServletResponse {
- private Http http;
- protected HttpServletRequestImpl request;
- private SocketInterface socket;
- protected ServletOutputStreamImpl servletOutputStream;
- protected String charset = null;
- protected static final String defaultCharset = "ISO-8859-1"; //$NON-NLS-1$
-
- protected int contentLength = 0;
- protected String contentType = null;
- protected Vector cookies = null;
- protected Hashtable headers = null;
- protected int status = SC_OK;
- protected String statusString = "OK"; //$NON-NLS-1$
-
- private boolean gotOutputStream = false;
- protected PrintWriter writer = null;
-
- private boolean keepAlive = false;
-
- public HttpServletResponseImpl(SocketInterface socket, Http http) throws IOException {
- this.http = http;
- this.socket = socket;
- servletOutputStream = new ServletOutputStreamImpl(socket.getOutputStream(), this);
- }
-
- /**
- * Called by the request in its constructor.
- */
- protected void setRequest(HttpServletRequestImpl request) {
- this.request = request;
- }
-
- /**
- * Adds the specified cookie to the response. It can be called
- * multiple times to set more than one cookie.
- *
- * @param cookie the Cookie to return to the client
- */
- public void addCookie(Cookie cookie) {
- if (cookies == null) {
- synchronized (this) {
- if (cookies == null) {
- cookies = new Vector(20);
- }
- }
- }
-
- synchronized (cookies) {
- if (!cookies.contains(cookie)) {
- //System.out.println("addCookie: "+cookie.getName()+"="+cookie.getValue());
- cookies.addElement(cookie);
- }
- }
-
- //http.logDebug("ServletResponse::addCookie: added cookie "+cookie.getName());
- }
-
- /**
- * Checks whether the response message header has a field with
- * the specified name.
- *
- * @param name the header field name
- * @return true if the response message header has a field with
- * the specified name; false otherwise
- */
- public boolean containsHeader(String name) {
- if (headers == null) {
- return (false);
- }
-
- Object value = headers.get(name);
-
- if (value != null) {
- return (true);
- }
-
- Enumeration headerEnumeration = headers.keys();
-
- while (headerEnumeration.hasMoreElements()) {
- String key = (String) headerEnumeration.nextElement();
-
- if (name.equalsIgnoreCase(key)) {
- return (true);
- }
- }
-
- return (false);
- }
-
- /**
- * Encodes the specified URL for use in the
- * <code>sendRedirect</code> method or, if encoding is not needed,
- * returns the URL unchanged. The implementation of this method
- * should include the logic to determine whether the session ID
- * needs to be encoded in the URL. Because the rules for making
- * this determination differ from those used to decide whether to
- * encode a normal link, this method is seperate from the
- * <code>encodeUrl</code> method.
- *
- * <p>All URLs sent to the HttpServletResponse.sendRedirect
- * method should be run through this method. Otherwise, URL
- * rewriting cannot be used with browsers which do not support
- * cookies.
- *
- * @param url the url to be encoded.
- * @return the encoded URL if encoding is needed; the unchanged URL
- * otherwise.
- * deprecated
- *
- * @see #sendRedirect
- * @see #encodeUrl
- */
-
- public String encodeRedirectUrl(String url) {
- return (encodeRedirectURL(url));
- }
-
- /**
- * Encodes the specified URL for use in the
- * <code>sendRedirect</code> method or, if encoding is not needed,
- * returns the URL unchanged. The implementation of this method
- * should include the logic to determine whether the session ID
- * needs to be encoded in the URL. Because the rules for making
- * this determination differ from those used to decide whether to
- * encode a normal link, this method is seperate from the
- * <code>encodeUrl</code> method.
- *
- * <p>All URLs sent to the HttpServletResponse.sendRedirect
- * method should be run through this method. Otherwise, URL
- * rewriting canont be used with browsers which do not support
- * cookies.
- *
- * <p>After this method is called, the response should be considered
- * to be committed and should not be written to.
- *
- * @param url the url to be encoded.
- * @return the encoded URL if encoding is needed; the unchanged URL
- * otherwise.
- *
- * @see #sendRedirect
- * @see #encodeUrl
- */
-
- public String encodeRedirectURL(String url) {
- return (url);
- }
-
- /**
- * Encodes the specified URL by including the session ID in it,
- * or, if encoding is not needed, returns the URL unchanged.
- * The implementation of this method should include the logic to
- * determine whether the session ID needs to be encoded in the URL.
- * For example, if the browser supports cookies, or session
- * tracking is turned off, URL encoding is unnecessary.
- *
- * <p>All URLs emitted by a Servlet should be run through this
- * method. Otherwise, URL rewriting cannot be used with browsers
- * which do not support cookies.
- *
- * @param url the url to be encoded.
- * @return the encoded URL if encoding is needed; the unchanged URL
- * otherwise.
- * deprecated
- */
- public String encodeUrl(String url) {
- return (encodeURL(url));
- }
-
- /**
- * Encodes the specified URL by including the session ID in it,
- * or, if encoding is not needed, returns the URL unchanged.
- * The implementation of this method should include the logic to
- * determine whether the session ID needs to be encoded in the URL.
- * For example, if the browser supports cookies, or session
- * tracking is turned off, URL encoding is unnecessary.
- *
- * <p>All URLs emitted by a Servlet should be run through this
- * method. Otherwise, URL rewriting cannot be used with browsers
- * which do not support cookies.
- *
- * @param url the url to be encoded.
- * @return the encoded URL if encoding is needed; the unchanged URL
- * otherwise.
- */
-
- public String encodeURL(String url) {
- return (url);
- }
-
- /**
- * Close the response output.
- *
- */
- public void close() {
- if (writer != null) {
- writer.close();
- } else {
- try {
- servletOutputStream.close();
- } catch (IOException e) {
- // TODO: consider logging
- }
- }
-
- if (!keepAlive) /* if the no Keep-Alive, then close socket */
- {
- try {
- socket.close();
- } catch (IOException e) {
- // TODO: consider logging
- }
- }
- }
-
- /**
- * Returns the character set encoding used for this MIME body.
- * The character encoding is either the one specified in the
- * assigned content type, or one which the client understands
- * as specified in the Accept-Charset header of the request.
- * If no charset can be determined, it defaults to the
- * value of the System property 'file.encoding' if that
- * is a supported character set. If it is not supported, then
- * we use <tt>ISO-8859-1</tt> as the character set.
- */
- public String getCharacterEncoding() {
- if (charset == null) {
- OutputStream dummy = new ByteArrayOutputStream();
- // BUGBUG Per the spec, the default charset is ISO8859_1
- // Servlet 2.3 Section 5.4
-
- /* Get the default file encoding charset */
- String fileEncoding = (new SecureAction()).getProperty("file.encoding", defaultCharset); //$NON-NLS-1$
- if ((fileEncoding == null) || (fileEncoding.length() < 1)) {
- fileEncoding = defaultCharset;
- }
- String fileEncodingAlias = null;
-
- /* We need to look at Accept-Charset from the request to
- * select the encoding charset.
- */
- String accept = request.getHeaderUpper("ACCEPT-CHARSET"); //$NON-NLS-1$
-
- if (accept != null) {
- /*
- * We prefer the file.encoding charset if specified
- * in the Accept-Charset and supported by the JRE. Otherwise,
- * we simply select the first value supported by the
- * JRE. We do not support the q value in Accept-Charset.
- */
-
- Tokenizer tokenizer = new Tokenizer(accept);
-
- parseloop: while (true) {
- String acceptCharset = tokenizer.getToken(",;"); //$NON-NLS-1$
-
- if (!acceptCharset.equals("*")) //$NON-NLS-1$
- {
- try /* is charset valid? */
- {
- String encodingAlias = new OutputStreamWriter(dummy, acceptCharset).getEncoding();
-
- if (charset == null) /* charset has not been set */
- {
- charset = acceptCharset;
- } else {
- if (fileEncodingAlias == null) {
- try {
- fileEncodingAlias = new OutputStreamWriter(dummy, fileEncoding).getEncoding();
- } catch (UnsupportedEncodingException ee) {
- // TODO: consider logging
- }
- }
-
- if (encodingAlias.equals(fileEncodingAlias)) {
- charset = acceptCharset; /* prefer the file.encoding charset */
-
- break parseloop;
- }
- }
- } catch (UnsupportedEncodingException e) {
- /* charset is not supported */
- }
- }
-
- char c = tokenizer.getChar();
-
- if (c == ';') {
- tokenizer.getToken(","); /* ignore q value *///$NON-NLS-1$
- c = tokenizer.getChar();
- }
-
- if (c == '\0') {
- break parseloop;
- }
- }
- }
-
- if (charset == null) /* if Accept-Charset did not produce a valid charset */
- {
- charset = fileEncoding;
-
- try /* is charset valid? */
- {
- new OutputStreamWriter(dummy, charset);
- } catch (UnsupportedEncodingException e) {
- /* charset is not supported */
- charset = defaultCharset;
- }
- }
- }
-
- return (charset);
- }
-
- /**
- * Returns an output stream for writing binary response data.
- *
- * @see #getWriter()
- * @exception IllegalStateException if getWriter has been
- * called on this same request.
- */
- public ServletOutputStream getOutputStream() {
- if (!gotOutputStream) {
- synchronized (this) {
- if (writer != null) {
- throw new IllegalStateException();
- }
- gotOutputStream = true;
- }
- }
-
- return (servletOutputStream);
- }
-
- /**
- * Returns a print writer for writing formatted text responses. The
- * MIME type of the response will be modified, if necessary, to reflect
- * the character encoding used, through the <em>charset=...</em>
- * property. This means that the content type must be set before
- * calling this method.
- *
- * @see #getOutputStream()
- * @see #setContentType(String)
- *
- * @exception UnsupportedEncodingException if no such charset can
- * be provided
- * @exception IllegalStateException if getOutputStream has been
- * called on this same request.
- * @exception IOException on other errors.
- */
- public PrintWriter getWriter() throws IOException {
- if (writer == null) {
- synchronized (this) {
- if (writer == null) {
- if (gotOutputStream) {
- throw new IllegalStateException();
- }
-
- String encoding = getCharacterEncoding();
-
- writer = new ServletPrintWriter(servletOutputStream, encoding);
-
- if (contentType == null) {
- // BUGBUG Must not set a default content type.
- // Servlet 2.3 Section 5.3
- contentType = "text/plain; charset=" + encoding; //$NON-NLS-1$
-
- setHeader("Content-Type", contentType); //$NON-NLS-1$
- } else {
- if (contentType.toLowerCase().indexOf("charset=") == -1) // 99372 //$NON-NLS-1$
- {
- contentType = contentType + "; charset=" + encoding; //$NON-NLS-1$
-
- setHeader("Content-Type", contentType); //$NON-NLS-1$
- }
- }
- }
- }
- }
-
- return (writer);
- }
-
- boolean gotStreamOrWriter() {
- return (writer != null || gotOutputStream);
- }
-
- /**
- * Sends an error response to the client using the specified
- * status code and a default message.
- * @param statusCode the status code
- * @exception IOException If an I/O error has occurred.
- */
- public void sendError(int statusCode) throws IOException {
- // BUGBUG Must clear buffer if response has not yet been committed
- // or throw an IllegalStateException.
- sendError(statusCode, http.getStatusPhrase(statusCode));
- }
-
- /**
- * Sends an error response to the client using the specified status
- * code and descriptive message. If setStatus has previously been
- * called, it is reset to the error status code. The message is
- * sent as the body of an HTML page, which is returned to the user
- * to describe the problem. The page is sent with a default HTML
- * header; the message is enclosed in simple body tags
- * (&lt;body&gt;&lt;/body&gt;).
- *
- * @param sc the status code
- * @param msg the detail message
- * @exception IOException If an I/O error has occurred.
- */
- public void sendError(int sc, String msg) throws IOException {
- // BUGBUG Must clear buffer if response has not yet been committed
- // or throw an IllegalStateException.
- status = sc;
- statusString = msg;
-
- if (Http.DEBUG) {
- http.logDebug("Error: " + sc + " - " + msg); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- servletOutputStream.print("<html><body><h3>"); //$NON-NLS-1$
- servletOutputStream.print(sc);
- servletOutputStream.print(" - "); //$NON-NLS-1$
- servletOutputStream.print(msg);
- servletOutputStream.print("</h3></body></html>"); //$NON-NLS-1$
- servletOutputStream.close(); /* commit and close the response */
-
- }
-
- /**
- * Sends a temporary redirect response to the client using the
- * specified redirect location URL. The URL must be absolute (for
- * example, <code><em>https://hostname/path/file.html</em></code>).
- * Relative URLs are not permitted here.
- *
- * @param location the redirect location URL
- * @exception IOException If an I/O error has occurred.
- */
- public void sendRedirect(String location) throws IOException {
- // BUGBUG The input URL may be relative. We must translate to
- // a fully qualified URL (it should already have been encoded).
- // If this cannot be done, throw an IllegalArgument exception.
- // BUGBUG Must clear buffer if response has not yet been committed
- // or throw an IllegalStateException.
- setStatus(SC_MOVED_TEMPORARILY);
- setHeader("Location", location); //$NON-NLS-1$
- servletOutputStream.close(); /* commit and close the response */
- }
-
- /**
- * Sets the content length for this response.
- *
- * @param len the content length
- */
-
- public void setContentLength(int len) {
- // BUGBUG response should be considered committed and closed
- // when content length has been written.
- // Not sure if content length is bytes or chars?
- contentLength = len;
- setIntHeader("Content-Length", len); //$NON-NLS-1$
- }
-
- /**
- * Sets the content type for this response. This type may later
- * be implicitly modified by addition of properties such as the MIME
- * <em>charset=&lt;value&gt;</em> if the service finds it necessary,
- * and the appropriate media type property has not been set.
- *
- * <p>This response property may only be assigned one time. If a
- * writer is to be used to write a text response, this method must
- * be called before the method <code>getWriter</code>. If an
- * output stream will be used to write a response, this method must
- * be called before the output stream is used to write response
- * data.
- *
- * @param type the content's MIME type
- * @see #getOutputStream()
- * @see #getWriter()
- */
- public void setContentType(String type) {
- if (contentType == null) {
- synchronized (this) {
- if (contentType == null) {
- contentType = type;
-
- setHeader("Content-Type", type); //$NON-NLS-1$
-
- int index = type.indexOf(';', 0);
- if (index >= 0) {
- Tokenizer tokenizer = new Tokenizer(type);
-
- // TODO: verify next statement. It was String mimetype = tokenizer.getToken(";");
- tokenizer.getToken(";"); //$NON-NLS-1$
- tokenizer.getChar(); /* eat semicolon */
-
- parseloop: while (true) {
- String attribute = tokenizer.getToken("="); //$NON-NLS-1$
- char c = tokenizer.getChar();
-
- if (c != '=') {
- break parseloop; /* invalid content type */
- }
-
- String value = tokenizer.getString(";"); //$NON-NLS-1$
- c = tokenizer.getChar();
-
- if ("charset".equalsIgnoreCase(attribute)) //$NON-NLS-1$
- {
- charset = value;
- }
-
- if (c == '\0') {
- break parseloop;
- }
- }
- }
- }
- }
- }
- }
-
- /**
- * This method was created in VisualAge.
- */
- protected void setCookies() {
- if (cookies == null) {
- return;
- }
-
- int numCookies = cookies.size();
-
- if (numCookies > 0) {
- StringBuffer value = new StringBuffer(256);
-
- for (int i = 0; i < numCookies; i++) {
- Cookie cookie = (Cookie) cookies.elementAt(i);
-
- if (i > 0) {
- value.append(',');
- }
-
- value.append(cookie.getName());
- value.append("=\""); //$NON-NLS-1$
- value.append(cookie.getValue());
- value.append('\"');
- if ((cookie.getVersion()) != 0) {
- value.append(";Version="); //$NON-NLS-1$
- value.append(cookie.getVersion());
- }
- if ((cookie.getComment()) != null) {
- value.append(";Comment=\""); //$NON-NLS-1$
- value.append(cookie.getComment());
- value.append('\"');
- }
- if ((cookie.getDomain()) != null) {
- value.append(";Domain=\""); //$NON-NLS-1$
- value.append(cookie.getDomain());
- value.append('\"');
- }
- if ((cookie.getMaxAge()) != -1) {
- value.append(";Max-Age=\""); //$NON-NLS-1$
- value.append(cookie.getMaxAge());
- value.append('\"');
- }
- if ((cookie.getPath()) != null) {
- value.append(";Path=\""); //$NON-NLS-1$
- value.append(cookie.getPath());
- value.append('\"');
- }
- if (cookie.getSecure()) {
- value.append(";Secure"); //$NON-NLS-1$
- }
- }
-
- setHeader("Set-Cookie", value.toString()); //$NON-NLS-1$
- //System.out.println("Set-Cookie: "+value.toString());
- }
- }
-
- /**
- *
- * Adds a field to the response header with the given name and
- * date-valued field. The date is specified in terms of
- * milliseconds since the epoch. If the date field had already
- * been set, the new value overwrites the previous one. The
- * <code>containsHeader</code> method can be used to test for the
- * presence of a header before setting its value.
- *
- * @param name the name of the header field
- * @param date the header field's date value
- *
- * @see #containsHeader
- */
- public void setDateHeader(String name, long date) {
- HttpDate d = new HttpDate(date);
- setHeader(name, d.toString());
- }
-
- /**
- *
- * Adds a field to the response header with the given name and value.
- * If the field had already been set, the new value overwrites the
- * previous one. The <code>containsHeader</code> method can be
- * used to test for the presence of a header before setting its
- * value.
- *
- * @param name the name of the header field
- * @param value the header field's value
- *
- * @see #containsHeader
- */
- public void setHeader(String name, String value) {
- // BUGBUG Headers set after the response is committed must be ignored
- // Servlet 2.2 Section 6.2
- if (headers == null) {
- synchronized (this) {
- if (headers == null) {
- headers = new Hashtable(31);
- }
- }
- }
- headers.put(name, value);
- }
-
- /**
- * Adds a field to the response header with the given name and
- * integer value. If the field had already been set, the new value
- * overwrites the previous one. The <code>containsHeader</code>
- * method can be used to test for the presence of a header before
- * setting its value.
- *
- * @param name the name of the header field
- * @param value the header field's integer value
- *
- * @see #containsHeader
- */
- public void setIntHeader(String name, int value) {
- setHeader(name, String.valueOf(value));
- }
-
- /**
- * Sets the status code for this response. This method is used to
- * set the return status code when there is no error (for example,
- * for the status codes SC_OK or SC_MOVED_TEMPORARILY). If there
- * is an error, the <code>sendError</code> method should be used
- * instead.
- *
- * @param statusCode the status code
- *
- * @see #sendError
- */
- public void setStatus(int statusCode) {
- status = statusCode;
- statusString = http.getStatusPhrase(statusCode);
- }
-
- /**
- * Sets the status code and message for this response. If the
- * field had already been set, the new value overwrites the
- * previous one. The message is sent as the body of an HTML
- * page, which is returned to the user to describe the problem.
- * The page is sent with a default HTML header; the message
- * is enclosed in simple body tags (&lt;body&gt;&lt;/body&gt;).
- *
- * @param si the status code
- * @param ss the status message
- * deprecated
- */
- public void setStatus(int si, String ss) {
- status = si;
- statusString = ss;
-
- }
-
- /**
- * Write the response headers to the ServletOutputStream.
- *
- * @param length Content length of the of the buffered content
- * or -1 if the length is unknown.
- */
- void writeHeaders(int length) throws IOException {
- setCookies();
-
- if ((length != -1) && !containsHeader("Content-Length")) //$NON-NLS-1$
- {
- setContentLength(length);
- }
-
- if (containsHeader("Content-Length")) //$NON-NLS-1$
- {
- String requestConnection = request.getHeaderUpper("CONNECTION"); //$NON-NLS-1$
-
- if (requestConnection != null) {
- if (requestConnection.toLowerCase().indexOf("keep-alive") >= 0) //$NON-NLS-1$
- {
- setHeader("Connection", "Keep-Alive"); //$NON-NLS-1$ //$NON-NLS-2$
-
- keepAlive = true;
- }
- }
- }
-
- if (!keepAlive) {
- setHeader("Connection", "close"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- servletOutputStream.print("HTTP/1.0 "); //$NON-NLS-1$
- servletOutputStream.print(status);
- servletOutputStream.print(" "); //$NON-NLS-1$
- servletOutputStream.println(statusString);
-
- // System.out.print("HTTP/1.0 ");
- // System.out.print(status);
- // System.out.print(" ");
- // System.out.println(statusString);
-
- /* Write response headers */
- if (headers != null) {
- Enumeration headerEnumeration = headers.keys();
- while (headerEnumeration.hasMoreElements()) {
- String name = (String) headerEnumeration.nextElement();
- String value = (String) headers.get(name);
- servletOutputStream.print(name);
- servletOutputStream.print(": "); //$NON-NLS-1$
- servletOutputStream.println(value);
-
- // System.out.print(name);
- // System.out.print(": ");
- // System.out.println(value);
- }
- }
-
- servletOutputStream.println(); /* Terminate the headers */
-
- // System.out.println();
- }
-
- /**
- * @see javax.servlet.http.HttpServletResponse#addDateHeader(String, long)
- */
- public void addDateHeader(String name, long date) throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.http.HttpServletResponse#addHeader(String, String)
- */
- public void addHeader(String name, String value) throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.http.HttpServletResponse#addIntHeader(String, int)
- */
- public void addIntHeader(String name, int value) throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.ServletResponse#flushBuffer()
- */
- public void flushBuffer() throws IOException, UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.ServletResponse#getBufferSize()
- */
- public int getBufferSize() throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.ServletResponse#getLocale()
- */
- public Locale getLocale() throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.ServletResponse#isCommitted()
- */
- public boolean isCommitted() throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.ServletResponse#reset()
- */
- public void reset() throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.ServletResponse#resetBuffer()
- */
- public void resetBuffer() throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.ServletResponse#setBufferSize(int)
- */
- public void setBufferSize(int size) throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.ServletResponse#setLocale(Locale)
- */
- public void setLocale(Locale loc) throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /* JavaServlet 2.4 API - For compilation only. Will not implement.
- *
- */
- public String getContentType() {
- //return contentType;
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /* For compilation only. Will not implement.
- *
- */
- public void setCharacterEncoding(String arg0) {
- //this.contentType = contentType;
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
-
- }
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/HttpSessionContextImpl.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/HttpSessionContextImpl.java
deleted file mode 100644
index dfcaf3ec1..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/HttpSessionContextImpl.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2009 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http.servlet;
-
-import java.util.Enumeration;
-import java.util.Vector;
-import javax.servlet.http.HttpSession;
-import javax.servlet.http.HttpSessionContext;
-
-/**
- * A HttpSessionContext is a grouping of HttpSessions associated with a single
- * entity. This interface gives servlets access to
- * methods for listing the IDs and for retrieving a session based on its ID.
- *
- * <p>Servlets get the HttpSessionContext object by calling the
- * getSessionContext()
- * method of HttpSession.
- *
- * @see HttpSession
- * @deprecated
- */
-public class HttpSessionContextImpl implements HttpSessionContext {
-
- /**
- * Returns an enumeration of all of the session IDs in this context.
- *
- * @return an enumeration of all session IDs in this context
- * @deprecated
- */
- public Enumeration getIds() {
- return ((new Vector(0)).elements());
- }
-
- /**
- * Returns the session bound to the specified session ID.
- *
- * @param sessionId the ID of a particular session object
- * @return the session name. Returns null if the session ID does not refer
- * to a valid session.
- * @deprecated
- */
- public HttpSession getSession(String sessionId) {
- return (null);
- }
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/HttpSessionImpl.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/HttpSessionImpl.java
deleted file mode 100644
index e26fabe18..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/HttpSessionImpl.java
+++ /dev/null
@@ -1,501 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2007 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http.servlet;
-
-import java.util.Enumeration;
-import java.util.Hashtable;
-import javax.servlet.ServletContext;
-import javax.servlet.http.*;
-import org.eclipse.equinox.http.Http;
-import org.eclipse.equinox.http.HttpMsg;
-
-/**
- * The implementation of the HttpSession interface.
- *
- * <pre>
- *
- * //Get the session object - "request" represents the HTTP servlet request
- * HttpSession session = request.getSession(true);
- * <BR>
- * //Get the session data value - an Integer object is read from
- * //the session, incremented, then written back to the session.
- * //sessiontest.counter identifies values in the session
- * Integer ival = (Integer) session.getValue("sessiontest.counter");
- * if (ival==null)
- * ival = new Integer(1);
- * else
- * ival = new Integer(ival.intValue() + 1);
- * session.putValue("sessiontest.counter", ival);
- *
- * </pre>
- *
- * <P> When an application layer stores or removes data from the
- * session, the session layer checks whether the object implements
- * HttpSessionBindingListener. If it does, then the object is notified
- * that it has been bound or unbound from the session.
- *
- * <P>An implementation of HttpSession represents the server's view
- * of the session. The server considers a session to be new until
- * it has been joined by the
- * client. Until the client joins the session, the isNew method
- * returns true. A value of true can indicate one of these three cases:
- * <UL>
- * <LI>the client does not yet know about the session
- * <LI>the session has not yet begun
- * <LI>the client chooses not to join the session. This case will occur
- * if the client supports
- * only cookies and chooses to reject any cookies sent by the server.
- * If the server supports URL rewriting, this case will not commonly occur.
- * </UL>
- *
- * <P>It is the responsibility of developers
- * to design their applications to account for situations where a client
- * has not joined a session. For example, in the following code
- * snippet isNew is called to determine whether a session is new. If it
- * is, the server will require the client to start a session by directing
- * the client to a welcome page <tt>welcomeURL</tt> where
- * a user might be required to enter some information and send it to the
- * server before gaining access to
- * subsequent pages.
- *
- * <pre>
- * //Get the session object - "request" represents the HTTP servlet request
- * HttpSession session = request.getSession(true);
- * <BR>
- * //insist that the client starts a session
- * //before access to data is allowed
- * //"response" represents the HTTP servlet response
- * if (session.isNew()) {
- * response.sendRedirect (welcomeURL);
- * }
- *
- * </pre>
- *
- * @see HttpSessionBindingListener
- * @see HttpSessionContext
- *
- */
-
-public class HttpSessionImpl implements HttpSession {
- protected Http http;
- protected String sessionId;
- protected Hashtable values;
- protected long creationTime; /* milliseconds */
- protected long lastAccess; /* milliseconds */
- protected boolean isValid;
- protected boolean canExpire;
- protected Cookie cookie;
- protected long maxInactive; /* milliseconds */
- // BUGBUG cookie name MUST be "JSESSIONID"
- // Servlet 2.2 Section 7.1.2
- protected static final String sessionCookieName = "org.eclipse.equinox.http.session"; //$NON-NLS-1$
-
- protected HttpSessionImpl(Http http) {
- this.http = http;
- lastAccess = -1;
- maxInactive = -1;
- canExpire = false;
- isValid = true;
- sessionId = String.valueOf(hashCode());
- values = new Hashtable();
- creationTime = System.currentTimeMillis();
- cookie = new Cookie(sessionCookieName, sessionId);
- // BUGBUG Sessions should be ServletContext specific. That is
- // the ServletContext should manage the sessions.
- // Servlet 2.2 Section 7.3
- http.addSession(this);
- }
-
- /**
- * Return the cookie associated with this session.
- *
- * @return Session cookie
- */
- protected Cookie getCookie() {
- return (cookie);
- }
-
- /**
- * Returns the time at which this session representation was created,
- * in milliseconds since midnight, January 1, 1970 UTC.
- *
- * @return the time when the session was created
- */
- public long getCreationTime() {
- return (creationTime);
- }
-
- /**
- * Returns the identifier assigned to this session. An HttpSession's
- * identifier is a unique string that is created and maintained by
- * HttpSessionContext.
- *
- * @return the identifier assigned to this session
- */
- public String getId() {
- return (sessionId);
- }
-
- /**
- * Returns the last time the client sent a request carrying the identifier
- * assigned to the session, or -1 if the session is new. Time is expressed
- * as milliseconds since midnight, January 1,
- * 1970 UTC.
- *
- * Application level operations, such as getting or setting a value
- * associated with the session, do not affect the access time.
- *
- * <P> This information is particularly useful in session management
- * policies. For example,
- * <UL>
- * <LI>a session manager could leave all sessions
- * which have not been used in a long time
- * in a given context.
- * <LI>the sessions can be sorted according to age to optimize some task.
- * </UL>
- *
- * @return the last time the client sent a request carrying the identifier
- * assigned to the session
- */
- public long getLastAccessedTime() {
- return (lastAccess);
- }
-
- /**
- * Returns the maximum amount of time, in seconds, that a session is
- * guaranteed to be maintained in the servlet engine without a request from
- * the client. After the maximum inactive time, the session may be expired
- * by the servlet engine. If this session will not expire, this method will
- * return -1. This method should throw an IllegalStateException if it is
- * called after this session has been invalidated.
- *
- * @return the maximum inactive interval
- * @throws IllegalStateException
- */
- public int getMaxInactiveInterval() {
- checkValid();
-
- if (canExpire) {
- return ((int) (maxInactive / 1000L));
- }
- return (-1);
- }
-
- /**
- * Sets the amount of time that a session can be inactive
- * before the servlet engine is allowed to expire it.
- *
- * @param interval Time in seconds.
- */
- public void setMaxInactiveInterval(int interval) {
- if (isValid) {
- if (interval == -1) {
- maxInactive = -1;
- canExpire = false;
- } else {
- if (interval < 0) {
- throw new IllegalArgumentException("negative value"); //$NON-NLS-1$
- }
- maxInactive = interval * 1000L;
- canExpire = true;
- }
- }
- }
-
- /**
- * Returns the context object within which sessions on the server are held.
- *
- * This method has been deprecated as all the methods of HttpSessionContext
- * are deprecated. This method should now return an object which has an
- * empty implementation of the HttpSessionContext interface.
- *
- * @return An empty implementation of the HttpSessionContext interface.
- * @deprecated As of Servlet version 2.1.
- */
- public HttpSessionContext getSessionContext() {
- return (new HttpSessionContextImpl());
- }
-
- /**
- * Returns the object bound to the given name in the session's
- * application layer data. Returns null if there is no such binding.
- *
- * @param name the name of the binding to find
- * @return the value bound to that name, or null if the binding does
- * not exist.
- * @exception IllegalStateException if an attempt is made to access
- * HttpSession's session data after it has been invalidated
- */
- public Object getValue(String name) {
- checkValid();
-
- return (values.get(name));
- }
-
- /**
- * Returns an array of the names of all the application layer
- * data objects bound into the session. For example, if you want to delete
- * all of the data objects bound into the session, use this method to
- * obtain their names.
- *
- * @return an array containing the names of all of the application layer
- * data objects bound into the session
- * @exception IllegalStateException if an attempt is made to access
- * session data after the session has been invalidated
- */
- public String[] getValueNames() {
- checkValid();
-
- return (getValueNames0());
- }
-
- private String[] getValueNames0() {
- synchronized (values) {
- int size = values.size();
- String[] names = new String[size];
-
- if (size > 0) {
- int i = 0;
- Enumeration valueEnumeration = values.keys();
- while (valueEnumeration.hasMoreElements()) {
- names[i] = (String) valueEnumeration.nextElement();
- i++;
- }
- }
-
- return (names);
- }
- }
-
- /**
- * Causes this representation of the session to be invalidated and removed
- * from its context.
- *
- */
- public synchronized void invalidate() {
- if (isValid) {
- /*
- * Remove session.
- */
- http.removeSession(this);
-
- /*
- * Unbind values.
- */
- String[] names = getValueNames0();
- int size = names.length;
-
- for (int i = 0; i < size; i++) {
- String name = names[i];
-
- Object oldValue = values.remove(name);
-
- unbound(name, oldValue);
- }
-
- /*
- * invalidate session
- */
- isValid = false;
- values = null;
- canExpire = false;
- }
- }
-
- /**
- * A session is considered to be "new" if it has been created by the server,
- * but the client has not yet acknowledged joining the session. For example,
- * if the server supported only cookie-based sessions and the client had
- * completely disabled the use of cookies, then calls to
- * HttpServletRequest.getSession() would
- * always return "new" sessions.
- *
- * @return true if the session has been created by the server but the
- * client has not yet acknowledged joining the session; false otherwise
- * @exception IllegalStateException if an attempt is made to access
- * session data after the session has been invalidated
- */
- public boolean isNew() {
- checkValid();
-
- return (lastAccess == -1);
- }
-
- /**
- * Binds the specified object into the session's application layer data
- * with the given name. Any existing binding with the same name is
- * replaced. New (or existing) values that implement the
- * HttpSessionBindingListener interface will call its
- * valueBound() method.
- *
- * @param name the name to which the data object will be bound. This
- * parameter cannot be null.
- * @param value the data object to be bound. This parameter cannot be null.
- * @exception IllegalStateException if an attempt is made to access
- * session data after the session has been invalidated
- */
- public void putValue(String name, Object value) {
- checkValid();
-
- Object oldValue = values.put(name, value);
-
- unbound(name, oldValue);
-
- // BUGBUG valueBound must be called before the object is available
- // via getValue.
- // Servlet 2.2 Section 7.4
- bound(name, value);
- }
-
- /**
- * Notify HttpSessionBindingListener of valueBound event.
- *
- * @param name the name to which the data object will be bound. This
- * parameter cannot be null.
- * @param value the data object to be bound. This parameter cannot be null.
- */
- private void bound(String name, Object value) {
- if (value instanceof HttpSessionBindingListener) {
- HttpSessionBindingEvent e = new HttpSessionBindingEvent(this, name);
-
- try {
- ((HttpSessionBindingListener) value).valueBound(e);
- } catch (Throwable t) {
- if (Http.DEBUG) {
- http.logDebug("HttpSessionImpl.putValue event exception", t); //$NON-NLS-1$
- }
- }
- }
- }
-
- /**
- * Removes the object bound to the given name in the session's
- * application layer data. Does nothing if there is no object
- * bound to the given name. The value that implements the
- * HttpSessionBindingListener interface will call its
- * valueUnbound() method.
- *
- * @param name the name of the object to remove
- * @exception IllegalStateException if an attempt is made to access
- * session data after the session has been invalidated
- */
- public void removeValue(String name) {
- checkValid();
-
- Object oldValue = values.remove(name);
-
- unbound(name, oldValue);
- }
-
- /**
- * Notify HttpSessionBindingListener of valueUnbound event.
- *
- * @param name the name to which the data object will be bound. This
- * parameter cannot be null.
- * @param value the data object to be bound.
- */
- private void unbound(String name, Object value) {
- if (value instanceof HttpSessionBindingListener) {
- HttpSessionBindingEvent e = new HttpSessionBindingEvent(this, name);
-
- try {
- ((HttpSessionBindingListener) value).valueUnbound(e);
- } catch (Throwable t) {
- if (Http.DEBUG) {
- http.logDebug("HttpSessionImpl.removeValue event exception", t); //$NON-NLS-1$
- }
- }
- }
- }
-
- /**
- * If the session has expired, invalidate it.
- * If access it true and the session is valid, update
- * the lastAccess time.
- *
- * @return true if the session is valid.
- */
- public boolean isValid(boolean access) {
- if (canExpire) {
- long currentTime = System.currentTimeMillis();
-
- long compareTime = (lastAccess == -1) ? creationTime : lastAccess;
-
- if ((currentTime - compareTime) > maxInactive) {
- invalidate();
- }
- }
-
- if (access && isValid) {
- lastAccess = System.currentTimeMillis();
- }
-
- return (isValid);
- }
-
- /**
- * If the session has expired, invalidate it.
- * If the session is invalid, throw an IllegalStateException
- *
- * @throws IllegalStateException
- */
- private void checkValid() {
- if (canExpire) {
- long currentTime = System.currentTimeMillis();
-
- long compareTime = (lastAccess == -1) ? creationTime : lastAccess;
-
- if ((currentTime - compareTime) > maxInactive) {
- invalidate();
- }
- }
-
- if (!isValid) {
- throw new IllegalStateException("HttpSession has been invalidated"); //$NON-NLS-1$
- }
- }
-
- /**
- * @see javax.servlet.http.HttpSession#getAttribute(String)
- */
- public Object getAttribute(String name) throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.http.HttpSession#getAttributeNames()
- */
- public Enumeration getAttributeNames() throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.http.HttpSession#getServletContext()
- */
- public ServletContext getServletContext() throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.http.HttpSession#removeAttribute(String)
- */
- public void removeAttribute(String name) throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.http.HttpSession#setAttribute(String, Object)
- */
- public void setAttribute(String name, Object value) throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/RequestDispatcherImpl.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/RequestDispatcherImpl.java
deleted file mode 100644
index 09fca65f6..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/RequestDispatcherImpl.java
+++ /dev/null
@@ -1,294 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2009 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http.servlet;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.Locale;
-import javax.servlet.*;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletResponse;
-import org.eclipse.equinox.http.HttpMsg;
-import org.eclipse.equinox.http.Registration;
-
-public class RequestDispatcherImpl implements RequestDispatcher {
- protected Registration reg;
- protected String requestURI;
-
- class Response implements HttpServletResponse {
- protected ServletResponse response;
-
- protected Response(ServletResponse response) {
- this.response = response;
- }
-
- public String getCharacterEncoding() {
- return (null);
- }
-
- public PrintWriter getWriter() throws IOException {
- return (response.getWriter());
- }
-
- public ServletOutputStream getOutputStream() throws IOException {
- return (response.getOutputStream());
- }
-
- public String encodeRedirectURL(String url) {
- return (null);
- }
-
- public String encodeRedirectUrl(String url) {
- return (null);
- }
-
- public String encodeURL(String url) {
- return (null);
- }
-
- public String encodeUrl(String url) {
- return (null);
- }
-
- public void sendRedirect(String url) {
- // do nothing
- }
-
- public boolean containsHeader(String header) {
- return (false);
- }
-
- public void addCookie(Cookie cookie) {
- // do nothing
- }
-
- public void sendError(int errorCode) {
- // do nothing
- }
-
- public void sendError(int errorCode, String error) {
- // do nothing
- }
-
- public void setContentLength(int length) {
- // do nothing
- }
-
- public void setContentType(String contentType) {
- // do nothing
- }
-
- public void setStatus(int status) {
- // do nothing
- }
-
- public void setStatus(int status, String statusPhrase) {
- // do nothing
- }
-
- public void setHeader(String key, String value) {
- // do nothing
- }
-
- public void setIntHeader(String key, int value) {
- // do nothing
- }
-
- public void setDateHeader(String key, long date) {
- // do nothing
- }
-
- /**
- * @see javax.servlet.http.HttpServletResponse#addDateHeader(String, long)
- */
- public void addDateHeader(String name, long date) throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.http.HttpServletResponse#addHeader(String, String)
- */
- public void addHeader(String name, String value) throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.http.HttpServletResponse#addIntHeader(String, int)
- */
- public void addIntHeader(String name, int value) throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.ServletResponse#flushBuffer()
- */
- public void flushBuffer() throws IOException, UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.ServletResponse#getBufferSize()
- */
- public int getBufferSize() throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.ServletResponse#getLocale()
- */
- public Locale getLocale() throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.ServletResponse#isCommitted()
- */
- public boolean isCommitted() throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.ServletResponse#reset()
- */
- public void reset() throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.ServletResponse#resetBuffer()
- */
- public void resetBuffer() throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.ServletResponse#setBufferSize(int)
- */
- public void setBufferSize(int size) throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.ServletResponse#setLocale(Locale)
- */
- public void setLocale(Locale loc) throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /*
- * JavaServlet 2.4 API - For complilation only - Not Implemented
- */
- public String getContentType() {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /*
- * JavaServlet 2.4 API - For complilation only - Not Implemented
- */
- public void setCharacterEncoding(String arg0) {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
-
- }
-
- }
-
- public RequestDispatcherImpl(Registration reg, String requestURI) {
- this.reg = reg;
- this.requestURI = requestURI;
- }
-
- /**
- * Used for forwarding a request from this servlet to another
- * resource on the server. This method is useful when one servlet
- * does preliminary processing of a request and wants to let
- * another object generate the response.
- *
- * <p>The <tt>request</tt> object passed to the target object
- * will have its request URL path and other path parameters
- * adjusted to reflect the target URL path of the target object.
- *
- * <p>You cannot use this method if a <tt>ServletOutputStream</tt>
- * object or <tt>PrintWriter</tt> object has been obtained from
- * the response. In that case, the method throws an
- * <tt>IllegalStateException</tt>
- *
- * @param req the client's request on the servlet
- * @param res the client's response from the servlet
- * @exception ServletException if a servlet exception is thrown by the
- * target servlet
- * @exception IOException if an I/O Exception occurs
- * @exception IllegalStateException if the ServletOutputStream or a writer
- * had already been obtained from the response object
- */
- public void forward(ServletRequest req, ServletResponse res) throws ServletException, IOException {
- // BUGBUG If the response has already been committed, then an
- // IllegalStateException must be thrown. Otherwise, the response
- // buffer must be cleared before calling.
- // Servlet 2.2 Section 8.4
- try {
- HttpServletRequestImpl request = (HttpServletRequestImpl) req;
- HttpServletResponseImpl response = (HttpServletResponseImpl) res;
-
- if (response.gotStreamOrWriter()) {
- throw new IllegalStateException();
- }
-
- String newRequestLine = request.getMethod() + " " + requestURI + " " + request.getProtocol(); //$NON-NLS-1$ //$NON-NLS-2$
- request.parseRequestLine(newRequestLine);
-
- reg.service(request, response);
-
- // BUGBUG Response must be committed and closed before returning.
- // Servlet 2.2 Section 8.4
- } catch (ClassCastException e) {
- throw new ServletException(HttpMsg.HTTP_SERVLET_EXCEPTION, e);
- }
- }
-
- /**
- * Used for including the content generated by another server
- * resource in the body of a response. In essence, this method
- * enables programmatic server side includes.
- *
- * <p>The request object passed to the target object will reflect
- * the request URL path and path info of the calling request.
- * The response object only has access to the calling servlet's
- * <tt>ServletOutputStream</tt> object or <tt>PrintWriter</tt>
- * object.
- *
- * <p>An included servlet cannot set headers. If the included
- * servlet calls a method that may need to set headers (such as
- * sessions might need to), the method is not guaranteed to work.
- * As a servlet developer, you must ensure that any methods
- * that might need direct access to headers are properly resolved.
- * To ensure that a session works correctly, start the session
- * outside of the included servlet, even if you use session tracking.
- *
- * @param req the client's request on the servlet
- * @param res the client's response from the servlet
- * @exception ServletException if a servlet exception is thrown by the
- * target servlet
- * @exception IOException if the ServletOutputStream or a writer
- * had already been obtained from the response object
- */
- public void include(ServletRequest req, ServletResponse res) throws ServletException, IOException {
- // BUGBUG need to set javax.servlet.include.* request
- // attributes before calling.
- // Servlet 2.2 Section 8.3.1
- try {
- ServletResponse response = new Response(res);
-
- reg.service(req, response);
- } catch (ClassCastException e) {
- throw new ServletException(HttpMsg.HTTP_SERVLET_EXCEPTION, e);
- }
- }
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/ServletConfigImpl.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/ServletConfigImpl.java
deleted file mode 100644
index dea55d091..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/ServletConfigImpl.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2005 IBM Corporation.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http.servlet;
-
-import java.util.*;
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
-import org.eclipse.equinox.http.HttpMsg;
-
-public class ServletConfigImpl implements ServletConfig {
- protected ServletContext servletContext;
- protected Dictionary initParams;
-
- public ServletConfigImpl(ServletContext context, Dictionary params) {
- servletContext = context;
- initParams = params;
- }
-
- /**
- *
- * Returns a string containing the value of the named
- * initialization parameter of the servlet, or null if the
- * parameter does not exist. Init parameters have a single string
- * value; it is the responsibility of the servlet writer to
- * interpret the string.
- *
- * @param name the name of the parameter whose value is requested
- */
- public String getInitParameter(String name) {
- if (initParams != null) {
- return ((String) initParams.get(name));
- }
- return (null);
- }
-
- /**
- * Returns the names of the servlet's initialization parameters
- * as an enumeration of strings, or an empty enumeration if there
- * are no initialization parameters.
- */
- public Enumeration getInitParameterNames() {
- if (initParams != null) {
- return (initParams.keys());
- }
- return (new Vector(0).elements());
- }
-
- /**
- * Returns the context for the servlet.
- */
-
- public ServletContext getServletContext() {
- return (servletContext);
- }
-
- /**
- * @see javax.servlet.ServletConfig#getServletName()
- */
- public String getServletName() throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/ServletContextImpl.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/ServletContextImpl.java
deleted file mode 100644
index 015e4883f..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/ServletContextImpl.java
+++ /dev/null
@@ -1,450 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2009 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http.servlet;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.*;
-import javax.servlet.*;
-import org.eclipse.equinox.http.*;
-import org.osgi.service.http.HttpContext;
-
-public class ServletContextImpl implements ServletContext {
- protected Hashtable attributes = null;
- protected Http http;
- protected HttpListener listener;
- protected HttpContext httpContext;
- protected int useCount;
-
- public ServletContextImpl(Http http, HttpListener listener, HttpContext httpContext) {
- this.http = http;
- this.listener = listener;
- this.httpContext = httpContext;
- useCount = 0;
- }
-
- public int incrUseCount() {
- useCount++;
-
- return (useCount);
- }
-
- public int decrUseCount() {
- useCount--;
-
- return (useCount);
- }
-
- /**
- * Returns the value of the named attribute of the network service,
- * or null if the attribute does not exist. This method allows
- * access to additional information about the service, not already
- * provided by the other methods in this interface. Attribute names
- * should follow the same convention as package names. The package
- * names java.* and javax.* are reserved for use by Javasoft, and
- * com.sun.* is reserved for use by Sun Microsystems.
- *
- * @param name the name of the attribute whose value is required
- * @return the value of the attribute, or null if the attribute
- * does not exist.
- */
- public Object getAttribute(String name) {
- if (attributes != null) {
- return (attributes.get(name));
- }
-
- return (null);
- }
-
- /**
- * Returns an enumeration of the attribute names present in this
- * context.
- */
-
- public Enumeration getAttributeNames() {
- if (attributes != null) {
- return (attributes.keys());
- }
-
- return ((new Vector(0).elements()));
- }
-
- /**
- * Returns a <tt>ServletContext</tt> object for a particular
- * URL path. This allows servlets to potentially gain access
- * to the resources and to obtain <tt>RequestDispatcher</tt>
- * objects from the target context.
- *
- * <p>In security concious environments, the servlet engine
- * may always return null for any given URL path.
- *
- * @param uripath
- */
-
- //We should be the only ServletContext out there.
- public ServletContext getContext(String uripath) {
- Registration reg = listener.getRegistration(uripath);
-
- if (reg == null) {
- return (null);
- }
-
- if (httpContext != reg.getHttpContext()) {
- return (null);
- }
-
- return (this);
- }
-
- /**
- * Returns the major version of the servlet API that this
- * servlet engine supports. All 2.1 compliant implementations
- * must return the integer 2 from this method.
- *
- * @return 2
- */
-
- public int getMajorVersion() {
- return (2);
- }
-
- /**
- * Returns the mime type of the specified file, or null if not known.
- * @param file name of the file whose mime type is required
- */
- public String getMimeType(String file) {
- String mimeType = httpContext.getMimeType(file);
- if (mimeType != null)
- return (mimeType);
- return (http.getMimeType(file));
- }
-
- /**
- * Returns the minor version of the servlet API that this
- * servlet engine supports. All 2.1 compliant implementations
- * must return the integer 1 from this method.
- *
- * @return 1
- */
-
- public int getMinorVersion() {
- return (1);
- }
-
- /**
- * Applies alias rules to the specified virtual path in URL path
- * format, that is, <tt>/dir/dir/file.ext</tt>. Returns a
- * String representing the corresponding real path in the
- * format that is appropriate for the operating system the
- * servlet engine is running under (including the proper path
- * separators).
- *
- * <p>This method returns null if the translation could not
- * be performed for any reason.
- *
- * @param path the virtual path to be translated into a real path
- */
-
- public String getRealPath(String path) {
- /* We always return null because our web applications
- * originate in bundles and there is no path on the local
- * file system for the bundles contents.
- */
- return (null);
- }
-
- /**
- * Returns a <tt>RequestDispatcher</tt> object for the specified
- * URL path if the context knows of an active source (such as
- * a servlet, JSP page, CGI script, etc) of content for the
- * particular path. This format of the URL path must be of the
- * form <tt>/dir/dir/file.ext</tt>. The servlet engine is responsible
- * for implementing whatever functionality is required to
- * wrap the target source with an implementation of the
- * <tt>RequestDispatcher</tt> interface.
- *
- * <p>This method will return null if the context cannot provide
- * a dispatcher for the path provided.
- *
- * @param urlpath Path to use to look up the target server resource
- * @see RequestDispatcher
- */
- public RequestDispatcher getRequestDispatcher(String urlpath) {
- // BUGBUG need to support query string in the urlpath
- // Servlet 2.2 Section 8.1.1
-
- if (Http.DEBUG) {
- http.logDebug(" getRequestDispatcher: " + urlpath); //$NON-NLS-1$
- }
-
- Registration reg = listener.getRegistration(urlpath);
-
- if (reg == null) {
- return (null);
- }
-
- if (httpContext != reg.getHttpContext()) {
- return (null);
- }
-
- return (new RequestDispatcherImpl(reg, urlpath));
- }
-
- /**
- * Returns a URL object of a resource that is mapped to a
- * corresponding URL path. The URL path must be of the form
- * <tt>/dir/dir/file.ext</tt>. This method allows a servlet
- * to access content to be served from the servlet engines
- * document space in a system independent manner. Resources
- * could be located on the local file system, a remote
- * file system, a database, or a remote network site.
- *
- * <p>This method may return null if there is no resource
- * mapped to the given URL path.
- *
- * <p>The servlet engine must implement whatever URL handlers
- * and <tt>URLConnection</tt> objects are necessary to access
- * the given content.
- *
- * <p>This method does not fill the same purpose as the
- * <tt>getResource</tt> method of <tt>java.lang.Class</tt>.
- * The method in <tt>java.lang.Class</tt> looks up resources
- * based on class loader. This method allows servlet engines
- * to make resources avaialble to a servlet from any source
- * without regards to class loaders, location, etc.
- *
- * @param path Path of the content resource
- * @exception MalformedURLException if the resource path is
- * not properly formed.
- */
-
- public URL getResource(String path) throws MalformedURLException {
- return (httpContext.getResource(path));
-
- }
-
- /**
- * Returns an <tt>InputStream</tt> object allowing access to
- * a resource that is mapped to a corresponding URL path. The
- * URL path must be of the form <tt>/dir/dir/file.ext</tt>.
- *
- * <p>Note that meta-information such as content length and
- * content type that are available when using the
- * <tt>getResource</tt> method of this class are lost when
- * using this method.
- *
- * <p>This method may return null if there is no resource
- * mapped to the given URL path.
- * <p>The servlet engine must implement whatever URL handlers
- * and <tt>URLConnection</tt> objects are necessary to access
- * the given content.
- *
- * <p>This method does not fill the same purpose as the
- * <tt>getResourceAsStream</tt> method of <tt>java.lang.Class</tt>.
- * The method in <tt>java.lang.Class</tt> looks up resources
- * based on class loader. This method allows servlet engines
- * to make resources available to a servlet from any source
- * without regards to class loaders, location, etc.
- *
- * @param path
- */
-
- public InputStream getResourceAsStream(String path) {
- try {
- URL url = httpContext.getResource(path);
- if (url != null)
- return url.openStream();
- } catch (IOException ex) {
- // TODO: consider logging
- }
- return null;
- }
-
- /**
- * Returns the name and version of the network service under which
- * the servlet is running. The form of this string must begin with
- * <tt>&lt;servername&gt;/&lt;versionnumber&gt;</tt>. For example
- * the Java Web Server could return a string of the form
- * <tt>Java Web Server/1.1.3</tt>. Other optional information
- * can be returned in parenthesis after the primary string. For
- * example, <tt>Java Web Server/1.1.3 (JDK 1.1.6; Windows NT 4.0 x86)
- * </tt>.
- */
- public String getServerInfo() {
- return ("Equinox HttpService/1.0"); //$NON-NLS-1$
- }
-
- /**
- * Originally defined to return a servlet from the context
- * with the specified name. This method has been deprecated and
- * only remains to preserve binary compatibility.
- * This method will always return null.
- *
- * @deprecated This method has been deprecated for
- * servlet lifecycle reasons. This method will be permanently
- * removed in a future version of the Servlet API.
- */
- public Servlet getServlet(String name) {
- return (null);
- }
-
- /**
- * Originally defined to return an <tt>Enumeration</tt> of
- * <tt>String</tt> objects containing all the servlet names
- * known to this context.
- * This method has been deprecated and only remains to preserve
- * binary compatibility. This methd must always return an
- * empty enumeration.
- *
- * @deprecated This method has been deprecated for
- * servlet lifecycle reasons. This method will be permanently
- * removed in a future version of the Servlet API.
- */
- public Enumeration getServletNames() {
- return ((new Vector(0).elements()));
- }
-
- /**
- * Originally defined to return an <tt>Enumeration</tt> of
- * <tt>Servlet</tt> objects containing all the servlets
- * known to this context.
- * This method has been deprecated and only remains to preserve
- * binary compatibility. This method must always return an empty
- * enumeration.
- *
- * @deprecated This method has been deprecated for
- * servlet lifecycle reasons. This method will be permanently
- * removed in a future version of the Servlet API.
- */
- public Enumeration getServlets() {
- return ((new Vector(0).elements()));
- }
-
- /**
- * Logs the specified message and a stack trace of the given
- * exception to the context's log. The
- * name and type of the servlet log is servlet engine specific,
- * but is normally an event log.
- *
- * @param exception the exception to be written
- * @param msg the message to be written
- *
- * @deprecated Use log(String message, Throwable t) instead
- */
- public void log(Exception exception, String msg) {
- log(msg, exception);
- }
-
- /**
- * Logs the specified message to the context's log. The
- * name and type of the servlet log is servlet engine specific,
- * but is normally an event log.
- *
- * @param msg the message to be written
- */
- public void log(String msg) {
- http.logInfo(msg);
- }
-
- /**
- * Logs the specified message and a stack trace of the given
- * <tt>Throwable</tt> object to the context's log. The
- * name and type of the servlet log is servlet engine specific,
- * but is normally an event log.
- *
- * @param message the message to be written
- * @param throwable the exception to be written
- */
-
- public void log(String message, Throwable throwable) {
- http.logError(message, throwable);
- }
-
- /**
- * Removes the attribute from the context that is bound to a particular
- * name.
- *
- * @param name the name of the attribute to remove from the context
- */
-
- public void removeAttribute(String name) {
- if (attributes != null) {
- attributes.remove(name);
- }
- }
-
- /**
- * Binds an object to a given name in this context. If an object
- * is already bound into the context with the given name,
- * it will be replaced.
- *
- * Attribute names should follow the same convention as package names.
- * Names matching java.*, javax.*, and sun.* are reserved for
- * definition by this specification or by the reference implementation.
- *
- * @param name the name of the attribute to store
- * @param object the value of the attribute
- */
-
- public void setAttribute(String name, Object object) {
- if (attributes == null) {
- synchronized (this) {
- if (attributes == null) {
- attributes = new Hashtable(31);
- }
- }
- }
-
- attributes.put(name, object);
- }
-
- /**
- * @see javax.servlet.ServletContext#getInitParameter(String)
- */
- public String getInitParameter(String name) throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.ServletContext#getInitParameterNames()
- */
- public Enumeration getInitParameterNames() throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.ServletContext#getNamedDispatcher(String)
- */
- public RequestDispatcher getNamedDispatcher(String name) throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.ServletContext#getResourcePaths(String)
- */
- public Set getResourcePaths(String path) throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- /**
- * @see javax.servlet.ServletContext#getServletContextName()
- */
- public String getServletContextName() throws UnsupportedOperationException {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
- public String getContextPath() {
- throw new UnsupportedOperationException(HttpMsg.HTTP_ONLY_SUPPORTS_2_1);
- }
-
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/ServletInputStreamImpl.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/ServletInputStreamImpl.java
deleted file mode 100644
index 08a3a9e93..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/ServletInputStreamImpl.java
+++ /dev/null
@@ -1,514 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2009 IBM Corporation.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http.servlet;
-
-import java.io.IOException;
-import java.io.InputStream;
-import javax.servlet.ServletInputStream;
-
-/**
- * An input stream for reading servlet requests, it provides an
- * efficient readLine method. This is an abstract class, to be
- * implemented by a network services writer. For some application
- * protocols, such as the HTTP POST and PUT methods, servlet writers
- * use the input stream to get data from clients. They access the
- * input stream via the ServletRequest's getInputStream method,
- * available from within the servlet's service method. Subclasses of
- * ServletInputStream must provide an implementation of the read()
- * method.
- *
- * <p>
- * This InputStream Object just forwards all requests to the real InputStream object
- * It is intended that that would be the real Sock InputStream. This has some
- * problems if we ever need to restart the stream with another Servlet/etc, so this
- * may need to change some day change.
- */
-public class ServletInputStreamImpl extends ServletInputStream {
- private InputStream in;
- private ServletInputStream servletInputStream = null;
-
- protected ServletInputStreamImpl(InputStream in) {
- super();
- this.in = in;
- }
-
- private void checkOpen() throws IOException {
- if (in == null) {
- throw new IOException("ServletInputStream closed"); //$NON-NLS-1$
- }
- }
-
- /**
- * Returns the number of bytes that can be read from this input
- * stream without blocking. The available method of
- * <code>InputStream</code> returns <code>0</code>. This method
- * <B>should</B> be overridden by subclasses.
- *
- * @return the number of bytes that can be read from this input stream
- * without blocking.
- * @exception IOException if an I/O error occurs.
- * @since JDK1.0
- */
- public int available() throws IOException {
- checkOpen();
-
- return in.available();
- }
-
- /**
- * Closes this input stream and releases any system resources
- * associated with the stream.
- * <p>
- * The <code>close</code> method of <code>InputStream</code> does nothing.
- *
- * @exception IOException if an I/O error occurs.
- * @since JDK1.0
- */
- public void close() throws IOException {
- in = null;
- }
-
- /**
- * Return the ServletInputStream to use for reading data after the
- * HTTP headers have been read. If a Content-Length header is available
- *
- * @param len Content-Length of InputStream
- * @return InputStream for use by servlets
- */
- ServletInputStream getServletInputStream(int len) {
- if (servletInputStream == null) {
- synchronized (this) {
- if (servletInputStream == null) {
- if (len > 0) {
- servletInputStream = new ContentLength(this, len);
- } else {
- servletInputStream = this;
- }
- }
- }
- }
-
- return servletInputStream;
- }
-
- /**
- * Marks the current position in this input stream. A subsequent
- * call to the <code>reset</code> method repositions this stream at
- * the last marked position so that subsequent reads re-read the same
- * bytes.
- * <p>
- * The <code>readLimit</code> arguments tells this input stream to
- * allow that many bytes to be read before the mark position gets
- * invalidated.
- * <p>
- * The <code>mark</code> method of <code>InputStream</code> does nothing.
- *
- * @param readLimit the maximum limit of bytes that can be read before
- * the mark position becomes invalid.
- * @see java.io.InputStream#reset()
- * @since JDK1.0
- */
- public void mark(int readLimit) {
- in.mark(readLimit);
- }
-
- /**
- * Tests if this input stream supports the <code>mark</code>
- * and <code>reset</code> methods. The <code>markSupported</code>
- * method of <code>InputStream</code> returns <code>false</code>.
- *
- * @return <code>true</code> if this true type supports the mark and reset
- * method; <code>false</code> otherwise.
- * @see java.io.InputStream#mark(int)
- * @see java.io.InputStream#reset()
- * @since JDK1.0
- */
- public boolean markSupported() {
- return in.markSupported();
- }
-
- /**
- * Reads the next byte of data from this input stream. The value
- * byte is returned as an <code>int</code> in the range
- * <code>0</code> to <code>255</code>. If no byte is available
- * because the end of the stream has been reached, the value
- * <code>-1</code> is returned. This method blocks until input data
- * is available, the end of the stream is detected, or an exception
- * is thrown.
- * <p>
- * A subclass must provide an implementation of this method.
- *
- * @return the next byte of data, or <code>-1</code> if the end of the
- * stream is reached.
- * @exception IOException if an I/O error occurs.
- * @since JDK1.0
- */
- public int read() throws IOException {
- checkOpen();
-
- return in.read();
- }
-
- /**
- * Reads up to <code>b.length</code> bytes of data from this input
- * stream into an array of bytes.
- * <p>
- * The <code>read</code> method of <code>InputStream</code> calls
- * the <code>read</code> method of three arguments with the arguments
- * <code>b</code>, <code>0</code>, and <code>b.length</code>.
- *
- * @param b the buffer into which the data is read.
- * @return the total number of bytes read into the buffer, or
- * <code>-1</code> is there is no more data because the end of
- * the stream has been reached.
- * @exception IOException if an I/O error occurs.
- * @see java.io.InputStream#read(byte[], int, int)
- * @since JDK1.0
- */
- public int read(byte[] b) throws IOException {
- checkOpen();
-
- return in.read(b, 0, b.length);
- }
-
- /**
- * Reads up to <code>len</code> bytes of data from this input stream
- * into an array of bytes. This method blocks until some input is
- * available. If the argument <code>b</code> is <code>null</code>, a
- * <code>NullPointerException</code> is thrown.
- * <p>
- * The <code>read</code> method of <code>InputStream</code> reads a
- * single byte at a time using the read method of zero arguments to
- * fill in the array. Subclasses are encouraged to provide a more
- * efficient implementation of this method.
- *
- * @param b the buffer into which the data is read.
- * @param off the start offset of the data.
- * @param len the maximum number of bytes read.
- * @return the total number of bytes read into the buffer, or
- * <code>-1</code> if there is no more data because the end of
- * the stream has been reached.
- * @exception IOException if an I/O error occurs.
- * @see java.io.InputStream#read()
- * @since JDK1.0
- */
- public int read(byte[] b, int off, int len) throws IOException {
- checkOpen();
-
- return in.read(b, off, len);
- }
-
- /**
- * Repositions this stream to the position at the time the
- * <code>mark</code> method was last called on this input stream.
- * <p>
- * The <code>reset</code> method of <code>InputStream</code> throws
- * an <code>IOException</code>, because input streams, by default, do
- * not support <code>mark</code> and <code>reset</code>.
- * <p>
- * Stream marks are intended to be used in
- * situations where you need to read ahead a little to see what's in
- * the stream. Often this is most easily done by invoking some
- * general parser. If the stream is of the type handled by the
- * parser, it just chugs along happily. If the stream is not of
- * that type, the parser should toss an exception when it fails,
- * which, if it happens within readlimit bytes, allows the outer
- * code to reset the stream and try another parser.
- *
- * @exception IOException if this stream has not been marked or if the
- * mark has been invalidated.
- * @see java.io.InputStream#mark(int)
- * @see java.io.IOException
- * @since JDK1.0
- */
- public void reset() throws IOException {
- checkOpen();
-
- in.reset();
- }
-
- /**
- * Skips over and discards <code>n</code> bytes of data from this
- * input stream. The <code>skip</code> method may, for a variety of
- * reasons, end up skipping over some smaller number of bytes,
- * possibly <code>0</code>. The actual number of bytes skipped is
- * returned.
- * <p>
- * The <code>skip</code> method of <code>InputStream</code> creates
- * a byte array of length <code>n</code> and then reads into it until
- * <code>n</code> bytes have been read or the end of the stream has
- * been reached. Subclasses are encouraged to provide a more
- * efficient implementation of this method.
- *
- * @param len the number of bytes to be skipped.
- * @return the actual number of bytes skipped.
- * @exception IOException if an I/O error occurs.
- * @since JDK1.0
- */
- public long skip(long len) throws IOException {
- checkOpen();
-
- return in.skip(len);
- }
-
- /**
- * ServletInputStream which limit readable data to the specified content length.
- * After the number of bytes have been read, EOF(-1) is returned from the read
- * method.
- *
- */
- static class ContentLength extends ServletInputStream {
- private int contentLength;
- private int mark;
- private ServletInputStream in;
-
- ContentLength(ServletInputStream in, int len) {
- super();
- this.in = in;
- contentLength = len;
- mark = len;
- }
-
- /**
- * Returns the number of bytes that can be read from this input
- * stream without blocking. The available method of
- * <code>InputStream</code> returns <code>0</code>. This method
- * <B>should</B> be overridden by subclasses.
- *
- * @return the number of bytes that can be read from this input stream
- * without blocking.
- * @exception IOException if an I/O error occurs.
- * @since JDK1.0
- */
- public int available() throws IOException {
- int avail = in.available();
-
- if (contentLength < avail) {
- return contentLength;
- }
-
- return avail;
- }
-
- /**
- * Closes this input stream and releases any system resources
- * associated with the stream.
- * <p>
- * The <code>close</code> method of <code>InputStream</code> does nothing.
- *
- * @exception IOException if an I/O error occurs.
- * @since JDK1.0
- */
- public void close() throws IOException {
- in.close();
- }
-
- /**
- * Marks the current position in this input stream. A subsequent
- * call to the <code>reset</code> method repositions this stream at
- * the last marked position so that subsequent reads re-read the same
- * bytes.
- * <p>
- * The <code>readLimit</code> arguments tells this input stream to
- * allow that many bytes to be read before the mark position gets
- * invalidated.
- * <p>
- * The <code>mark</code> method of <code>InputStream</code> does nothing.
- *
- * @param readLimit the maximum limit of bytes that can be read before
- * the mark position becomes invalid.
- * @see java.io.InputStream#reset()
- * @since JDK1.0
- */
- public void mark(int readLimit) {
- in.mark(readLimit);
-
- mark = contentLength;
- }
-
- /**
- * Tests if this input stream supports the <code>mark</code>
- * and <code>reset</code> methods. The <code>markSupported</code>
- * method of <code>InputStream</code> returns <code>false</code>.
- *
- * @return <code>true</code> if this true type supports the mark and reset
- * method; <code>false</code> otherwise.
- * @see java.io.InputStream#mark(int)
- * @see java.io.InputStream#reset()
- * @since JDK1.0
- */
- public boolean markSupported() {
- return in.markSupported();
- }
-
- /**
- * Reads the next byte of data from this input stream. The value
- * byte is returned as an <code>int</code> in the range
- * <code>0</code> to <code>255</code>. If no byte is available
- * because the end of the stream has been reached, the value
- * <code>-1</code> is returned. This method blocks until input data
- * is available, the end of the stream is detected, or an exception
- * is thrown.
- * <p>
- * A subclass must provide an implementation of this method.
- *
- * @return the next byte of data, or <code>-1</code> if the end of the
- * stream is reached.
- * @exception IOException if an I/O error occurs.
- * @since JDK1.0
- */
- public int read() throws IOException {
- if (contentLength <= 0) {
- return -1;
- }
-
- int read = in.read();
-
- contentLength--;
-
- return read;
- }
-
- /**
- * Reads up to <code>b.length</code> bytes of data from this input
- * stream into an array of bytes.
- * <p>
- * The <code>read</code> method of <code>InputStream</code> calls
- * the <code>read</code> method of three arguments with the arguments
- * <code>b</code>, <code>0</code>, and <code>b.length</code>.
- *
- * @param b the buffer into which the data is read.
- * @return the total number of bytes read into the buffer, or
- * <code>-1</code> is there is no more data because the end of
- * the stream has been reached.
- * @exception IOException if an I/O error occurs.
- * @see java.io.InputStream#read(byte[], int, int)
- * @since JDK1.0
- */
- public int read(byte[] b) throws IOException {
- if (contentLength <= 0) {
- return -1;
- }
-
- int len = b.length;
-
- if (contentLength < len) {
- len = contentLength;
- }
-
- int read = in.read(b, 0, len);
-
- contentLength -= read;
-
- return read;
- }
-
- /**
- * Reads up to <code>len</code> bytes of data from this input stream
- * into an array of bytes. This method blocks until some input is
- * available. If the argument <code>b</code> is <code>null</code>, a
- * <code>NullPointerException</code> is thrown.
- * <p>
- * The <code>read</code> method of <code>InputStream</code> reads a
- * single byte at a time using the read method of zero arguments to
- * fill in the array. Subclasses are encouraged to provide a more
- * efficient implementation of this method.
- *
- * @param b the buffer into which the data is read.
- * @param off the start offset of the data.
- * @param len the maximum number of bytes read.
- * @return the total number of bytes read into the buffer, or
- * <code>-1</code> if there is no more data because the end of
- * the stream has been reached.
- * @exception IOException if an I/O error occurs.
- * @see java.io.InputStream#read()
- * @since JDK1.0
- */
- public int read(byte[] b, int off, int len) throws IOException {
- if (contentLength <= 0) {
- return -1;
- }
-
- if (contentLength < len) {
- len = contentLength;
- }
-
- int read = in.read(b, off, len);
-
- contentLength -= read;
-
- return read;
- }
-
- /**
- * Repositions this stream to the position at the time the
- * <code>mark</code> method was last called on this input stream.
- * <p>
- * The <code>reset</code> method of <code>InputStream</code> throws
- * an <code>IOException</code>, because input streams, by default, do
- * not support <code>mark</code> and <code>reset</code>.
- * <p>
- * Stream marks are intended to be used in
- * situations where you need to read ahead a little to see what's in
- * the stream. Often this is most easily done by invoking some
- * general parser. If the stream is of the type handled by the
- * parser, it just chugs along happily. If the stream is not of
- * that type, the parser should toss an exception when it fails,
- * which, if it happens within readlimit bytes, allows the outer
- * code to reset the stream and try another parser.
- *
- * @exception IOException if this stream has not been marked or if the
- * mark has been invalidated.
- * @see java.io.InputStream#mark(int)
- * @see java.io.IOException
- * @since JDK1.0
- */
- public void reset() throws IOException {
- in.reset();
-
- contentLength = mark;
- }
-
- /**
- * Skips over and discards <code>n</code> bytes of data from this
- * input stream. The <code>skip</code> method may, for a variety of
- * reasons, end up skipping over some smaller number of bytes,
- * possibly <code>0</code>. The actual number of bytes skipped is
- * returned.
- * <p>
- * The <code>skip</code> method of <code>InputStream</code> creates
- * a byte array of length <code>n</code> and then reads into it until
- * <code>n</code> bytes have been read or the end of the stream has
- * been reached. Subclasses are encouraged to provide a more
- * efficient implementation of this method.
- *
- * @param len the number of bytes to be skipped.
- * @return the actual number of bytes skipped.
- * @exception IOException if an I/O error occurs.
- * @since JDK1.0
- */
- public long skip(long len) throws IOException {
- if (contentLength <= 0) {
- return 0;
- }
-
- if (contentLength < len) {
- len = contentLength;
- }
-
- long skipped = in.skip(len);
-
- contentLength -= skipped;
-
- return skipped;
- }
- }
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/ServletOutputStreamImpl.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/ServletOutputStreamImpl.java
deleted file mode 100644
index c59a6de4f..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/ServletOutputStreamImpl.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2007 IBM Corporation.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http.servlet;
-
-import java.io.*;
-import javax.servlet.ServletOutputStream;
-
-/**
- * The implementation of javax.servlet.ServletOutputStream.
- *
- * When a flush or close method is called on an implementation of this class, any
- * data buffered by the servlet engine is sent to the client and the response is
- * considered to be "committed". Note that calling close on an object of this type
- * doesn't necessarily close the underlying socket stream.
- */
-
-//BUGBUG - override print methods for better performance!!!!
-class ServletOutputStreamImpl extends ServletOutputStream {
- private static final int mtuSize = 1460;
-
- /** Actual output stream */
- final private BufferedOutputStream realOut;
-
- /** response object */
- final private HttpServletResponseImpl response;
-
- /** false if the ServletOutputStream has been closed */
- private boolean open;
-
- /** Place to buffer the output data */
- private ByteArrayOutputStream buffer;
-
- /** Place to buffer the output data */
- private OutputStream out;
-
- /** true if we need to write the response headers */
- private boolean writeHeaders;
-
- /** true if the flush method should flush */
- private boolean flush;
-
- /** true if this ServletOutputStream is closing */
- private boolean closing;
-
- ServletOutputStreamImpl(OutputStream realOut, HttpServletResponseImpl response) {
- if (realOut instanceof BufferedOutputStream)
- this.realOut = (BufferedOutputStream) realOut;
- else
- // use a common mtuSize as the buffer size (bug 179282)
- this.realOut = new BufferedOutputStream(realOut, mtuSize);
- this.response = response;
-
- // BUGBUG Make the default buffer size configurable.
- buffer = new ByteArrayOutputStream(8192); /* start with a 8k buffer */
- out = buffer; /* begin with buffer */
- open = true;
- writeHeaders = true;
- closing = false;
- flush = true;
- }
-
- /**
- * This method is called by a wrapper to disable normal flush
- * function until the close method is called.
- */
- synchronized void disableFlush() {
- flush = false; /* disable flush until we are closed */
- }
-
- public synchronized void close() throws IOException {
- if (open) {
- closing = true; /* allow content size to be calculated */
- flush = true; /* enable normal flush function */
-
- flush();
-
- open = false; /* disable this ServletOutputStream */
- }
- }
-
- public synchronized void flush() throws IOException {
- if (open) {
- if (writeHeaders) {
- if (flush) {
- /* These must be set before calling writeHeaders */
- writeHeaders = false;
- out = realOut;
-
- /* write the response headers */
- response.writeHeaders(closing ? buffer.size() : -1);
-
- /* copy the buffered output to the real OutputStream */
- buffer.writeTo(out);
-
- /* dereference buffer so it may be garbage collected */
- buffer = null;
-
- out.flush();
- }
- } else {
- out.flush();
- }
- } else {
- throw new IOException("closed"); //$NON-NLS-1$
- }
- }
-
- public synchronized void write(byte[] bytes) throws IOException {
- if (open) {
- out.write(bytes, 0, bytes.length);
- } else {
- throw new IOException("closed"); //$NON-NLS-1$
- }
- }
-
- public synchronized void write(byte[] bytes, int off, int len) throws IOException {
- if (open) {
- out.write(bytes, off, len);
- } else {
- throw new IOException("closed"); //$NON-NLS-1$
- }
- }
-
- public synchronized void write(int b) throws IOException {
- if (open) {
- out.write(b);
- } else {
- throw new IOException("closed"); //$NON-NLS-1$
- }
- }
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/ServletPrintWriter.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/ServletPrintWriter.java
deleted file mode 100644
index e4c1bb55b..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/servlet/ServletPrintWriter.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2005 IBM Corporation.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.http.servlet;
-
-import java.io.*;
-
-/**
- * PrintWriter subclass for servlets. This class wraps a
- * ServletOutputStream to support Content-Length generation.
- */
-class ServletPrintWriter extends PrintWriter {
- /** underlying ServletOutputStream */
- private ServletOutputStreamImpl out;
-
- /**
- * Create the PrintWriter w/o autoflush for the specified encoding.
- *
- * @param out Underlying ServletOutputStream.
- * @param encoding Encoding to use for the
- * @throws UnsupportedEncodingException if the encoding is not supported.
- */
- ServletPrintWriter(ServletOutputStreamImpl out, String encoding) throws UnsupportedEncodingException {
- super(new OutputStreamWriter(out, encoding), false);
-
- this.out = out;
- }
-
- /**
- * Close this PrintWriter.
- *
- * Tell the underlying ServletOutputStream we are closing.
- */
- public void close() {
- out.disableFlush(); /* disable flush operation until closed */
-
- super.close();
- }
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/status.codes b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/status.codes
deleted file mode 100644
index bb4fe9cf6..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/http/status.codes
+++ /dev/null
@@ -1,52 +0,0 @@
-###############################################################################
-# Copyright (c) 2005 IBM Corporation.
-# 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:
-# IBM Corporation - initial API and implementation
-###############################################################################
-
-# This file is used by the web server to provide a mapping of status code to
-# status phrases.
-# Format: StatusCode StatusPhrase
-
-100 Continue
-101 Switching Protocols
-200 OK
-201 Created
-202 Accepted
-203 Non-Authoritative Information
-204 No Content
-205 Reset Content
-206 Partial Content
-300 Multiple Choices
-301 Moved Permanently
-302 Moved Temporarily
-303 See Other
-304 Not Modified
-305 Use Proxy
-400 Bad Request
-401 Unauthorized
-402 Payment Required
-403 Forbidden
-404 Not Found
-405 Method Not Allowed
-406 Not Acceptable
-407 Proxy Authentication Required
-408 Request Time-out
-409 Conflict
-410 Gone
-411 Length Required
-412 Precondition Failed
-413 Request Entity Too Large
-414 Request-URI Too Large
-415 Unsupported Media Type
-500 Internal Server Error
-501 Not Implemented
-502 Bad Gateway
-503 Service Unavailable
-504 Gateway Time-out
-505 HTTP Version not supported
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/socket/ServerSocketInterface.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/socket/ServerSocketInterface.java
deleted file mode 100644
index fd4addf6b..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/socket/ServerSocketInterface.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2005 IBM Corporation.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.socket;
-
-/** ServerSocketInterface.java
- *
- *
- */
-
-import java.io.IOException;
-
-public interface ServerSocketInterface {
- public SocketInterface acceptSock() throws IOException;
-
- public void close() throws IOException;
-
- public void setAddress(String address);
-
- public String getAddress();
-
- public int getLocalPort();
-
- public String getScheme();
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/socket/SocketInterface.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/socket/SocketInterface.java
deleted file mode 100644
index b84bd147d..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/socket/SocketInterface.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2005 IBM Corporation.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.socket;
-
-/** SocketInterface.java
- *
- *
- */
-
-import java.io.*;
-import java.net.InetAddress;
-import java.net.SocketException;
-
-public interface SocketInterface {
- /* Standard java.net.Socket methods */
- public void close() throws IOException;
-
- public InetAddress getInetAddress();
-
- public InetAddress getLocalAddress();
-
- public int getLocalPort();
-
- public InputStream getInputStream() throws IOException;
-
- public OutputStream getOutputStream() throws IOException;
-
- public void setSoTimeout(int timeout) throws SocketException;
-
- public int getSoTimeout() throws SocketException;
-
- /* Http Methods */
- /**
- * Return the scheme this socket is using.
- *
- * @return Either "http" or "https".
- */
- public String getScheme();
-
- /**
- * Test to see if the socket has been closed.
- *
- * @return true if close has been called on this socket.
- */
- public boolean isClosed();
-
- /**
- * Test to see if the socket is active.
- *
- * @return true if markActive has been called.
- */
- public boolean isActive();
-
- /**
- * Mark the socket active.
- *
- */
- public void markActive();
-
- /**
- * Mark the socket inactive.
- *
- */
- public void markInactive();
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/socket/https/HttpsServerSocket.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/socket/https/HttpsServerSocket.java
deleted file mode 100644
index 57b9ca5d7..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/socket/https/HttpsServerSocket.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2006 IBM Corporation and others.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.socket.https;
-
-import java.io.IOException;
-import java.net.*;
-import javax.net.ServerSocketFactory;
-import org.eclipse.equinox.socket.ServerSocketInterface;
-import org.eclipse.equinox.socket.SocketInterface;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.util.tracker.ServiceTracker;
-import org.osgi.util.tracker.ServiceTrackerCustomizer;
-
-public class HttpsServerSocket implements ServerSocketInterface, ServiceTrackerCustomizer {
-
- protected String address = null;
- protected BundleContext context = null;
- protected int port = 443;
- protected int backlog = 50;
- protected InetAddress bindAddr = null;
-
- protected ServiceTracker st = null;
- protected ServerSocketFactory ssf = null;
- protected ServerSocket ss = null;
- protected ServerSocket dummyss = null;
-
- /**
- * Constructor for HttpsServerSockets
- */
- public HttpsServerSocket(BundleContext context, int port) throws IOException {
- this(context, port, 50);
- }
-
- /**
- * HttpServerSocket constructor comment.
- * @param port int
- * @param backlog int
- * @exception java.io.IOException The exception description.
- */
- public HttpsServerSocket(BundleContext context, int port, int backlog) throws java.io.IOException {
- this(context, port, backlog, null);
- }
-
- /**
- * HttpServerSocket constructor comment.
- * @param port int
- * @param backlog int
- * @param bindAddr java.net.InetAddress
- * @exception java.io.IOException The exception description.
- */
- public HttpsServerSocket(BundleContext context, int port, int backlog, InetAddress bindAddr) throws java.io.IOException {
- this.context = context;
- this.port = port;
- this.backlog = backlog;
- this.bindAddr = bindAddr;
- // Try to configure a normal ServerSocket with the settings to see
- // if the ServerSocket can be created. If no exception is thrown
- // then the port is available
- dummyss = new ServerSocket(port, backlog, bindAddr);
-
- st = new ServiceTracker(context, "javax.net.ssl.SSLServerSocketFactory", this); //$NON-NLS-1$
- st.open();
- }
-
- /**
- * @see ServerSocketInterface#acceptSock()
- */
- public synchronized SocketInterface acceptSock() throws IOException {
- while (this.ssf == null) {
- try {
- wait();
- } catch (InterruptedException e) {
- throw new IOException();
- }
- }
- if (ss == null) {
- if (dummyss != null) {
- dummyss.close();
- dummyss = null;
- }
- ss = ssf.createServerSocket(port, backlog, bindAddr);
- }
- Socket socket = ss.accept();
- return new HttpsSocket(socket);
- }
-
- /**
- * @see ServerSocketInterface#close()
- */
- public void close() throws IOException {
- if (ss != null) {
- ss.close();
- }
- }
-
- /**
- * @see ServerSocketInterface#getLocalPort()
- */
- public int getLocalPort() {
- if (ss != null) {
- return ss.getLocalPort();
- }
- return 0;
- }
-
- /**
- * @see ServerSocketInterface#getScheme()
- */
- public String getScheme() {
- return ("https"); //$NON-NLS-1$
- }
-
- public String getAddress() {
- return address;
- }
-
- public void setAddress(String address) {
- this.address = address;
- }
-
- public synchronized Object addingService(ServiceReference reference) {
- if (ssf == null) {
- ssf = (ServerSocketFactory) context.getService(reference);
- notify();
- return ssf;
- }
- return null;
- }
-
- public void modifiedService(ServiceReference reference, Object service) {
- // do nothing
- }
-
- public synchronized void removedService(ServiceReference reference, Object service) {
- ssf = null;
- if (ss != null) {
- try {
- ss.close();
- } catch (IOException e) {
- // TODO: consider logging
- }
- ss = null;
- }
- context.ungetService(reference);
- }
-
-}
diff --git a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/socket/https/HttpsSocket.java b/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/socket/https/HttpsSocket.java
deleted file mode 100644
index 082015bb3..000000000
--- a/bundles/org.eclipse.equinox.http/src/org/eclipse/equinox/socket/https/HttpsSocket.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 1999, 2005 IBM Corporation.
- * 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:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.socket.https;
-
-import java.io.*;
-import java.net.*;
-import org.eclipse.equinox.socket.SocketInterface;
-
-public class HttpsSocket implements SocketInterface {
- protected Socket socket;
- protected boolean closed = false;
- private boolean active = false;
- private InputStream in = null;
-
- public HttpsSocket(Socket socket) {
- this.socket = socket;
- }
-
- public void close() throws IOException {
- closed = true;
- socket.close();
- }
-
- public InetAddress getInetAddress() {
- return socket.getInetAddress();
- }
-
- public InetAddress getLocalAddress() {
- return socket.getLocalAddress();
- }
-
- public int getLocalPort() {
- return socket.getLocalPort();
- }
-
- /**
- * Wrap the real socket input stream in a buffered input stream
- *
- * @return a buffered InputStream which wraps the real input stream.
- * @throws IOException
- */
- public InputStream getInputStream() throws IOException {
- if (in == null) {
- synchronized (this) {
- if (in == null) {
- in = new BufferedInputStream(socket.getInputStream());
- }
- }
- }
-
- return in;
- }
-
- public OutputStream getOutputStream() throws IOException {
- return socket.getOutputStream();
- }
-
- public void setSoTimeout(int timeout) throws SocketException {
- socket.setSoTimeout(timeout);
- }
-
- public int getSoTimeout() throws SocketException {
- return socket.getSoTimeout();
- }
-
- /**
- * Return the scheme this socket is using.
- *
- * @return "https".
- */
- public String getScheme() {
- return "https"; //$NON-NLS-1$
- }
-
- /**
- * Test to see if the socket is closed.
- *
- * @return true if close has been called.
- */
- public boolean isClosed() {
- return closed;
- }
-
- /**
- * Test to see if the socket is active.
- *
- * @return true if markActive has been called.
- */
- public boolean isActive() {
- return active;
- }
-
- /**
- * Mark the socket active.
- *
- */
- public void markActive() {
- active = true;
- }
-
- /**
- * Mark the socket inactive.
- *
- */
- public void markInactive() {
- active = false;
- }
-
-}

Back to the top