Create an interface proxy that uses HTTP to communicate with the server
side object that exposes the corresponding JMX invoke operation. Any request
to this servlet receives a serialized object stream containing a
MarshalledValue with the Naming proxy as its content.
| Method from org.jboss.invocation.http.server.HttpProxyFactory Detail: |
protected void checkInvokerURL() throws UnknownHostException {
if( invokerURL == null )
{
// First check for a global bind address
String host = ServerConfigUtil.getSpecificBindAddress();
if( host == null )
{
InetAddress addr = InetAddress.getLocalHost();
host = useHostName ? addr.getHostName() : addr.getHostAddress();
}
String url = invokerURLPrefix + host + invokerURLSuffix;
setInvokerURL(url);
}
}
Validate that the invokerURL is set, and if not build it from
the invokerURLPrefix + host + invokerURLSuffix. The host value will be
taken from the jboss.bind.address system property if its a valid
address, InetAddress.getLocalHost otherwise. |
protected Invoker createInvoker() throws Exception {
checkInvokerURL();
HttpInvokerProxy delegateInvoker = new HttpInvokerProxy(invokerURL);
return delegateInvoker;
}
|
protected ArrayList defineDefaultInterceptors() {
ArrayList tmp = new ArrayList();
tmp.add(ClientMethodInterceptor.class);
tmp.add(InvokerInterceptor.class);
return tmp;
}
Build the default interceptor list. This consists of:
ClientMethodInterceptor
InvokerInterceptor |
public Element getClientInterceptors() {
return interceptorConfig;
}
|
public Class getExportedInterface() {
return exportedInterface;
}
|
public ObjectName getInvokerName() {
return jmxInvokerName;
}
|
public String getInvokerURL() {
return invokerURL;
}
|
public String getInvokerURLPrefix() {
return invokerURLPrefix;
}
|
public String getInvokerURLSuffix() {
return invokerURLSuffix;
}
|
public String getJndiName() {
return jndiName;
}
|
public Object getProxy() {
return theProxy;
}
|
public Object getProxy(Object id) {
Class[] ifaces = {exportedInterface};
ArrayList interceptorClasses = null; //defineInterceptors();
ClassLoader loader = Thread.currentThread().getContextClassLoader();
GenericProxyFactory proxyFactory = new GenericProxyFactory();
Object newProxy = null;
/*
Object newProxy = proxyFactory.createProxy(id, jmxInvokerName,
null, null, null, interceptorClasses, loader, ifaces);
*/
return newProxy;
}
|
public boolean getUseHostName() {
return useHostName;
}
|
public void setClientInterceptors(Element config) throws Exception {
this.interceptorConfig = config;
Iterator interceptorElements = MetaData.getChildrenByTagName(interceptorConfig, "interceptor");
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if( interceptorClasses != null )
interceptorClasses.clear();
else
interceptorClasses = new ArrayList();
while( interceptorElements != null && interceptorElements.hasNext() )
{
Element ielement = (Element) interceptorElements.next();
String className = null;
className = MetaData.getElementContent(ielement);
Class clazz = loader.loadClass(className);
interceptorClasses.add(clazz);
}
}
|
public void setExportedInterface(Class exportedInterface) {
this.exportedInterface = exportedInterface;
}
|
public void setInvokerName(ObjectName jmxInvokerName) {
this.jmxInvokerName = jmxInvokerName;
}
|
public void setInvokerURL(String invokerURL) {
// Replace any system properties in the URL
String tmp = StringPropertyReplacer.replaceProperties(invokerURL);
this.invokerURL = tmp;
log.debug("Set invokerURL to "+this.invokerURL);
}
|
public void setInvokerURLPrefix(String invokerURLPrefix) {
this.invokerURLPrefix = invokerURLPrefix;
}
|
public void setInvokerURLSuffix(String invokerURLSuffix) {
this.invokerURLSuffix = invokerURLSuffix;
}
|
public void setJndiName(String jndiName) {
this.jndiName = jndiName;
}
|
public void setUseHostName(boolean flag) {
this.useHostName = flag;
}
|
protected void startService() throws Exception {
/** Create an HttpInvokerProxy that posts invocations to the
externalURL. This proxy will be associated with a naming JMX invoker
given by the jmxInvokerName.
*/
Invoker delegateInvoker = createInvoker();
Integer nameHash = new Integer(jmxInvokerName.hashCode());
log.debug("Bound delegate: "+delegateInvoker
+" for invoker="+jmxInvokerName);
/* Create a binding betweeh the invoker name hash and the jmx name
This is used by the HttpInvoker to map from the Invocation ObjectName
hash value to the target JMX ObjectName.
*/
Registry.bind(nameHash, jmxInvokerName);
Object cacheID = null;
String proxyBindingName = null;
Class[] ifaces = {exportedInterface};
/* Initialize interceptorClasses with default client interceptor list
if no client interceptor configuration was provided */
if( interceptorClasses == null )
interceptorClasses = defineDefaultInterceptors();
ClassLoader loader = Thread.currentThread().getContextClassLoader();
GenericProxyFactory proxyFactory = new GenericProxyFactory();
theProxy = proxyFactory.createProxy(cacheID, jmxInvokerName,
delegateInvoker, jndiName, proxyBindingName, interceptorClasses,
loader, ifaces);
log.debug("Created HttpInvokerProxy for invoker="+jmxInvokerName
+", nameHash="+nameHash);
if( jndiName != null )
{
InitialContext iniCtx = new InitialContext();
Util.bind(iniCtx, jndiName, theProxy);
log.debug("Bound proxy under jndiName="+jndiName);
}
}
|
protected void stopService() throws Exception {
Integer nameHash = new Integer(jmxInvokerName.hashCode());
Registry.unbind(jmxInvokerName);
Registry.unbind(nameHash);
if( jndiName != null )
{
InitialContext iniCtx = new InitialContext();
Util.unbind(iniCtx, jndiName);
}
}
|