Hello there,
after an export and several attempts to import my realm to another docker container I decided to write here a post and ask for help.
I used to have a docker container with configured Keycloak realm which I was using. I exported my configuration and wanted to create a new one. (Docker)
I tried it with docker-compose so in my environment configuration I’ve added
KEYCLOAK_IMPORT=path/to/file.json
and ran it up. I ended with an error:
Unable to import realm test from file.
My first thoughts were that I did something wrong so I looked up at the docs (on hub.docker) and realised that there is a way to do it manually by standalone.sh. I also tried it with no success.
INFO [org.keycloak.exportimport.dir.DirImportProvider] (ServerService Thread Pool -- 70) Importing from directory /opt/jboss/keycloak/imports/keycloak-export/test-realm.json
ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 70) MSC000001: Failed to start service jboss.deployment.unit."keycloak-server.war".undertow-deployment: org.jboss.msc.service.StartException in service jboss.deployment.unit
."keycloak-server.war".undertow-deployment: java.lang.RuntimeException: RESTEASY003325: Failed to construct public org.keycloak.services.resources.KeycloakApplication()
Also when I got my fresh keycloak installation with master realm, import in panel does not work for my export. It does work when I create a new realm with name of the realm I would like to import and import it in there.
What also should be mentioned that while importing an existing realm the console says that it’s about to delete the existing one and afterwards fails.
Has somebody faced similar issue and got a fix for this?
I assume you both meant the last comment from @Robinyo.
I saw it before posting mine, well I tried it today again and it’s not working.
What I did:
started a container with keycloak (my previous one)
entered my container with keycloak (docker exec)
exported data from keycloak to keycloak-export.json (standalone)
copied json from container to my local directory (docker cp)
added volume in my docker-compose to keycloak
started my second container with keycloak (docker-compose)
entered my fresh created container with keycloak (docker exec)
executed import method as described in the given thread (standalone)
Errors:
[org.keycloak.exportimport.util.ImportUtils] (ServerService Thread Pool – 59) Realm ‘master’ already exists. Removing it before import
ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool – 59) MSC000001: Failed to start service jboss.deployment.unit.“keycloak-server.war”.undertow-deployment: org.jboss.msc.service.StartException in service jboss.deployment.unit.“keycloak-server.war”.undertow-deployment: java.lang.RuntimeException: RESTEASY003325: Failed to construct public org.keycloak.services.resources.KeycloakApplication()
ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation (“add”) failed - address: ([(“deployment” => “keycloak-server.war”)]) - failure description: {“WFLYCTL0080: Failed services” => {“jboss.deployment.unit."keycloak-server.war".undertow-deployment” => “java.lang.RuntimeException: RESTEASY003325: Failed to construct public org.keycloak.services.resources.KeycloakApplication()
Caused by: java.lang.RuntimeException: RESTEASY003325: Failed to construct public org.keycloak.services.resources.KeycloakApplication()
Caused by: java.lang.NullPointerException”}}
INFO [org.jboss.as.server] (Thread-1) WFLYSRV0220: Server shutdown has been requested via an OS signal
INFO [org.wildfly.extension.undertow] (MSC service thread 1-4) WFLYUT0004: Undertow 2.0.27.Final stopping
INFO [org.jboss.as.server.deployment] (MSC service thread 1-1) WFLYSRV0028: Stopped deployment keycloak-server.war (runtime-name: keycloak-server.war) in 209ms
ERROR [org.jboss.as.server] (ServerService Thread Pool – 43) WFLYSRV0021: Deploy of deployment “keycloak-server.war” was rolled back with the following failure message:
{“WFLYCTL0080: Failed services” => {“jboss.deployment.unit."keycloak-server.war".undertow-deployment” => “java.lang.RuntimeException: RESTEASY003325: Failed to construct public org.keycloak.services.resources.KeycloakApplication()
Caused by: java.lang.RuntimeException: RESTEASY003325: Failed to construct public org.keycloak.services.resources.KeycloakApplication()
Caused by: java.lang.NullPointerException”}}
I’ll include my docker-compose in case that I did something something wrong here:
You need to provide the commands that you executed (rather than just describing what you think you did). The following steps (with the actual commands) worked for me.
I think that I’m facing the same issue, but I noticed that the problem can be at the export step, instead of the import.
Can you verify if the file generated by the export command really contains the realm that you’re looking for?
In my case, the command that you used to export your data only exports de master realm and in a invalid format. When I tried to export only the relevant realm. I used this command:
ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([("subsystem" => "microprofile-metrics-smallrye")]): java.lang.NullPointerException
at org.wildfly.extension.microprofile.metrics-smallrye@18.0.1.Final//org.wildfly.extension.microprofile.metrics.MicroProfileMetricsSubsystemAdd$2.execute(MicroProfileMetricsSubsystemAdd.java:86)
at org.jboss.as.controller@10.0.3.Final//org.jboss.as.controller.AbstractOperationContext.executeStep(AbstractOperationContext.java:999)
at org.jboss.as.controller@10.0.3.Final//org.jboss.as.controller.AbstractOperationContext.processStages(AbstractOperationContext.java:743)
at org.jboss.as.controller@10.0.3.Final//org.jboss.as.controller.AbstractOperationContext.executeOperation(AbstractOperationContext.java:467)
at org.jboss.as.controller@10.0.3.Final//org.jboss.as.controller.OperationContextImpl.executeOperation(OperationContextImpl.java:1413)
at org.jboss.as.controller@10.0.3.Final//org.jboss.as.controller.ModelControllerImpl.boot(ModelControllerImpl.java:521)
at org.jboss.as.controller@10.0.3.Final//org.jboss.as.controller.AbstractControllerService.boot(AbstractControllerService.java:472)
at org.jboss.as.controller@10.0.3.Final//org.jboss.as.controller.AbstractControllerService.boot(AbstractControllerService.java:434)
at org.jboss.as.server@10.0.3.Final//org.jboss.as.server.ServerService.boot(ServerService.java:435)
at org.jboss.as.server@10.0.3.Final//org.jboss.as.server.ServerService.boot(ServerService.java:394)
at org.jboss.as.controller@10.0.3.Final//org.jboss.as.controller.AbstractControllerService$1.run(AbstractControllerService.java:374)
at java.base/java.lang.Thread.run(Thread.java:834)
Can you verify if you’re not facing the same issue?
it still does not work and throws the same errors as already posted.
What is also a weird behaviour the exported file can not be imported in the web interface. It only works when I manually create realm with the same name and then import the exported data.
Maybe the problem is something else entirely. When trying to do the same as you, importing a single JSON file containing the master realm and other I get the following fatal error earlier than the one you mentioned.
FATAL [org.keycloak.services] (ServerService Thread Pool – 70) java.lang.RuntimeException: Failed to parse json
The export JSON file is valid but maybe Keycloak can’t import a single file with multiple realms?
I am running 9.0.0.
UPDATE Import/export multiple realms which contains master
The following works for me, I needed to add - Dkeycloak.profile.feature.upload_scripts=enabled
Keycloak uses it’s own API to upload the files and then import them
I’ve executed your commands and for me there’s also missing:
-Djboss.socket.binding.port-offset=100
because of
Failed to start service org.wildfly.undertow.listener.default: org.jboss.msc.service.StartException in service org.wildfly.undertow.listener.default: Address already in use /127.0.0.1:8080
The export action was sucessfull as always - both methods tested singleFile and dir.
There was no problem with json format in my case.
07:11:37,341 INFO [org.keycloak.exportimport.dir.DirImportProvider] (ServerService Thread Pool – 63) Importing from directory /opt/jboss/keycloak/imports/export-dir
07:11:37,831 INFO [org.keycloak.services] (ServerService Thread Pool – 63) KC-SERVICES0030: Full model import requested. Strategy: OVERWRITE_EXISTING
07:11:38,100 INFO [org.keycloak.exportimport.util.ImportUtils] (ServerService Thread Pool – 63) Realm ‘master’ already exists. Removing it before import
07:11:40,395 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool – 63) MSC000001: Failed to start service jboss.deployment.unit.“keycloak-server.war”.undertow-deployment: org.jboss.msc.service.StartException in service jboss.deployment.unit.“keycloak-server.war”.undertow-deployment: java.lang.RuntimeException: RESTEASY003325: Failed to construct public org.keycloak.services.resources.KeycloakApplication()
at org.wildfly.extension.undertow@18.0.1.Final//org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:81)
Caused by: java.lang.NullPointerException
at org.keycloak.keycloak-services@8.0.2//org.keycloak.url.DefaultHostnameProvider.resolveUri(DefaultHostnameProvider.java:83)
Are you by any chance trying to upgrade for an older version.
According to the release notes and upgrade notes there was a change in the hostname provider. https://www.keycloak.org/docs/latest/upgrading/#new-default-hostname-provider
Just throwing some ideas here now, check you standalone-ha.xml for spi name=“hostname” and see if that complies with the new ones if you are upgrading.
@zonaut, that was a clean installation from a docker image.
I searched the web for something similar, even went through jira tickets but haven’t found anything about it. (I must be blind, because you found something :D)
It was a search on org.keycloak.url.DefaultHostnameProvider.resolveUri(DefaultHostnameProvider that brought me there, I wouldn’t have found it otherwise
11:38:48,752 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([("subsystem" => "microprofile-metrics-smallrye")]): java.lang.NullPointerException
at org.wildfly.extension.microprofile.metrics-smallrye@19.1.0.Final//org.wildfly.extension.microprofile.metrics.MicroProfileMetricsSubsystemAdd$2.execute(MicroProfileMetricsSubsystemAdd.java:86)
at org.jboss.as.controller@11.1.1.Final//org.jboss.as.controller.AbstractOperationContext.executeStep(AbstractOperationContext.java:999)
at org.jboss.as.controller@11.1.1.Final//org.jboss.as.controller.AbstractOperationContext.processStages(AbstractOperationContext.java:743)
at org.jboss.as.controller@11.1.1.Final//org.jboss.as.controller.AbstractOperationContext.executeOperation(AbstractOperationContext.java:467)
at org.jboss.as.controller@11.1.1.Final//org.jboss.as.controller.OperationContextImpl.executeOperation(OperationContextImpl.java:1413)
at org.jboss.as.controller@11.1.1.Final//org.jboss.as.controller.ModelControllerImpl.boot(ModelControllerImpl.java:527)
at org.jboss.as.controller@11.1.1.Final//org.jboss.as.controller.AbstractControllerService.boot(AbstractControllerService.java:515)
at org.jboss.as.controller@11.1.1.Final//org.jboss.as.controller.AbstractControllerService.boot(AbstractControllerService.java:477)
at org.jboss.as.server@11.1.1.Final//org.jboss.as.server.ServerService.boot(ServerService.java:448)
at org.jboss.as.server@11.1.1.Final//org.jboss.as.server.ServerService.boot(ServerService.java:401)
at org.jboss.as.controller@11.1.1.Final//org.jboss.as.controller.AbstractControllerService$1.run(AbstractControllerService.java:416)
at java.base/java.lang.Thread.run(Thread.java:834)
I confirm that even with the latest 12.0.4 Docker image, the realm import using env var REALM_IMPORT is no only not working but prevent Keycloak from starting.
Yeah it just doesn’t work in 12.0.4 here as well.
Export works fine but import doesn’t work at all, and yes i tried everything i read on the whole internet and i still get Java NullPointerException