What should I replace WebServiceTemplate with when converting from Spring 3 to Spring 5 - spring

I have a project I am converting. Most of it was easy but for some reason I can't find a recent implementation of the org.springframework.ws.client.core.WebServiceTemplate anywhere. Is there a swap out replacement? If not how would I do something similar? It looks to just be serializing. Code looks like...
JAXBElement xmlResponse = (JAXBElement) something.getTemplateSearch().marshalSendAndReceive(...)
Also we are not allowed to use
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
<version>3.0.10.RELEASE</version>
</dependency>
Due to a security issue

Related

WebClient create java.lang.ExceptionInInitializerError: null ExchangeStrategies.withDefaults

I'm trying to play around Spring WebFlux Webclient.
Tried to create a simple webclient in a quartz cron job
this.webClient = WebClient.create(this.queryUrl);
I made sure the queryUrl is valid.
However, I've got an error as following:
java.lang.ExceptionInInitializerError: null
at org.springframework.web.reactive.function.client.ExchangeStrategies.withDefaults(ExchangeStrategies.java:67)
at org.springframework.web.reactive.function.client.DefaultWebClientBuilder.initExchangeStrategies(DefaultWebClientBuilder.java:302)
at org.springframework.web.reactive.function.client.DefaultWebClientBuilder.build(DefaultWebClientBuilder.java:269)
at org.springframework.web.reactive.function.client.WebClient.create(WebClient.java:154)
Tracing into the code, I've found that
DefaultExchangeStrategiesBuilder is null.
Does anyone have any idea what is missing?
It's a simple web client.
Thanks.
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.13.0</version>
</dependency>
Adding these dependencies and making sure the versions are the same.
I only had jackson-core before.
I tried to move the job out of quartz and ran it directly in main.
it still threw an exception, but it's different and I then looked it up
and some one has asked the issue and the solution to make sure both jackson packages need to be included and versions must be same.
I then added them to the pom file. try to run the job and it worked.
Putting the job back to quartz to run and it also worked.

Spring Data Projection not working

I want to use spring projection in my project. I am doing exactly as mentioned at this url http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#projections
interface NoAddresses {
String getFirstName();
String getLastName();
}
The only difference is my interface is public. and is not in the same package as the repository. Is that a requirement?
Still I see the whole entities are being returned, instead of just the projected columns.
I have
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.10.2.RELEASE</version>
</dependency>
Doesn't work. Do i need to add some dependency to make the projection work? I am not using spring-boot but just the spring-data stuff in my project, running on tomcat server.
thanks
Chahat

WildFly 10, JCache - method caching

i have simple application using Spring Boot. I wanted allow method caching with JSR107 - JCache. So with help of tutorial i put together this code :
#CacheResult(cacheName = "testpoc")
public Country getCountry(Integer id){
System.out.println("---> Loading country with code '" + id + "'");
return new Country(id, "X", "Title");
}
with this POM file
...
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.4.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
<version>1.4.0.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
...
(dependency 'spring-boot-starter-web' is there for simple REST service which call getCountry method)
Everything works like documentations says - method is invoked only once.
Now i wanted to try it on WildFly 10 application server
I have modified pom file :
excluded tomcat
exluded spring-boot-starter-cache
added infinispan-jcache (because i want to use cache configured / managed by wildfly in standalone/domain.xml)
Check pom file here on pastebin.
Problem is, that i am receiving following error :
Cannot find cache named 'java:jboss/infinispan/app-cache'
(i have tried to use both JNDI assigned and name to infinispan cache configured in wildfly).
Following code created Cache object (so i can used it) :
CacheManager cacheManager = Caching.getCachingProvider().getCacheManager();
Cache<String, String> cache = cacheManager.createCache("testpoc", new MutableConfiguration<String, String>());
Question :
It is possible to use JCache method caching on WildFly 10 using Infinispan managed by WildFly ?
Or Infinispan should be used for method caching like JCache, hence JCache has "more functionality" than Infinispan.
Thank you very much
PS :It is not problem for me to put whole code on github and post link - it is few lines of code ...
There are a couple of problems with your approach so let me go through them in steps.
At first you need to use proper Infinispan setup. Infinispan bits shipped with WF should be considered as internal or private. In order to use Infinispan in your app properly - either add org.infinispan:infinispan-embedded to your deployment or install Infinispan Wildfly modules. You can find installation guide here (it's a bit outdated but still, the procedure is exactly the same - unpack modules into WF and use Dependencies MANIFEST.MF entry).
Once you have successfully installed Infinispan (or added it to your app), you need to consider whether you want to use Spring Cache or JCache. If you're only interested in using annotations - I would recommend the former since it's much easier to setup (all you need to do is to add #EnableCaching to one of your configurations). Finally with Spring Cache you will create an Infinispan CacheManager bean. An example can be found here.
Final note - if you still need to use JCache - use this manual to setup Caching Provider.

Injecting spring dependencies into Domain objects best practices?

I've scraped all over many resources, and have made this work and it's kinda complex, which turns me into asking for review and other ideas on how to properly inject spring dependencies into DomainObjects ..
My solution so far includes ..
Defining the dependencies needed for loadweaving
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-instrument</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
And then .. configure it in the spring context file :
<context:spring-configured />
<context:load-time-weaver/>
Using #Configurable for my domain classes :
#Configurable
public class MyDomainClass {
....
}
And of course, using these VM arguments :
-XX:-UseSplitVerifier -javaagent:C:/Users/albert/.m2/repository/org/springframework/spring-instrument/3.0.6.RELEASE/spring-instrument-3.0.6.RELEASE.jar
For this current solution, i have the feeling that this seems too much, like the lots of dependencies needed, and also the VM args, which i would dislike when deploying in production server where i have to use specific options, which i fear could be not supported in the future or perhaps have different behaviours between version.
Im thinking of doing domainObjects with prototype scope, but i fear the dependencies issues when fetching the domain objects from the database (not from applicationContext).
Please share your experiences, thank you !
1: When you start injection stuff dynamically into domain objects, they're really not domain objects any more in the sense that the domain should reflect your information model, independent of any business rules and functional logic.
2: Remember KISS (keep it simple...). At some point, someone else might have to take ownership and maintain your code so have some mercy on that person :)
I would call this an anti-pattern, which in my opinion should be avoided.
If you use compile time waving, then you will not need the VM argument.

using javax.cache.CacheManager with EhCache

I am trying to use javax.cache.CacheManager JSR107 API using EhCache as caching solutioarin provider. But I am unable to find any such resources.
As per the link at http://ehcache.org/documentation/integrations/jsr107 , it says that ehcache jsr107 is still in draft phase. Can any one please confirm if it's still the case?
Any sample code to use net sf cacheManager using JSR107 javax.cache.* classes?
Thanks,
Harish
As specified in this page:
Because JCACHE has not yet been released the JCACHE API that Ehcache
implements has been released as net.sf.jsr107cache.
This effort can be found in the Github repository. If you see JCacheManager implements javax.cache.CacheManager
Here's a better answer now the API is finalised. Stick this in your pom:
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>jcache</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.jsr107.ri</groupId>
<artifactId>cache-annotations-ri-guice</artifactId>
<version>1.0.0</version>
</dependency>
And you're off. Annotate with any of the annotations like this: (good luck finding the javadocs!)
#CacheResult(cacheName = "monthly")
public List<QueryResult> monthly(String prefix) {
//...
}
I agree though, the documentation sucks.
Here's more javax.cache info if you're interested.

Resources