2

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?

fo0
  • 186
  • 4
  • 12
  • Are you sure that the password is send by `password` field and that it is **not encrypted**? The fast hint - try to set header and get page by some tool. In Linux you could use `curl` (I quickly help: http://stackoverflow.com/a/356714). – jsosnowski Sep 24 '15 at 09:29
  • This was only an example, take an attribute what you want. And there is no other option, i need to do it with Vaadin :-/ – fo0 Sep 25 '15 at 22:18
  • Was any solution found for this? I also have a use case where we need to integrate a 3rd party API and must open the link with additional parameters in the header (callback_uri, scope, etc.) The RequestHandler example I also found but doesn't forward the parameters passed the redirect (the response is sent to the redirect but a new request is then made to open the external URL, where the headers are not added.) – fakataha Feb 18 '16 at 21:25
  • I didn't found a solution till now :-/ – fo0 Feb 24 '16 at 09:28

0 Answers0