I want to visit an external website from my Vaadin Application with modified headers.
Visiting an external Website is pretty Simple: For example:
Link link = new Link("Open", new ExternalResource("externalSite"));
But how can i add the headers to my request. In my scenario i want to open that external Site and adding the a password like "abc" to the header ... for example (its only pseudocode !!)
Link link = new Link("Open", new ExternalResource("externalSite"));
link.header("password", "abc");
link.open();
I found a possible solution in Vaadin, but i cant get it running: https://vaadin.com/forum/#!/thread/8862254/8862912
protected void init(VaadinRequest request) {
// Add a custom request handler
VaadinSession.getCurrent().addRequestHandler(new RequestHandler() {
@Override
public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response)
throws IOException {
if ("/redirect".equals(request.getPathInfo())) {
response.setStatus(307); // Temporary Redirect
response.setHeader("Location", "http://1.1.1.1");
response.setHeader("password", "abc");
return true;
}
return false;
}
});
final VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);
setContent(layout);
final Resource redirectResource = new ExternalResource("vaadin://../redirect");
// Redirect to the custom request handler using a link
Link link = new Link("Redirect", redirectResource);
layout.addComponent(link);
}
In addition i tried to use Javascript to get a rediret with modified headers:
String js = "xmlhttp.setRequestHeader(password, \"abc\");"
+ "xmlhttp.open(\"POST\", http://1.1.1.1);";
Page.getCurrent().getJavaScript().execute(js);
But nothing worked no "request" header has been set on the target external Website, ... any ideas what i do wrong?