Quarkus org.jboss.resteasy.spi.UnhandledException: Unable to find a MessageBodyReader of content-type application/json - json

I am trying to implement the REst Client example from the Quarkus website (code 1:1): https://quarkus.io/guides/rest-client
When I launch http://localhost:8080/country/name/greece I get:
Error handling ce3120e3-1a55-418e-a5a1-a17a80d7e278-1, org.jboss.resteasy.spi.UnhandledException: javax.ws.rs.ProcessingException: RESTEASY003145: Unable to find a MessageBodyReader of content-type application/json;charset=utf-8 and type interface java.util.Set
After some reading on the internets I stumbled upon a hint, that it could be connected to a missing Jackson dependency.
So I added the below and reran (same error regardless of the version):
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
<version>1.3.0.Alpha2</version>
</dependency>
Now I get the following issue:
Error handling 00077d3a-bbdb-48ee-b84b-653bf98baefc-2, org.jboss.resteasy.spi.UnhandledException:
javax.ws.rs.ProcessingException: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException:
Unrecognized field "topLevelDomain" (class org.acme.Country),
not marked as ignorable (4 known properties: "capital", "alpha2Code", "name", "currencies"])
My stack is Quarkus 1.2.1, JDK 12.0.2 and Windows 10.
Any ideas what I might be doing wrong?

I had the same error at my project, it stopped happening when I added this dependency:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jsonb</artifactId>
</dependency>

Related

JMockit with EclEmma code coverage issue

Before anyone downvotes me for a duplicate question.... I have read all the other StackOverflow answers related to this topic and nothing has answered my question.
So I am using JMockit 1.19, below is my pom.xml dependencies for Jmockit and Junit
<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
</dependency>
I am using EclEmma 2.3.2 plugin as installed via Eclipse Marketplace.
However I am getting several different issues at once when I try to view my code coverage.
For one I get the following exception log:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:386)
at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401)
Caused by: java.lang.RuntimeException: Class java/util/UUID could not be instrumented.
at org.jacoco.agent.rt.internal_9dd1198.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:138)
at org.jacoco.agent.rt.internal_9dd1198.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:99)
at org.jacoco.agent.rt.internal_9dd1198.PreMain.createRuntime(PreMain.java:55)
at org.jacoco.agent.rt.internal_9dd1198.PreMain.premain(PreMain.java:47)
... 6 more
Caused by: java.lang.NoSuchFieldException: $jacocoAccess
at java.lang.Class.getField(Class.java:1695)
at org.jacoco.agent.rt.internal_9dd1198.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:136)
... 9 more
FATAL ERROR in native method: processing of -javaagent failed
Exception in thread "main"
I also get two pop-ups that say....
popup 1) - "No coverage data has been collected during this coverage session. Please do not terminate the Java process manually from Eclipse."
pupup 2) - "Error while dumping coverage data (code 5013). com.mountainminds.eclemma.internal.core.launching.AgentServer"
In order to get JMockit to run successfully I am providing the JVM argument
-javaagent:C:/Users/vn90614/.m2/repository/org/jmockit/jmockit/1.19/jmockit-1.19.jar
I think this argument is realted to the issue
Ok, so I FINALLY solved this issue after almost a week of working on this and asking everyone in the office. I had linked another project on my build path and that's what caused this issue. Not only did it affect this but this caused a ton of issues with JMockit, Mockito, and PowerMock functions. Linking projects on your build path WILL cause issues for testing frameworks and code coverage.

Google cloud SQL connection

I am trying to connect to google cloud SQL. I was able to successfully do that a couple of days ago but right now I am facing some issues with that.
The problem that is occurring is
Loading class com.mysql.jdbc.Driver'. This is deprecated. The new driver class iscom.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
since it automatically loads com.mysql.cj.jdbc.Driver I am getting the following error:
java.sql.SQLNonTransientConnectionException: Could not create connection to database server.
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:676)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:663)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:653)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:638)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:606)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:1837)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:1653)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:662)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:352)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:221)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:270)
at com.example.endpoints.insertUser.doPost(insertUser.java:160)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:821)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:583)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1158)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:511)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1090)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:213)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:109)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:119)
at org.eclipse.jetty.server.Server.handle(Server.java:517)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:306)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:242)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:261)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:75)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:213)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:147)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)
at java.lang.Thread.run(Thread.java:745)
**Caused by: java.lang.ClassCastException: com.google.cloud.sql.mysql.SocketFactory cannot be cast to com.mysql.cj.api.io.SocketFactory**
at com.mysql.cj.core.io.AbstractSocketConnection.createSocketFactory(AbstractSocketConnection.java:129)
at com.mysql.cj.mysqla.io.MysqlaSocketConnection.connect(MysqlaSocketConnection.java:56)
at com.mysql.cj.mysqla.MysqlaSession.connect(MysqlaSession.java:144)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:1783)
... 33 more
check the bold part....
the url I am using to make connection is this:-
"jdbc:mysql://google/*****?cloudSqlInstance=******&socketFactory=com.google.cloud.sql.mysql.SocketFactory&user=****&password=****&useSSL=true"
I think the problem is that you are using mysql-socket-factory which have class com.google.cloud.sql.mysql.SocketFactory implements com.mysql.jdbc.SocketFactory
Try this one: mysql-socket-factory-connector-j-6
If you are using the following dependencies
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>*.*.*</version>
</dependency>
<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>mysql-socket-factory</artifactId>
<version>*.*.*</version>
</dependency>
use this starter instead
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-sql-mysql</artifactId>
<version>1.0.0.RELEASE</version>
</dependency>
I had a Very similar issue that may have the same root cause
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create socket factory 'com.google.cloud.sql.mysql.SocketFactory' due to underlying exception:
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
...
Caused by: java.lang.ClassCastException: com.google.cloud.sql.mysql.SocketFactory cannot be cast to com.mysql.jdbc.SocketFactory
at com.mysql.jdbc.MysqlIO.createSocketFactory(MysqlIO.java:3324)
... 80 more
Which was very strange since I had everything working previously.
Turns out that my wifi connection was on the wrong network and I had no connectivity. When I fixed my network connection, the DB connection worked again. Tried enabling and disabling wifi to be sure. Yep, very confusing error for the actual problem.
Hope this helps out someone with the same issue.

error while loading DefaultFormats, Scala signature DefaultFormats has wrong version

I am trying to parse json using lift-json. I am following this link: http://alvinalexander.com/scala/scala-json-array-parser-parsing-example-lift-json. I am encountering the following error:
error while loading DefaultFormats, Scala signature DefaultFormats has wrong version
[error] expected: 5.0
[error] found: 4.1 in DefaultFormats.class
How do I get rid of it?
This error appear due to using wrong version of lift-json. Use the correct version compatible with Scala version. The following dependency fixed the issue due to compatible version with Scala 2.11
<dependency>
<groupId>net.liftweb</groupId>
<artifactId>lift-json_2.11</artifactId>
<version>3.0.1</version>
</dependency>
I hope this helps anyone gets the same issue in the future.

CXF - No message body reader

I've tried many of the solutions in this forum to address this issue with no luck. I am using Apache CXF (v.2.5.11) and I need to post some Json to a REST endpoint and have the data unmarshaled to a Java object (e.g. Map).
When I post the request I get an internal server error with
org.apache.cxf.jaxrs.utils.JAXRSUtils readFromMessageBody
WARNING: No message body reader has been found for request class Map, ContentType : application/json.
I tried the solution here but with class com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider and maven artifact jackson-jaxrs-json-provider (version 2.5.4). No luck.
My endpoint is defined as such:
#POST
#Path("/test")
#Consumes(MediaType.APPLICATION_JSON)
#Produces(MediaType.APPLICATION_JSON)
public Response test(Map<String, Object> test) {
...
}
UPDATE
So I've figured out that if I go back to an old codehaus version of the JacksonJsonProvider, marshalling works fine:
Spring context:
<jaxrs:providers>
<bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
</jaxrs:providers>
With dependency:
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<version>1.9.0</version>
</dependency>
So I guess something has changed in the fasterxml 2.4+ version.
I encountered the same issue.
According to http://osdir.com/ml/users-cxf-apache/2013-06/msg00212.html there was an error in cxf prior to 2.7.6
So try upgrading to cxf 2.7.6 (or newer) and your code should be working again.

Primefaces 5.1 and Wildfly does not deploy

I'm migrating my Glassfish app to Wildfly and there seems to be a compatibility error with Primefaces 5.1 JSF and Wildfly's bundled version. When I go to deploy, I get the following error:
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.VerifyError: (class: org/primefaces/component/api/UIData, method: getDataModel signature: )Ljavax/faces/model/DataModel;) Incompatible argument to function
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:219)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:87)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.start(UndertowDeploymentService.java:72)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
... 3 more
Has anyone else gotten this error? Any help is greatly appreciated.
The real answer was the JSF API/Impl wasn't included as a dependency in the jboss-deployment-structure. This caused all sorts of linkage errors. Once I added the following to my deployment/subdeployments in the file, the application bootstrapped.
<dependencies>
<module name="javax.faces.api" />
<module name="com.sun.jsf-impl" />
</dependencies>