# HG changeset patch # User Sebastien Jodogne # Date 1697709338 -7200 # Node ID 88c1614fb3dc6f32fe474055a6e9ff3cb3405271 # Parent 26c08ff926a3aacd00de07845575d0cc4f32577f added sample basic plugin diff -r 26c08ff926a3 -r 88c1614fb3dc .hgignore --- a/.hgignore Thu Oct 19 11:21:20 2023 +0200 +++ b/.hgignore Thu Oct 19 11:55:38 2023 +0200 @@ -3,10 +3,14 @@ syntax: glob *~ +JavaSDK/i/ +Plugin/Build/ Plugin/ThirdPartyDownloads/ Plugin/i/ Plugin/r/ +Plugin/s/ Plugin/w32/ Plugin/w64/ -Plugin/s/ -JavaSDK/i/ +Samples/Basic/.idea/ +Samples/Basic/OrthancStorage/ +Samples/Basic/target/ diff -r 26c08ff926a3 -r 88c1614fb3dc .reuse/dep5 --- a/.reuse/dep5 Thu Oct 19 11:21:20 2023 +0200 +++ b/.reuse/dep5 Thu Oct 19 11:55:38 2023 +0200 @@ -3,7 +3,7 @@ Upstream-Contact: Sebastien Jodogne Source: https://orthanc.uclouvain.be/ -Files: NEWS README +Files: NEWS README Samples/Basic/NOTES.txt Copyright: 2023 Sebastien Jodogne, UCLouvain, Belgium License: CC0-1.0 diff -r 26c08ff926a3 -r 88c1614fb3dc Samples/Basic/NOTES.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Samples/Basic/NOTES.txt Thu Oct 19 11:55:38 2023 +0200 @@ -0,0 +1,29 @@ +To run this sample Java plugin: + + +(1) Make sure to build the C++ plugin: + +# cd ../../Plugin/ +# mkdir Build +# cd Build +# cmake .. -DCMAKE_BUILD_TYPE=Release +# make -j4 + + +(2) Compile the Java plugin using Maven: + +# cd ../../Samples/Basic +# mvn package + + +(3) Start Orthanc: + +On Ubuntu 22.04: + +# LD_LIBRARY_PATH=/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/ Orthanc ./configuration.json + + +(4) Call the REST API implemented by the Java plugin: + +# curl http://localhost:8042/java +Hello from Java! diff -r 26c08ff926a3 -r 88c1614fb3dc Samples/Basic/configuration.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Samples/Basic/configuration.json Thu Oct 19 11:55:38 2023 +0200 @@ -0,0 +1,8 @@ +{ + "Plugins" : [ "../../Plugin/Build" ], + "Java" : { + "Enabled" : true, + "Classpath" : "target/Basic-0.0-SNAPSHOT-jar-with-dependencies.jar", + "InitializationClass" : "Main" + } +} diff -r 26c08ff926a3 -r 88c1614fb3dc Samples/Basic/pom.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Samples/Basic/pom.xml Thu Oct 19 11:55:38 2023 +0200 @@ -0,0 +1,70 @@ + + + + + + 4.0.0 + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + maven-assembly-plugin + + + package + + single + + + + + + jar-with-dependencies + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + + + add-source + generate-sources + + add-source + + + + ${project.basedir}/../../JavaSDK/be/uclouvain/orthanc + + + + + + + + + + OrthancJava + Basic + 0.0-SNAPSHOT + + + + diff -r 26c08ff926a3 -r 88c1614fb3dc Samples/Basic/src/main/java/Main.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Samples/Basic/src/main/java/Main.java Thu Oct 19 11:55:38 2023 +0200 @@ -0,0 +1,46 @@ +/** + * SPDX-FileCopyrightText: 2023 Sebastien Jodogne, UCLouvain, Belgium + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +/** + * Java plugin for Orthanc + * Copyright (C) 2023 Sebastien Jodogne, UCLouvain, Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + **/ + + +import be.uclouvain.orthanc.Callbacks; +import be.uclouvain.orthanc.RestOutput; +import be.uclouvain.orthanc.HttpMethod; + +import java.util.Map; + +public class Main { + static { + Callbacks.register("/java", new Callbacks.OnRestRequest() { + @Override + public void call(RestOutput output, + HttpMethod method, + String uri, + String[] regularExpressionGroups, + Map headers, + Map getParameters, + byte[] body) { + output.answerBuffer("Hello from Java!\n".getBytes(), "text/plain"); + } + }); + } +}