Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 19:57
    mbhave demilestoned #21903
  • 19:57
    mbhave milestoned #21903
  • 19:57
    mbhave demilestoned #24308
  • 19:57
    mbhave milestoned #24308
  • 19:57
    mbhave closed #24308
  • 19:57

    mbhave on master

    Correct external application pr… (compare)

  • 19:53
    mbhave labeled #24308
  • 19:00
    scottfrederick labeled #24324
  • 19:00
    scottfrederick unlabeled #24324
  • 19:00
    scottfrederick closed #24324
  • 19:00
    scottfrederick commented #24324
  • 18:00
    spring-issuemaster labeled #24325
  • 17:56
    dreis2211 opened #24325
  • 17:30
    mbhave assigned #24308
  • 16:58
    mbhave milestoned #24319
  • 16:58
    mbhave labeled #24319
  • 16:58
    mbhave unlabeled #24319
  • 16:58
    mbhave labeled #24298
  • 16:50
    spring-issuemaster labeled #24324
  • 16:47
    ztomic opened #24324
James Howe
@OrangeDog
:point_up: November 30, 2020 5:11 PM I'm unable to reproduce this in a standalone minimal test
molexx
@molexx
I want to catch things like NullPointerException so I can log the request, but if I add an @ExceptionHandler that accepts a RuntimeException it bypasses Spring's default handing of things like unmapped paths and unauthorised mappings, what's best practise here please?
James Howe
@OrangeDog
You can either rethrow or return a null view I think, and then it will go through the defaults
molexx
@molexx
@OrangeDog Thanks, that works, I have to specify a list of which exception types I want to log though and I can't use RuntimeException as AccessDeniedException is one of those but NoHandlerFoundException is a ServletException. I'd like to identify which exceptions have a handling/mapping to a HTTP status and which just default to 500 - its only the latter I want to log.
James Howe
@OrangeDog
See DefaultHandlerExceptionResolver
If it's just logging then it would probably be easier to use a filter, which can check the current status and recorded exception
molexx
@molexx
Thanks. I'd like to log just the unhandled ones. Extending DefaultHandlerExceptionResolver seems to get close but it doesn't handle AccessDeniedException so there may be others too.
molexx
@molexx
Actually it looks like NoHandlerFoundException doesn't even get to HandlerExceptionResolver.resolveException(). Odd because it is expecting it.
James Howe
@OrangeDog
IIRC there are ~3 handlers involved by default
And there are other filters handling things like security exceptions
So again, if you just want to log, use a Filter instead
Or, I'm pretty sure there's already a logger you can turn on
molexx
@molexx
Ah didn't realise multiple were used. Hmm I might be breaking something then by registering a somewhat-duplicate DefaultHandlerExceptionResolver.
happy to use a Filter but I only want to log unhandled errors, is there a reliable way to tell that from a Filter?
James Howe
@OrangeDog
You said you wanted the 500 ones
And again, I'm pretty sure it already logs "unhandled" errors
molexx
@molexx
Stacktraces are indeed already logged by Spring but in the case of unexpected errors (e.g. NullPointerException) I want to log other request things like path and query string and current userId from the securityContext.
I thought there would be a place to override where uncaught/unhandled errors are defaulted.
You're right that 500 will probably do though, I'll add a Filter for that. Thanks.
James Howe
@OrangeDog
Or use Elastic APM or similar
molexx
@molexx
hmmm that would be nice eventually! Luckily at the moment errors are rare, just uninfomative.
James Howe
@OrangeDog
You can add another handler at the end of the chain, but then you have to set the whole thing up manually. HandlerExceptionResolverComposite is the top-level one. But that's still below the filters, if they throw something.
molexx
@molexx

You can add another handler at the end of the chain, but then you have to set the whole thing up manually

Would @Order with a high number work to put it at the end of the existing autoconfigured ones?

molexx
@molexx
...doesn't matter as the Security exceptions are handled by a Filter not a HandlerExceptionResolver.
molexx
@molexx
Thanks @OrangeDog , Filter seems to be working OK.
James Howe
@OrangeDog

Would @Order with a high number work to put it at the end of the existing autoconfigured ones?

Perhaps. I can only see the manual setup for it, not if Boot has a bean-based one.

I think you implement WebMvcConfigurer.extendHandlerExceptionResolvers
molexx
@molexx

Ah that looks handy thanks and works but not for the security exceptions, as you said above they must be handled by filters outside of the HandlerExceptionResolvers.

Filter will have to do, thanks.

Sean Burke
@seanburke-wf
I'm a bit confused by behavior I'm seeing with SecurityContextHolder.strategyName. I have a WebSecurityConfigurerAdapter with a @PostConstruct to set strategyName to MODE_INHERITABLETHREADLOCAL. If I leave tests as they are and run tests for a single class, they all fail due to missing security context. If I remove the @PostConstruct, only tests which spawn a new thread fail. If I set strategyName in the test setup, all tests succeed. I'm unclear what could be happening to cause this behavior.
Sean Burke
@seanburke-wf
In researching, it seems the problem is that @BeforeAll runs well before the spring app is instantiated, but that makes me wonder if there's a hook I can use to run once the app is instantiated but before tests run.
James Howe
@OrangeDog
You'd want a context initialiser or event listener. Or simpler is to use @BeforeEach
vetrivel98
@vetrivel98
HI guys I am new to spring I have been developing a project with spring boot,mvc and thymeleaf template . i have been facing some problems in it can someone help me please?
If there anyone to help please notify i will explain my problem
Yann-Thomas LE MOIGNE
@yatho
Hi guys,
I would like to test my spring security configuration. I add the possibility to connect multiple ldaps servers, configures from properties. I have some difficulties to test multiple ldap server configuration. Is it possible to declare multiple embedded ldap for testing this functionnality ?
Patrice Blanchardie
@pblanchardie
Hi! In SpringBootTests, JPA/Hibernate "lazy" is ignored, everything is eagerly fetched. open-in-view is false. I'm going crazy, any clue? :D
James Howe
@OrangeDog
Are you using @SpringBootTest or one of the slices?
Patrice Blanchardie
@pblanchardie
I'm using @SpringBootTest only
Patrice Blanchardie
@pblanchardie
Solved: I added @LazyToOne(LazyToOneOption.NO_PROXY) to optional lazy @ManyToOnes (bytecode enhancement was already in place)
Jorge F. Sánchez
@jfsanchez_gitlab

Hello community, I have an issue using Spring WebClient to consume a server API which require a ssl client certificate during the SSL Handshake.
I have the 3 files, client_cert.pem,the client_cert.key and the CARoot file (root.pem). Then I created the keystore.jks file
openssl pkcs12 -export -in certs/client_cert.pem -inkey certs/client_cert.key -certfile certs/root.pem -name "my-client" -out certs/client_cert.p12
and
keytool -importkeystore -srcstoretype PKCS12 -srckeystore certs/client_cert.p12 -destkeystore keystore.jks.
From this point I build my WebClient instance like this:

private val ksKeys = KeyStore.getInstance("JKS").also {
    it.load(FileInputStream("keystore.jks"), passphrase)
}

private val kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()).also {
    it.init(ksKeys, passphrase)
}

private val sslContext = SslContextBuilder.forClient()
    .protocols("SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2")
    .trustManager(InsecureTrustManagerFactory.INSTANCE)
    .keyStoreType("JKS")
    .keyManager(kmf)
    .build()

private val httpClient = HttpClient.create()
    .secure { it.sslContext(sslContext) }

private val client = WebClient.builder()
    .clientConnector(ReactorClientHttpConnector(httpClient))
    .baseUrl(baseUrl)
    .build()

Then, when I use this WebClient instance to consume the server, I receive a WWW-Authenticate: Bearer error="invalid_client", error_description="Bad client credentials" response header,
which means the certificate credentials are wrong. But If I execute the same request but with cURL, it works curl --tlsv1.2 --tls-max 1.2 --location --request POST 'https://example.com/api/v1/token' --header 'Accept: application/json' --cert certs/client_cert.pem --key certs/client_cert.key -k
What I am doing wrong?
Do you have any advice?

Brian Clozel
@bclozel
@jfsanchez_gitlab it looks rather specific to Reactor's HttpClient (I guess you can reproduce the same issue without the WebClient being involved). Could ask in #reactor/reactor ? I don't know if HttpClient supports client certs, nor what would be the best way to troubleshoot this issue.
Jorge F. Sánchez
@jfsanchez_gitlab
@bclozel oh that's a big issue for me then :). Ok, I will ask them. Thx for your help.
songyijia
@songyijia
hello
Mukhtar Suleimenov
@makekz
Hello
I have a problem with Eureka
When pipeline is done, kubernetes upping one microservice and down old microservice. In eureka old microservice with status DOWN, but new one doesn't shows.
In service log I can see that microservice registered in Eureka.
How can I autorefresh status every 5 seconds in Eureka?
Tried
eureka.client.service-url.defaultZone=${EUREKA_HOST}
eureka.client.healthcheck.enabled=true
management.endpoint.health.show-details=always
, but it doesn't helped me
Tarun Raghunandan Kaushik
@TarunRKaushik
hello community,
I was trying to run some spring batch jobs in parallel using spring-cloud-data-flow(scdf) composed tasks. Some of the jobs return this error:
org.springframework.cloud.dataflow.rest.client.DataFlowClientException: Could not obtain last_insert_id(); nested exception is java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30000ms.
Also tried increasing hikari pool size to 20 from 10. Still giving the same error.
Mukhtar Suleimenov
@makekz
@TarunRKaushik hello I had this error when mongodb shutting down
In your case I think there is a problem with SQL connection.