0

how can I add a robots.txt file to a Vaadin application?

I found nearly nothing related, but what I found states that there is no support for such a file.

I'm using Vaadin 7.1.1 with JBoss 7.1.1 and Vaadin-CDI-Integration.


My workaround approach is: By adding RobotsUI to the project, the URL http://localhost:8080/App/robots.txt becomes accessible.

@CDIUI(value="robots.txt")
public class RobotsUI extends UI {

    @Override
    protected void init(VaadinRequest request) {
        // Send a response with mimetype 
        // `text/plain` with self defined content.
    }

}

My problem is: How can I deliver a self-edited, text/plain response?

Thanks for any help :-)

aboger
  • 2,214
  • 6
  • 33
  • 47

2 Answers2

2

I successfully published text/plain by adding a common HttpServlet to the project:

@WebServlet("/robots.txt")
public class RobotsServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.getWriter().write("Text...\n");
    }

}
aboger
  • 2,214
  • 6
  • 33
  • 47
1

Do it outside of Vaadin, register a filter before vaadin servlet and in case of robots.txt uri return your robots file. Or add some static resource serving servlet registered lets say to /static/* and bind your /robots.txt redirect with UrlRewrite.

Milan Baran
  • 4,133
  • 2
  • 32
  • 49
  • Nice idea to solve the issue outside of Vaadin. Thereupon I based my answer which in addition avoids the JAR package. Thanks! – aboger Aug 18 '13 at 20:35