📄 httpjmsserver.java
字号:
/**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "Exolab" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of Exoffice Technologies. For written permission,
* please contact info@exolab.org.
*
* 4. Products derived from this Software may not be called "Exolab"
* nor may "Exolab" appear in their names without prior written
* permission of Exoffice Technologies. Exolab is a registered
* trademark of Exoffice Technologies.
*
* 5. Due credit should be given to the Exolab Project
* (http://www.exolab.org/).
*
* THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2000-2003 (C) Exoffice Technologies Inc. All Rights Reserved.
*
* $Id: HttpJmsServer.java,v 1.7 2003/09/25 12:37:56 tanderson Exp $
*/
package org.exolab.jms.server.http;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingException;
import org.exolab.jms.client.http.HttpJmsConstants;
import org.exolab.jms.client.mipc.IpcJmsConstants;
import org.exolab.jms.config.Configuration;
import org.exolab.jms.config.ConfigurationManager;
import org.exolab.jms.config.Connector;
import org.exolab.jms.config.ConnectorHelper;
import org.exolab.jms.config.ConnectorResource;
import org.exolab.jms.config.HttpConfigurationType;
import org.exolab.jms.config.ServerConfiguration;
import org.exolab.jms.config.TcpConfigurationType;
import org.exolab.jms.config.types.SchemeType;
import org.exolab.jms.server.ConnectionFactoryHelper;
import org.exolab.jms.server.JmsServerIfc;
import org.exolab.jms.server.ServerException;
/**
* This class enables clients to connect to the JMS server via
* a HTTP server.
* It must be used in conjunction with the TCP connector.
*
* @version $Revision: 1.7 $ $Date: 2003/09/25 12:37:56 $
* @author <a href="mailto:mourikis@intalio.com">Jim Mourikis</a>
*/
public class HttpJmsServer implements JmsServerIfc {
/**
* Construct a new <code>HttpJmsServer</code>
*/
public HttpJmsServer() {
}
/**
* Initialise the server
*/
public void init() throws ServerException {
HttpConfigurationType config =
ConfigurationManager.getConfig().getHttpConfiguration();
if (config.getProxyHost() != null) {
System.setProperty("http.proxyHost", config.getProxyHost());
}
if (config.hasProxyPort()) {
System.setProperty("http.proxyPort",
Integer.toString(config.getProxyPort()));
}
}
// implementation of JmsServerIfc.bindConnectionFactories
public void bindConnectionFactories(Context context)
throws NamingException, ServerException {
Configuration config = ConfigurationManager.getConfig();
// retrieve the configuration information from the configuration
// manager
ServerConfiguration server = config.getServerConfiguration();
TcpConfigurationType tcp = config.getTcpConfiguration();
String host = normalizeHost(server.getHost());
String internalHost = normalizeHost(tcp.getInternalHost());
// we need to put together a list of parameters that the
// connection factories will need to use to connect
// to this server
Hashtable env = new Hashtable();
env.put(getHttpServerProperty(), getHttpServerURL());
env.put(IpcJmsConstants.IPC_SERVER_HOST, host);
env.put(IpcJmsConstants.IPC_SERVER_PORT,
Integer.toString(tcp.getPort()));
if (internalHost != null) {
env.put(IpcJmsConstants.IPC_INTERNAL_SERVER_HOST, internalHost);
}
Connector connector = ConfigurationManager.getConnector(getScheme());
ConnectorResource resource =
ConnectorHelper.getConnectorResource(getScheme());
Class proxy;
String className = resource.getServer().getProxyClass();
try {
proxy = Class.forName(className);
} catch (ClassNotFoundException exception) {
throw new ServerException(
"Failed to locate the server proxy class: " + className);
}
ConnectionFactoryHelper.bind(
context, connector.getConnectionFactories(), proxy, env);
}
/**
* Returns the connector scheme for this server.
*/
protected SchemeType getScheme() {
return SchemeType.HTTP;
}
/**
* Returns the HTTP configuration
*/
protected HttpConfigurationType getHttpConfiguration() {
return ConfigurationManager.getConfig().getHttpConfiguration();
}
/**
* Returns the HTTP server URL property name, used in the construction
* of connection factories
*/
protected String getHttpServerProperty() {
return HttpJmsConstants.HTTP_SERVER_URL;
}
/**
* Returns the HTTP server URL, used in the construction of connection
* factories
*/
protected String getHttpServerURL() {
HttpConfigurationType config = getHttpConfiguration();
String host = config.getHost();
// NOTE: host should not be converted to an IP address
// refer to bug 806377 - HTTPS connector shouldn't convert host
// names
int port = config.getPort();
String url = getScheme() + "://" + host + ":" + port;
String path = config.getServerServlet();
if (!path.startsWith("/")) {
url += "/" + path;
} else {
url += path;
}
return url;
}
/**
* This method will normalize the host name. If the host is localhost then
* it will be converted to the corresponding IP address
*
* @param host - the raw host name
* @return the normalized IP address
*/
protected String normalizeHost(String host) {
String server = host;
// ensure that the host is not null
if (host == null) {
return host;
}
if (host.equals("localhost")) {
try {
server = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException ignore) {
// ignore
}
}
return server;
}
} //-- HttpJmsServer
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -