openstack4j
openstack4j copied to clipboard
Can't list networks - HTTP 406
The following snippet of code seems to stop working for me after a few runs - very odd:
final Identifier domainId = Identifier.byId("default");
final OSClient.OSClientV3 client = OSFactory.builderV3()
.endpoint("http://11.22.33.44:5000/v3")
.credentials("admin", "xx2342343242471", domainId)
.perspective(Facing.ADMIN)
.scopeToProject(Identifier.byName("admin"), domainId)
.authenticate();
client.networking().network().list().stream().map(Network::getId).forEach(System.out::println);
Exception in thread "main" ClientResponseException{message=The server could not comply with the request since it is either malformed or otherwise incorrect., status=406, status-code=NOT_ACCEPTABLE}
at org.openstack4j.core.transport.HttpExceptionHandler.mapException(HttpExceptionHandler.java:38)
at org.openstack4j.core.transport.HttpExceptionHandler.mapException(HttpExceptionHandler.java:23)
at org.openstack4j.core.transport.HttpEntityHandler.handleLessThan500(HttpEntityHandler.java:101)
at org.openstack4j.core.transport.HttpEntityHandler.handle(HttpEntityHandler.java:47)
at org.openstack4j.connectors.httpclient.HttpResponseImpl.getEntity(HttpResponseImpl.java:67)
at org.openstack4j.openstack.internal.BaseOpenStackService$Invocation.execute(BaseOpenStackService.java:225)
at org.openstack4j.openstack.internal.BaseOpenStackService$Invocation.execute(BaseOpenStackService.java:207)
at org.openstack4j.openstack.networking.internal.NetworkServiceImpl.list(NetworkServiceImpl.java:50)
at test.Main.main(Main.java:30)
Other services seem to be working perfectly - they all always return valid data. Is there some sort of rate limiting going on here?
Openstack4j version - 3.2.0 OpenStack version - Rocky
I noticed that it occurs when I have openstack4j-httpclient
in my dependencies.
is there any other solution than changing the http client? it's the only one where image upload works for me (without dumping everything to RAM :))
Exactly same for me - only openstack4j-httpclient works with Image, but than Network management is impossible.
@koztom I found a solution that works for me so far:
HttpClientFactory.registerInterceptor((httpClient, requestConfig, config) -> {
httpClient.addInterceptorFirst((HttpRequestInterceptor) (httpRequest, httpContext) -> httpRequest.removeHeaders("Accept"));
});
Should be executed before authenticating.
Thank you for this solution, however I cannot use it.
I made mistake - I meant openstack4j-http-connector
, in my case openstack4j-httpclient
is not working at all, because of jackson issue: NoSuchMethodError: com.fasterxml.jackson.databind.ObjectMapper
In dependencies I have of course proper version, exclude com.github.fge: jackson-coreutils
which required older version of jackson-databind
, but still maven additionaly downloads old version 2.3.2. Probably it is so because I'm working on Glassfish 4.1.
Edit: Ok, I moved to Glassfish 5 and your method seems working, thank you! I wouldn't have thought of it.