package com.dbxml.db.server.services;
/*
* dbXML - Native XML Database
* Copyright (c) 1999-2006 The dbXML Group, L.L.C.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* $Id: HTTPService.java,v 1.4 2006/02/02 19:04:15 bradford Exp $
*/
import com.dbxml.db.server.SimpleService;
import com.dbxml.db.server.dbXML;
import com.dbxml.labrador.http.HTTPServerBase;
import com.dbxml.labrador.http.NIOHTTPServer;
import com.dbxml.labrador.http.SecureHTTPServer;
import com.dbxml.labrador.http.StandardHTTPServer;
import com.dbxml.util.Configuration;
import com.dbxml.util.dbXMLException;
/**
* HTTPService is a dbXML Service wrapper around the Labrador HTTP Server.
* This means that the only type of content that can be retrieved is based
* on the web services hub.
*/
public final class HTTPService extends SimpleService {
private static final String HOST = "host";
private static final String PORT = "port";
private static final String SECURE = "secure";
private static final String KEYFILE = "keyfile";
private static final String KEYPASS = "keypass";
private static final String TRUSTFILE = "trustfile";
private static final String TRUSTPASS = "trustpass";
private static final String CLIENTAUTH = "clientauth";
private static final String BLOCKING = "blocking";
private HTTPServerBase server;
private boolean secure;
private boolean blocking;
public void setConfig(Configuration config) throws dbXMLException {
super.setConfig(config);
blocking = config.getBooleanAttribute(BLOCKING, false);
secure = config.getBooleanAttribute(SECURE, false);
if ( secure ) {
SecureHTTPServer s = new SecureHTTPServer();
s.setKeyFile(config.getAttribute(KEYFILE));
s.setKeyPass(config.getAttribute(KEYPASS));
s.setTrustFile(config.getAttribute(TRUSTFILE));
s.setTrustPass(config.getAttribute(TRUSTPASS));
s.setClientAuth(config.getBooleanAttribute(CLIENTAUTH));
server = s;
}
else if ( blocking )
server = new StandardHTTPServer();
else
server = new NIOHTTPServer();
int defaultPort;
if ( secure )
defaultPort = dbXML.DEFAULT_SSL_PORT;
else
defaultPort = dbXML.DEFAULT_PORT;
String host = config.getAttribute(HOST, dbXML.DEFAULT_HOST);
int port = config.getIntAttribute(PORT, defaultPort);
server.setHostName(host);
server.setPort(port);
}
public int start() {
server.start();
String hostName = server.getHostName();
StringBuffer sb = new StringBuffer();
sb.append("started ");
if ( hostName != null && hostName.length() > 0 )
sb.append("on "+hostName+" ");
if ( blocking )
sb.append("(Blocking) ");
sb.append("at ");
if ( secure )
sb.append("secure ");
sb.append("port "+server.getPort());
statusMsg = sb.toString();
status = STATE_STARTED;
return RESULT_OK;
}
public int stop() {
server.shutdown();
return super.stop();
}
}