Testing Alfresco Java services - java

I am looking for a method for testing Alfresco repository Java services without the need for deploying to a Tomcat server.
My idea is to start Alfresco embedded from a JUnit testclass, inject the classes I want to test into the Alfresco Spring configuration and test the classes using JUnit test methods.
The Alfresco sample application "FirstFoundationClient" is a good entry point for getting the above working but when I try to start the sample with a H2 memory database in MySQL-mode it outputs the following error:
SqlMapException: The <sqlMap> resource is missing: /alfresco/ibatis/#resource.dialect#/qname-insert-SQLMap.xml
My alfresco-global.properties configuration in the sample project:
dir.root=./alf_data
db.driver=org.h2.Driver
db.url=jdbc:h2:alf_data/h2_data/alfresco;MODE=MySQL
db.username=alfresco
db.password=alfresco
Can anyone help me with:
how to get FirstFoundationClient (from Alfresco Enterprise SDK 3.4.0) running using a H2 database
how to inject the classes under test so I can access them from the Spring application context (like standard Alfresco services are accessed in the FirstFoundationClient sample)

If you're willing to give the maven way a try, I published a little tutorial about how to use H2 with Alfresco. Here's a project where I'm leveraging that approach that you might use as a template.
NOTE: Alfresco v4.x might not be compatible with H2 - PostgreSQL mode
EDIT: the new h2-support v1.2 supports Alfresco4
EDIT: h2-support now supports up to Alfresco 4.0.2

Related

Spring Boot 2.6.12 compatibility with Spring Cloud (Config) 2021.0.4

I'm trying to update my project Spring Boot version from 2.4.13 to 2.6.12
We were using Spring Cloud 2020.0.0-M6 and I also wanted to bump the version to 2021.0.4
Now my application won't load its remote configuration even though I can see in the logs that it finds the service and the configuration!!
In the above picture you can see my app does find the config-service once deployed to our Development environment.
And after that, it throws me an error because it's trying to use its local configuration where I'm using Environment Variables set from my IDE, using the following syntax ${var}, to replace the value depending on the Run/Debug Configuration.
In the meantime, I'm trying to use Spring Boot 2.6.11 with Spring Cloud 2021.0.4. If I can't get it to work I will have to downgrade it to the last working version until I find the problem.
Any help is appreciated!
Thanks

Is it possible to make a Spring MVC web app run as a "standalone executable" with Java and Tomcat embedded?

I have a web app built with Java, Spring MVC, and JDBC. The result is a WAR file.
To run it, the user has to install Java 8 JDK and Tomcat, and deploy the WAR file to the Tomcat server.
It would be great if they could just download the one file run it as a standalone application.
That is, run "the WAR file" and just browse to http://localhost:8080/myapp
Also, on Windows it would be great it was setup as a Server (like Tomcat is when installed with the installer).
Is there any way to do this? Maybe with Spring Boot or something new like that?
Yep, Spring boot is the way to go.
It allows you to build an executable Jar with all dependencies and a Tomcat (by default, can be changed) embedded.
But users will still need to download a JRE to execute the Jar, and a database if it's required, but you can use en embedded database like H2, HSQLDB..., depends what is your needs.
Yes . you can use spring boot to achieve your results. Kindly refer the below link for sample code
https://mkyong.com/spring-boot/spring-boot-hello-world-example-jsp/
You can use embedded jetty server using maven but that would require you to setup few things your app and may have align your existing app, please check this article for more information.
Jetty is similar to tomcat server in terms of running spring application, there are not much difference in terms of development. Tomcat is just more famous.
Other option as others said, is to migrate your app to spring boot which would be easy if you already have app written in spring (But that depends how much code you have and how much time you have)

WebServlet annotation not working in production (works in development)

I am using Google App Engine STANDARD (SDK 1.9.62) and have set my appengine-web.xml to use java8 runtime and trying to get a simple servlet example. Works as expected in local dev server but gives me a 404 error in the google cloud. I WANT to use the Google App Engine standard environment (not flex). Is there a yaml entry or xml entry I need to turn on for this to work? How can I be sure that GAE is using the 3.1 servlet spec and not 2.5?
App Engine Standard uses appengine-web.xml, whereas Flexible uses app.yaml.
Now, this Java-docs-sample us using the pom.xml to set dependencies. you can see the versions of the dependencies set there.
In this case, that sample can be deployed with mvn appengine:deploy and the endpoint serving in App Engine would be /requests. i.e https://project-name.appspot.com/requests which should return a "hello, world"
Ok. Mystery solved. I had two versions running in deployment and an original java7, servlet 2.5 api version was handling all traffic. My INTENDED version, which was a java8, servlet 3.x was sitting idle and getting 0% traffic. Once I used the version migration function in google's cloud console, the servlets annotated with servlet 3.x annotations started working.

MVN WebApplication Template with Spring Securing + Hibernate

I am looking for a mvn project template that can be downloaded and used as a kick-off for a web application.
The requeriments are:
Spring security (for user authentication and pages accesing control)
Hibernate integration (for data persistance like users and more)
The application must run on tomcat (i use TomEE)
I have a web application already running with pages and servlets and daos, persistence.xml and more. The problem is that i cant find the way to integrate this app with spring security, and for this reason i am looking for a project template...
Give Spring Boot a shot. You can either use Spring Tool Suite or Spring Initializer site to get a secure web app running and using hibernate as ORM.
You can later choose to run the app in the embedded Tomcat/Jetty or package as WAR and deploy in container of your choice.

From GAE to Cloudfoundry

I'd like to know the main differences between CloudFoundry and Google App Engine for a personnal project.
I have a web application that currently runs on GAE and i'am thinking to move it to CloudFoundry for various technical reasons.
I'd like to use :
Spring MVC & Spring Security.
a full implementation of JPA instead of DataNucleus.
mavenize my project properly, i can't make the maven-gae-plugin works.
Is CloudFoundry a good alternative to GAE in my case?
What is the complexity of the migration?
Thanks
It shouldn't be too hard to migrate the app.
http://blog.springsource.org/2011/11/10/using-cloud-foundry-services-with-spring-part-4-%E2%80%93-spring-profiles/ and the whole series of articles has lot of details on how to bind your Spring app to a cloudfoundry data source.
http://blog.springsource.com/2011/09/22/rapid-cloud-foundry-deployments-with-maven/ has details about the cloudfoundry maven plugin, for deployment
To migrate your data, you may want to use the remote api http://code.google.com/appengine/docs/java/tools/remoteapi.html or bulkloader to export, then CloudFoundry Caldecott to import your data in CloudFoundry http://blog.cloudfoundry.com/post/12928974099/now-you-can-tunnel-into-any-cloud-foundry-data-service
http://start.cloudfoundry.com/frameworks/java/spring/spring.html the getting started in cloudfoundry for spring is a good place to start learning about deploying spring apps to cloudfoundry.
I hope this helps.
I can only answer the maven part: see this for a working multimodule example: https://github.com/leanengine/LeanEngine-Server
you must use it like this:
mvn gae:unpack // downloads GAE classes to your maven repo
mvn clean install package
cd lean-server-example
mvn gae:execute // starts a local server

Categories

Resources