在openfire中创建用户时遇到问题

时间:2017-11-02 12:33:54

标签: java openfire keycloak

我有以下简单的代码,当我没有依赖时

AuthenticationToken authenticationToken = new AuthenticationToken("admin", "password");
        RestApiClient restApiClient = new RestApiClient("http://192.168.20.97", 7070, authenticationToken);
        UserEntity userEntity = new UserEntity("dasddasd","dsadsadasd", "", "password");
        restApiClient.createUser(userEntity);


<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-client</artifactId>
    <version>3.1.4.Final</version>
</dependency>

当我添加上面的依赖项时,它会抛出以下错误

Exception in thread "main" javax.ws.rs.ProcessingException: RESTEASY004655: Unable to invoke request
    at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:316)
    at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:462)
    at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:498)
    at org.jboss.resteasy.client.jaxrs.internal.ClientInvocationBuilder.method(ClientInvocationBuilder.java:295)
    at org.igniterealtime.restclient.RestClient.call(RestClient.java:145)
    at org.igniterealtime.restclient.RestClient.post(RestClient.java:91)
    at org.igniterealtime.restclient.RestApiClient.createUser(RestApiClient.java:92)
    at app.Test.main(Test.java:20)
Caused by: javax.ws.rs.ProcessingException: RESTEASY003215: could not find writer for content-type application/xml type: org.igniterealtime.restclient.entity.UserEntity
    at org.jboss.resteasy.core.interception.jaxrs.ClientWriterInterceptorContext.throwWriterNotFoundException(ClientWriterInterceptorContext.java:40)
    at org.jboss.resteasy.core.interception.jaxrs.AbstractWriterInterceptorContext.getWriter(AbstractWriterInterceptorContext.java:146)
    at org.jboss.resteasy.core.interception.jaxrs.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:121)
    at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.writeRequestBody(ClientInvocation.java:390)
    at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.writeRequestBodyToOutputStream(ApacheHttpClient4Engine.java:630)
    at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.buildEntity(ApacheHttpClient4Engine.java:595)
    at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.loadHttpMethod(ApacheHttpClient4Engine.java:483)
    at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:305)
    ... 7 more

我需要以上依赖关系来在Keycloak中创建用户

2 个答案:

答案 0 :(得分:0)

您可能只需要添加以下依赖项,以便集成 jackson 框架。它将自动编组/解组JSON和XML。

<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jackson2-provider</artifactId>
    <version>3.1.4.Final</version>
</dependency>

答案 1 :(得分:0)

最终问题是XML vs JSON。如果查看RestApiClient使用的source to RestClient,它总是以XML格式发送。 Keycloak总是JSON,所以它不能谈论XML。

您似乎可以使用RestClientBuilder设置Accepts标题,但Content-Type是硬编码的。