I had a maven JSF/JPA web application that was connected to MySQL 5.x developed using Netbeans 12. The application was running fine until I updated the MySQL version from 5.x to 8.x. Since that update, I can not configure the database to connect to the JSF application. The connection to MySQL 8.x is working within Netbeans, but not working when deploying the application.
The current configuration include EclipseLink 2.7.7, MySQL 8.0.23, and GlassFish 5(5.0.1) / Payara 5(5.2021.1). It is not possible to make a successful connection to MySQL. I also failed to establish connection inside JDBS Connection Pool of GlassFish and Payara admin consoles. Can someone please direct me to a source where MySQL version 8 is linked to Payara or GlassFish?
The error displayed in the Payara admin console is as follows.
An error has occurred Ping Connection Pool failed for pooConnection.
Connection could not be allocated because: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. Please check the server.log for more details.
The log file contains the following.
[javax.enterprise.resource.resourceadapter.com.sun.enterprise.connectors.service] [tid: _ThreadID=161 _ThreadName=admin-thread-pool::admin-listener(3)] [timeMillis: 1613549343463] [levelValue: 900] [[
RAR8054: Exception while creating an unpooled [test] connection for pool [ pooConnection ], Connection could not be allocated because: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.]]
[2021-02-17T13:39:03.472+0530] [Payara 5.2021.1] [SEVERE] [] [org.glassfish.admingui] [tid: _ThreadID=139 _ThreadName=admin-thread-pool::admin-listener(1)] [timeMillis: 1613549343472] [levelValue: 1000] [[
RestResponse.getResponse() gives FAILURE. endpoint = 'http://localhost:4848/management/domain/resources/ping-connection-pool.json'; attrs = '{id=pooConnection}']]
In order to connect to Payara Server, the only effective way I found was creating a Connection Pool directly in the Domain Admin Console.
It may seem a long way now, but after completing it will become second nature:
Download MySQL8 Java Connector available at https://dev.mysql.com/downloads/connector/j/
and unzip to any folder:
It will extract to something like:
mysql-connector-java-8.0.23 2/mysql-connector-java-8.0.23.jar
1) Make sure you have Payara Server up and running:
cd PATH_TO_PAYARA/bin
2) Start/Restart it
./asadmin start-domain
Note: This will start domain1 by default
3) Install the MySQL8 Connector
./asadmin add-library PATH_TO_MYSQL_CONNECTOR.jar
4) (required) Restart Payara
./asadmin restart-domain
5) Access Admin Console at http://localhost:4848/common/index.jsf
6) In the sidebar navigate to "JDBC" -> "JDBC Connection Pools" menu
7) From there, click "New" to add new Connection Pool
You can have as many as you want. So if you have tried before, you may keep your pools there.
8) In: New JDBC Connection Pool (Step 1 of 2)
Pool Name: MySQL8Pool (or whatever you want)
Resource Type: javax.sql.DataSource
Database Driver Vendor: MySQL8
Click "Next"
9) Scroll down to "Adicional Properties"
Select all and "Delete Properties"
10) Add 6 Properties with the keys/values as:
DatabaseName YOUR_DB_NAME
User YOUR_DB_USER
Password YOUR_DB_PASSWORD
ServerName localhost
PortNumber 3306
UseSSL false
Click "Save"
11) In the sidebar navigate to "JDBC" -> "JDBC Resources" menu
12) From there, click "New" to add new JDBC Resource
And fill:
JNDI Name: jdbc/MySQL8App
PoolName: MySQL8Pool
Click "Save"
From now own I assume you are using Maven.
13) In you pom.xml make sure you have Eclipse Persistence
In you tag:
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.core</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.asm</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.antlr</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa.jpql</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.moxy</artifactId>
<version>2.7.7</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.2.1</version>
</dependency>
14) Create a persistence unit in
In persistence.xml file:
<persistence-unit name="mysql8PU" transaction-type="JTA">
<jta-data-source>jdbc/MySQL8App</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<shared-cache-mode>NONE</shared-cache-mode>
<!--properties>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create OR create OR complete remove this line"/-->
</properties>
</persistence-unit>
Note that in jta-data-source it points to jdbc/MySQL8App and from now own it can be used any where in your code so that after built Payara is able to now we injected it.
PersistenceService.java
package com.your.package.services
import javax.enterprise.context.ApplicationScoped;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
#ApplicationScoped
public class PersistenceService {
#PersistenceContext(unitName = "mysql8PU")
EntityManager entityManager;
}
Now rebuild and rerun you project and everything should be fine!
Configure your connecion just in four steps:
Copy Mysql JDBC driver JAR to $PAYARA_HOME/glassfish/domains/$YOUR_DOMAIN/lib/ e. g.
cp mysql-connector-java-8.0.22.jar /opt/payara5/glassfish/domains/domain1/lib/
Create XML resources descriptor file, name it glassfish-resources.xml. Specify apprpriate params:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<jdbc-connection-pool connection-creation-retry-interval-in-seconds="30" connection-validation-method="auto-commit" datasource-classname="com.mysql.cj.jdbc.MysqlDataSource" wrap-jdbc-objects="false" res-type="javax.sql.DataSource" name="mysql_mydb_rootPool" is-connection-validation-required="true" connection-creation-retry-attempts="10" validate-atmost-once-period-in-seconds="60">
<property name="User" value="root"/>
<property name="Password" value="secret"/>
<property name="URL" value="jdbc:mysql://localhost:3306/voyager?zeroDateTimeBehavior=convertToNull&serverTimezone=UTC&useSSL=false"/>
<property name="driverClass" value="com.mysql.cj.jdbc.Driver"/>
<property name="characterEncoding" value="utf-8"/>
</jdbc-connection-pool>
<jdbc-resource enabled="true" jndi-name="jdbc/mydb" object-type="user" pool-name="mysql_mydb_rootPool"/>
</resources>
Add resources to Payara
$PAYARA_HOME/bin/asadmin add-resources glassfish-resources.xml
Restart your domain
$PAYARA_HOME/bin/asadmin restart-domain
Related
I want to use JDBC mysql with Spring cloud config server, but always failed, this is what I am doing:
Spring cloud version: Finchley.SR2
In POM.xml
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
</exclusion>
</exclusions>
</dependency>
Inside the application.config:
spring.profiles.active= jdbc
spring.datasource.url=jdbc:mysql://localhost:3306/config_db
spring.datasource.username=root
spring.datasource.password=12345
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.platform= mysql
spring.cloud.config.server.jdbc.sql= SELECT `key`, `value` FROM `properties` WHERE `application`=? AND `profile`=? AND `label`=?;
spring.cloud.config.server.jdbc.order=0
spring.cloud.config.server.default-profile=production
spring.cloud.config.server.default-label=latest
Finally, when I start server, I am getting below errors:
APPLICATION FAILED TO START
Description:
Invalid config server configuration.
Action:
If you are using the git profile, you need to set a Git URI in your configuration. If you are using a native profile and have spring.cloud.config.server.bootstrap=true, you need to use a composite configuration.
I am not using git here, why the error is about git url?
I had the same issue when used MySQL.
It seems to be an issue with MySQL JdbcTemplate (look here).
I switched to H2 to store configuration and it works.
I wonder if there any workaround to use MySQL?
I got the same error when I attempt to remove the DataSourceAutoConfiguration.class on start up i.e.
#SpringBootApplication(exclude = {DataSourceAutoConfiguration.class })
When I just used
#SpringBootApplication
everything worked as expected.
My reason for excluding the class was to stop the auto generation of a password on startup.
I have a spring boot application which uploads files to S3 bucket.
I am receiving the following error whenever the application tries to upload a file. The stack trace is a huge one. So I am providing only a part of it.
java.lang.IllegalStateException: Socket not created by this factory
at org.apache.http.util.Asserts.check(Asserts.java:34) ~[httpcore-4.4.6.jar:4.4.6]
at org.apache.http.conn.ssl.SSLSocketFactory.isSecure(SSLSocketFactory.java:435) ~[httpclient-4.5.3.jar:4.5.3]
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:186) ~[httpclient-4.5.3.jar:4.5.3]
I am using the following dependency
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.123</version>
</dependency>
I have even tried with
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
</parent>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-aws</artifactId>
</dependency>
<!--<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-aws-context</artifactId>
</dependency>
But sill getting the same type of error
I have tried using both TransferManager as well as putObject() method from AmazonS3 but with same error.
The application was running well a few days back and the error has started to come only very recently.
I had the same issue on v1.10.12 of the SDK, I switched to v1.11.136 and that resolved my issue, add the code below, to your pom file
<!-- AWS S3 Dependencies-->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.136</version>
</dependency>
<!-- End of AWS S3 Dependencies -->
It would be useful to post more of the stack-trace so we can see at what point in the SDK lifecycle the exception is being generated (the stack-trace above only shows the apache classes). Can you also show how you're configuring the S3 client?
Are you configuring a custom SocketFactory? The check in question is looking to see if the Socket that the SocketFactory created is in fact an SSLSocket if not - that's where it bombs - you can see that from the Apache code here.
I'm new with Liferay portal.
here is my config
--Liferay 6.1 deployed on JBoss AS 7.1.1 Final
--Maven 3.1.1
I can easily deploy my portlet(maven project) in local Liferay instance
but i'm trying to deploy this portlet to a remote instance
here is a part of my pom.xml
<properties>
<liferay.version>6.1.2</liferay.version>
<liferay.parent.server>C:\DEV\Env\JBoss</liferay.parent.server>
<liferay.auto.deploy.dir>${liferay.parent.server}\deploy</liferay.auto.deploy.dir>
<liferay.app.server.deploy.dir>${liferay.parent.server}\jboss-as-7.1.1.Final\standalone\deployments</liferay.app.server.deploy.dir>
<liferay.app.server.lib.global.dir>${liferay.parent.server}\jboss-as-7.1.1.Final\modules\com\liferay\portal\main</liferay.app.server.lib.global.dir>
<liferay.app.server.portal.dir>${liferay.parent.server}\jboss-as-7.1.1.Final\standalone\deployments\ROOT.war</liferay.app.server.portal.dir>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.liferay.maven.plugins</groupId>
<artifactId>liferay-maven-plugin</artifactId>
<version>${liferay.version}</version>
<configuration>
<autoDeployDir>${liferay.auto.deploy.dir}</autoDeployDir>
<appServerDeployDir>${liferay.app.server.deploy.dir}</appServerDeployDir>
<appServerLibGlobalDir>${liferay.app.server.lib.global.dir}</appServerLibGlobalDir>
<appServerPortalDir>${liferay.app.server.portal.dir}</appServerPortalDir>
<liferayVersion>${liferay.version}</liferayVersion>
<pluginType>portlet</pluginType>
</configuration>
</plugin>
...
</build>
I would " liferay.parent.server " to target the remote directory something like 192.168.1.2/Env/JBoss
I have been working on for a long time
i will really appreciate your helps
Thank you
You need to install the Remote IDE Connector plugin to the remote instance of Liferay portal.
There are both CE version and EE version
Now you can deploy it via your Eclipse: tutorial
Or you can use Jenkins plugin, but be aware this issue (you need to download the source, fix it, and build it)
I remember that Liferay not support remote connector for JBoss.You can see this documents regard enter link description here Maven plugin for JBoss.
Sure, you can do remote deploy by maven plugin. You can read this guide http://www.dontesta.it/blog/en/blog-2/cms/liferay/liferay-maven-come-fare-il-deploy-remoto-dei-plugin/
In this article we will see a possible solution for remotely deploying the artifact of a Liferay project based on the maven
The plugin maven wagon-maven-plugin (or wagon) is what will allow you copy the WAR of our portlet on the remote server and then the hot deployment of Liferay (of which I recommend reading the hot deployment versus auto deploy) will carry out the actual installation. Listing 1 shows the wagon plugin configuration included within the plugins section of our project pom.
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>1.0</version>
<configuration>
<fromDir>${project.build.directory}/</fromDir>
<includes>*.war</includes>
<url>scp://${jboss.deploy.username}:${jboss.deploy.password}#${jboss.deploy.hostname}/</url>
<toDir>${jboss.deploy.liferay.dir}</toDir>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.8</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
I would like to use Cargo to deploy my maven generated war file to a remote JBoss Server that is already running.
I have configured my pom.xml like this:
...
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-controller-client</artifactId>
<version>7.1.0.Final</version>
</dependency>
</dependencies>
<configuration>
<!-- Container configuration -->
<container>
<timeout>300000</timeout> <!-- 5 minutes -->
<containerId>jboss71x</containerId>
<type>remote</type>
</container>
<!-- Configuration to use with the container -->
<configuration>
<type>runtime</type>
<properties>
<cargo.hostname><myIP></cargo.hostname>
<cargo.jboss.management.port>9999</cargo.jboss.management.port>
<cargo.remote.username><myUser></cargo.remote.username>
<cargo.remote.password><myPass></cargo.remote.password>
</properties>
</configuration>
<!-- Deployer configuration -->
<deployer>
<type>remote</type>
</deployer>
<!-- Deployables configuration -->
<deployables>
<deployable>
<groupId>de.<myGroup></groupId>
<artifactId><myArtifact></artifactId>
<type>war</type>
<pingURL>http://<myIP>:8080/<myContextPath></pingURL>
<pingTimeout>60000</pingTimeout>
</deployable>
</deployables>
</configuration>
</plugin>
...
Of course all variables of the form <my...> are filled out with the real values.
If I run this with the maven command:
mvn -X cargo:deploy
The maven console says:
...
Sep 12, 2012 5:06:12 PM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.0.3.GA
Sep 12, 2012 5:06:12 PM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 3.2.2.GA
[DEBUG] [swordCallbackHandler] Responded to a RealmCallback
[DEBUG] [swordCallbackHandler] Responded to a NameCallback
[DEBUG] [swordCallbackHandler] Responded to a PasswordCallback
[INFO] [Boss7xRemoteDeployer] The deployment has failed: org.codehaus.cargo.util.CargoException: Cannot deploy deployable org.codehaus.cargo.container.jboss.deployable.JBossWAR[myWar.war]
...
On the running JBoss server I can see a logging message in the console like this:
17:07:24,197 ERROR [org.jboss.remoting.remote.connection] (Remoting "pc09:MANAGEMENT" read-1) JBREM000200: Remote connection failed: java.io.IOException: Eine vorhandene Verbindung wurde vom Remotehost geschlossen.
(sorry for the german inside of the log. It basically says: An existing connection was closed by the remote host.)
Does anybody have an idea what could be wrong or how I could get more debug info from cargo to find out what exactly the problem is?
BTW: I have used the JBoss CLI access to that Jboss Server for Arquillian tests so I am pretty confident that the access to that Jboss server via CLI should be ok.
EDIT:
Seems like I have to undeploy first. To reassure that the access to the CLI works I just connected to it using the jboss-cli.bat. Then I just coincidentally undeployed the existing war and after that the deployment via cargo started to work.
(Can I close this question or mark it as resolved in any way?)
Recently, I have used Eclipse and Oracle Glassfish server plugin to deploy my webapplications on the server.
However, I would like to do it in batch mode using Maven 2 and also do some testing before deploying.
I would like to do following tasks:
Get required dependencies (if any) from any repository (which shall I use?).
Run unit tests
If tests successful, deploy it
I am running Maven 2 and Glassfish 3.2.1
Can you support me with some example project including pom.xml file? Is there any knowledge resource for this kind of things?
Best regards
The process you describes is very common.
Indeed, maven itselft will
A Build Lifecycle is Made Up of Phases
Each of these build lifecycles is defined by a different list of build phases, wherein a build phase represents a stage in the lifecycle.
For example, the default lifecycle has the following build phases (for a complete list of the build phases, refer to the Lifecycle Reference):
validate - validate the project is correct and all necessary information is available
compile - compile the source code of the project
test - test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
package - take the compiled code and package it in its distributable format, such as a JAR.
integration-test - process and deploy the package if necessary into an environment where integration tests can be run
verify - run any checks to verify the package is valid and meets quality criteria
install - install the package into the local repository, for use as a dependency in other projects locally
deploy - done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.
These build phases (plus the other build phases not shown here) are executed sequentially to complete the default lifecycle. Given the build phases above, this means that when the default lifecycle is used, Maven will first validate the project, then will try to compile the sources, run those against the tests, package the binaries (e.g. jar), run integration tests against that package, verify the package, install the verifed package to the local repository, then deploy the installed package in a specified environment.
To do all those, you only need to call the last build phase to be executed, in this case, deploy:
mvn deploy
You should use the maven glassfish plugin, and then execute
mvn glassfish:deploy
Here the full ewample from the official documentation :
...
<build>
...
<plugins>
...
<plugin>
<groupId>org.glassfish.maven.plugin</groupId>
<artifactId>maven-glassfish-plugin</artifactId>
<version>2.1</version>
<configuration>
<glassfishDirectory>${glassfish.home}</glassfishDirectory>
<user>${domain.username}</user>
<adminPassword>${domain.password}</adminPassword>
<!-- <passFile>path/to/asadmin/passfile</passFile> -->
<autoCreate>true</autoCreate>
<debug>true</debug>
<echo>false</echo>
<terse>true</terse>
<skip>${test.int.skip}</skip>
<domain>
<name>${project.artifactId}</name>
<adminPort>4848</adminPort>
<httpPort>8080</httpPort>
<httpsPort>8443</httpsPort>
<iiopPort>3700</iiopPort>
<jmsPort>7676</jmsPort>
<reuse>false</reuse>
<jvmOptions>
<option>-Djava.security.auth.login.config=${project.build.testOutputDirectory}/login.conf</option>
</jvmOptions>
<properties>
<property>
<name>server.log-service.file</name>
<value>${domain.log.dir}/server.log</value>
</property>
</properties>
<auth>
<realm>
<name>testRealm</name>
<className>com.sun.enterprise.security.auth.realm.file.FileRealm</className>
<properties>
<property>
<name>jaas-context</name>
<value>test</value>
</property>
<property>
<name>file</name>
<value>${project.build.outputDirectory}/keyfile</value>
</property>
</properties>
</realm>
</auth>
<!-- <resourceDescriptor>path/to/resources.xml</resourceDescriptor> -->
<resources>
<connectionFactory>
<jndiName>jms/testQueueConnectionFactory</jndiName>
<type>queueConnectionFactory</type>
<properties>
<property>
<name>UserName</name>
<value>guest</value>
</property>
<property>
<name>Password</name>
<value>guest</value>
</property>
<property>
<name>AddressList</name>
<value>localhost:7676</value>
</property>
</properties>
</connectionFactory>
<jmsTopic>
<jndiName>jms/testTopic</jndiName>
<destinationName>TestTopic</destinationName>
<connectionFactory>
<jndiName>jms/testTopicConnectionFactory</jndiName>
<properties>
<property>
<name>UserName</name>
<value>guest</value>
</property>
<property>
<name>Password</name>
<value>guest</value>
</property>
<property>
<name>AddressList</name>
<value>localhost:7676</value>
</property>
</properties>
</connectionFactory>
</jmsTopic>
<jdbcDataSource>
<name>SomeDS</name>
<type>connectionPoolDataSource</type>
<poolName>SomePool</poolName>
<className>com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource</className>
<description>Some JDBC Connection Pool</description>
<allowNonComponentCallers>false</allowNonComponentCallers>
<validateConnections>true</validateConnections>
<validationMethod>metaData</validationMethod>
<properties>
<property>
<name>portNumber</name>
<value>3306</value>
</property>
<property>
<name>password</name>
<value>somePassword</value>
</property>
<property>
<name>user</name>
<value>someUser</value>
</property>
<property>
<name>serverName</name>
<value>some.host.somewhere</value>
</property>
<property>
<name>databaseName</name>
<value>SomeDB</value>
</property>
</properties>
</jdbcDataSource>
</resources>
</domain>
<components>
<component>
<name>${project.artifactId}</name>
<artifact>${project.build.directory}/artifacts/${project.build.finalName}.war</artifact>
</component>
</components>
</configuration>
</plugin>
...
</plugins>
...
</build>
...
</project>
I'm assuming you mean GlassFish Server 3.1.2 :-)
Using Maven with GlassFish documentation is covered in the Embedded Server Guide:
http://docs.oracle.com/cd/E26576_01/doc.312/e24932/embedded-server-guide.htm#gijhs
Hope this helps.