tyrus
  1. tyrus
  2. TYRUS-56

content root directory configuration in Server class for static content

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.0-b08
    • Fix Version/s: 1.4
    • Component/s: server
    • Labels:
      None

      Description

      Server class is also a simple web server, but I haven't found any way to map a physical directory for the virtual root path (it seems that it's only configurable the virtual "context" for the websocket services).

      I had to deal with too many classes to instantiate a web server with html documents & resources in the "root" context, and websocket services in subcontexts:

      String rootWebSocketsPath = "";   
      String rootDocDirectory = "/home/myuser/projects/websockets/tests";
      TyrusContainer tyrusContainer = new org.glassfish.tyrus.container.grizzly.GrizzlyEngine();
      TyrusServer tyrusServer = tyrusContainer.createServer(rootDocDirectory, port);
      DefaultServerConfiguration serverConfig = new DefaultServerConfiguration();
      TyrusServerContainer server = new TyrusServerContainer(tyrusServer, rootWebSocketsPath, serverConfig);
      server.publish(MyEndpoint.class);
      server.start();

      I would like that ServerContainerFactory's create method had an additional parameter for the "rootDocDirectory"
      i.e:

          /**
           * Creates a new server container based on the supplied container provider.
           *
           * @param providerClass Container provider implementation class.
           * @param rootDocDirectory Physical directory with resources for the virtual root context ("/")
           * @param contextPath URI path at which the websocket server should be exposed at.
           * @param port Port at which the server should listen.
           * @param configuration Server configuration.
           * @return New instance of {@link TyrusServerContainer}.
           */
          public static TyrusServerContainer create(Class<? extends TyrusContainer> providerClass, String rootDocDirectory, String contextPath, int port,
                                               ServerConfiguration configuration) {
              TyrusContainer containerProvider;
              try {
                  containerProvider = providerClass.newInstance();
              } catch (Exception e) {
                  throw new RuntimeException("Failed to instantiate provider class: " + providerClass.getName(), e);
              }
              return new TyrusServerContainer(containerProvider.createServer(rootDocDirectory, port), contextPath, configuration);
          }

        Activity

        Hide
        Pavel Bucek added a comment -

        fix merged to mater branch.

        now you can do something like:

                final HashMap<String, Object> properties = new HashMap<String, Object>();
                properties.put(Server.STATIC_CONTENT_ROOT, "/Users/pavel/tyrus/tyrus");
        
                final Server server = new Server(properties /*, additional params like endpoint classes etc */);
                server.start();

        there are some default values set in this simple sample, like host ("localhost") and port (8025). I can make a GET request /pom.xml and it will return the content of Tyrus main pom).

        Feel free to comment, reopen this issue or create new one if you want this feature improved.

        Show
        Pavel Bucek added a comment - fix merged to mater branch. now you can do something like: final HashMap< String , Object > properties = new HashMap< String , Object >(); properties.put(Server.STATIC_CONTENT_ROOT, "/Users/pavel/tyrus/tyrus" ); final Server server = new Server(properties /*, additional params like endpoint classes etc */); server.start(); there are some default values set in this simple sample, like host ("localhost") and port (8025). I can make a GET request /pom.xml and it will return the content of Tyrus main pom). Feel free to comment, reopen this issue or create new one if you want this feature improved.

          People

          • Assignee:
            Pavel Bucek
            Reporter:
            jmarine
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: