Сбой библиотеки ключей Java в файле JAR - PullRequest
0 голосов
/ 02 октября 2018

У меня есть небольшой веб-клиент, который выглядит примерно так:

public static void main(String[] args) {
    Keycloak keycloak = KeycloakBuilder.builder() //
            .realm("VertxTestRealm") //
            .serverUrl("http://localhost:8085/auth")//
            .clientId("VertxTestClient") //
            .clientSecret("f230275b-61e8-4d5f-8bbd-276a77a1d5f1") //
            .username("MyUsername") //
            .password("MyPassword") //
            .grantType(OAuth2Constants.PASSWORD).build();

    AccessTokenResponse tokenResponse = keycloak.tokenManager().getAccessToken();
    String token = tokenResponse == null ? null : tokenResponse.getToken();
    System.out.println(token);
}

Этот код прекрасно работает, когда в Eclipse выполняется исключение.Однако, когда я создаю JAR-файл, я получаю следующее исключение:

javax.ws.rs.ProcessingException: RESTEASY004655: Unable to invoke request
            at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:321)
            at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:439)
            at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invokeSync(ClientInvoker.java:148)
            at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:112)
            at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:76)
            at com.sun.proxy.$Proxy10.grantToken(Unknown Source)
            at org.keycloak.admin.client.token.TokenManager.grantToken(TokenManager.java:89)
            at org.keycloak.admin.client.token.TokenManager.getAccessToken(TokenManager.java:69)
            at ChangeService.Verticle.retrieveJWT(Verticle.java:47)
            at ChangeService.Verticle.start(Verticle.java:23)
            at io.vertx.core.impl.DeploymentManager.lambda$doDeploy$8(DeploymentManager.java:483)
            at io.vertx.core.impl.ContextImpl.lambda$wrapTask$2(ContextImpl.java:339)
            at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
            at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
            at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:463)
            at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:886)
            at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
            at java.lang.Thread.run(Unknown Source) 
Caused by: javax.ws.rs.ProcessingException: RESTEASY003215: could not find writer for content-type application/x-www-form-urlencoded type: javax.ws.rs.core.Form$1
            at org.jboss.resteasy.core.interception.ClientWriterInterceptorContext.throwWriterNotFoundException(ClientWriterInterceptorContext.java:40)
            at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.getWriter(AbstractWriterInterceptorContext.java:146)
            at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:121)
            at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.writeRequestBody(ClientInvocation.java:394)
            at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.writeRequestBodyToOutputStream(ApacheHttpClient4Engine.java:666)
            at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.buildEntity(ApacheHttpClient4Engine.java:631)
            at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.loadHttpMethod(ApacheHttpClient4Engine.java:509)
            at org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine.invoke(ApacheHttpClient4Engine.java:310)
            ... 17 more

Мой pom.xml выглядит так:

<dependencies>
  <dependency>
    <groupId>org.keycloak</groupId>
    <artifactId>keycloak-admin-client</artifactId>
    <version>4.5.0.Final</version>
  </dependency>
  <dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-client</artifactId>
    <version>3.6.1.Final</version>
  </dependency>
  <dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jackson2-provider</artifactId>
    <version>3.6.1.Final</version>
  </dependency>
</dependencies>

<build>
  <plugins>
    <plugin>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.3</version>
      <configuration>
        <source>1.8</source>
        <target>1.8</target>
      </configuration>
    </plugin>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-shade-plugin</artifactId>
      <version>2.3</version>
      <executions>
        <execution>
          <phase>package</phase>
          <goals>
            <goal>shade</goal>
          </goals>
          <configuration>
            <filters>
              <filter>
                <artifact>*:*</artifact>
                <excludes>
                  <exclude>META-INF/*.SF</exclude>
                  <exclude>META-INF/*.DSA</exclude>
                  <exclude>META-INF/*.RSA</exclude>
                </excludes>
              </filter>
            </filters>
            <transformers>
              <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                <manifestEntries>
                  <Main-Class>playarounds.ServiceMainClass</Main-Class>
                </manifestEntries>
              </transformer>
            </transformers>
            <artifactSet/>
            <outputFile>${project.build.directory}/${project.artifactId}-${project.version}-fat.jar</outputFile>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

1 Ответ

0 голосов
/ 09 октября 2018

Я нашел решение своей проблемы.

См. Ответ на этот вопрос: провайдеры resteasy отсутствуют после пакета mvn

...