Reputation: 518
I am getting below error when I try starting Grizzly server from Java code. Please help.
javax.ws.rs.ProcessingException: Failed to start Grizzly HTTP server: Cannot assign requested address: bind at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory.createHttpServer(GrizzlyHttpServerFactory.java:299) at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory.createHttpServer(GrizzlyHttpServerFactory.java:119) at org.alm.TestClient.setUp(TestClient.java:40) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80) at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:525) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:202) at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:130) at
org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:173)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:105) at org.testng.TestRunner.runWorkers(TestRunner.java:1178) at org.testng.TestRunner.privateRun(TestRunner.java:757) at org.testng.TestRunner.run(TestRunner.java:608) at org.testng.SuiteRunner.runTest(SuiteRunner.java:334) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291) at org.testng.SuiteRunner.run(SuiteRunner.java:240) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1158) at org.testng.TestNG.runSuitesLocally(TestNG.java:1083) at org.testng.TestNG.run(TestNG.java:999) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76) Caused by: java.net.BindException: Cannot assign requested address: bind at sun.nio.ch.Net.bind0(Native Method)
Code
@BeforeClass
public void setUp() throws Exception
{
final ResourceConfig rc = new ResourceConfig(AlmApiStub.class);
System.out.println(config.host()+config.port());
server = GrizzlyHttpServerFactory.createHttpServer(
URI.create(String.format("https://%s:%s/", config.host(), config.port())), rc);
}
Upvotes: 1
Views: 2509
Reputation: 297
I just experienced this error but for a different reason: DNS.
TLDR: verify your host maps to your machine.
I configured my service to run using www.sample.com [use your hostname] but it was mapped to a different machine's IP address. While I had mapped it in the host file it wasn't being honored. That is a mystery for a different day. When I changed the hostname to test.sample.com and verified it mapped to localhost I was able to bind to the address:port I wanted.
Upvotes: 0
Reputation: 31437
javax.ws.rs.ProcessingException: Failed to start Grizzly HTTP server: Cannot assign requested address: bind at
Make sure, there aren't any application running on same machine, using same port i.e. 8443
. Because Grizzly would be trying to acquire same port, but it might be held-up by another application on same machine. Alternatively, you could try assigning different port.
Upvotes: 2