Skip to content

Allow Grizzly HttpServer to have configurable portRange #3443

Open
@jerseyrobot

Description

@jerseyrobot

My use case is to simply start a GrizzlyHttpServer without knowing the port on which it will be bound, but by specifying a port range on which it should bind.

Today, here is what I'm forced to do:

HttpServer server = GrizzlyHttpServerFactory.createHttpServer(new URI("http://localhost/api"), config, false); NetworkListener grizzlyListener = server.getListener("grizzly");

// Set a range instead a single port Field portField = grizzlyListener.getClass().getDeclaredField("port");
portField.setAccessible(true);
portField.set(grizzlyListener, -1);
Field portRangeField = grizzlyListener.getClass().getDeclaredField("portRange");
portRangeField.setAccessible(true);
portRangeField.set(grizzlyListener, new PortRange(49152, 65535)); // low & high thanks to http://stackoverflow.com/a/2675399/535203 
server.start();

I think it should be easier if the port and portRange of grizzly NetworkListener fields were publicly settable.

Affected Versions

[2.22.2, 2.24, 2.23.2]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions