001/*
002 * Copyright 2012 Atteo.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
005 * in compliance with the License. You may obtain a copy of the License at
006 *
007 * http://www.apache.org/licenses/LICENSE-2.0
008 *
009 * Unless required by applicable law or agreed to in writing, software distributed under the License
010 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
011 * or implied. See the License for the specific language governing permissions and limitations under
012 * the License.
013 */
014package org.atteo.moonshine.jminix;
015
016import javax.inject.Singleton;
017import javax.xml.bind.annotation.XmlElement;
018import javax.xml.bind.annotation.XmlIDREF;
019import javax.xml.bind.annotation.XmlRootElement;
020
021import org.atteo.moonshine.TopLevelService;
022import org.atteo.moonshine.services.ImportService;
023import org.atteo.moonshine.webserver.ServletContainer;
024import org.jminix.console.servlet.MiniConsoleServlet;
025
026import com.google.inject.Module;
027import com.google.inject.PrivateModule;
028
029/**
030 * JMX web console.
031 * <p>
032 * The console is based on <a href="http://code.google.com/p/jminix/">JMiniX</a>.
033 * </p>
034 * <p>
035 * Due to the limitation of JMiniX you need to append trailing '/' in the URL
036 * to access it.
037 * </p>
038 */
039@XmlRootElement(name = "jminix")
040public class JMinix extends TopLevelService {
041    @XmlElement
042    @XmlIDREF
043    @ImportService
044    private ServletContainer servletContainer;
045
046    @XmlElement
047    private String pattern = "/jmx/*";
048
049    @Override
050    public Module configure() {
051        return new PrivateModule() {
052            @Override
053            protected void configure() {
054                bind(MiniConsoleServlet.class).in(Singleton.class);
055                servletContainer.addServlet(getProvider(MiniConsoleServlet.class), pattern);
056            }
057        };
058    }
059}