I am trying to implement the OAuth2 Client Credentials flow with Spring's WebClient like it's described by Baeldung (see here: https://www.baeldung.com/spring-webclient-oauth2).
When I write this line of code
ServerOAuth2AuthorizedClientExchangeFilterFunction oauth =
new ServerOAuth2AuthorizedClientExchangeFilterFunction(
clientRegistrations,
new UnAuthenticatedServerOAuth2AuthorizedClientRepository());
IntelliJ says that it doesn't know "ServerOAuth2AuthorizedClientExchangeFilterFunction".
The documentation of spring says that the package to import is as follows (see here: https://docs.spring.io/spring-security/site/docs/current-SNAPSHOT/api/org/springframework/security/oauth2/client/web/reactive/function/client/ServerOAuth2AuthorizedClientExchangeFilterFunction.html):
org.springframework.security.oauth2.client.web.reactive.function.client
I have the following dependencies concerning Spring Security OAuth2:
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.5.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-client</artifactId>
<version>5.5.1</version>
<type>pom</type>
</dependency>
When I try to manually import it, I come until here:
org.springframework.security.oauth2.client
IntelliJ suggests me a few options, but I need .web which is not listed.
Here is an image of IntelliJs suggestions
And then no suggestions for ".web.reactive.function.client".
Why doesn't this work?
Many thanks
Related
I have installed and setup graphqldgs on a spring boot project following the guide here: https://netflix.github.io/dgs/getting-started/
When i try to write a test case - following the guide here: https://netflix.github.io/dgs/query-execution-testing/ - I am unable to import one of the values, as shown below
import com.netflix.graphql.dgs.autoconfig.DgsAutoConfiguration
I cannot locate DgsAutoConfiguration. The only thing i have is an asterix (*) after dot notation below:
import com.netflix.graphql.dgs.autoconfig.
I have these graphqldgs pom dependencies below:
<dependency>
<groupId>com.netflix.graphql.dgs</groupId>
<artifactId>graphql-dgs-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.netflix.graphql.dgs</groupId>
<artifactId>graphql-dgs-platform-dependencies</artifactId>
<!-- The DGS BOM/platform dependency. This is the only place you set version of DGS -->
<version>4.9.16</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Any help is appreciated. Thanks!
I am using the following starter for Graphql integration
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphql-spring-boot-starter</artifactId>
<version>6.0.1</version>
</dependency>
I am not sure how to override the SimpleDataFetcherExceptionHandler with my own CustomExceptionHandler. The library already autowires a lot of stuff. Do I need to create a separate configuration for graphQl object? The documentation is not much helpful.
I also tried to integrate #ControllerAdvice to my Graphql java spring boot application but the errors are not matched by the exception handlers inside it. They are handled by GraphQl error handler. How does error propagates inside Graphql?
How can I change this behaviour?
I have this and it's working for me. Pretty much regular spring stuff for exception handling, but there is no #ControllerAdvice (it's kotlin btw, if you can't understand - let me know, but I think it's pretty clear even without kotlin knowledge).
import org.springframework.web.bind.annotation.ExceptionHandler
import com.oembedler.moon.graphql.boot.error.ThrowableGraphQLError
internal class GraphQLExceptionHandler {
#ExceptionHandler(AppException::class)
fun handleGenericException(ex: AppException): ThrowableGraphQLError {
return ThrowableGraphQLError(ex)
}
#ExceptionHandler(Exception::class)
fun handleGenericException(ex: Exception): ThrowableGraphQLError {
return ThrowableGraphQLError(TechnicalException())
}
}
#Configuration
internal open class GraphQLConfiguration {
#Bean
open fun graphQLExceptionHandler(): GraphQLExceptionHandler {
return GraphQLExceptionHandler()
}
}
I have quite a few dependencies tho, in case they matter here:
<graphql.version>5.4.1</graphql.version>
<graphql-datetime-spring-boot-starter.version>1.4.0</graphql-datetime-spring-boot-starter.version>
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphql-spring-boot-starter</artifactId>
<version>${graphql.version}</version>
</dependency>
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphiql-spring-boot-starter</artifactId>
<version>${graphql.version}</version>
</dependency>
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>voyager-spring-boot-starter</artifactId>
<version>${graphql.version}</version>
</dependency>
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphql-java-tools</artifactId>
<version>${graphql.version}</version>
</dependency>
<dependency>
<groupId>com.zhokhov.graphql</groupId>
<artifactId>graphql-datetime-spring-boot-starter</artifactId>
<version>${graphql-datetime-spring-boot-starter.version}</version>
</dependency>
I am a new user of log4j2. Based on Log4j2 performance tests introduction, and it may need to generate a large number of csv files for data processing. I plan to migrate a project from JUL to log4j2. This is a multi-threaded project that uses a lot of loggers. But the test results are not satisfactory . Where did I get it wrong?
the compare results
The dependency configuration is as follows:
<!-- Log4j2 api -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.11.1</version>
</dependency>
<!-- Log4j2 impl.-->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.11.1</version>
</dependency>
<!-- for Log4j2 asynchronous logging-->
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
<version>3.4.2</version>
</dependency>
<!-- for Log4j2 csvlayout-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.5</version>
</dependency>
File "log4j2.xml" has multiple similar appenders and loggers, for example:
partial configuration for log4j2.xml
Java related code is as follows:
System.setProperty("log4j2.isThreadContextMapInheritable", "true");
String renameCsvFile = new String( inputDir.getName() + StaticUtils.SEPARATOR +"log"+ StaticUtils.SEPARATOR + "rename");
ThreadContext.put("module3", renameCsvFile);
rename_logger = LogManager.getLogger("myrenamelog");
rename_logger.info("rename logging", "Timestamp","Level", "OrignalPath","RenamedPath","Status", "Message", "Layer#", "Thread#");
rename_logger.info("rename logging...", Instant.now(),"info",file.getAbsolutePath(),newName.getAbsolutePath(),"success"," ","Layer#",Thread.currentThread().getName());
I would suggest you upgrade to the latest release. Specifically, LOG4J2-2644, which was addressed in Log4j 2.12.1, should impact some of your performance times. However, as in LOG4J2-2792, some applications that rely heavily on filters might need to disable eagerly obtaining the location.
If after testing with a newer version you still have problems please create a Jira issue with Log4j. Ideally you should either provide a sample test suite to demonstrate the problem and/or a snapshot created with a profiling tool such as YourKit that can help identify the problem areas.
I have a issue to setup azure monitoring in spring boot project.
i have the error at each start:
instrumentationKey must be set to report metrics to Azure Monitor.
i have set the application.properties with the following properties:
azure.application-insights.instrumentation-key=VALID-UUID
spring.application.name=test
the dependency of the project looks like:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-spring-boot-metrics-starter</artifactId>
<version>2.1.4</version>
</dependency>
As per this https://learn.microsoft.com/en-us/azure/azure-monitor/app/micrometer-java#using-spring-2x documentation you need to add application-insights-springboot-starter as well.
Otherwise, you can set key as azuremonitor.instrumentationKey. My recommendation would be to add application-insights-springboot-starter along with azure-spring-boot-metrics-starter
Tracing by dependency
azure-spring-boot-metrics-starterazure-spring-boot-metrics-starter -->
micrometer-registry-azure-monitor -->
com.microsoft.azure:applicationinsights-core
Your error message come from AzureMonitorConfig
So I think the key be modify to
azuremonitor.instrumentationKey
Im using the Keycloak admin client (version 4.5.0.Final) and am trying to do some simple queries such as looking up a user. The client code is running in a plugin module in another java server, not standalone. The code looks like this:
...
try {
Keycloak kc = Keycloak.getInstance(URL, REALM, USER, PWD, CLIENT_ID);
UserRepresentation kcuser = kc.realm(REALM).users().get(USER).toRepresentation();
trace(String.format("Got user: %s", kcuser.toString()));
} catch (Exception e) {
trace("Error authenticating: " + e);
}
...
It creates the kc instance successfully, but barfs when trying to look up the user.
This is the error:
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)
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.$Proxy362.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 org.keycloak.admin.client.token.TokenManager.getAccessTokenString(TokenManager.java:64)
at org.keycloak.admin.client.resource.BearerAuthFilter.filter(BearerAuthFilter.java:52)
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.filterRequest(ClientInvocation.java:587)
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:436)
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.$Proxy372.toRepresentation(Unknown Source)
...
My pom has the latest dependencies and classpath seems ok, any ideas why this is not working?
<properties>
<keycloak.version>4.5.0.Final</keycloak.version>
<resteasy.version>3.6.1.Final</resteasy.version>
</properties>
<dependencies>
<dependency>
<groupId>org.keycloak</groupId>
<artifactId>keycloak-admin-client</artifactId>
<version>${keycloak.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>${resteasy.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-multipart-provider</artifactId>
<version>${resteasy.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
<version>${resteasy.version}</version>
</dependency>
</dependencies>
I noticed that during the instantiation of a new Keycloak instance, resteasy is checking here for the available providers with the help of the current thread. In version 3.9.1.Final which is currently used by the last keycloak-admin-client so far (version 11.0.0).
In my specific case we are using keycloak-admin-client in combination with graphql-java and CompletableFuture.supplyAsync for our data loaders. Which implies that in some cases, without further configuration, the current thread is not an instance of Thread but actually ForkJoinWorkerThread. Which apparently breaks the retrieval of the providers.
I am still a beginner to java so I would be glad if someone could explain why the registerProviders method does not work with a ForkJoinWorkerThread.
I learned on DZone is that JVM sizes the commonPool to two threads when you have more than 2 CPUs available. So I tried and noticed that my app works with 2 CPUs, but I have the same error (RESTEASY003215) with 3 CPUs.
My current "workaround" is to to use CompletableFuture.completedStage when loading data using the keycloak-admin-client.