/*
 * Copyright 2009-2012 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package info.joseluismartin.remoting.rmi;

import java.io.Serializable;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.springframework.remoting.rmi.RmiInvocationHandler;
import org.springframework.remoting.support.RemoteInvocationBasedAccessor;

/**
 * Aop Alliance Interceptor that delegate calls to a RmiInvocationHandler.
 *
 * @author Jose Luis Martin - (jlm@joseluismartin.info)
 */
public class RmiServiceInterceptor extends RemoteInvocationBasedAccessor 
	implements MethodInterceptor, Serializable  {
	
	private RmiInvocationHandler invocationHandler; 
	
	public RmiServiceInterceptor(RmiInvocationHandler invocationHandler) {
		this.invocationHandler = invocationHandler;
	}

	/**
	 * {@inheritDoc}
	 */
	public Object invoke(MethodInvocation invocation) throws Throwable {
		return invocationHandler.invoke(createRemoteInvocation(invocation));
	}
}

@@ -685,16 +685,49 @@
 lizable;
+%0Aimport java.rmi.RemoteException;
 %0A%0Aimport
@@ -823,16 +823,127 @@
 cation;%0A
+import org.apache.commons.lang.StringUtils;%0Aimport org.springframework.remoting.rmi.RmiClientInterceptorUtils;%0A
 import o
@@ -1072,16 +1072,17 @@
 essor;%0A%0A
+%0A
 /**%0A * A
@@ -1610,16 +1610,25 @@
 wable %7B%0A
+%09%09try %7B%0A%09
 %09%09return
@@ -1690,13 +1690,526 @@
 tion));%0A
+%09%09%7D%0A%09%09catch (RemoteException ex) %7B%0A%09%09%09%09throw RmiClientInterceptorUtils.convertRmiAccessException(%0A%09%09%09%09    invocation.getMethod(), ex, RmiClientInterceptorUtils.isConnectFailure(ex), %0A%09%09%09%09    extractServiceUrl());%0A%09%09%09%7D%0A%09%7D%0A%0A%09/**%0A%09 * Try to extract service Url from invationHandler.toString();%0A%09 * @return Service Url%0A%09 */%0A%09private String extractServiceUrl() %7B%0A%09%09String toParse = invocationHandler.toString();%0A%09%09return %09%22rmi://%22 + StringUtils.substringBefore(StringUtils.substringAfter(toParse, %22endpoint:%5B%22), %22%5D%22);%0A
 %09%7D%0A%7D%0A

Add method to extract service url