Mercurial > hg > orthanc-java
changeset 9:88c1614fb3dc
added sample basic plugin
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 19 Oct 2023 11:55:38 +0200 |
parents | 26c08ff926a3 |
children | 6b9433432ee0 |
files | .hgignore .reuse/dep5 Samples/Basic/NOTES.txt Samples/Basic/configuration.json Samples/Basic/pom.xml Samples/Basic/src/main/java/Main.java |
diffstat | 6 files changed, 160 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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/
--- 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 <s.jodogne@gmail.com> 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
--- /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!
--- /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" + } +}
--- /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 @@ +<?xml version='1.0' encoding='UTF-8'?> + +<!-- + + SPDX-FileCopyrightText: 2023 Sebastien Jodogne, UCLouvain, Belgium + SPDX-License-Identifier: GPL-3.0-or-later + +--> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.8</source> + <target>1.8</target> + </configuration> + </plugin> + + <!-- https://stackoverflow.com/a/1729094 --> + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <executions> + <execution> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + </execution> + </executions> + <configuration> + <descriptorRefs> + <descriptorRef>jar-with-dependencies</descriptorRef> + </descriptorRefs> + </configuration> + </plugin> + + <!-- Include the Orthanc Java SDK --> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <executions> + <execution> + <id>add-source</id> + <phase>generate-sources</phase> + <goals> + <goal>add-source</goal> + </goals> + <configuration> + <sources> + <source>${project.basedir}/../../JavaSDK/be/uclouvain/orthanc</source> + </sources> + </configuration> + </execution> + </executions> + </plugin> + + </plugins> + </build> + + <groupId>OrthancJava</groupId> + <artifactId>Basic</artifactId> + <version>0.0-SNAPSHOT</version> + + <dependencies> + </dependencies> +</project>
--- /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 <http://www.gnu.org/licenses/>. + **/ + + +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<String, String> headers, + Map<String, String> getParameters, + byte[] body) { + output.answerBuffer("Hello from Java!\n".getBytes(), "text/plain"); + } + }); + } +}