1

I made a restful service by netbeans from my localhost and I choose glassfish 4.1.1 as my webserver then I wanted to test it. it was working when it wanted to give me an xml response but when I tried to get an JSON response it gave me a 500 ERROR as below

GET RequestFailed RequestFailed --> Status: (500) 
Response: {

HTTP Status 500 - Internal Server Error


type Exception report

messageInternal Server Error

descriptionThe server encountered an internal error that prevented it from fulfilling this request.

exception 
javax.servlet.ServletException: javax.ejb.EJBException


root cause 
javax.ejb.EJBException


root cause 
javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: 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.
Error Code: 0


root cause 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Error in allocating a connection. Cause: 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.
Error Code: 0


root cause 
java.sql.SQLException: Error in allocating a connection. Cause: 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.


root cause 
javax.resource.spi.ResourceAllocationException: Error in allocating a connection. Cause: 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.


root cause 
com.sun.appserv.connectors.internal.api.PoolingException: 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.


root cause 
com.sun.appserv.connectors.internal.api.PoolingException: 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.


root cause 
com.sun.appserv.connectors.internal.api.PoolingException: 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.


root cause 
javax.resource.spi.ResourceAllocationException: 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.


root cause 
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 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.


root cause 
java.net.ConnectException: Connection refused: connect


note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 4.1.1 logs.


GlassFish Server Open Source Edition 4.1.1 

}

I searched on web and stack and see that it occursed because of eclipselink so I tested it with eclipselink 2.6.3 and 2.6.1 and reinstall my localhost but got errors again:

GET RequestFailed RequestFailed --> Status: (500) 
Response: {
HTTP Status 500 - Internal Server Error

type Exception report

messageInternal Server Error

descriptionThe server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.persistence.jaxb.BeanValidationHelper
root cause

org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.persistence.jaxb.BeanValidationHelper
root cause

java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.persistence.jaxb.BeanValidationHelper
note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 4.1.1 logs.

GlassFish Server Open Source Edition 4.1.1


}

sorry for my bad English language and thank you so much for putting your time for my problem even if just read it.

Seyed Ali Roshan
  • 1,476
  • 1
  • 18
  • 37

2 Answers2

1

The stacktrace shows that the code is failing with java.lang.NoClassDefFoundError

java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.persistence.jaxb.BeanValidationHelper

Make sure that org.eclipse.persistence.jaxb.BeanValidationHelper class dependecy is present during the runtime.

You can read more about NoClassDefFoundError @ How to solve java.lang.NoClassDefFoundError?

=========================================================================== Update:

It looks like there is a bug with GlassFish 4.1.1. The JIRA is still OPEN https://java.net/jira/browse/GLASSFISH-21440. There is one JIRA on Jersey as well https://java.net/jira/browse/JERSEY-2888. At the end, they have provided some workaround for the problem. Please verfiy with that workaround.

Community
  • 1
  • 1
Rolson Quadras
  • 446
  • 3
  • 8
  • in netbeanse restful project i have no web.pom how should I find that it works? – Seyed Ali Roshan Jul 09 '16 at 13:47
  • It looks like there is a bug with GlassFish 4.1.1. The JIRA is still OPEN https://java.net/jira/browse/GLASSFISH-21440. I have updated my answer. Hope you would be able to get it working with the work around mentioned in https://java.net/jira/browse/JERSEY-2888. – Rolson Quadras Jul 09 '16 at 16:25
  • Yes it's is about 1 year old bug in 4.1.1 I change my glassfish to 4.1 and everything work normal Thank you for your time – Seyed Ali Roshan Jul 14 '16 at 18:28
1

for making the Solution bold and clear,

recording to upper answer, in this case all you need to don't use glassfish 4.1.1 ,just install glassfish 4.1 and this matter solved (because solving the 4.1.1 error took too long time from me and i suggest you to Do not try to solve it)

Seyed Ali Roshan
  • 1,476
  • 1
  • 18
  • 37