Does anyone know the analog of swagger-doclet but which works with JDK 14?
This doclet generates swagger spec by javax.ws.rs annotations and javadocs and it doesn't require swagger annotations
For example, I have such endpoint:
/**
* Receives sync requests from the clients and puts the received event to the queue with partition key based on the user's id.
*
* #param thriftRequest user's event
* #return the number of users in the saved event.
*/
#POST
#Path("/notifications")
#Timed
public TNotificationsResponse notifications(final TNotificationsRequest thriftRequest) {
...
}
I tried swagger-core but it generates spec ignoring javadocs :(
Related
I have application.yml configuration i.e
cloud:
stream:
poller:
# Cron for polling data.
cron: 0 0/30 * * * *
........
I am facing errors like
Description:
The following configuration properties are mutually exclusive:
spring.integration.poller.cron
spring.integration.poller.fixed-delay
spring.integration.poller.fixed-rate
However, more than one of those properties has been configured at the same time:
spring.integration.poller.cron
spring.integration.poller.fixed-delay
Action:
Update your configuration so that only one of the mutually exclusive properties is configured.
Even though I haven't added fix-delay it shows that I have added it.
I saw that PollerConfigEnvironmentPostProcessor class adds fixed-delay if the property is absent. So how can I use the cron expression?
//TODO Must remain after removal of deprecated code above in the future
streamPollerProperties.putIfAbsent(INTEGRATION_PROPERTY_PREFIX + "fixed-delay", "1s");
streamPollerProperties.putIfAbsent(INTEGRATION_PROPERTY_PREFIX + "max-messages-per-poll", "1");
I have also checked with spring integration poller properties instead of spring cloud stream poller as it is deprecated but getting the same error
integration:
poller:
cron: 0 0/30 * * * *
Earlier with spring cloud version 2020.0.2, it was working fine. As soon as I update the spring cloud version to 2021.0.1, error gets started
This is bug. That:
streamPollerProperties.putIfAbsent(INTEGRATION_PROPERTY_PREFIX + "fixed-delay", "1s");
has to be conditional if there is no spring.integration.poller.fixed-delay or spring.integration.poller.cron present yet.
As a workaround I suggest to implement an EnvironmentPostProcessor like this:
public class RemoveStreamPollerEnvironmentPostProcessor implements EnvironmentPostProcessor {
#Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
environment.getPropertySources().remove("spring.integration.poller");
}
}
This way all the spring.integration.poller. properties related to Spring Cloud Stream will be removed from the environment. But those configured manually based on the spring.integration.poller. will still be present.
Therefore your:
spring:
integration:
poller:
cron: 0 0/30 * * * *
will be good.
NOTE: the EnvironmentPostProcessor has to be registered in the spring.factories.
I am using Spring Session to store the application session in an external store, in this case the Infinispan cache.
To do so, I implemented a custom SessionRepository that uses Infinispan's RemoteCacheManager underneath.
"Normal" objects from the session are stored and unmarshalled without any problem.
My application is integrated with Keycloak for SSO, using Keycloak's Spring Boot Adapter. This sets a session object of type RefreshableKeycloakSecurityContext. This is the call to save the session in the remote cache, as you can see the Refreshable... has some attributes (KeycloakDeployment, SpringSecurityTokenStore) that are set:
But when the Refreshable... attribute is retrieved from the session store, KeycloakDeployment and some other attributes are gone:
With them gone some functionality provided by the adapter such as refresh token is lost, as you can see in the next bit from Refreshable... where it needs to have a deployment:
Any idea how I could make those attributes be stored an retrieved from Infinispan?
UPDATE
RefreshableKeycloakSecurityContext defines KeycloakDeployment and AdapterTokenStore as transient, so the are not meant to be serialized. The problem with this is that it breaks the adapter when the session is extenernalized of simply serialized... any workaround?
package org.keycloak.adapters;
...
/**
* #author Bill Burke
* #version $Revision: 1 $
*/
public class RefreshableKeycloakSecurityContext extends KeycloakSecurityContext {
protected static Logger log = Logger.getLogger(RefreshableKeycloakSecurityContext.class);
protected transient KeycloakDeployment deployment;
protected transient AdapterTokenStore tokenStore;
protected String refreshToken;
There is a bug in the adapter version we are using, fixed as stated in the following Red Hat issue: https://issues.redhat.com/browse/KEYCLOAK-6752?attachmentViewMode=list
Spring Integration's FtpInboundFileSynchronizer allows for the setting of a Comparator<FTPFile> to allow ordering of the downloads. The documentation says:
Starting with version 5.1, the synchronizer can be provided with a Comparator. This is useful when restricting the number of files fetched with maxFetchSize.
This is fine for #Bean configuration:
#Bean
public FtpInboundFileSynchronizer ftpInboundFileSynchronizer(...)
FtpInboundFileSynchronizer synchronizer = new FtpInboundFileSynchronizer(sessionFactory);
...
synchronizer.setComparator(comparator);
return synchronizer;
}
But if I want to programatically assemble flows, the Java DSL is encouraged.
StandardIntegrationFlow flow = IntegrationFlows
.from(Ftp.inboundAdapter(ftpFileSessionFactory, comparator)
.maxFetchSize(1)
...
The comparator in the Ftp.inboundAdapter(...) factory method is only for the comparison of files locally, after they have been downloaded. There are configuration settings that get passed to the synchronizer here (like remote directory, timestamp, etc.). But there is no setting for the synchronizer equivalent to setting it above.
Solution attempt:
The alternative is to create the synchronizer as non-bean, create the FtpInboundFileSynchronizingMessageSource in a similar way, and use IntegrationFlows.from(source) to assemble the synchronizer results in a runtime exception when the flow is registered with the flow context:
Creating EvaluationContext with no beanFactory
java.lang.RuntimeException: No beanFactory
at org.springframework.integration.expression.ExpressionUtils.createStandardEvaluationContext(ExpressionUtils.java:90) ~[spring-integration-core-5.3.2.RELEASE.jar:5.3.2.RELEASE]
at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer.afterPropertiesSet(AbstractInboundFileSynchronizer.java:299) ~[spring-integration-file-5.3.2.RELEASE.jar:5.3.2.RELEASE]
That makes sense; the FtpInboundFileSynchronizer is not supposed to be constructed outside of a context. (Though this does appear to work.) But how, in that case, can I dynamically assemble ftp integration flows with a synchronizer configured with a Comparator<FTPFile>?
Looks like we have missed to expose that remoteComparator option in DSL.
Feel free to raise a GH issue or even contribute a fix: https://github.com/spring-projects/spring-integration/issues
As a workaround for dynamic flows, I really would suggest to go a separate FtpInboundFileSynchronizer and FtpInboundFileSynchronizingMessageSource and then use the mentioned IntegrationFlows.from(source). What you probably miss in your configuration is this API:
/**
* Add an object which will be registered as an {#link IntegrationFlow} dependant bean in the
* application context. Usually it is some support component, which needs an application context.
* For example dynamically created connection factories or header mappers for AMQP, JMS, TCP etc.
* #param bean an additional arbitrary bean to register into the application context.
* #return the current builder instance
*/
IntegrationFlowRegistrationBuilder addBean(Object bean);
I mean that FtpInboundFileSynchronizingMessageSource is OK to pass to the from() as a is, but synchronizer has to be added as an extra bean for registration.
Another more fancy way is to consider to use a new feature called DSL extensions: https://docs.spring.io/spring-integration/docs/5.3.2.RELEASE/reference/html/dsl.html#java-dsl-extensions
So, you can extend that FtpInboundChannelAdapterSpec to provide a missed option to configure for an internal synchronizer.
I want some messageId kind of thing when I am sending to Rabbit Mq Queue as I will get when sending to IBM MQ using jms. I am using spring MQ amqp starter dependency with Spring Boot. Configuration is done only in application.yml (property file). I am using Rabbit template for sending.
rabbitMqTemplate.convertAndSend(EMPTY_STRING,queueName, message, messagePostProcessor);
I have tried messagePostProcessor. Any help is appreciated. I had a look into below content. But didnt understand how to implement. Does it require special configuration (connectionfactory/ container)?
https://www.rabbitmq.com/confirms.html
Unlike JMS, the rabbit client doesn't assign message ids.
However, you can configure the RabbitTemplate's MessageConverter to create an id, which you can then retrieve with a post processor.
See AbstractMessageConverter...
/**
* Flag to indicate that new messages should have unique identifiers added to their properties before sending.
* Default false.
* #param createMessageIds the flag value to set
*/
public void setCreateMessageIds(boolean createMessageIds) {
this.createMessageIds = createMessageIds;
}
For message confirmations, see the reference manual. But that is unrelated to the message id property.
What is the difference between RestTemplate and its test version? When we do exception handling through #ControllerAdvice, RestTemplate is throwing the exception, but for same flow test version is returning json containing exception details.
So, I wanted to see the summary of differences between them.
The restTemplate give you more possibility, testRestTemplate is only a wrapper of restTemplate which offers you convenient approach, like you said, it doesn't throw exception, but wrap it with json response, such behavior should be implemented by yourself in the real application, but you may not care in the test.
here is the javadoc from testRestTemplate
/**
* Convenient subclass of {#link RestTemplate} that is suitable for integration tests.
* They are fault tolerant, and optionally can carry Basic authentication headers. If
* Apache Http Client 4.3.2 or better is available (recommended) it will be used as the
* client, and by default configured to ignore cookies and redirects.
*
* #author Dave Syer
* #author Phillip Webb
*/
The similar pattern can be found by ReflectionTestUtils and ReflectionUtils