1

Earlier we used to host client and service code on separate instances, let's say client code which consists of html, css, js is hosted on a S3 bucket while we'd launch a java based Beanstalk environment.

Now I've to ship both of them together to be hosted on a single machine, what's the industry standard, how should I go about it and configure web.xml or something else?

My web.xml looks like this.

<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
    <servlet>
        <servlet-name>Service</servlet-name>
        <servlet-class>com.domain.Service</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Service</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>
App2015
  • 973
  • 1
  • 7
  • 19
  • Industry using Docker to run independent applications on the same instance. – GarRudo Feb 01 '18 at 18:44
  • actually it's more of serving static content through my servlet along with web services, I may be missing the point here since I'm not much familiar with docker – App2015 Feb 01 '18 at 18:47
  • If it's a classic set up, you place your static files inside web directory along the side with WEB-INF where web.xml sits. Tomcat will pick it up. – GarRudo Feb 01 '18 at 19:00
  • I'll be sending the host the files so I've no way of testing it, I'm confused because my servlet is intercepting all requests, see `url-pattern` and I'm using `service` method in my servlet which receives all requests, will it work for static content? and will it serve index.html if a user accesses the domain name? – App2015 Feb 01 '18 at 19:05
  • This could be what you looking for https://stackoverflow.com/a/3582215/4481947 – GarRudo Feb 01 '18 at 19:15
  • thanks, could you tell me more about docker config? can different subdomains route to different applications in docker on the same instance? – App2015 Feb 01 '18 at 19:25
  • in response to linked SO answer, where this request will go to? if let's http://example.com, will it go to index.html or the servlet? – App2015 Feb 01 '18 at 19:28
  • About the Docker, yes subdomains can route to different applications, but mind that applications can't use common port. About Java Servlet, whatever you put inside web directory is used by Servlet as a content. So every incoming request to a Tomcat is going through HttpServlet. – GarRudo Feb 01 '18 at 19:45
  • so let's say api.example.org and admin.example.org can't share port 443, or is there something else to manage both? About Java Servlet, the problem is I'm manually checking for all the required REST endpoints and throwing 400 bad request if it is not matching any of this, I worry if a request for .css file goes to the servlet and it's going to end up as a bad request. – App2015 Feb 01 '18 at 19:50
  • Docker is not for routing dns, its a virtual environment for you application, for example your host instance doesnt have java 8, but application dependent on it, Docker will provide java 8 for it. Tomcat is routing your application end points to a static pages (html, jsp, xhtml, etc) and provides access to other resources (css, js, ...). Servlet is the Java abstraction for http communication with Clients,managing, filtering and processing requests and responses, linking it to your static content. You can program on top of this abstraction to add your business logic. – GarRudo Feb 01 '18 at 20:07

0 Answers0