Использование Джерси с открытой свободой в Gradle - PullRequest
0 голосов
/ 06 апреля 2019

У меня есть простая установка с Gradle и Open Liberty.В этом посте https://openliberty.io/blog/2018/12/14/microprofile21-18004.html написано

«Open Liberty теперь имеет реактивные расширения для JAX-RS 2.1, так что вы можете использовать провайдеров из Apache CXF и Jersey»

Но я могузаставить его работать с Джерси

Я перепробовал различные конфигурации моего файла build.gradle и server.xml, но все еще не могу заставить его работать и не нашел документации.

build.gradle

apply plugin: 'war'
apply plugin: 'liberty'
apply plugin: 'java-library'

group = 'x.y.z'
version = '1.0-SNAPSHOT'
description = "X Y Z"

sourceCompatibility = 1.8
targetCompatibility = 1.8
tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}



buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'net.wasdev.wlp.gradle.plugins:liberty-gradle-plugin:2.6.3'
    }
}

repositories {
    mavenCentral()
}

//required for compiling, testing and running the application
dependencies {

    implementation group: 'org.glassfish.jersey.core', name: 'jersey-client', version: '2.26'
    implementation group: 'org.glassfish.jersey.core', name: 'jersey-common', version: '2.26'
    implementation group: 'org.glassfish.jersey.core', name: 'jersey-server', version: '2.26'

    providedCompile group:'javax.servlet', name:'javax.servlet-api', version:'3.1.0'
    testCompile group:'commons-httpclient', name:'commons-httpclient', version:'3.1'
    testCompile group:'junit', name:'junit', version:'4.12'

    libertyRuntime group:'io.openliberty', name:'openliberty-runtime', version:'19.0.0.3'

    // This dependency is exported to consumers, that is to say found on their compile classpath.
    api 'org.apache.commons:commons-math3:3.6.1'

    // This dependency is used internally, and not exposed to consumers on their own compile classpath.
    implementation 'com.google.guava:guava:27.0.1-jre'
    testImplementation 'junit:junit:4.12'
}

//Extra properties for project level 
ext {
    appName = project.name
    testServerHttpPort = 9080
    testServerHttpsPort = 9443
    warContext = appName
}

liberty {
    server {
        name = "${appName}Server"
        configFile = file("src/main/liberty/config/server.xml")
        bootstrapProperties = ['default.http.port': testServerHttpPort,
                               'default.https.port': testServerHttpsPort,
                               'app.context.root': warContext]
        packageLiberty {
            archive = "$buildDir/${appName}.zip"
            include = "usr"
        }
    }
}

war {
    archiveName = "${baseName}.${extension}"
}

//unit test configuration
test {
    reports.html.destination = file("$buildDir/reports/unit")
    reports.junitXml.destination = file("$buildDir/test-results/unit")
    exclude '**/it/**'
}

//integration test configuration
task integrationTest(type: Test) {
    group 'Verification'
    description 'Runs the integration tests.'
    reports.html.destination = file("$buildDir/reports/it")
    reports.junitXml.destination = file("$buildDir/test-results/it")
    include '**/it/**'
    exclude '**/unit/**'

    systemProperties = ['liberty.test.port': testServerHttpPort, 'war.name': warContext]
}

task openBrowser {
    description = 'Open browser to http://localhost:8080/${warContext}'
    doLast {
        java.awt.Desktop.desktop.browse
            "http://localhost:${testServerHttpPort}/${appName}".toURI()
    }
}

task openTestReport {
    description = 'Open browser to the test report'
    doLast {
        java.awt.Desktop.desktop.browse file("$buildDir/reports/it/index.html").toURI()
    }
}

clean.dependsOn 'libertyStop'
check.dependsOn 'integrationTest'
integrationTest.dependsOn 'libertyStart'
integrationTest.finalizedBy 'libertyStop'
integrationTest.finalizedBy 'openTestReport'
libertyPackage.dependsOn 'libertyStop'

server.xml

<?xml version="1.0" encoding="UTF-8"?>
<server description="new server">
    <featureManager>
        <!--   <feature>jsp-2.3</feature> -->
        <!--  <feature>jaxrs-2.1</feature> -->
        <feature>servlet-4.0</feature>
        <!--  
         -->
    </featureManager>
    <httpEndpoint id="defaultHttpEndpoint"
                  httpPort="${default.http.port}"
                  httpsPort="${default.https.port}" />
    <applicationManager autoExpand="true"/>
    <webApplication contextRoot="${app.context.root}" location="${app.context.root}.war" />
</server>

HelloWorldService

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;

@Path("/hello")
public class HelloWorldService {

    @GET
    @Path("/{param}")
    public Response getMsg(@PathParam("param") String msg) {
        String output = "Jersey say : " + msg;
        return Response.status(200).entity(output).build();
    }

}

Когда я пытаюсь попасть в конечную точку, я получаю 404

curl localhost:9080/XYZ/hello/jersey

Ошибка 404: java.io.FileNotFoundException: SRVE0190E: Файл не найден: / hello / jersey

Любая помощь НАМНОГО оценена!

...