	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String id = null;
		String dsPhysicalLocation = null;
		String dsControlGroupType = null;
		String user = null;
		String pass = null;
		MIMETypedStream mimeTypedStream = null;
		DisseminationService ds = null;
		Timestamp keyTimestamp = null;
		Timestamp currentTimestamp = null;
		PrintWriter out = null;
		ServletOutputStream outStream = null;
		String requestURI = request.getRequestURL().toString() + "?"
				+ request.getQueryString();
		id = request.getParameter("id").replaceAll("T", " ");
        LOG.debug("Datastream tempID=" + id);
        LOG.debug("DRS doGet()");
		try {
			if (id == null || id.equalsIgnoreCase("")) {
				String message = "[DatastreamResolverServlet] No datastream ID "
						+ "specified in servlet request: "
						+ request.getRequestURI();
                LOG.error(message);
				response
						.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
				response.sendError(
						HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
				return;
			}
			id = id.replaceAll("T", " ").replaceAll("/", "").trim();
			ds = new DisseminationService();
			dsRegistry = DisseminationService.dsRegistry;
			DatastreamMediation dm = (DatastreamMediation) dsRegistry.get(id);
			if (dm == null) {
				StringBuffer entries = new StringBuffer();
				Iterator eIter = dsRegistry.keySet().iterator();
				while (eIter.hasNext()) {
					entries.append("'" + (String) eIter.next() + "' ");
				}
				throw new IOException(
						"Cannot find datastream in temp registry by key: " + id
								+ "\n" + "Reg entries: " + entries.toString());
			}
			dsPhysicalLocation = dm.dsLocation;
			dsControlGroupType = dm.dsControlGroupType;
			user = dm.callUsername;
			pass = dm.callPassword;
			if (LOG.isDebugEnabled()) {
				LOG.debug("**************************** DatastreamResolverServlet dm.dsLocation: "
								+ dm.dsLocation);
				LOG.debug("**************************** DatastreamResolverServlet dm.dsControlGroupType: "
								+ dm.dsControlGroupType);
				LOG.debug("**************************** DatastreamResolverServlet dm.callUsername: "
								+ dm.callUsername);
				LOG.debug("**************************** DatastreamResolverServlet dm.Password: "
								+ dm.callPassword);
				LOG.debug("**************************** DatastreamResolverServlet dm.callbackRole: "
								+ dm.callbackRole);
				LOG.debug("**************************** DatastreamResolverServlet dm.callbackBasicAuth: "
								+ dm.callbackBasicAuth);
				LOG.debug("**************************** DatastreamResolverServlet dm.callBasicAuth: "
								+ dm.callBasicAuth);
				LOG.debug("**************************** DatastreamResolverServlet dm.callbackSSl: "
								+ dm.callbackSSL);
				LOG.debug("**************************** DatastreamResolverServlet dm.callSSl: "
								+ dm.callSSL);
				LOG.debug("**************************** DatastreamResolverServlet non ssl port: "
								+ fedoraServerPort);
				LOG.debug("**************************** DatastreamResolverServlet ssl port: "
								+ fedoraServerRedirectPort);
			}
			if (request.getRequestURI().endsWith("getDS")
					&& (ServerUtility.isURLFedoraServer(dsPhysicalLocation)
							|| dsControlGroupType.equals("M") || dsControlGroupType
							.equals("X"))) {
				if (LOG.isDebugEnabled())
					LOG.debug("*********************** Changed role from: "
									+ dm.callbackRole
									+ "  to: "
									+ BackendPolicies.BACKEND_SERVICE_CALL_UNSECURE);
				dm.callbackRole = BackendPolicies.BACKEND_SERVICE_CALL_UNSECURE;
			}
			if (dm.callbackRole.equals(BackendPolicies.FEDORA_INTERNAL_CALL)) {
				if (dm.callbackSSL) {
					dsPhysicalLocation = dsPhysicalLocation.replaceFirst(
							"http:", "https:");
					dsPhysicalLocation = dsPhysicalLocation.replaceFirst(
							fedoraServerPort, fedoraServerRedirectPort);
					if (LOG.isDebugEnabled())
						LOG.debug("*********************** DatastreamResolverServlet -- Was Fedora-to-Fedora call -- modified dsPhysicalLocation: "
										+ dsPhysicalLocation);
				}
			}
			keyTimestamp = Timestamp.valueOf(ds.extractTimestamp(id));
			currentTimestamp = new Timestamp(new Date().getTime());
            LOG.debug("dsPhysicalLocation=" + dsPhysicalLocation
                    + "dsControlGroupType=" + dsControlGroupType);
            long diff = currentTimestamp.getTime() - keyTimestamp.getTime();
            LOG.debug("Timestamp diff for mechanism's reponse: " 
                        + diff + " ms.");
			if (diff > (long) datastreamMediationLimit) {
				out = response.getWriter();
				response.setContentType(HTML_CONTENT_TYPE);
				out
						.println("<br><b>[DatastreamResolverServlet] Error:</b>"
								+ "<font color=\"red\"> Mechanism has failed to respond "
								+ "to the DatastreamResolverServlet within the specified "
								+ "time limit of \""
								+ datastreamMediationLimit
								+ "\""
								+ "milliseconds. Datastream access denied.");
                LOG.error("Mechanism failed to respond to "
                        + "DatastreamResolverServlet within time limit of "
                        + datastreamMediationLimit);
				out.close();
				return;
			}
			if (dm.callbackRole == null) {
				throw new AuthzOperationalException(
						"no callbackRole for this ticket");
			}
			String targetRole = 
					dm.callbackRole; 
			String[] targetRoles = { targetRole };
			Context context = ReadOnlyContext.getContext(
					Constants.HTTP_REQUEST.REST.uri, request); 
			if (request.getRemoteUser() == null) {
    			LOG.debug("DatastreamResolverServlet: unAuthenticated request");
			} else {
				if (((ExtendedHttpServletRequest)request).isUserInRole(targetRole)) {
					LOG.debug("DatastreamResolverServlet: user has required role");
				} else {
					LOG.debug("DatastreamResolverServlet: authZ exception in validating user");
					throw new AuthzDeniedException("wrong user for this ticket");
				}
			}
			if (LOG.isDebugEnabled()) {
				LOG.debug("debugging backendService role");
				LOG.debug("targetRole=" + targetRole);
				int targetRolesLength = targetRoles.length;
				LOG.debug("targetRolesLength=" + targetRolesLength);
				if (targetRolesLength > 0) {
					LOG.debug("targetRoles[0]=" + targetRoles[0]);
				}
				int nSubjectValues = context.nSubjectValues(targetRole);
				LOG.debug("nSubjectValues=" + nSubjectValues);
				if (nSubjectValues > 0) {
					LOG.debug("context.getSubjectValue(targetRole)="
							+ context.getSubjectValue(targetRole));
				}
				Iterator it = context.subjectAttributes();
				while (it.hasNext()) {
					String name = (String) it.next();
					String value = context.getSubjectValue(name);
					LOG.debug("another subject attribute from context "
									+ name + "=" + value);
				}
				it = context.environmentAttributes();
				while (it.hasNext()) {
					String name = (String) it.next();
					String value = context.getEnvironmentValue(name);
					LOG.debug("another environment attribute from context "
									+ name + "=" + value);
				}
			}
            LOG.debug("DatastreamResolverServlet: about to do final authZ check");
			Authorization authorization = (Authorization) s_server
					.getModule("fedora.server.security.Authorization");
			authorization.enforceResolveDatastream(context, keyTimestamp);
			LOG.debug("DatastreamResolverServlet: final authZ check suceeded.....");
			if (dsControlGroupType.equalsIgnoreCase("E")) {
				if (LOG.isDebugEnabled()) {
					for (Enumeration e = request.getHeaderNames(); e
							.hasMoreElements();) {
						String name = (String) e.nextElement();
						Enumeration headerValues = request.getHeaders(name);
						StringBuffer sb = new StringBuffer();
						while (headerValues.hasMoreElements()) {
							sb.append((String) headerValues.nextElement());
						}
						String value = sb.toString();
						LOG.debug("DATASTREAMRESOLVERSERVLET REQUEST HEADER CONTAINED: "
										+ name + " : " + value);
					}
				}
				ExternalContentManager externalContentManager = (ExternalContentManager) s_server
						.getModule("fedora.server.storage.ExternalContentManager");
				mimeTypedStream = externalContentManager.getExternalContent(
						dsPhysicalLocation, context);
				outStream = response.getOutputStream();
				response.setContentType(mimeTypedStream.MIMEType);
				Property[] headerArray = mimeTypedStream.header;
				if (headerArray != null) {
					for (int i = 0; i < headerArray.length; i++) {
						if (headerArray[i].name != null
								&& !(headerArray[i].name
										.equalsIgnoreCase("content-type"))) {
							response.addHeader(headerArray[i].name,
									headerArray[i].value);
							LOG.debug("THIS WAS ADDED TO DATASTREAMRESOLVERSERVLET RESPONSE HEADER FROM ORIGINATING PROVIDER "
										+ headerArray[i].name
										+ " : " + headerArray[i].value);
						}
					}
				}
				int byteStream = 0;
				byte[] buffer = new byte[255];
				while ((byteStream = mimeTypedStream.getStream().read(buffer)) != -1) {
					outStream.write(buffer, 0, byteStream);
				}
				buffer = null;
				outStream.flush();
			} else if (dsControlGroupType.equalsIgnoreCase("M")
					|| dsControlGroupType.equalsIgnoreCase("X")) {
				String PID = null;
				String dsVersionID = null;
				String dsID = null;
				String[] s = dsPhysicalLocation.split("\\+");
				if (s.length != 3) {
					String message = "[DatastreamResolverServlet]  The "
							+ "internal Fedora datastream id:  \""
							+ dsPhysicalLocation + "\"  is invalid.";
					LOG.error(message);
					throw new ServletException(message);
				}
				PID = s[0];
				dsID = s[1];
				dsVersionID = s[2];
                LOG.debug("PID=" + PID + ", dsID=" + dsID + ", dsVersionID="
                        + dsVersionID);
				DOReader doReader = m_manager.getReader(
						Server.USE_DEFINITIVE_STORE, context, PID);
				Datastream d = (Datastream) doReader.getDatastream(dsID,
						dsVersionID);
                LOG.debug("Got datastream: " + d.DatastreamID);
				InputStream is = d.getContentStream();
				int bytestream = 0;
				response.setContentType(d.DSMIME);
				outStream = response.getOutputStream();
				byte[] buffer = new byte[255];
				while ((bytestream = is.read(buffer)) != -1) {
					outStream.write(buffer, 0, bytestream);
				}
				buffer = null;
				is.close();
			} else {
				out = response.getWriter();
				response.setContentType(HTML_CONTENT_TYPE);
				out.println("<br>[DatastreamResolverServlet] Unknown "
								+ "dsControlGroupType: " + dsControlGroupType
								+ "</br>");
                LOG.error("Unknown dsControlGroupType: " + dsControlGroupType);
			}
		} catch (AuthzException ae) {
            LOG.error("Authorization failure resolving datastream"
                    + " (actionLabel=" + ACTION_LABEL + ")", ae);
			throw RootException.getServletException(ae, request, ACTION_LABEL,
					new String[0]);
		} catch (Throwable th) {
            LOG.error("Error resolving datastream", th);
			String message = "[DatastreamResolverServlet] returned an error. The "
					+ "underlying error was a  \""
					+ th.getClass().getName()
					+ "  The message was  \"" + th.getMessage() + "\".  ";
			throw new ServletException(message);
		} finally {
			if (out != null)
				out.close();
			if (outStream != null)
				outStream.close();
			dsRegistry.remove(id);
		}
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String id = null;
		String dsPhysicalLocation = null;
		String dsControlGroupType = null;
		String user = null;
		String pass = null;
		MIMETypedStream mimeTypedStream = null;
		DisseminationService ds = null;
		Timestamp keyTimestamp = null;
		Timestamp currentTimestamp = null;
		PrintWriter out = null;
		ServletOutputStream outStream = null;
		String requestURI = request.getRequestURL().toString() + "?"
				+ request.getQueryString();
		id = request.getParameter("id").replaceAll("T", " ");
        LOG.debug("Datastream tempID=" + id);
        LOG.debug("DRS doGet()");
		try {
			if (id == null || id.equalsIgnoreCase("")) {
				String message = "[DatastreamResolverServlet] No datastream ID "
						+ "specified in servlet request: "
						+ request.getRequestURI();
                LOG.error(message);
				response
						.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
				response.sendError(
						HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message);
				return;
			}
			id = id.replaceAll("T", " ").replaceAll("/", "").trim();
			ds = new DisseminationService();
			dsRegistry = DisseminationService.dsRegistry;
			DatastreamMediation dm = (DatastreamMediation) dsRegistry.get(id);
			if (dm == null) {
				StringBuffer entries = new StringBuffer();
				Iterator eIter = dsRegistry.keySet().iterator();
				while (eIter.hasNext()) {
					entries.append("'" + (String) eIter.next() + "' ");
				}
				throw new IOException(
						"Cannot find datastream in temp registry by key: " + id
								+ "\n" + "Reg entries: " + entries.toString());
			}
			dsPhysicalLocation = dm.dsLocation;
			dsControlGroupType = dm.dsControlGroupType;
			user = dm.callUsername;
			pass = dm.callPassword;
			if (LOG.isDebugEnabled()) {
				LOG.debug("**************************** DatastreamResolverServlet dm.dsLocation: "
								+ dm.dsLocation);
				LOG.debug("**************************** DatastreamResolverServlet dm.dsControlGroupType: "
								+ dm.dsControlGroupType);
				LOG.debug("**************************** DatastreamResolverServlet dm.callUsername: "
								+ dm.callUsername);
				LOG.debug("**************************** DatastreamResolverServlet dm.Password: "
								+ dm.callPassword);
				LOG.debug("**************************** DatastreamResolverServlet dm.callbackRole: "
								+ dm.callbackRole);
				LOG.debug("**************************** DatastreamResolverServlet dm.callbackBasicAuth: "
								+ dm.callbackBasicAuth);
				LOG.debug("**************************** DatastreamResolverServlet dm.callBasicAuth: "
								+ dm.callBasicAuth);
				LOG.debug("**************************** DatastreamResolverServlet dm.callbackSSl: "
								+ dm.callbackSSL);
				LOG.debug("**************************** DatastreamResolverServlet dm.callSSl: "
								+ dm.callSSL);
				LOG.debug("**************************** DatastreamResolverServlet non ssl port: "
								+ fedoraServerPort);
				LOG.debug("**************************** DatastreamResolverServlet ssl port: "
								+ fedoraServerRedirectPort);
			}
			if (request.getRequestURI().endsWith("getDS")
					&& (ServerUtility.isURLFedoraServer(dsPhysicalLocation)
							|| dsControlGroupType.equals("M") || dsControlGroupType
							.equals("X"))) {
				if (LOG.isDebugEnabled())
					LOG.debug("*********************** Changed role from: "
									+ dm.callbackRole
									+ "  to: "
									+ BackendPolicies.BACKEND_SERVICE_CALL_UNSECURE);
				dm.callbackRole = BackendPolicies.BACKEND_SERVICE_CALL_UNSECURE;
			}
			if (dm.callbackRole.equals(BackendPolicies.FEDORA_INTERNAL_CALL)) {
				if (dm.callbackSSL) {
					dsPhysicalLocation = dsPhysicalLocation.replaceFirst(
							"http:", "https:");
					dsPhysicalLocation = dsPhysicalLocation.replaceFirst(
							fedoraServerPort, fedoraServerRedirectPort);
					if (LOG.isDebugEnabled())
						LOG.debug("*********************** DatastreamResolverServlet -- Was Fedora-to-Fedora call -- modified dsPhysicalLocation: "
										+ dsPhysicalLocation);
				}
			}
			keyTimestamp = Timestamp.valueOf(ds.extractTimestamp(id));
			currentTimestamp = new Timestamp(new Date().getTime());
            LOG.debug("dsPhysicalLocation=" + dsPhysicalLocation
                    + "dsControlGroupType=" + dsControlGroupType);
            long diff = currentTimestamp.getTime() - keyTimestamp.getTime();
            LOG.debug("Timestamp diff for mechanism's reponse: " 
                        + diff + " ms.");
			if (diff > (long) datastreamMediationLimit) {
				out = response.getWriter();
				response.setContentType(HTML_CONTENT_TYPE);
				out
						.println("<br><b>[DatastreamResolverServlet] Error:</b>"
								+ "<font color=\"red\"> Mechanism has failed to respond "
								+ "to the DatastreamResolverServlet within the specified "
								+ "time limit of \""
								+ datastreamMediationLimit
								+ "\""
								+ "milliseconds. Datastream access denied.");
                LOG.error("Mechanism failed to respond to "
                        + "DatastreamResolverServlet within time limit of "
                        + datastreamMediationLimit);
				out.close();
				return;
			}
			if (dm.callbackRole == null) {
				throw new AuthzOperationalException(
						"no callbackRole for this ticket");
			}
			String targetRole = 
					dm.callbackRole; 
			String[] targetRoles = { targetRole };
			Context context = ReadOnlyContext.getContext(
					Constants.HTTP_REQUEST.REST.uri, request); 
			if (request.getRemoteUser() == null) {
    			LOG.debug("DatastreamResolverServlet: unAuthenticated request");
			} else {
				LOG.debug("DatastreamResolverServlet: user==" + request.getRemoteUser());	
			}
			if (LOG.isDebugEnabled()) {
				LOG.debug("debugging backendService role");
				LOG.debug("targetRole=" + targetRole);
				int targetRolesLength = targetRoles.length;
				LOG.debug("targetRolesLength=" + targetRolesLength);
				if (targetRolesLength > 0) {
					LOG.debug("targetRoles[0]=" + targetRoles[0]);
				}
				int nSubjectValues = context.nSubjectValues(targetRole);
				LOG.debug("nSubjectValues=" + nSubjectValues);
				if (nSubjectValues > 0) {
					LOG.debug("context.getSubjectValue(targetRole)="
							+ context.getSubjectValue(targetRole));
				}
				Iterator it = context.subjectAttributes();
				while (it.hasNext()) {
					String name = (String) it.next();
					String value = context.getSubjectValue(name);
					LOG.debug("another subject attribute from context "
									+ name + "=" + value);
				}
				it = context.environmentAttributes();
				while (it.hasNext()) {
					String name = (String) it.next();
					String value = context.getEnvironmentValue(name);
					LOG.debug("another environment attribute from context "
									+ name + "=" + value);
				}
			}
            LOG.debug("DatastreamResolverServlet: about to do final authZ check");
			Authorization authorization = (Authorization) s_server
					.getModule("fedora.server.security.Authorization");
			authorization.enforceResolveDatastream(context, keyTimestamp);
			LOG.debug("DatastreamResolverServlet: final authZ check suceeded.....");
			if (dsControlGroupType.equalsIgnoreCase("E")) {
				if (LOG.isDebugEnabled()) {
					for (Enumeration e = request.getHeaderNames(); e
							.hasMoreElements();) {
						String name = (String) e.nextElement();
						Enumeration headerValues = request.getHeaders(name);
						StringBuffer sb = new StringBuffer();
						while (headerValues.hasMoreElements()) {
							sb.append((String) headerValues.nextElement());
						}
						String value = sb.toString();
						LOG.debug("DATASTREAMRESOLVERSERVLET REQUEST HEADER CONTAINED: "
										+ name + " : " + value);
					}
				}
				ExternalContentManager externalContentManager = (ExternalContentManager) s_server
						.getModule("fedora.server.storage.ExternalContentManager");
				mimeTypedStream = externalContentManager.getExternalContent(
						dsPhysicalLocation, context);
				outStream = response.getOutputStream();
				response.setContentType(mimeTypedStream.MIMEType);
				Property[] headerArray = mimeTypedStream.header;
				if (headerArray != null) {
					for (int i = 0; i < headerArray.length; i++) {
						if (headerArray[i].name != null
								&& !(headerArray[i].name
										.equalsIgnoreCase("content-type"))) {
							response.addHeader(headerArray[i].name,
									headerArray[i].value);
							LOG.debug("THIS WAS ADDED TO DATASTREAMRESOLVERSERVLET RESPONSE HEADER FROM ORIGINATING PROVIDER "
										+ headerArray[i].name
										+ " : " + headerArray[i].value);
						}
					}
				}
				int byteStream = 0;
				byte[] buffer = new byte[255];
				while ((byteStream = mimeTypedStream.getStream().read(buffer)) != -1) {
					outStream.write(buffer, 0, byteStream);
				}
				buffer = null;
				outStream.flush();
			} else if (dsControlGroupType.equalsIgnoreCase("M")
					|| dsControlGroupType.equalsIgnoreCase("X")) {
				String PID = null;
				String dsVersionID = null;
				String dsID = null;
				String[] s = dsPhysicalLocation.split("\\+");
				if (s.length != 3) {
					String message = "[DatastreamResolverServlet]  The "
							+ "internal Fedora datastream id:  \""
							+ dsPhysicalLocation + "\"  is invalid.";
					LOG.error(message);
					throw new ServletException(message);
				}
				PID = s[0];
				dsID = s[1];
				dsVersionID = s[2];
                LOG.debug("PID=" + PID + ", dsID=" + dsID + ", dsVersionID="
                        + dsVersionID);
				DOReader doReader = m_manager.getReader(
						Server.USE_DEFINITIVE_STORE, context, PID);
				Datastream d = (Datastream) doReader.getDatastream(dsID,
						dsVersionID);
                LOG.debug("Got datastream: " + d.DatastreamID);
				InputStream is = d.getContentStream();
				int bytestream = 0;
				response.setContentType(d.DSMIME);
				outStream = response.getOutputStream();
				byte[] buffer = new byte[255];
				while ((bytestream = is.read(buffer)) != -1) {
					outStream.write(buffer, 0, bytestream);
				}
				buffer = null;
				is.close();
			} else {
				out = response.getWriter();
				response.setContentType(HTML_CONTENT_TYPE);
				out.println("<br>[DatastreamResolverServlet] Unknown "
								+ "dsControlGroupType: " + dsControlGroupType
								+ "</br>");
                LOG.error("Unknown dsControlGroupType: " + dsControlGroupType);
			}
		} catch (AuthzException ae) {
            LOG.error("Authorization failure resolving datastream"
                    + " (actionLabel=" + ACTION_LABEL + ")", ae);
			throw RootException.getServletException(ae, request, ACTION_LABEL,
					new String[0]);
		} catch (Throwable th) {
            LOG.error("Error resolving datastream", th);
			String message = "[DatastreamResolverServlet] returned an error. The "
					+ "underlying error was a  \""
					+ th.getClass().getName()
					+ "  The message was  \"" + th.getMessage() + "\".  ";
			throw new ServletException(message);
		} finally {
			if (out != null)
				out.close();
			if (outStream != null)
				outStream.close();
			dsRegistry.remove(id);
		}
	}
