Inject a list of maps from application.yml into service - groovy

I am trying to inject a list of maps from my application.yml configuration file into my Spring Boot service. Here is the configuration in application.yml:
devoxx:
cfpApis:
-
url: http://cfp.devoxx.be/api/conferences
youtubeChannelId: UCCBVCTuk6uJrN3iFV_3vurg
-
url: http://cfp.devoxx.fr/api/conferences
-
url: http://cfp.devoxx.ma/api/conferences
youtubeChannelId: UC6vfGtsJr5RoBQBcHg24XQw
-
url: http://cfp.devoxx.co.uk/api/conferences
-
url: http://cfp.devoxx.pl/api/conferences
And here is my property in my service:
#Value("devoxx.cfpApis")
List<Map<String,String>> cfpApis
But there must be something wrong because when I try to run my application, I get the following exception:
java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [java.util.Map]: no matching editors or conversion strategy found
Any idea of what I'm doing wrong?
FYI, I'm trying to migrate a Grails 3 project into a vanilla Spring Boot project and this configuration works in Grails 3, but Grails has its own YAML processors.

Thanks to #Morfic's comment, here is how i ended up solving that problem.
I tagged my service class with #ConfigurationProperties(prefix="devoxx") annotation. And in my service, I now have a property called cfpApis, with the following declaration:
List<Map<String,String>> cfpApis
And this works great.

Related

.NET Core Keyword not supported: 'server'

The sample application on the following page does not start.
https://learn.microsoft.com/en-us/azure/app-service/tutorial-dotnetcore-sqldb-app?pivots=platform-linux
https://github.com/azure-samples/dotnetcore-sqldb-tutorial
As stated in the documentation
After downloading the sample application and creating the DataBase to connect to, an error will occur when the database migration is executed.
$ export ConnectionStrings__MyDbConnection="Server=tcp:db-host.database.windows.net,1433;Database=coreDB;User ID=<username>;Password=<password>;Encrypt=true;Connection Timeout=30;"
$ dotnet ef database update
Build started...
Build succeeded.
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
Entity Framework Core 3.1.3 initialized 'MyDatabaseContext' using provider 'Microsoft.EntityFrameworkCore.Sqlite' with options: None
System.ArgumentException: Keyword not supported: 'server'.
at Microsoft.Data.Sqlite.SqliteConnectionStringBuilder.GetIndex(String keyword)
at Microsoft.Data.Sqlite.SqliteConnectionStringBuilder.set_Item(String keyword, Object value)
at System.Data.Common.DbConnectionStringBuilder.set_ConnectionString(String value)
at Microsoft.Data.Sqlite.SqliteConnectionStringBuilder..ctor(String connectionString)
at Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal.SqliteDatabaseCreator.Exists()
at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.Exists()
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Keyword not supported: 'server'.
Do you know the cause?
I'm using .NET Core 3.1.
If your intention is really use SQLite then you should check this patterns of connections string:
https://learn.microsoft.com/en-us/dotnet/standard/data/sqlite/connection-strings
If not, your code is accidentally calling the SQLite extension to configure your DbContext... Do a full search (Ctrl+Shift+F) in the entire solution for UseSqlite method and replace it for the desired database provider extension (probably will require a new package reference to your project)
The cause was that SQlite was specified where SQL server should be specified.
services.AddDbContext<MyDatabaseContext>(options =>
options. UseSqlite(Configuration.GetConnectionString("MyDbConnection")));
services.AddDbContext<MyDatabaseContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("MyDbConnection")));
Thank you for your cooperation.

Configuring Reportportal with Java +TestNG or Java + Log4j

Have been trying to configure Reportportal withe a sample project. The following steps have been done:
1.Start a Docker and get the reportporal page up and running.
2.In the Java project, added the bintray repository, java-agent-testng, logger-java-log4j dependencies.
3.Included log4j.properties file in the project and also the log4j.appender line for reprortportal
log4j.appender.reportportal=com.epam.ta.reportportal.log4j.appender.ReportPortalAppender
log4j.appender.reportportal.layout=org.apache.log4j.PatternLayout
log4j.appender.reportportal.layout.ConversionPattern=[%d{HH:mm:ss}] %-5p (%F:%L) - %m%n
4.Included log4j info lines for one of the #Test methods.
5.Ran the Test script and made sure the log info line is seen on the console.
6.However, the reportportal dashboard still shows "No Results Found"
7.Also, added the following line for the Test Method.
#Listeners({ReportPortalTestNGListener.class})
8. This threw an exception with Jackson.
A few questions running in my mind:
1.Do we need both TestNG and Log4j to integrate with reportportal or just one of them is fine.
2. With the above steps carried out, is there anything that has been missed. Why am I not seeing data on my reportportal dashboard.
I only did this using the testNG integration. We do have log4j but didn't needed that to post the tests in RP.
I do not however, have any screenshots or attachments.I think that is log4j integration.
#Chethan Swaroop
TestNG integration will send events as testStarted, testEnded into ReportPortal.
This will help to represent structure of test cases and statuses in RP.
Log4J integration (logger appender) will forward logs output into RP server, associating log line with active test case at the moment.
You can have only testNG integration, without logs (log4j), but you can't have log4j, without testing engine integration (testNG in you case)
Please try examples with you local ReportPortal instance:
https://github.com/reportportal/example-java-TestNG/tree/master/logback/src/main/java/com/epam/rp/tests

Database Connection in Jhipster Application while using Docker

I am building an application using Jhipster.
My sample application-prod.yml looks like below as provided by Jhipster
spring:
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:mysql://localhost:3306/MyModule?useUnicode=true&characterEncoding=utf8&useSSL=false
name:
username: hello
password: hello
hikari:
data-source-properties:
...
jpa:
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
database: MYSQL
show-sql: false
org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
...
When I run the application without docker I get a mysql error if the username/password is incorrect which is normal.
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
But if I am running the same application using docker image and provide the db properties in the docker compose file, the properties in the application-prod.yml file seems to get ignored. That is, even if the database properties in the application properties file is incorrect but the correct values are provided in the docker compose file, the application seems to work fine when run using docker image and can connect to the database.
The entries in the docker file is given below
version: '2'
services:
mymodule-mysql:
container_name: mymodule-mysql
image: mysql:5.7.13
environment:
- MYSQL_USER=root
- MYSQL_ROOT_PASSWORD=root
- MYSQL_ALLOW_EMPTY_PASSWORD=no
- MYSQL_DATABASE=mymodule
ports:
- 3306:3306
command: mysqld --lower_case_table_names=1 --skip-ssl
It seems that the environment variables in the docker compose file is overriding the properties application-dev.yml file. Is my thought correct ?
It will be good if someone can explain in details how this works in jhipster.
your observation is correct: the values specified over environment variables are overriding the ones specified in the yml file in the jar. This behavior has nothing to do with JHipster. This is pure spring-boot. Here is a short overview of the order how properties are override (from the spring doc)
Spring Boot uses a very particular PropertySource order that is designed to allow sensible overriding of values. Properties are considered in the following order:
Devtools global settings properties on your home directory (~/.spring-boot-devtools.properties when devtools is active).
#TestPropertySource annotations on your tests.
#SpringBootTest#properties annotation attribute on your tests.
Command line arguments.
Properties from SPRING_APPLICATION_JSON (inline JSON embedded in an environment variable or system property)
ServletConfig init parameters.
ServletContext init parameters.
JNDI attributes from java:comp/env.
Java System properties (System.getProperties()).
OS environment variables.
A RandomValuePropertySource that only has properties in random.*.
Profile-specific application properties outside of your packaged jar (application-{profile}.properties and YAML variants)
Profile-specific application properties packaged inside your jar (application-{profile}.properties and YAML variants)
Application properties outside of your packaged jar (application.properties and YAML variants).
Application properties packaged inside your jar (application.properties and YAML variants).
#PropertySource annotations on your #Configuration classes.
Default properties (specified using SpringApplication.setDefaultProperties).
the entries in the yml file for mysql docker that you post here are the credential to the root user of RDMS mysql database which is startting as a docker service. This dose not mean that your application will use those credential. It can be that you have the same credential also in the application-prod.yml file which has been add to your war during packaging phase and then this war was put into your docker.
In the app.yml file which is used for starting docker-compose you should have also some environment varaible, e.g.
environment:
- SPRING_PROFILES_ACTIVE=prod
- SPRING_DATASOURCE_URL=jdbc:mysql://mysql:3306/myDataBase?useUnicode=true&characterEncoding=utf8&useSSL=false
- JHIPSTER_SLEEP=10 # gives time for the database to boot before the application
for spring which are overriding your application-prod.yml files. Also is importat that the mysql container is known to your app container.

unable to load data in own table of database on dev profile inmomery in jhipster

Hello Everyone,
I am working on jhipster.I have created a database on dev profile and it is created fine.but when i will try to load data into table using csv file then getting a exception.Please help me.
Error creating bean with name 'org.springframework.scheduling.annotation.SchedulingConfiguration': Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.springframework.scheduling.annotation.SchedulingConfiguration.setBeanFactory(Lorg/springframework/beans/factory/BeanFactory;)V
Thanks in advance.
email;firstName;middleName;lastName;sex;aboutYou;dateOfBirth;password;picture;isActive;createdDate
test#gmail.com;charn;jeet;singh;b;aboutme;NULL;b8f57d6d6ec0a60dfe2e20182d4615b12e321cad9e2979e0b9f81e0d6eda78ad9b6dcfe53e4e22d1;NULL;1;NULL
The problem is that you hit a specific bug in Spring Boot, which masks your original exception:
https://github.com/spring-projects/spring-boot/issues/253
In order to see your "real" exception, either:
Migrate to the latest "SNAPSHOT" version of Spring Boot, as it looks to be solved now
Remove the configuration from your AsyncConfiguration class, which is responsible for this bug

Spring WS with webServiceTemplate.marshalSendAndReceive returns Received error for request, Service Unavailable : Not Found [404]

I'm trying to ammend an existing SOAP Webservice that uses Spring-WS and JAXB on Tomcat. I've created the new WAR file with my changes and deployed it in the webapps foder under Tomcat installation.
When calling the original (already existing) methods of the service, the service SOAP request and response is fine. But when calling the service on the new method, I get service SOAP response of service unavailable and not found [404]
2011-07-25 12:58:23,365 DEBUG [org.springframework.ws.client.core.WebServiceTemplate] - Opening [org.springframework.ws.transport.http.HttpUrlConnection#12b9f14] to [http://<service URL>]
2011-07-25 12:58:23,521 DEBUG [org.springframework.ws.soap.saaj.support.SaajUtils] - SOAPElement [com.sun.xml.internal.messaging.saaj.soap.ver1_1.Envelope1_1Impl] implements SAAJ 1.3
2011-07-25 12:58:23,552 DEBUG [org.springframework.ws.soap.saaj.support.SaajUtils] - SOAPElement [com.sun.xml.internal.messaging.saaj.soap.ver1_1.Body1_1Impl] implements SAAJ 1.3
2011-07-25 12:58:23,896 DEBUG [org.springframework.ws.client.MessageTracing.sent] - Sent request [<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><ns2:DelRequest xmlns:ns2="http://<changed_address>"><ns2:userId>ncc1#%</ns2:userId><ns2:dateFromMillis>1308956400000</ns2:dateFromMillis><ns2:dateToMillis>1311634800000</ns2:dateToMillis></ns2:DelRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>]
2011-07-25 12:58:25,318 DEBUG [org.springframework.ws.client.core.WebServiceTemplate] - Received error for request [SaajSoapMessage {http://<changed_address>}DelRequest]
2011-07-25 12:58:25,318 ERROR [net.msgplugin.controller.DeleteController] - Conversation service unavailable at: http://, Not Found [404] , null
I've imported the project into Eclipse and have made the following changes to the project properties:
1) With in Project Facets, I've checked the 'Dynamic Web Module' and 'Java' Facets.
2) In Java EE Module Dependencies, I've checked Maven Dependencies.
Two things which are to be noted here are:
a) The developer was using JBoss when developing the Webservice but recently the project was chagned to Tomcat.
b) The project has a MAVEN folder structure, hence the web.xml file is in src/main/webapp/WEB-INF folder rather than WebContent/WEB-INF, taht got created when I selected the 'Dynamic Web Module' facet.
Any suggestions wld be hugely appreciated?
Thanks
========================================================================
HI
I managed to fix the Not Found [404] error but am now getting another error.
Upon further investigation and debuggin into WebServiceTemplate and MessageDispatcher classes, I found that following output on the console:
DEBUG [org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter] - Accepting incoming [org.springframework.ws.transport.http.HttpServletConnection#11f05a1] to [http://<Service_URL>]
TRACE [org.springframework.ws.server.MessageTracing.received] - Received request [<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><ns2:DelRequest xmlns:ns2="http://<changed_address>"><ns2:userId>ncc1#%</ns2:userId><ns2:dateFromMillis>1309042800000</ns2:dateFromMillis><ns2:dateToMillis>1311721200000</ns2:dateToMillis></ns2:DelRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>]
DEBUG [org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping] - Looking up endpoint for [{<changed_address>}DelRequest]
DEBUG [org.springframework.ws.soap.server.SoapMessageDispatcher] - Endpoint mapping [org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping#6ee035] maps request to endpoint [public final net.org.messagehistory.schema.GetDelResponse net.org.messagehistory.service.endpoint.MessageHistoryEndpoint.delHistory(net.org.messagehistory.schema.GetListRequest) throws javax.xml.datatype.DatatypeConfigurationException]
DEBUG [org.springframework.ws.soap.server.SoapMessageDispatcher] - Testing endpoint adapter [org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter#1a23f67]
DEBUG [org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter] - Unmarshalled payload request to [net.org.messagehistory.schema.DelRequest#c76003]
The end error message is now 'Argument type Mismatch' which I found was generated from one of the methods from within WebServiceTemplate.class
Can somebody suggest what coudl be the problem here?
Managed to get this sorted. So, just wanted to share the solution that somebody might find helpful.
Make sure that the Endpoint method is annotated with the following
#PayloadRoot(localPart = MESSAGES_TO_DELETE, namespace = MESSAGE_NAMESPACE)
where localpart is the same as the your payload request in the schema.xsd
Thanks

Resources