Is there an equivalent for Spy++ for java swing applications?
I work with a third party application that contains a huge number of screens that get invoked via a reflection based mechanism.
Whenever an issue occurs the only way to locate the problem code is to search through the source (we have access to the source but cannot fix and deploy due to contractual obligations) for a specific string sequence that occurs on the window in question. eg if I see the string "XYZ" on the buggy window I have to search against the source for that string to locate the java file in which the bug exists.
Is there a tool that will let me, at runtime, point to a Swing screen and return the class from which the screen is generated?
Have you tried using Swing Explorer? It is more or less meant for similar tasks. I'm unaware of whether it will display the actual class that contains the component, but it certainly is capable of displaying the component hierarchy. You might want to check the ability to obtain the addition trace which contains the stack trace of the events leading to the component's addition to the tree.
Related
I have noticed that when I create a new thread using the request thread factory provided by GAE then the new thread has the same Environment as the parent thread. (The identityHashCode of the current environment is the same in both threads.)
On the one hand, this is nice because the newly created thread starts with the same context as the parent.
The problem is that the Environment is not immutable. It contains the ".currentNamespace" attribute which is used in namespace handling. If one of the threads changes the current namespace it is applied on all threads which is clearly not what I want.
My idea to fix this was that I created an own Environment implementation and when a new thread is created I copy the content of the current environment into this new environment and set this environment as current on the new thread. So the new thread starts with the same context but it can independently change later.
This solution worked during initial testing but then I run into a problem
Caused by: java.lang.ClassCastException: MyEnvironmentImplementation cannot be cast to com.google.apphosting.runtime.ApiProxyImpl$EnvironmentImpl
at com.google.apphosting.runtime.ApiProxyImpl.log(ApiProxyImpl.java:67)
I have no access to the code of com.google.apphosting.runtime.ApiProxyImpl but it is clear that this method tries to cast the interface it received into its own implementation class without checking the type.
I find this strange because there is a void setEnvironmentFactory(ApiProxy.EnvironmentFactory factory) in the ApiProxy so it is expected that someone might use a different implementation of the Environment interface than the default one.
Is there another way to use different namespaces in different request threads?
Is this unchecked casting considered a bug or is it fundamentally wrong to use my own Environment implementation?
I use app engine standard with 1.9.84 of the java sdk.
Edit:
It is actually documented that "This should not be used from user-code." on the
ApiProxy.setEnvironmentForCurrentThread() and ApiProxy.setEnvironmentFactory() methods. So my suggested workaround is not expected to work. You shouldn't try something like it either.
No need to use Google API threads. Do not let Google API's cause you problems. Do this yourself outside of the browser as I describe here.
Write a program that sub-classes your browser, and subclass each window that is opened. Then run a javascript on each page that saves your result to the location bar where it is easy to collect it later. Then collect that information from the location bar and then put the previous (which was in the location bar) back into it so that it will be seen as being the same as it was before.
If you want to use that data in a different web page then put it there via your separate program.
Each opened browser window could theoretically be running a separate google api process.
With your program subclassing all of the browser windows separately, have your program to share information between them without the google api getting confused.
Like this:
Write a program (in VB6 sp5 I did this years ago. Never use any later version of Visual Studio for anything. In C++11 this should work.).
Using FireFox as a browser for this example.
(1) Have your program start and Subclass FireFox.
(2) Have your program tell Firefox to open up a new window (might need to make this a FireFox "new tab" or maybe not).
(3) Tell your program to get the pre-handle of the newly opening window. Do this quickly and keep trying (up to 30 seconds if you have an overloaded operating system) until you get the pre-handle, then assign a new Window's handle to that new window or new tab.
(4) Use that new handle and send a javascript to the address bar (minus the "j"), meaning that you send an entire "avascript..." to that address bar, then add the previous "j" since if FireFox detects that you placed any command into the addressbar with the entire word "javascript" it will stop you from doing some things (if I recall correctly).
(5) Run that javascript obtaining from or placing into each page your changes.
(6) The web pages in the browser, having the javascript running in them do part of the work.
(7) No need to use Google API threads.
I am dealing with a peculiar issue.
After spying on a Java GUI that I have made (this might be important or it might not!), I am able to highlight correctly the components of the window.
But when I close the window and then open it again, it fails twice to highlight any component and then it highlights them correctly from that point on.
In order to spy on the elements I have used the Java Mode (I assume that this based on the Java Access Bridge).
Also, when I try to Open Application Navigator, but that also failed, although I have pasted the related files from the java access bridge.
It is really weird and there seems to be no easy answer for my problem.
This is not something specific to Java, and is observed for many applications. Check whether the application needs to load some data from a backend server to function properly. The UI elements of the application might get loaded quickly, however some their attributes might still be loading from a backend server, and until it is full loaded the attributes would not match with the values you captured.
Is it possible in java to get text from a tooltip in a gui that I didnt make. For example, I may be in a web browser or on a desktop application with my java program running in the background. I want to get any tooltip info that pops up (at anytime) and return it to the java program.
Just to clarify i'm not asking about how to create tooltips or get tooltip data in gui I make only tooltips that appear in other 3rd party software. Thanks.
The Tooltip Text has to be "somewhere" in the software. "Somewhere" can be a handful of different places, depending on how the software is built and distributed:
String literals in the sourcecode (and thus in the bytecode, too), this often happens to non-internationalized programs
resource bundles, i.e. the Strings are externalized from the source code into a separate file (usually one per supported UI-language)
If the software is distributed as *.jar-File, use your favorite unzip-software to decompress is (when in doubt, use 7zip).
Look around for *.properties-files, these may contain the resource bundles (= collection of UI-text-Strings) you are looking for.
If you can't find resource bundles, the Tooltip Text is probably hidden in String literals directly in the bytecode. Use something like strings(1) on *nix-ish platforms (no link for this one, seems I can only post 2 links) or Strings on Windows to extract the printable Strings from the *.class-files.
Note that you might find lots of printable Strings in there, so you might want to filter them using a suitable regular expression.
I'm working with a legacy Java app that is new to me so one way to figure out how it works and find things easier, I have thought would be to be able to get the full stack trace after I perform actions, so as to be able to see which classes are being used based on a particular UI action. I had thought this was possible in the debugger but it seems that it only works if I insert a breakpoint and in this case part of the purpose of this is so that I don't have to know what's being called to be able to insert the breakpoint first (as this would help tell me that).
I apologize if this is a basic question, I have searched on this but I'm not finding the correct answer.
This doesn't directly answer your question, but maybe it will solve your problem better. Take a look at BTrace. It lets you instrument a running Java app and insert some basic code of your own. You could, for instance, have it write out entire method call chains to help you find your way through the app. It's somewhat similar to AspectJ, but with an entirely different purpose and requiring no change in the project source:
"BTrace is a safe, dynamic tracing tool for Java. BTrace works by dynamically (bytecode) instrumenting classes of a running Java program. BTrace inserts tracing actions into the classes of a running Java program and hotswaps the traced program classes."
A few suggestions:
Some profilers will allow you to walk from any particular method up (and sometimes down) to see what's calling and being called. I've found this surprising informative about flow, even in apps I thought I knew well.
For understanding the mainline flow, I don't think there's a better substitute for working interactively with a debugger. It will lead you into learning other important things. Not what you wanted to hear, I know. This presumes that you can rapidly restart the app when you miss a key off-ramp.
Reverse-designing large legacy apps is the one place where I use UML fairly regularly. There's too much to keep in my head to form a good big picture. If you have a UML tool that will do reverse-engineering, load it up with the app, then probably prune down hard on the classes you don't care about, because they are trivial or obvious. Arrange the diagrams in a way that helps you understand. I've used Together, Magic Draw, and Visual Paradigm in this way. Together worked the best - but it was a decade ago.
When you are in the debugger perspective, you will see a view showing the launched processes. In that view you can tell it to pause all threads of a process. Once stopped, you will be able to browse through threads to see what they are all doing. To try to catch what a particular action is doing, you would have to start the action and then quickly pause all threads.
You could always run the application with the VM arg of -verbose:class. You could then watch the console output and see what classes the VM is loading when you perform a particular action. This could possibly give you a starting place for where to place breakpoints. This won't always work depending on the scenario, but may be helpful.
Another trick you can use is to figure what classes you know that have to be involved in the code path you are trying to trap. For instance, you mentioned that it's a Java EE web app and therefore the action is likely some kind of a servlet interaction (at some level). I don't have the API in front of me, but you can place a breakpoint on the method in the response object where the output stream is retrieved. Once that breaks, you will know the code that's trying to service the request.
You can always see where a method is called by clicking "Open Call Hierarchy" from eclipse (left click on the selected method or CTRL+ALT+H ). Also, you always can inspect where a method/class is defined by clicking "Open Declaration" (left click on the selected method/class or F3).
I'm creating a Win32 application that controls another application which is coded in Java using AWT components. I figured that if I can retrieve the main List of the application and cast it with the JLIB library I'd be able to read its content.
First of all, am I right or I won't be able to get the real content of the List ? If I'm right I'd like to know how to achieve this since I didn't found any good spy software for Java and Spy++ only show a SunAwtComponent. Which I presume in the container for the whole Java application.
I'm not expecting someone to tell me how to do the whole thing but only a couple of direction would be really great since I've been looking for that for a while now.
Thanks for the replies !!!
Quite likely the Java application actually uses Swing, not AWT. Swing draws its own widgets on top of a single AWTComponent, so the list widget that you see doesn't exist from Windows point of view.
I assume you cannot modify this Java application so that it can be controlled over some reasonable API (e.g. JMX or REST)?
You can try running the JVM with JPDA debugging interface enabled. You can then use JPDA APIs to change data structures and directly call methods on any object in that program. Finding the right ones to call will be hard, though.
See http://download.oracle.com/javase/6/docs/jdk/api/jpda/jdi/index.html