/******************************************************************************* * Copyright (c) 2014 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.orion.server.cf.handlers.v1; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.eclipse.core.runtime.*; import org.eclipse.orion.internal.server.servlets.ServletResourceHandler; import org.eclipse.orion.server.cf.CFProtocolConstants; import org.eclipse.orion.server.cf.commands.ParseManifestCommand; import org.eclipse.orion.server.cf.jobs.CFJob; import org.eclipse.orion.server.cf.manifest.v2.ManifestParseTree; import org.eclipse.orion.server.cf.objects.Manifest; import org.eclipse.orion.server.cf.servlets.AbstractRESTHandler; import org.eclipse.orion.server.core.IOUtilities; import org.eclipse.orion.server.core.ServerStatus; import org.eclipse.osgi.util.NLS; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class ManifestsHandlerV1 extends AbstractRESTHandler<Manifest> { private final Logger logger = LoggerFactory.getLogger("org.eclipse.orion.server.cf"); //$NON-NLS-1$ public ManifestsHandlerV1(ServletResourceHandler<IStatus> statusHandler) { super(statusHandler); } @Override protected Manifest buildResource(HttpServletRequest request, String path) throws CoreException { return null; } @Override protected CFJob handleGet(Manifest manifest, HttpServletRequest request, HttpServletResponse response, final String path) { /* if true, forces to parse the given manifest and *not* to assume a default 'manifest.yml' in parents folder */ String strictString = IOUtilities.getQueryParameter(request, CFProtocolConstants.KEY_STRICT); final boolean strict = strictString != null ? Boolean.parseBoolean(strictString) : false; return new CFJob(request, false) { @Override protected IStatus performJob() { try { ParseManifestCommand parseManifestCommand = new ParseManifestCommand(null, userId, path); parseManifestCommand.setStrict(strict); IStatus status = parseManifestCommand.doIt(); if (!status.isOK()) return status; ManifestParseTree manifest = parseManifestCommand.getManifest(); Manifest resp = new Manifest(manifest); return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, resp.toJSON()); } catch (Exception e) { String msg = NLS.bind("Failed to handle request for {0}", path); //$NON-NLS-1$ ServerStatus status = new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e); logger.error(msg, e); return status; } } }; } }