Package org.housecream.restmcu.it

Source Code of org.housecream.restmcu.it.RestmcuServerSample

/**
*
*     Copyright (C) Housecream.org
*
*     This program is free software: you can redistribute it and/or modify
*     it under the terms of the GNU Affero General Public License as published by
*     the Free Software Foundation, either version 3 of the License, or any later version.
*
*     This program is distributed in the hope that it will be useful,
*     but WITHOUT ANY WARRANTY; without even the implied warranty of
*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*     GNU Affero General Public License for more details.
*
*     You should have received a copy of the GNU Affero General Public License
*     along with this program.  If not, see <http://www.gnu.org/licenses/>
*/
package org.housecream.restmcu.it;

import java.util.Arrays;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.transport.Destination;
import org.apache.cxf.transport.http_jetty.JettyHTTPDestination;
import org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine;
import org.apache.cxf.transport.http_jetty.ServerEngine;
import org.housecream.restmcu.it.resource.NotifyResource;
import fr.norad.jaxrs.client.server.rest.RestBuilder;

public class RestmcuServerSample {

    private Server server;

    public RestmcuServerSample() {
        NotifyResource notifyResource = new NotifyResource();
        server = new RestBuilder().buildServer("http://0.0.0.0:6786", Arrays.asList(notifyResource));
        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                server.stop();
            }
        });
    }

    public static void main(String[] args) throws InterruptedException {
        RestmcuServerSample restmcuSample = new RestmcuServerSample();

        Destination dest = restmcuSample.server.getDestination();

        JettyHTTPDestination jettyDestination = JettyHTTPDestination.class.cast(dest);
        ServerEngine engine = jettyDestination.getEngine();
        JettyHTTPServerEngine serverEngine = JettyHTTPServerEngine.class.cast(engine);
        org.eclipse.jetty.server.Server httpServer = serverEngine.getServer();

        httpServer.join();
    }
}
TOP

Related Classes of org.housecream.restmcu.it.RestmcuServerSample

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.