From 034421763fbf824f15cb5af888ef5b059488f125 Mon Sep 17 00:00:00 2001 From: Gunter Zeilinger Date: Sun, 1 Jul 2018 17:22:34 +0200 Subject: [PATCH] initial commit --- .gitignore | 8 + c-echo-scp/pom.xml | 68 +++++++++ .../quickstart/cechoscp/CEchoSCP.java | 121 +++++++++++++++ .../src/main/resources/log4j.properties | 5 + c-echo-scu/pom.xml | 67 +++++++++ .../quickstart/cechoscu/CEchoSCU.java | 141 ++++++++++++++++++ .../src/main/resources/log4j.properties | 5 + pom.xml | 75 ++++++++++ quickstartparent.iml | 9 ++ 9 files changed, 499 insertions(+) create mode 100644 .gitignore create mode 100644 c-echo-scp/pom.xml create mode 100644 c-echo-scp/src/main/java/org/dcm4che3/quickstart/cechoscp/CEchoSCP.java create mode 100644 c-echo-scp/src/main/resources/log4j.properties create mode 100644 c-echo-scu/pom.xml create mode 100644 c-echo-scu/src/main/java/org/dcm4che3/quickstart/cechoscu/CEchoSCU.java create mode 100644 c-echo-scu/src/main/resources/log4j.properties create mode 100644 pom.xml create mode 100644 quickstartparent.iml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9eb9278 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +.classpath +.project +*.iml +.settings/ +.idea/ +target/ +.recommenders/ +.metadata/ diff --git a/c-echo-scp/pom.xml b/c-echo-scp/pom.xml new file mode 100644 index 0000000..aa7cf72 --- /dev/null +++ b/c-echo-scp/pom.xml @@ -0,0 +1,68 @@ + + + + + + quickstart-parent + org.dcm4che.quickstart + 5.13.3 + + 4.0.0 + + c-echo-scp + + + + org.dcm4che + dcm4che-core + ${project.version} + + + org.dcm4che + dcm4che-net + ${project.version} + + + + \ No newline at end of file diff --git a/c-echo-scp/src/main/java/org/dcm4che3/quickstart/cechoscp/CEchoSCP.java b/c-echo-scp/src/main/java/org/dcm4che3/quickstart/cechoscp/CEchoSCP.java new file mode 100644 index 0000000..28cd1b9 --- /dev/null +++ b/c-echo-scp/src/main/java/org/dcm4che3/quickstart/cechoscp/CEchoSCP.java @@ -0,0 +1,121 @@ +/* + * **** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is part of dcm4che, an implementation of DICOM(TM) in + * Java(TM), hosted at https://github.com/dcm4che. + * + * The Initial Developer of the Original Code is + * J4Care. + * Portions created by the Initial Developer are Copyright (C) 2015-2018 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * See @authors listed below + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * **** END LICENSE BLOCK ***** + * + */ + +package org.dcm4che3.quickstart.cechoscp; + +import org.dcm4che3.data.UID; +import org.dcm4che3.net.ApplicationEntity; +import org.dcm4che3.net.Connection; +import org.dcm4che3.net.Device; +import org.dcm4che3.net.TransferCapability; + +import java.io.IOException; +import java.security.GeneralSecurityException; +import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; + +/** + * @author Gunter Zeilinger + * @since Jul 2018 + */ +public class CEchoSCP { + private Device device; + private ApplicationEntity ae; + private Connection conn; + + public CEchoSCP(String calledAET, String bindAddress, int port) { + device = new Device("c-echo-scp"); + ae = new ApplicationEntity(calledAET); + conn = new Connection(null, "127.0.0.1", port); + conn.setBindAddress(bindAddress); + device.addApplicationEntity(ae); + device.addConnection(conn); + ae.addConnection(conn); + ae.addTransferCapability(new TransferCapability(null, + UID.VerificationSOPClass, TransferCapability.Role.SCP, UID.ImplicitVRLittleEndian)); + } + + public void setExecutor(Executor executor) { + device.setExecutor(executor); + } + + public void setScheduledExecutor(ScheduledExecutorService executor) { + device.setScheduledExecutor(executor); + } + + public void start() throws IOException, GeneralSecurityException { + device.bindConnections(); + } + + public static void main(String[] args) throws Exception { + CLI cli = CLI.parse(args); + ExecutorService executor = Executors.newCachedThreadPool(); + ScheduledExecutorService scheduledExecutor = Executors.newSingleThreadScheduledExecutor(); + CEchoSCP scp = new CEchoSCP(cli.calledAET, cli.bindAddress, cli.port); + scp.setExecutor(executor); + scp.setScheduledExecutor(scheduledExecutor); + scp.start(); + } + + private static class CLI { + final String calledAET; + final String bindAddress; + final int port; + + CLI(String[] args) { + calledAET = args[0]; + bindAddress = args[1]; + port = Integer.parseInt(args[2]); + } + + static CLI parse(String[] args) { + try { + return new CLI(args); + } catch (IndexOutOfBoundsException | NumberFormatException e) { + System.out.println("Usage: c-echo-scp "); + System.exit(-1); + return null; + } + } + } +} diff --git a/c-echo-scp/src/main/resources/log4j.properties b/c-echo-scp/src/main/resources/log4j.properties new file mode 100644 index 0000000..896dfe1 --- /dev/null +++ b/c-echo-scp/src/main/resources/log4j.properties @@ -0,0 +1,5 @@ +log4j.rootLogger=DEBUG, stdout + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %-5p - %m\n diff --git a/c-echo-scu/pom.xml b/c-echo-scu/pom.xml new file mode 100644 index 0000000..59357ca --- /dev/null +++ b/c-echo-scu/pom.xml @@ -0,0 +1,67 @@ + + + + + + quickstart-parent + org.dcm4che.quickstart + 5.13.3 + + 4.0.0 + + c-echo-scu + + + + org.dcm4che + dcm4che-core + ${project.version} + + + org.dcm4che + dcm4che-net + ${project.version} + + + \ No newline at end of file diff --git a/c-echo-scu/src/main/java/org/dcm4che3/quickstart/cechoscu/CEchoSCU.java b/c-echo-scu/src/main/java/org/dcm4che3/quickstart/cechoscu/CEchoSCU.java new file mode 100644 index 0000000..be8e38d --- /dev/null +++ b/c-echo-scu/src/main/java/org/dcm4che3/quickstart/cechoscu/CEchoSCU.java @@ -0,0 +1,141 @@ +/* + * **** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is part of dcm4che, an implementation of DICOM(TM) in + * Java(TM), hosted at https://github.com/dcm4che. + * + * The Initial Developer of the Original Code is + * J4Care. + * Portions created by the Initial Developer are Copyright (C) 2015-2018 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * See @authors listed below + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * **** END LICENSE BLOCK ***** + * + */ + +package org.dcm4che3.quickstart.cechoscu; + +import org.dcm4che3.data.UID; +import org.dcm4che3.net.*; +import org.dcm4che3.net.pdu.AAssociateRQ; +import org.dcm4che3.net.pdu.PresentationContext; + +import java.io.IOException; +import java.security.GeneralSecurityException; +import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; + +/** + * @author Gunter Zeilinger + * @since Jul 2018 + */ +public class CEchoSCU { + + private Device device; + private ApplicationEntity ae; + private Connection conn; + + public CEchoSCU(String callingAET) { + device = new Device("c-echo-scu"); + ae = new ApplicationEntity(callingAET); + conn = new Connection(); + device.addApplicationEntity(ae); + device.addConnection(conn); + ae.addConnection(conn); + } + + public void setExecutor(Executor executor) { + device.setExecutor(executor); + } + + public void setScheduledExecutor(ScheduledExecutorService executor) { + device.setScheduledExecutor(executor); + } + + public void echo(String calledAET, String hostName, int port) + throws IOException, InterruptedException, GeneralSecurityException, IncompatibleConnectionException { + Association as = ae.connect(mkConnection(hostName, port), mkAARQ(calledAET)); + as.cecho(); + as.release(); + } + + private AAssociateRQ mkAARQ(String calledAET) { + AAssociateRQ aarq = new AAssociateRQ(); + aarq.setCallingAET(ae.getAETitle()); // if not explicitly set, will be set in ae.connect(). + aarq.setCalledAET(calledAET); + aarq.addPresentationContext(new PresentationContext(1, + UID.VerificationSOPClass, UID.ImplicitVRLittleEndian)); + return aarq; + } + + private Connection mkConnection(String hostName, int port) { + return new Connection("dicom", hostName, port); + } + + public static void main(String[] args) throws Exception { + CLI cli = CLI.parse(args); + ExecutorService executor = Executors.newSingleThreadExecutor(); + ScheduledExecutorService scheduledExecutor = Executors.newSingleThreadScheduledExecutor(); + try { + CEchoSCU scu = new CEchoSCU(cli.callingAET); + scu.setExecutor(executor); + scu.setScheduledExecutor(scheduledExecutor); + scu.echo(cli.calledAET, cli.hostname, cli.port); + } finally { + executor.shutdown(); + scheduledExecutor.shutdown(); + } + } + + private static class CLI { + final String callingAET; + final String calledAET; + final String hostname; + final int port; + + CLI(String[] args) { + callingAET = args[0]; + calledAET = args[1]; + hostname = args[2]; + port = Integer.parseInt(args[3]); + } + + static CLI parse(String[] args) { + try { + return new CLI(args); + } catch (IndexOutOfBoundsException | NumberFormatException e) { + System.out.println("Usage: c-echo-scu "); + System.exit(-1); + return null; + } + } + } +} diff --git a/c-echo-scu/src/main/resources/log4j.properties b/c-echo-scu/src/main/resources/log4j.properties new file mode 100644 index 0000000..896dfe1 --- /dev/null +++ b/c-echo-scu/src/main/resources/log4j.properties @@ -0,0 +1,5 @@ +log4j.rootLogger=DEBUG, stdout + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %-5p - %m\n diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..fb2fc34 --- /dev/null +++ b/pom.xml @@ -0,0 +1,75 @@ + + + + + 4.0.0 + + org.dcm4che.quickstart + quickstart-parent + 5.13.3 + pom + + + UTF-8 + + + + + + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + + + + + + + c-echo-scu + c-echo-scp + + + \ No newline at end of file diff --git a/quickstartparent.iml b/quickstartparent.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/quickstartparent.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file