📄 httpjmsserverstub.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 2001,2003 (C) Exoffice Technologies Inc. All Rights Reserved.
*
* $Id: HttpJmsServerStub.java,v 1.8 2003/08/07 13:32:51 tanderson Exp $
*
* Date Author Changes
* 12 Oct 2001 mourikis Created
*/
package org.exolab.jms.client.http;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Vector;
import javax.jms.ExceptionListener;
import javax.jms.JMSException;
import org.exolab.core.http.HttpClient;
import org.exolab.jms.client.JmsConnectionStubIfc;
import org.exolab.jms.client.JmsServerStubIfc;
/**
* This class is repsonsible for opening an http connection to the server
* and creating HttpJmsConnections.
*
* @version $Revision: 1.8 $ $Date: 2003/08/07 13:32:51 $
* @author <a href="mailto:mourikis@exolab.org">Jim Mourikis</a>
* @see org.exolab.core.http.HttpClient
*/
public class HttpJmsServerStub implements JmsServerStubIfc {
/**
* The server URL
*/
private String _url;
/**
* The connection label. @todo - HttpClient doesn't appear to use this
*/
private String _label = "HttpJmsServerStub";
/**
* The exception listener is used to communicate server connection
* problems
*/
private ExceptionListener _listener = null;
/**
* Default constructor
*/
public HttpJmsServerStub() {
}
/**
* The constructor has a collection of environment variables
* which it uses to construct a connection to the remote
* server
*
* @param env the connection properties
* @throws JMSException if required connection properties aren't specified
*/
public HttpJmsServerStub(Hashtable env) throws JMSException {
_url = (String) env.get(HttpJmsConstants.HTTP_SERVER_URL);
if (_url == null) {
throw new JMSException("Required property not specified: " +
HttpJmsConstants.HTTP_SERVER_URL);
}
}
/**
* Instantiate an instance of this stub with the specified URL
*
* @param url url of the server hosting the servlet.
*/
public HttpJmsServerStub(String url) {
_url = url;
}
/**
* Create a connection to the JMS Server.
*
* @param clientId the identity of client
* @param username the client username
* @param password the client password
* @throws JMSException if the connection cannot be created
*/
public JmsConnectionStubIfc createConnection(
String clientId, String username, String password)
throws JMSException {
JmsConnectionStubIfc stub = null;
try {
Vector v = pack("createConnection", clientId, username, password);
HttpClient connection = new HttpClient(_url, _label);
connection.send(v);
String connectionId = (String) checkReply(connection,
"createConnection");
stub = new HttpJmsConnectionStub(
connection, clientId, connectionId);
} catch (IOException exception) {
throw new JMSException("Failed to create connection, URL=" +
_url + ": " + exception);
}
return stub;
}
// implementation of JmsServerStubIfc.setExceptionListener
public void setExceptionListener(ExceptionListener listener) {
_listener = listener;
}
/**
* Set the URL
*
* @param URL the webserver URL
*/
protected void setURL(String URL) {
_url = URL;
}
/**
* The the connection label
*/
protected void setLabel(String label) {
_label = label;
}
/**
* A convenience method to check the success of operations which return
* a true on sucess.
*
* @param connection the connection
* @param method The requested server function.
* @return the result of the call, or <code>null</code> if the call
* didn't return a result
* @throws JMSException for any failure.
*/
protected Object checkReply(HttpClient connection, String method)
throws JMSException {
Object result = null;
Vector v = null;
try {
v = (Vector) connection.receive();
} catch (Exception err) {
// rethrow as a JMSException
throw new JMSException("Operation " + method + " failed: " + err);
}
if (v != null) {
Boolean b = (Boolean) v.get(0);
if (!b.booleanValue()) {
if (v.get(1) instanceof JMSException) {
throw (JMSException) v.get(1);
} else {
throw new JMSException("Operation " + method +
" failed:\n" + v.get(1));
}
}
result = v.get(1);
} else {
throw new JMSException("Unknown connection error for " + method);
}
return result;
}
/**
* Pack all the data that is required by the server in a vector.
* Set the size of the vector to be exactly the right size for efficiency.
*
* @param method The function to activate on the server.
* @param id The unique client id.
* @param username
* @param password
* @return Vector The vector containing all the data.
*/
protected Vector pack(String method, String id, String username,
String password) {
Vector v = new Vector(5);
v.add("org.exolab.jms.server.mipc.IpcJmsServerConnection");
v.add(method);
v.add(id);
v.add(username);
v.add(password);
return v;
}
} //-- HttpJmsServerStub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -