01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.geronimo.console.car;
17:
18: import java.net.URLEncoder;
19:
20: import org.apache.geronimo.kernel.Kernel;
21: import org.apache.geronimo.kernel.KernelRegistry;
22: import org.apache.geronimo.kernel.config.ConfigurationManager;
23: import org.apache.geronimo.kernel.config.ConfigurationStore;
24: import org.apache.geronimo.kernel.config.ConfigurationUtil;
25: import org.apache.geronimo.kernel.config.NoSuchConfigException;
26: import org.apache.geronimo.kernel.repository.Artifact;
27:
28: import javax.servlet.ServletException;
29: import javax.servlet.http.HttpServlet;
30: import javax.servlet.http.HttpServletRequest;
31: import javax.servlet.http.HttpServletResponse;
32: import java.io.IOException;
33:
34: /**
35: * Servlet that lets you download a CAR from the repository
36: *
37: * @version $Rev: 616572 $ $Date: 2008-01-29 16:37:26 -0800 (Tue, 29 Jan 2008) $
38: */
39: public class CARExportServlet extends HttpServlet {
40: protected void doGet(HttpServletRequest request,
41: HttpServletResponse response) throws ServletException,
42: IOException {
43: String configId = request.getParameter("configId");
44: if (configId == null) {
45: throw new ServletException(
46: "No configId specified for CAR download");
47: }
48: Artifact artifact = Artifact.create(configId);
49: Kernel kernel = KernelRegistry.getSingleKernel();
50: ConfigurationManager mgr = ConfigurationUtil
51: .getConfigurationManager(kernel);
52: ConfigurationStore store = mgr
53: .getStoreForConfiguration(artifact);
54: try {
55: response.setContentType("application/zip");
56: String filename = artifact.getArtifactId() + "-"
57: + artifact.getVersion() + "." + artifact.getType();
58: response.setHeader("Content-Disposition",
59: "attachment; filename="
60: + URLEncoder.encode(filename, "UTF-8"));
61: store.exportConfiguration(artifact, response
62: .getOutputStream());
63: } catch (NoSuchConfigException e) {
64: throw new ServletException("No such configuration '"
65: + configId + "'");
66: }
67: }
68: }
|