setLocation() from UI.init() method - java

Is it possible to use getPage().setLocation(...) from the init() method of UI. I have to redirect user to external site, under certain conditions. So far, it does not work (Vaadin 7.0.2).
Here is the code example:
#Override
public void init(VaadinRequest request) {
if (myCondition)
getPage().setLocation("http://www.externalsite.com");
else {
....
}
}

That's strange that it isn't working for you... setLocation is all you need. Here is a working version: VaadinLocationRedirect. mvn package will build the widgetset, mvn jetty:run will host it. Let us know what the problem was if you figure it out.

Found my problem. I used old version of WidgetSet, which was left from 6.X times, and was not re-compiled with Vaadin 7. After I fixed it - it works fine.

Looks like you can call the open( URL ) method of the Window object to open another URL in the same or a new browser window to achieve the redirection to an external site.
As an alternative you can set the exit URL for the application via application.setExitUrl() call and then close the application by calling application.close() - your application session will be closed and browser redirected to the specified address.

Related

get springboot to route to your subdomain as opposed to localhost

Let's say I have a domain "example.com". Right now, using caddy, I have configured example.com to be a proxy for a springboot application running on localhost 8080. How do you properly go to other routes within the application? For example, if I go to https://example.com/user, the url will be: example.com/user. but if I route from within the springboot app from there to /login (lets say using return new RedirectView("/login") at the end of the user route in the controller), it will redirect me instead to http:serverIpAdress:8080/login. How could I get this to route to https://example.com/login?
It is not an issue with Spring; Caddy needs to be configured properly as follows:
subdomain {
proxy / ipAddress:port {
transparent
}
}
1) be careful with the spacing in the caddyfile. I had originally tried this and it did not work, and I believe the reason is because i created the file like this:subdomain {
proxy / ipAddress:port { transparent }}
2) little bit of confusion that it did work, as from many places I have seen on the internet it appeared they removed transparent from the api

App works in debugging mode, failes when ran directly

I have a testing application written in java-selenium. This app tests e-shop whether it is possible to buy products and many other functionalities.
Few days ago, I added a new functionality that tests whether the payment was successful. In case the order was not successful, "#errorBox" is added into the URL, therefore I am checking whether the URL consists of this sequence:
public void paymentCheck() {
String URL = driver.getCurrentUrl();
if (URL.contains("#errorBox")) {
data.put("paymentFailed", "true");
} else {
data.put("paymentFailed", "false");
}
}
If there is "#errorBox", paymentFailed = true is added to the dataset. Then I check its presence:
.paymentCheck();
if (dataRow.get("paymentFailed").equals("true")) {
resultLine.addTestResultLineItem(
new TestResultLineItemMessage("ERROR: Payment declined, transaction was not accepted.").setResult(Result.FAIL)
);
driver.quit();
}
And the problem is: When debugging, the check works just fine. When the app is ran directly, test fails because the application skips setting result as FAILED and does not kill the driver either.
Any ideas what is wrong here?
Any help is appreciated,
Thanks
When in debug model, some latency insert between each step, when run directly, we should add some sleep/wait before driver.getCurrentUrl() too.
From my experience, generally payment take little long time.
The script is working fine in debug mode and is failing in normal run. This is a clear indication of latency. Include Thread.sleep(seconds) in your code. Though it is not recommended to use thread.sleep(), it is a better option, since we don't know the nature of the application. Else you can try Implicit wait or explicit wait condition in your code.

Closing an application programmatically with custom error message?

I want to close my Android application with a method, but it should be shown a custom message (which I define for myself).
everything I found yet was "How to close my application" and I got more than 10 ways to close my application but I haven't found a way to set a custom message.
At the moment if my app crashes something like this appears:
[APPNAME] has been stopped
I want something like this
Congratulations! You found a bug, please submit it.
Is there even a way to do that? All methods I found just closed all activities or just forced an unresolveable error.
I don't think you need some code from me, but if you do, tell me.
(Language should be java and javascript/jQuery should be avoided)
You could try making a static stop method:
public static void stop(String message) {
Log.d(message);
System.exit(0);
}

How do you set up a redirect from www to non-www with Play! Java 2.3 running the default server?

I recently set up a website and pushed it to production using Digital Ocean. However, I noticed that for both SEO purposes and to make Facebook Share work appropriately, I should set up my server to redirect www. requests to non-www. I'm running Play! Java 2.3 with a PostgreSQL database and the default Netty server. Any advice would be greatly appreciated.
There are lots of ways of redirecting. I wouldn't say DNS-redirects are the correct and only way of doing it, it's one way. Google is just fine with you doing a 301 redirect with Play.
Here's one way of accomplishing it with Play! filters (scala):
object NonWwwFilter extends Filter {
def apply(f:RequestHeader => Future[Result])(rh: RequestHeader): Future[Result] =
if (rh.host.startsWith("www.")) {
Future.successful(Results.MovedPermanently("https://" + rh.host.substring(4) + rh.uri))
} else {
f(rh)
}
}
The right way to do it is to do in not on the framework/webserver side, but on the DNS-server side.
You can do it in DNS-management area of GoDaddy or any other domain name registrar.

Class not getting unloaded while exiting the application(Web start)?

I am working in a client-server application(web start) which is started by url http:\[ip of server]:[port]. It loads index.html in the browser and main application pops up in another window and here we have several option to see/perform status/action.
Recently i got an issue of server status being displayed as unknown which is default, but it after loading application it should be loaded. I found the cause of it, that method to display server status being executed at start, so i use while loop to check if application loads, then i executed that method. It worked.
But if i exit the pop up(main application) and refresh the url in main browser window, application pops up successfully but without server status, There is nothing about server status. It leads me to think that while cut the pop up, serverStatus class did not unload.
I tried to learn about class loader but did not get anything and not able to find anything in application source code about loading/unloading of a class.
Could someone please guide or give reference to a study materiel that could solve my problem.
Please pardon me if i am not clear in asking the exact question and please ask if more information is required. Thanks in Advance
The changed code is here:
#Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
PrintWriter out = new PrintWriter(
new OutputStreamWriter(response.getOutputStream(), "UTF-8"));
synchronized(this){
while(!notCompleted){
Thraed.sleep(100)}
out.println("<LABEL><B>" + discoveryStatusLabel_ +
" :</B></LABEL> <SPAN ID='DiscoveryStatus'>" +
discoveryStatus_ + "</SPAN>");}
}
where i added the while loop, and notCompleted is variable to check if application loaded fully.
Note: There are more code in doGet() and synchronized block apart from this.

Categories

Resources