How to resolve Struts 2 Json Interceptor invalid json exception - json

Hi i upgraded my struts project from 2.3.20 to 2.5.2 and when i am trying to run, it is throwing me exception in JsonInterceptor. I am unable to figure out why it throwing this exception after upgrading struts to 2.5.2. I have also change my struts.xml file according to it. But still it is showing me same error. Can anyone help me what i am missing.
Error Trace:
struts.xml
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<package name="default" extends="json-default,struts-default">
<interceptors>
<interceptor name="json" class="org.apache.struts2.json.JSONInterceptor"/>
<interceptor name="sessionInterceptor" class="com.comviva.mconnectui.custom.interceptors.SampleInterceptor"/>
<interceptor-stack name="customInterceptor">
<interceptor-ref name="sessionInterceptor" />
<interceptor-ref name="json" />
</interceptor-stack>
</interceptors>
</package>
</struts>

Related

Mysql Driver class com.mysql.jdbc.Driver is not a valid javax.sql.DataSource implementation from wildfly

maybe my setup is quite special, but I do have issues when I define a JDBC Datasource for Java EE container in my web.xml file.
I configured my Datasource in my web.xml as follow:
<data-source>
<name>java:app/myapp/DS</name>
<class-name>com.mysql.jdbc.Driver</class-name>
<url>jdbc:mysql://localhost:3306/database?useSSL=false&allowPublicKeyRetrieval=true</url>
<user>foo</user>
<password>pass</password>
<transactional>true</transactional>
<isolation-level>TRANSACTION_READ_COMMITTED</isolation-level>
<initial-pool-size>2</initial-pool-size>
<max-pool-size>10</max-pool-size>
<min-pool-size>5</min-pool-size>
<max-statements>0</max-statements>
</data-source>
After I use datasource's name as my jta-data-source in my persistence file as follow:
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="java-rs-with-hibernate" transaction-type="JTA">
<jta-data-source>java:app/myapp/DS</jta-data-source>
<class>com.patrickhub.ch.java_rs_with_hibernate.domain.Product</class>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="none"/>
<property name="javax.persistence.schema-generation.scripts.action" value="none"/>
</properties>
</persistence-unit>
</persistence>
And in my code I used the EntityManager to make request to the database.
But when I deploy it to wildfly 18.0.1, I get the following errors:
at org.jboss.as.connector#18.0.1.Final//org.jboss.as.connector.subsystems.datasources.AbstractDataSourceService.start(AbstractDataSourceService.java:174)
at org.jboss.msc#1.4.11.Final//org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1739)
at org.jboss.msc#1.4.11.Final//org.jboss.msc.service.ServiceControllerImpl$StartTask.execute(ServiceControllerImpl.java:1701)
at org.jboss.msc#1.4.11.Final//org.jboss.msc.service.ServiceControllerImpl$ControllerTask.run(ServiceControllerImpl.java:1559)
at org.jboss.threads#2.3.3.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads#2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1982)
at org.jboss.threads#2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
at org.jboss.threads#2.3.3.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1363)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: org.jboss.jca.deployers.common.DeployException: WFLYJCA0030: unable to deploy
at org.jboss.as.connector#18.0.1.Final//org.jboss.as.connector.subsystems.datasources.AbstractDataSourceService$AS7DataSourceDeployer.deploy(AbstractDataSourceService.java:376)
at org.jboss.as.connector#18.0.1.Final//org.jboss.as.connector.subsystems.datasources.AbstractDataSourceService.start(AbstractDataSourceService.java:160)
... 8 more
Caused by: org.jboss.as.controller.OperationFailedException: WFLYJCA0117: com.mysql.jdbc.Driver is not a valid javax.sql.DataSource implementation [ "WFLYJCA0117: com.mysql.jdbc.Driver is not a valid javax.sql.DataSource implementation" ]
... 10 more
I think that if I replace com.mysql.jdbc.Driver with com.mysql.jc.jdbc.Driver, it will deploy successfully but I still have the same problem and the same message error.
I don't know if I miss something on how to define a mysql JDBC datasource in web.xml file. but I think it is correct.
Please can someone help me.

Camel Bindy application JBoss EAP 6.1 Deployment issue

I am trying to deploy a camel application which reads CSV file and process it.I am trying to use camel bindy to unmarshal the csv to POJO.
The camel bindy module was not available in jboss EAP i have added it.
Camel Route:
<?xml version="1.0" encoding="ASCII"?>
<routes xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="switchyard://FileService" />
<log message="inside route" />
<doTry>
<split streaming="true">
<tokenize token="/n"></tokenize>
<unmarshal ref="bindyDataformat" >
<bindy classType="com.agcs.bih.prototypes.filetosca.Student" type="Csv"/>
</unmarshal>
<process ref="ProcessCSV"></process>
</split>
<doCatch>
<exception>java.lang.Exception</exception>
<log message="FileToScaRoute - message received: ${exception.message}" />
</doCatch>
</doTry>
</route>
</routes>
Iam getting the below exception during deployment.
Caused by: java.lang.IllegalArgumentException: Data format 'bindy-csv' could not be created. Ensure that the data format is valid and the associated Camel component is present on the classpath
Attaching server.log
Can you please help
It sounds like you are using JBoss FSW possibly? Fuse 6.3 on EAP 6.3 includes camel-bindy and there's an example included there for SwitchYard as well if you can upgrade.
Please see;
http://camel.apache.org/bindy.html
Make sure you have created bindyDataFormat
<dataFormats>
<bindy id="bindyDataformat" type="Csv" classType="org.apache.camel.bindy.model.Order"/>
</dataFormats>
After refering the link https://developer.jboss.org/thread/177124.I have added the manifest entry in maven jar plugin pom xml
<manifestEntries>
<Dependencies>org.apache.camel.bindy export services</Dependencies>
</manifestEntries>
iam able to unmarshal it to pojo using camel bindy now.

Cannot connect to the MySQL database using Spring Hibernate

I am completely new in Spring and fail to connect to my MySQL database by Spring Hibernate. I get
Request processing failed; nested exception is :
org.springframework.transaction.CannotCreateTransactionException:
Could not open JPA EntityManager for transaction; nested exception is
javax.persistence.PersistenceException:
org.hibernate.exception.GenericJDBCException: Could not open
connection
My applicationContext.xml
<context:annotation-config />
<context:component-scan base-package="Zoostore" />
<tx:annotation-driven />
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/zoostore?characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value="your_password"/>
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:dataSource-ref="dataSource"
/>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="entityManagerFactory"
p:persistenceUnitName="BookJpaPersistenceUnit"/>
<tx:annotation-driven transaction-manager="transactionManager"/>
And that is part of my controller code where I try to store data to database and get it from it
#RequestMapping(value = "saveadvert", method = RequestMethod.POST)
public ModelAndView saveAdvert(Advert advert) {
advert.setUserId(1);
advertService.persist(advert);
return new ModelAndView("test", "allAdverts", advertService.getAll());
This is the exception I get:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not open connection
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868)
javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
I can provide the root causes if necessary
Not sure which kind of error, I mention the conditions I had met.
make sure you open mysql service, you can test connect it with IDE database function, like IDEA.
take care of useSSL=false, sometimes it will be fatal.
If your mysql-connector-java's version is above 8.*, that you might need to change the datasource-driver-name to com.mysql.cj.jdbc.Driver
Though spring will help you change.
If you specify jpa with table's names, columns. Make sure you use the right grammar #Table(name='xxx') #Column(name= 'xxx')
Take care of the mysql server's port.
In windows. netstat -ano |findstr: 3306
taskkill /PIDĀ enterPIDĀ /F
In Linux netstat -anp |grep 3306 kill -9 pid
Check gradle or maven dependencies
And here is where I get stuck.
In spring-boot, you can make the configuration set up automatically. But you need to make the files right in their places.
xx.yml need put in resources(In IDEA, you need to specify the package as resources package)
xxxApplication.class(The spring-boot-starter class should be out of other classes, or you should specify the other classes' path.
First check your Sql client Version.
Goto Spring->ProjectName->WebContent->WEB-INF->lib and check you have the same mysql
connector jar version as of Sql Client.
Also change the same in Project->properties->Java-Build_path.
try this, it's works and solve your problem.
<beans xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"><context:annotation-config/><mvc:annotation-driven/><context:component-scan base-package="com.controller"/><bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"><property name="basename" value="/WEB-INF/Messages"/><property name="cacheSeconds" value="3000"/></bean><tx:annotation-driven transaction-manager="transactionManager"/><bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" p:sessionFactory-ref="sessionFactory"/><bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"><property name="dataSource" ref="dataSource"/><property name="hibernateProperties"><props><prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop><prop key="hibernate.show_sql">true</prop></props></property><property name="packagesToScan" value="com.controller"/></bean><bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" p:driverClassName="com.mysql.jdbc.Driver" p:url="jdbc:mysql://localhost:3306/demo1" p:username="root" p:password="chirag"/><bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"><property name="maxUploadSize" value="10000000000"/></bean><bean id="viewResolver" class="org.springframework.web.servlet.view.Inter`enter code here`nalResourceViewResolver" p:prefix="/views/" p:suffix=".jsp"/></beans>

code first -The provider did not return a ProviderManifestToken string

I wrote a windows form solution with 2 layers; one is DataAccess and the other is windows form.
I use Code first. If DataAccess Layer runs in the application console, there is no problem with the db. Create the schema and insert the data.
However, when I run the solution with Windows Form as the initial project and refer to DataAccess as a dll, I cannot build the database. It throws an exception.
I think that the app.config file is the problem, but if I copy the app.config file of DataAccess project to the windows form, it does not resolve the problem.
the config file of DataAcces layer:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
the exception:
"first exception for 'System.Data.Entity.Core.ProviderIncompatibleException' in EntityFramework.dll
Aditional Information: An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct."
Inner Exception:
{"The provider did not return a ProviderManifestToken string."}
The problem could be due to Error in connection string
or in my case it was that
SQL server service was not running
manually start the SQL service through SQL SERVER COnfiguration Manager
after a long deep search, i found that solution was "clean the solution".

OpenJPA + MySQL issue

I have been using OpenJPA with MySQL. Here is my persistence.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<!--
For DB connectivity
-->
<persistence version="1.0">
<persistence-unit name="jpa">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<class>com.Login</class>
</persistence-unit>
<properties>
<property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost:3306/jpa"/>
<property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver"/>
<property name="openjpa.ConnectionUserName" value="root"/>
<property name="openjpa.ConnectionPassword" value="root"/>
<property name="openjpa.jdbc.DBDictionary" value="mysql(SimulateLocking=true)"/>
<property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO"/>
</properties>
</persistence>
When I am executing my Java class, I am getting an exception which is given below. The same code is working fine if I use hibernate and change configuration in persistence.xml, But it is not working in OpenJPA. Can anyone help to solve this?
Exception in thread "main" javax.persistence.PersistenceException: Explicit persistence provider error(s) occurred for "jpa" after trying the following discovered implementations: org.apache.openjpa.persistence.PersistenceProviderImpl from provider: org.apache.openjpa.persistence.PersistenceProviderImpl
at javax.persistence.Persistence.createPersistenceException(Persistence.java:244)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:186)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:72)
at com.JPALogin.main(JPALogin.java:26)
Caused by: <openjpa-2.2.0-r422266:1244990 nonfatal general error> org.apache.openjpa.util.GeneralException: org.xml.sax.SAXException: file:/E:/work/JPAPlain/build/classes/META-INF/persistence.xml [Location: Line: 5, C: 28]: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'persistence'.
at org.apache.openjpa.lib.meta.XMLMetaDataParser.parseNewResource(XMLMetaDataParser.java:427)
at org.apache.openjpa.lib.meta.XMLMetaDataParser.parse(XMLMetaDataParser.java:347)
at org.apache.openjpa.lib.meta.XMLMetaDataParser.parse(XMLMetaDataParser.java:324)
at org.apache.openjpa.lib.meta.XMLMetaDataParser.parse(XMLMetaDataParser.java:297)
at org.apache.openjpa.persistence.PersistenceProductDerivation$ConfigurationParser.parse(PersistenceProductDerivation.java:772)
at org.apache.openjpa.persistence.PersistenceProductDerivation.parseResources(PersistenceProductDerivation.java:556)
at org.apache.openjpa.persistence.PersistenceProductDerivation.load(PersistenceProductDerivation.java:522)
at org.apache.openjpa.persistence.PersistenceProductDerivation.load(PersistenceProductDerivation.java:336)
at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:86)
at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:153)
at org.apache.openjpa.persistence.PersistenceProviderImpl.createEntityManagerFactory(PersistenceProviderImpl.java:62)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:152)
... 2 more
How about you try something like this?
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<!-- For DB connectivity -->
<persistence-unit name="jpa">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<class>com.Login</class>
<properties>
<property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost:3306/jpa" />
<property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver" />
<property name="openjpa.ConnectionUserName" value="root" />
<property name="openjpa.ConnectionPassword" value="root" />
<property name="openjpa.jdbc.DBDictionary" value="mysql(SimulateLocking=true)" />
<property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO" />
</properties>
</persistence-unit>
</persistence>
SAXParseException: cvc-elt.1: Cannot find the declaration of element 'persistence'. at org.apache.openjpa.lib.meta.XMLMetaDataParser.parseNewResource
I can't be sure, but it looks like the XML parser of your persistence.xml file is trying to validate the XML against a DTD, and it is complaining because it can't get a (useful) DTD. You might want to change the first line of your XML file to the following:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
I would not expect an invalid XML file or missing DTD to cause the parser to crash with a mysterious exception. So if that is the cause of the problem, I'd say the persistence provider code had a bug in it. I'd expect a more useful exception, with a message saying "invalid XML", or some such.