diff --git a/src/de/qtc/rmg/io/Formatter.java b/src/de/qtc/rmg/io/Formatter.java index b3556b1..1502536 100644 --- a/src/de/qtc/rmg/io/Formatter.java +++ b/src/de/qtc/rmg/io/Formatter.java @@ -99,7 +99,15 @@ public void listGuessedMethods(List results) for (MethodCandidate m : methods) { - Logger.printlnMixedYellow("-->", m.getSignature()); + if (client.remoteObject instanceof SpringRemotingWrapper) + { + Logger.printlnMixedYellow("-->",SpringRemotingWrapper.getSignature(m)); + } + + else + { + Logger.printlnMixedYellow("-->", m.getSignature()); + } } Logger.decreaseIndent(); diff --git a/src/de/qtc/rmg/operations/MethodGuesser.java b/src/de/qtc/rmg/operations/MethodGuesser.java index 4058b57..d48e6f0 100644 --- a/src/de/qtc/rmg/operations/MethodGuesser.java +++ b/src/de/qtc/rmg/operations/MethodGuesser.java @@ -19,6 +19,7 @@ import de.qtc.rmg.io.Logger; import de.qtc.rmg.utils.ProgressBar; import de.qtc.rmg.utils.RMGUtils; +import de.qtc.rmg.utils.RemoteInvocationHolder; import de.qtc.rmg.utils.SpringRemotingWrapper; import de.qtc.rmg.utils.UnicastWrapper; @@ -51,6 +52,7 @@ public class MethodGuesser private List clientList; private List knownClientList; private List> candidateSets; + private List> invocationHolderSets; /** * To create a MethodGuesser you need to pass the references for remote objects you want to guess on. @@ -68,6 +70,12 @@ public MethodGuesser(UnicastWrapper[] remoteObjects, Set candid this.knownClientList = new ArrayList(); this.candidateSets = RMGUtils.splitSet(candidates, RMGOption.THREADS.getValue()); + if (SpringRemotingWrapper.containsSpringRemotingClient(remoteObjects)) + { + Set invocationHolders = SpringRemotingWrapper.getInvocationHolders(candidates); + invocationHolderSets = RMGUtils.splitSet(invocationHolders, RMGOption.THREADS.getValue()); + } + if (!RMGOption.GUESS_FORCE_GUESSING.getBool()) { remoteObjects = handleKnownMethods(remoteObjects); @@ -283,16 +291,18 @@ public List guessMethods() for (RemoteObjectClient client : clientList) { - for (Set candidates : candidateSets) + if (client.remoteObject instanceof SpringRemotingWrapper) { - if (client.remoteObject instanceof SpringRemotingWrapper) + for (Set invoHolder : invocationHolderSets) { - Map invocations = SpringRemotingWrapper.buildInvocationMap(candidates); - Runnable r = new SpringGuessingWorker(client, invocations); + Runnable r = new SpringGuessingWorker(client, invoHolder); pool.execute(r); } + } - else + else + { + for (Set candidates : candidateSets) { Runnable r = new GuessingWorker(client, candidates); pool.execute(r); @@ -422,37 +432,37 @@ private class SpringGuessingWorker implements Runnable { protected String boundName; protected RemoteObjectClient client; - protected Map invocationMap; + protected Set invocationHolders; - public SpringGuessingWorker(RemoteObjectClient client, Map invocationMap) + public SpringGuessingWorker(RemoteObjectClient client, Set invocationHolders) { this.client = client; this.boundName = client.getBoundName(); - this.invocationMap = invocationMap; + this.invocationHolders = invocationHolders; } - protected void logHit(RemoteInvocation invocation) + protected void logHit(RemoteInvocationHolder invoHolder) { - MethodCandidate existingMethod = invocationMap.get(invocation); + MethodCandidate existingMethod = invoHolder.getCandidate(); String prefix = Logger.blue("[ " + Logger.padRight(boundName, padding) + " ] "); - Logger.printlnMixedYellow(prefix + "HIT! Method with signature", existingMethod.getSignature(), "exists!"); + Logger.printlnMixedYellow(prefix + "HIT! Method with signature", SpringRemotingWrapper.getSignature(existingMethod), "exists!"); client.addRemoteMethod(existingMethod); } public void run() { - for (RemoteInvocation invocation : invocationMap.keySet()) + for (RemoteInvocationHolder invocationHolder : invocationHolders) { try { - client.unmanagedCall(SpringRemotingWrapper.getInvokeMethod(), new MethodArguments(invocation, RemoteInvocation.class)); + client.unmanagedCall(SpringRemotingWrapper.getInvokeMethod(), new MethodArguments(invocationHolder.getInvo(), RemoteInvocation.class)); /* * We always provide an invalid argument count for our SpringRemoting calls. * We should never endup here, which would indicate a successful call. */ - unexpectedError(invocation, null); + unexpectedError(invocationHolder, null); } catch (java.lang.IllegalArgumentException e) @@ -462,7 +472,7 @@ public void run() * argument count during the call. If the method exists, this leads to an IllegalArgumentException, * which is used to identify valid methods. */ - logHit(invocation); + logHit(invocationHolder); } catch (java.lang.NoSuchMethodException e) @@ -492,7 +502,7 @@ public void run() /* * If we end up here, an unexpected exception was raised that indicates a general error. */ - unexpectedError(invocation, e); + unexpectedError(invocationHolder, e); } } @@ -501,7 +511,7 @@ public void run() /* * If we end up here, an unexpected exception was raised that indicates a general error. */ - unexpectedError(invocation, e); + unexpectedError(invocationHolder, e); } finally @@ -511,12 +521,12 @@ public void run() } } - private void unexpectedError(RemoteInvocation invocation, Exception e) + private void unexpectedError(RemoteInvocationHolder invoHolder, Exception e) { String info = ""; StringWriter writer = new StringWriter(); - Logger.printlnYellow(invocationMap.get(invocation).getSignature()); + Logger.printlnYellow(invoHolder.getCandidate().getSignature()); if (e != null) { diff --git a/src/de/qtc/rmg/utils/RemoteInvocationHolder.java b/src/de/qtc/rmg/utils/RemoteInvocationHolder.java new file mode 100644 index 0000000..b2238d1 --- /dev/null +++ b/src/de/qtc/rmg/utils/RemoteInvocationHolder.java @@ -0,0 +1,62 @@ +package de.qtc.rmg.utils; + +import java.util.Arrays; + +import org.springframework.remoting.support.RemoteInvocation; + +import de.qtc.rmg.internal.MethodCandidate; + +public class RemoteInvocationHolder +{ + private RemoteInvocation invo; + private MethodCandidate candidate; + + public RemoteInvocationHolder(RemoteInvocation invo, MethodCandidate candidate) + { + this.invo = invo; + this.candidate = candidate; + } + + public boolean equals(Object other) + { + if (other instanceof RemoteInvocationHolder) + { + RemoteInvocationHolder otherInvocation = (RemoteInvocationHolder)other; + + if (otherInvocation.getName().equals(this.getName())) + { + if (Arrays.equals(otherInvocation.getTypes(), this.getTypes())) + { + return true; + } + } + } + + return false; + } + + public int hashCode() + { + return invo.toString().hashCode(); + } + + public String getName() + { + return invo.getMethodName(); + } + + public Class[] getTypes() + { + return invo.getParameterTypes(); + } + + public MethodCandidate getCandidate() + { + return candidate; + } + + public RemoteInvocation getInvo() + { + return invo; + } +} diff --git a/src/de/qtc/rmg/utils/SpringRemotingWrapper.java b/src/de/qtc/rmg/utils/SpringRemotingWrapper.java index 3b71ef0..baf4fa7 100644 --- a/src/de/qtc/rmg/utils/SpringRemotingWrapper.java +++ b/src/de/qtc/rmg/utils/SpringRemotingWrapper.java @@ -1,8 +1,7 @@ package de.qtc.rmg.utils; import java.rmi.Remote; -import java.util.HashMap; -import java.util.Map; +import java.util.HashSet; import java.util.Set; import org.springframework.remoting.support.RemoteInvocation; @@ -10,7 +9,6 @@ import de.qtc.rmg.endpoints.KnownEndpointHolder; import de.qtc.rmg.internal.ExceptionHandler; import de.qtc.rmg.internal.MethodCandidate; -import de.qtc.rmg.io.Logger; import de.qtc.rmg.operations.RemoteObjectClient; import de.qtc.rmg.plugin.PluginSystem; import de.qtc.rmg.plugin.ReturnValueProvider; @@ -112,6 +110,11 @@ public boolean isRemotingCall(MethodCandidate targetMethod) return true; } + public String getInterfaceName() + { + return remotingInterfaceName; + } + public static RemoteInvocation buildRemoteInvocation(MethodCandidate targetMethod, Object[] args) { RemoteInvocation invo = new RemoteInvocation(); @@ -149,9 +152,9 @@ public static RemoteInvocation buildRemoteInvocation(MethodCandidate targetMetho return invo; } - public static Map buildInvocationMap(Set candidates) + public static Set getInvocationHolders(Set candidates) { - Map invocationMap = new HashMap(); + Set invocationHolderSet = new HashSet(); for (MethodCandidate candidate : candidates) { @@ -162,15 +165,31 @@ public static Map buildInvocationMap(Set