Wicket 9 - com/github/openjson/JSONException - json

I'm upgrading an old Wicket app to Wicket 9. (
"Out of the box", I'm getting a NoClassDefFoundError: com/github/openjson/JSONException
I've included all Wicket 9 Jars in the libraries.
Where this Class should come from ? What did I miss ?
ERROR [io.undertow.request] (default task-1) UT005023: Exception handling request to /misapps/xxxx/: java.lang.NoClassDefFoundError: com/github/openjson/JSONException
at deployment.xxxx.ear.xxxx.war//org.apache.wicket.extensions.ajax.markup.html.AjaxIndicatorAppender.<init>(AjaxIndicatorAppender.java:61)
at deployment.xxxx.ear.xxxx.war//org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxFallbackLink.<init>(IndicatingAjaxFallbackLink.java:40)

Looks like you miss the openjson dependency in your casspath.
If you are using maven, add the following to your pom:
<!-- https://mvnrepository.com/artifact/com.github.openjson/openjson -->
<dependency>
<groupId>com.github.openjson</groupId>
<artifactId>openjson</artifactId>
<version>1.0.12</version>
</dependency>

Related

Generated protoc file creates a target source with error

I have tried to make a project that connects to a DB and takes information and outputes them in a desktop application through grpc.
But, when I compile it I get "Error:(20,18) java: cannot find symbol" in a target file( which is auto-generated by protoc.
I can't understand the issue with this. I have tried to change the compiler of mvn, to change the version on protoc, to setup a different JDK, everything just gets worse that it already is.
My project can be viewed here : https://github.com/Diana-Ioana/grpc
My db and error with the generated target files that crashes is : https://imgur.com/a/T6taLXF
I have no idea what to do now. Any help would be greate, thank you!
It looks like the "cannot find symbol" is referring to javax.annotation.Generated. In that case you can add a dependency on annotations-api:
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>annotations-api</artifactId>
<version>6.0.53</version>
<!-- Generated has #Retention(SOURCE), so not needed at runtime -->
<scope>provided</scope>
</dependency>
Originally this answer suggested javax.annotation-api, but that library is licensed CDDL so gRPC changed its recommendation.
<!-- The old suggestion. Uses CDDL-licensed library -->
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.2</version>
</dependency>

error: package com.google.appengine.labs.repackaged.org.json does not exist

I want to return JSON object back to the client side.I add dependencies and it is not working again.What is the purpose of 'repackaged'?I can not find any documentation of this pacakge to add in pom.xml.It allows me to create a JSONObject but in my console appear this error?!
pom.xml
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-json-plugin</artifactId>
<version>${struts.version}</version>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-labs</artifactId>
<version>${appengine.app.version}</version>
<scope>test</scope>
</dependency>
I used Gson and works for me.It is easy to implement and convert Java object to JSON and vice versa!Here is GSON dependency:
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
Treat the 'repackaged' package as internal GAE implementation choices that may change. Such classes have their package path surgically altered to include repackaged so that they won't conflict with your choices.
I've had problems with Eclipse offering repackaged classes up as viable options. How to hide some Eclipse autocomplete results shows a way to fix that.
Just a follow up on this for IntelliJ users. You can tell the IDE to not offer repackaged classes in:
(for IntelliJ 2016.1)
Settings > Editor > General > Auto Import > Exclude from Import and
Completion
Enter there the following and you are done.
com.google.appengine.labs.repackaged
com.google.appengine.repackaged

Thymeleaf - Strict HTML parsing issue

HTML5 allows some tags to be written more liberally i.e without corresponding END tags. e.g. input need not be closed </input>.However if choose template mode HTML5 in Thymeleaf the Thymeleaf engine complains about this and does not parse the HTML template. I want to override this default Strict tag checking behavior. i.e Thymeleaf should parse an HTML template with meta and input (AND ALIKE) tags WITHOUT THEIR RESP. CLOSING TAGS. Pl. guide.
It also complains when you have something like this
<a href="/home/pic/image.png" download="/path/to/file" data-gallery></a>
It throws an exception when it encounters the data-gallery throws "should be followed by '=' " which is kind of annoying as it takes the flexibility out of HTML5.
All you have to do is run Thymeleaf in "LEGACYHTML5" mode and it works like a charm. Thanks to this and this post, I found the solution and am documenting in SO so others do not have to go through the same trouble in finding this answer.
To set the legacy mode you can define the bean in your Spring XML file:
<!-- View TemplateResolver -->
<bean id="templateResolver" class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
<property name="templateMode" value="LEGACYHTML5"/>
<property name="cacheable" value="false"/>
</bean>
or add the properties to the application.properties file:
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.cache=false
And in both cases you have to add the nekohtml jar to your project or, if you are running maven, you can add its dependency to your pom.xml
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.21</version>
</dependency>
Gradle
'net.sourceforge.nekohtml:nekohtml:1.9.21'
Here is how you can do it in a neat way
Step 1: Add thymeleaf mode to your application.properties file.
resources/application.properties
spring.thymeleaf.mode=LEGACYHTML5
Step 2: Add nekohtml dependency to your pom.xml file.
pom.xml
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
</dependency>
Using LEGACYHTML5 worked for me as well.
Also it is necessary to add
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
</dependency>
to pom.xml as stated above. But there is one more step which might occur. After doing those two steps I was getting:
java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal
To avoid this it is necessary to add
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.4.01</version>
</dependency>
to pom.xml

org.json.simple.JSONObject VS org.json.JSONObject , JSONException cannot be resolved to a type

First: can someone provide an explanation of the differences between org.json.simple.JSONObject and org.json.JSONObject?
Second: I have a code with org.json.JSONObject and org.json.JSONException. When I edit the code in eclipse ( JUNO) it resolves the type of JSONException and imports the package org.json.JSONException but when I run the project using maven in command line I have a problem ( JSONException cannot be resolved to a type). I tried to solve the issue by adding dependency to pom.xml like this :
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1</version>
</dependency>
but I am not sure if it is the right one . I even download the jar of org.
java-json.jar and add it to web deployment assembly but still the same error. Can anyone help ?
org.json and org.json.simple are two different Java libraries, which are incompatible with each other. The fact that they have the same name is only a misleading coincidence.
To compare the two libraries:
General comparison = http://www.rojotek.com/blog/2009/05/07/a-review-of-5-java-json-libraries/
org.json.simple = http://code.google.com/p/json-simple/
org.json = http://json.org/java

Jersey No WebApplication provider is present when jersey-* dependency added

I have a simple Spring & Jersey application, which works perfectly well for consuming requests through a simple Resource. However, I'd like to return a JSON response - containing a simple JSON serialization of an object. To achieve this, I've added a maven dependency for jersey-json. As soon as I add this dependency, however, I get this error at server startup:
com.sun.jersey.api.container.ContainerException: No WebApplication provider is present at
com.sun.jersey.spi.container.WebApplicationFactory.createWebApplication(WebApplicationFactory.java:69) at
com.sun.jersey.spi.container.servlet.ServletContainer.create(ServletContainer.java:391)
I'm not totally clear upon exactly what a provider is, but I'm pretty certain that there should be a default one found.
For completeness, here's my Resource:
#Path("/scan")
#Resource
#Component
public class ScanResource {
#GET
#Produces(MediaType.APPLICATION_JSON)
#Path("/{barcode}")
public List<Scan> getScansForBarcode(#PathParam("barcode") Long barcode){
..snip..
return results;
}
}
A Scan object is a simple Entity Bean object.
The mvn dependency is:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.11</version>
</dependency>
Does anyone know why I might be getting the No WebApplication provider is present Exception? Any thoughts on how I might resolve it?
Thanks
You need to have jersey-server jar on your classpath as well. And you need to make sure that all your jars are from the same version, Jersey runtime won't be able to use provided classes otherwise.
Additionally (most likely not relevant here, but..) there is a recent change in module structure - servlet dependencies were separated to new modules. So if you are using servlets, you might want to depend on jersey-servlet (which depends on jersey-server).
I am also had this issue. The issue was resolved by having same version for "jersey-json" and "jersey-servlet"maven dependencies.
EX:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.13</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
<version>1.13</version>
</dependency>