My goal is to be able to use HttpUnit to crawl around my webpage and see what is and is not firing in the background... I have gotten it to connect to my page, and if I set
HttpUnitOptions.setLoggingHttpHeaders(true);
I see the sorts of background calls that I care about. However, I do not know how to see those interactions within the program. most of the getText and getInputStream calls fo the WebResponse object seem to just be the HTML call, and don't log the various javascript calls that fire in the background. Is there a way to get a list of all of the things going on in the background? HttpUnit's documentation seems sparse.
Thanks!
I just stumbled upon the answer. it looks like you need to make a class that implements WebClientListener, and then call wc.addClientListener(new YourListener()); where wc is a WebClient.
I don't delete this so others can see...and perhaps there is more nuance to it than that.
Related
I'm debugging a project, an online banking website backend, that uses Spring. Often, all I have to latch on to in the bug report is which buttons to click to reproduce the bug. In the browser dev console, I then see the request URL and the response. I then have to somehow find the method mapped to that URL and start debugging.
What bothers me is that Eclipse's search features(that, or my ability to use them) leave a lot to be desired. I can't seem to find the method with one particular mapping, with something like https://ourcompany.com/ourapp/delegate/rest/account/foo/info
to work with, I string-search for "/info" or "/foo" or "foo/info", and get little results. All eclipse does is find some irrelevant file containing the string and open it, and then display(collapsed) a bunch of project folders below it, which I guess also contain files with the string somewhere in them.
Is there some more streamlined way to do this? Did I leave out something small but important from the search? How do I easily find which method in mapped to an URL such as the one in the example?
You can try to set a breakpoint inside
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter
See the method
#Override
public final ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
return handleInternal(request, response, (HandlerMethod) handler);
}
here you have handler object which keeps class you need. Not sure it works in 100% cases.
Assuming you are using annotations, it should be easy to find the controller just searching the Java class files. I would start by searching for the account controller. In here, I believe you will find a method mapped to "{id}/info" which should be what you're looking for.
As a sidenote, IntelliJ may be something to look into if you're looking for a fuller feature set. I work with it daily for Java, Spring, Struts, and web files, and it does a great job indexing and finding results with ease.
I need some help understanding a piece of code found in an application developed by my company. Because it is proprietary code I am not able to post the exact snippet but I will try to explain my problem.
The application is a java ee webapp, that has a listener implemented to catch a certain type of event. All normal so far...
Here's where it gets weird. The listener, after it catches the event it's looking for, triggers the same type of event from within itself, before finishing the rest of it's instructions.
It seems to be like calling a method from withing itself, only in this case it's a listener triggering the same event it is listening for.
It doesn't work, in this specific implementation, and that's a problem.
My question is: could this actually work?
I've tried to explain as best as I could but this is a strange piece of code. I tried to make a diagram of the way it is trying to work, maybe that will be more clear than my explanation. Image link below:
Please help me understand if what this person was trying to do is actually achievable or just very bad design.
Thanks in advance!
Sounds strange. It is normal for one event listener to "respond" by sending a separate event with the result - events are one way. Look carefully at the event identification, character for character, to ensure it really does send the same event it receives. Also, trying scrubbing out any company details and provide the code.
I´m using Selenium, and I need to start testing my page not only when the page is render, but when all javascript initialization is done. I´m looking to avoid Race condition on my test because some elements are not initialized properly yet.
Simple question there´s any way to ask the DOM when all javascript render has finish?.
We know when render has done because of onDocumentReady. But then, we can start initializing some javascripts, and doing some business logic.
I want to know if there´s any mechanism to know when all javascript execution has finish.
I read the use of promise object for some async initialization, but I was looking for a more generic way to know it.
There is no generic way to know that JavaScript code has finished doing its initialization. A single page can load dozens of JavaScript libraries that can all do their own thing. Even if you can detect that an initial Ajax operation has completed, there is generally no way to know that this initial operation won't be followed by other operations that are also part of the initialization.
What you have to do is find a way to determine that, as far as your test is concerned, the page is initialized enough for the test to start. How you do this depends on the JavaScript code that is running on your page. Here's an example. For some of my applications I use DataTables to manage some of my tables. The data that appears in a table is loaded through an Ajax call. For some tests, I know that once the data is loaded, the table will have X number of rows so I wait for this many rows to appear in the table and then proceed with the test. This works for some tests. For other tests that do more complicated testing, I have to register an event handler and listen for a table redraw event before the test can proceed. If the only thing I'm testing is the table, it would be wasteful to wait until other stuff on the page has finished initializing.
I'm working on a servlet to perform some logic specific to a resourceType in sling and set information to the request to be accessible via the jsp then handing off the request to the jsp similarly to the first solution provided in this answer.
Here's some example code to represent my situation:
#SlingServlet(
resourceTypes="myapp/components/mycomponent",
methods="GET",
extensions={"html"}
)
...
#Reference
private ServletResolver serlvetResolver;
protected void doGet(....) {
setPropertiesToRequest();
Servlet servlet = servletResolver.resolveServlet(resource, "....jsp");
servlet.service(slingRequest, slingResponse);
clearPropertiesFromRequest();
}
Because of this, I've noticed that I've lost sling's selector handling (I've had to roll my own simpler version to determine which jsp to render. Full featured sling selector handling is described in more detail here). I wanted to reach out to the stack overflow community and ask what else I may be missing out on by depriving the default get handler of the request. I've scanned through the source code but I think there may be more going on.
Secondly, I'd be interested in thoughts on how and where this approach may impact performance of the request resolution.
Thanks, Thomas
Processing the business logic in Java and delegating to scripts for rendering sounds like a job for the recently released Sling Models. Using that should remove the need to implement your own handling of selectors, as those won't affect the model selection, only the rendering scripts.
Not sure what you are trying to achieve here, but the main problem seems to me that your SlingServlet handles the html extension and by itself does not have selectors to filter a bit more. Thus it of course intercepts all the requests to your component. Then you have to take care of the selectors again to be able to choose the correct JSP.
The question is, why do you use a SlingServlet for it when you anyway do the rendering by JSP?
Can't you implement your logic in the JSP or better in a bean referenced in the JSP?
In our company we use our custom tag that takes care of this, but there are public frameworks available from other Adobe Partner:
https://github.com/Cognifide/Slice
http://neba.io/index.html
We have a Struts2 application using the <sx:tabbedpanel>. I know this has since been deprecated, but we have not yet had time to replace it.
We're populating the tabs by using the <sx:div> tag and specifying the href attribute, which makes an asynchronous call to the server to populate the contents of the tab. The downside to this is that we lose validation information like <s:actionerror>.
Here's what we think is happening... when the user performs an invalid action, the action class returns validation errors. When the resulting jsp is loaded, the validation messages are available. However, the <sx:div> then makes the asynchronous call back to the server to reload the contents. This time, the action class is just loading data to display, so it doesn't generate any validation messages. The results of this ajax call are then displayed in the browser, without any validation messages.
I've seen many examples on the web of using the <sx:div> tag this way within the tabbedpanel, so I'm guessing this is a problem that has been solved before, we just haven't found it.
Does anyone know of tutorials or examples that show how to do validation in this case?
Thanks for the help, I really appreciate it.
Would it make sense to put the errors outside of the tabbedpanel like:
<s:fielderror />
<sx:tabbedpanel...>
...
</sx:tabbedpanel>
Perhaps we can assist you a bit more if you can post some sample code or provide more info as to what kind of errors are expected and what the content of the tabbed panel is.
We found that we could populate the divs by using the <s:action> tag instead. This gets rendered at the time of the initial request, it does not make an ajax call later. Therefore, the JSPs have access to the validation messages and errors.