Jersey 2.26 app returns wrong date format in Glassfish 5.0 - glassfish

I'm trying to format the date returned by my rest services application which works fine in my embedded development environment (using https://github.com/akhikhl/gretty).
Some of my webservices are returning dates as string and I'm having different results in different environments.
In Glassfish 5.0 my dates are as 2017-12-05T21:37:24Z[UTC] while Jetty returns 2017-12-05T21:37:24+01:00 (CEST) which is parsable from my angularJS frontend application.
I have the following build.gradle build script in which none of the dependencies is set as provided.
/************* BUILD CONFIGURATION ***************/
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.akhikhl.gretty:gretty:2.0.0'
classpath 'org.hibernate:hibernate-gradle-plugin:5.2.11.Final'
}
}
// Apply the java plugin to add support for Java
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'war'
apply plugin: 'org.akhikhl.gretty'
apply plugin: 'org.hibernate.orm'
hibernate {
enhance {
enableDirtyTracking = true
}
}
gretty {
httpPort = 8080
contextPath = '/restapi'
fastReload = true
// ... many more properties
}
/************* RUNTIME CONFIGURATION ***************/
war.archiveName "restapi.war"
// In this section you declare where to find the dependencies of your project
repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
mavenCentral()
jcenter()
}
def jersey_version = 2.26
// In this section you declare the dependencies for your production and test code
dependencies {
// The production code uses the SLF4J logging API at compile time
compile 'org.slf4j:slf4j-api:1.7.21'
compile group: 'org.jboss.spec', name: 'jboss-javaee-7.0', version:'1.0.3.Final'
// groovy
compile 'org.codehaus.groovy:groovy-all:2.4.7'
// rest dependencies
compile 'javax.ws.rs:javax.ws.rs-api:2.0.1'
compile 'org.glassfish.jersey.containers:jersey-container-servlet:' + jersey_version
compile group: 'org.glassfish.jersey.media', name: 'jersey-media-moxy', version: jersey_version
compile group: 'org.glassfish.jersey.ext', name: 'jersey-entity-filtering', version: jersey_version
// id scrambling dependency
compile 'org.hashids:hashids:1.0.1'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.7'
compile group: 'org.apache.commons', name: 'commons-collections4', version: '4.1'
compile group: 'commons-codec', name: 'commons-codec', version: '1.11'
// database
compile 'javax.el:el-api:2.2'
compile 'mysql:mysql-connector-java:5.1.18'
compile 'org.hibernate:hibernate-core:5.2.11.Final'
compile group: 'org.hibernate', name: 'hibernate-c3p0', version: '5.2.11.Final'
compile 'org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final'
compile 'org.hibernate:hibernate-entitymanager:5.2.11.Final'
}
I tried using Jackson instead of MOXy by registering a feature in my (jersey) Application class but as soon as I register a whatever Feature in my application it breaks resulting in 404 errors at every resource request. That said I don't know if using Jackson or adding another Feature to manipulate the resulting date object (to even return a timestamp instead of an ISO date.

Related

"Could not find method wrapper()" in build.gradle file generated by openapi-generator kotlin client

I have a simple spring boot project using the kotlin gradle dsl. I want to generate an OpenApi client using the openapi client generator gradle Plugin. I have successfully done so, using this configuration. Until now, this was a single project build. But when i try to include it, i get an error message "Could not find method wrapper()".
This is how i generated the client and added it's file into my source sets:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.springframework.boot") version "3.0.2"
id("io.spring.dependency-management") version "1.1.0"
kotlin("jvm") version "1.7.22"
kotlin("plugin.spring") version "1.7.22"
id("org.openapi.generator") version "6.3.0"
}
// other dependencies
openApiGenerate {
generatorName.set("kotlin")
inputSpec.set("src/main/openapi/my-api.yml")
outputDir.set("$buildDir/generated/my-api")
packageName.set("com.myapi")
}
kotlin.sourceSets["main"].kotlin.srcDir("$buildDir/generated/my-api/src/main/kotlin")
Now i want to use this generated client in my project. It comes with it's own build.gradle (in groovy) which loads the necessary dependencies etc.
I have modified my settings.gradle.kts file accordingly:
rootProject.name = "myapp"
include("build:generated:my-api")
When i reload gradle, i get the follwing error:
> Could not find method wrapper() for arguments [build_gdswinwcvulw9afq79kj4v6h$_run_closure1#582f32f7] on project ':build:generated:my-api' of type org.gradle.api.Project.
This is due to the build.gradle file generated by the generator looking like this:
group 'org.openapitools'
version '1.0.0'
wrapper {
gradleVersion = '7.5'
distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
}
buildscript {
ext.kotlin_version = '1.7.21'
repositories {
maven { url "https://repo1.maven.org/maven2" }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin'
apply plugin: 'maven-publish'
repositories {
maven { url "https://repo1.maven.org/maven2" }
}
test {
useJUnitPlatform()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation "com.squareup.moshi:moshi-kotlin:1.13.0"
implementation "com.squareup.moshi:moshi-adapters:1.13.0"
implementation "com.squareup.okhttp3:okhttp:4.10.0"
testImplementation "io.kotlintest:kotlintest-runner-junit5:3.4.2"
}
I am using Gradle 7.6 and i am a bit out of ideas here since i am pretty new to Gradle.

Build Intellij plugin in IDEA 2019.1 & 2020.3

Building for IDEA 2019.1 works like a charm! I thought that building for 2020.3 would be just a matter of pointing to 2020.3 installation folder and that's it, but it is not being even close to it.
That's my gradle.build
group 'com.test.plugin'
version '1.0-SNAPSHOT'
buildscript {
repositories {
maven {
url "https://mydomain/repository/public-maven/"
}
}
dependencies {
classpath group: 'org.jetbrains.intellij.plugins', name: 'gradle-intellij-plugin', version: '0.6.5'
}
}
apply plugin: 'java'
apply plugin: 'org.jetbrains.intellij'
intellij {
localPath 'C:/Program Files/JetBrains/IntelliJ IDEA 2019.1.3'
}
sourceCompatibility = 1.8
repositories {
maven {
url "https://mydomain/repository/public-maven/"
}
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
runtime group: 'com.google.guava', name: 'guava', version: '23.0'
runtime group: 'org.apache.commons', name: 'commons-lang3', version: '3.11'
}
It is important to mention that since I'm working behind a restricted company proxy I can't just set the Intellij version in order to get the necessary distribution files to the build (Intellij.localPath)
Building it on IDEA 2019.1, JDK 1.8 works fine. In order to build the same code for a IDEA 2020.3 I just replaced the Intellij distribution path:
intellij {
//localPath 'C:/Program Files/JetBrains/IntelliJ IDEA 2019.1.3'
localPath 'C:/Dev/apps/ideaIU-2020.3'
}
Trying to build it now immediately throws it:
error: cannot access AnAction
bad class file: C:\Dev\apps\ideaIU-2020.3\lib\platform-api.jar(com/intellij/openapi/actionSystem/AnAction.class)
class file has wrong version 55.0, should be 52.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
What I understand form it is that AnAction class was built using Java 11. So, I replaced the project JDK to use also JDK11 and from that moment I started facing compilation errors, like com.intellij.psi.PsiJavaFile cannot be found.
I might be missing some conceptual point here.
it turns out there was a missing plugin dependency.
this line was not being effective to resolve such dependency. In order to fix that I had to remove apply plugin: 'java' and set intellij.plugin
intellij {
localPath 'C:/Dev/apps/ideaIU-2020.3'
plugin = ['com.intellij.java']
}

No screenshots are captured by serenity after test run

I have serenity.properties file with such configurations:
serenity.take.screenshots = BEFORE_AND_AFTER_EACH_STEP
webdriver.driver = "chrome"
Also I have PageObjects, Steps layer and Tests module
My Gradle build file looks like:
group 'com.am'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'net.serenity-bdd.aggregator'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
}
buildscript {
repositories {
mavenLocal()
jcenter()
}
dependencies {
classpath("net.serenity-bdd:serenity-gradle-plugin:1.4.0")
}
}
dependencies {
compile 'net.serenity-bdd:serenity-core:1.4.0'
compile 'net.serenity-bdd:serenity-junit:1.4.0'
compile 'junit:junit:4.12'
compile 'org.assertj:assertj-core:1.7.0'
compile 'org.slf4j:slf4j-simple:1.7.7'
compile group: 'net.serenity-bdd', name: 'serenity-rest-assured', version: '1.4.0'
compile group: 'org.jsoup', name: 'jsoup', version: '1.8.3'
compile 'ru.yandex.qatools.htmlelements:htmlelements-all:1.17'
}
gradle.startParameter.continueOnFailure = true
When I run tests with simple command
gradle clean test aggregate
Report is generated but without any screenshots.
My report looks like:
generated report
Could anybody please give an advice where am I wrong?
I think it's some simple one but I can't understand where...
In all manuals it says that serenity makes screenshots by default but I don't have any.
The issue is solved. Driver should be managed by Serenity but I used to create my own instance of a driver.
Resolution:
1. add Managed tag to tests
#Managed
WebDriver driver;
remove from all places any other driver instances.
check that serenity.properties contains (e.g)
webdriver.driver = chrome
webdriver.chrome.driver = pathtodriver/chromedriver.exe

IntelliJ Idea 16 CE gradle issues

In my gradle file I am trying to use the following to solve another issue. This is my gradle file:
group 'com.winapp'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'src/main/java/libs', include: ['*.jar'])
compile 'com.intellij:forms_rt:6.0.5'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
task copyDependenciesToTarget(type: Copy) {
println 'Copying dependencies to target...'
configurations.compile.collect().each { compileDependency ->
copy {
with from (compileDependency.getPath()) {
include '*'
}
into 'target/libs/libs'
}
}
}
build.dependsOn(copyDependenciesToTarget)
jar {
manifest.attributes(
"Main-Class": "Main",
"Class-Path": configurations.compile.collect { 'libs/' + it.getName()}.join(' ')
)
}
The problem are is this:
configurations.compile.collect().each { compileDependency ->
copy {
with from (compileDependency.getPath()) {
include '*'
}
into 'target/libs/libs'
}
}
When I run the application I get this Exception:
org.gradle.api.internal.file.copy.CopySpecWrapper_Decorated cannot be cast to org.gradle.api.internal.file.copy.CopySpecInternal
Main problem is, I have no idea how to fix this error, I simply want my project to create a JAR file that works with JDBC, using this gradle code seems to be a solution for that issue, but now I have run into another problem, yet again.
Please let me know if you require any additional information and thank you in advance. Literally, I cant even. This problem.
EDIT
As stated in the comments. My project runs fine when I run it through the IDE. There is an issue when I create a JAR file using gradle. The bare gradle file that IntelliJ created when I started the gradle project follows (Added the jar config so my Main class would be picked up):
group 'com.winapp'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'src/main/java/libs', include: ['*.jar'])
compile 'com.intellij:forms_rt:6.0.5'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
jar {
manifest.attributes(
"Main-Class": "Main",
"Class-Path": configurations.compile.collect { 'libs/' + it.getName()}.join(' ')
)
}
When I execute my app from terminal after the JAR has been created (keeping in mind there are no issues when hitting run in the IDE) with java -jar myAppName.jar:
java.lang.ClassNotFoundException: org.sqlite.JDBC
NOTE: Usually I get a full stack running a java app, but in this case the above is the only output.
I am using this JAR for my sqlite needs:
sqlite-jdbc-3.15.1
As a test I commented out the Sqlite usage in my application and the JAR file worked fine. My GUI was displayed and everything went as expected (all things considered). The JAR stops working when I add the sqlite JAR file usage (code). Added it the same as my other libs (like retrofit), so this seems to be quite a strange issue.
Please let me know if I have explained the issue correctly?

How to debug xtend code in IntelliJ + Gradle?

I have just started to learn Xtend (http://xtend-lang.org/) and try to write a small app in IntelliJ 2016 based on a Gradle project using the Xtext/Xtend 2.10.0 plugins from the standard repository. The problem is that I cannot debug my Xtend code. Breakpoints are all ignored although debugging of Java code works. Debugging Xtend code only works if I use the IntelliJ wizard and create a standard IntelliJ project without using Gradle. I don't know how to fix this? Do I miss something? Does debugging works different in a Gradle project?
Here my Gradle file:
group 'GradleXtend'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'org.xtext.xtend'
sourceCompatibility = 1.5
repositories {
jcenter()
mavenCentral()
}
dependencies {
compile 'org.eclipse.xtend:org.eclipse.xtend.lib:2.10.0'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.xtext:xtext-gradle-plugin:1.0.12'
}
}
xtend {
debugger {
//how to install debug info into generated Java code
//SMAP adds Xtend debug info on top of Java
//PRIMARY makes Xtend the only debug info (throws away Java line numbers)
//default is SMAP for Java projects and PRIMARY for Android
sourceInstaller = 'SMAP' //or 'PRIMARY' or 'NONE'
//whether to hide synthetic variables in the debugger
hideSyntheticVariables = false
}
}
My Xtend file:
package HelloWorld
class HelloWorld2 {
def static void main(String[] args) {
println("Hello")
}
}