|
@@ -0,0 +1,78 @@
|
|
|
+package com.zskk.service;
|
|
|
+
|
|
|
+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;
|
|
|
+import org.dcm4che3.data.UID;
|
|
|
+import org.dcm4che3.net.ApplicationEntity;
|
|
|
+import org.dcm4che3.net.Association;
|
|
|
+import org.dcm4che3.net.Connection;
|
|
|
+import org.dcm4che3.net.Device;
|
|
|
+import org.dcm4che3.net.IncompatibleConnectionException;
|
|
|
+import org.dcm4che3.net.pdu.AAssociateRQ;
|
|
|
+import org.dcm4che3.net.pdu.PresentationContext;
|
|
|
+
|
|
|
+public class DicomEchoService {
|
|
|
+
|
|
|
+ private Device device;
|
|
|
+ private ApplicationEntity ae;
|
|
|
+ private Connection 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()); // optional: will be set in ae.connect() if not explicitly set.
|
|
|
+ aarq.setCalledAET(calledAET);
|
|
|
+ aarq.addPresentationContext(new PresentationContext(1,
|
|
|
+ UID.VerificationSOPClass, UID.ImplicitVRLittleEndian));
|
|
|
+ return aarq;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Connection mkConnection(String hostName, int port) {
|
|
|
+ return new Connection(null, hostName, port);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param calledAeTitle
|
|
|
+ * @param host
|
|
|
+ * @param port
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public void doEcho(String calledAeTitle, String host, Integer port) throws Exception {
|
|
|
+ ExecutorService executor = Executors.newSingleThreadExecutor();
|
|
|
+ ScheduledExecutorService scheduledExecutor = Executors.newSingleThreadScheduledExecutor();
|
|
|
+ try {
|
|
|
+ device = new Device("c-echo-scu");
|
|
|
+ ae = new ApplicationEntity("c-echo-scu");
|
|
|
+ conn = new Connection();
|
|
|
+ device.addApplicationEntity(ae);
|
|
|
+ device.addConnection(conn);
|
|
|
+ ae.addConnection(conn);
|
|
|
+ this.setExecutor(executor);
|
|
|
+ this.setScheduledExecutor(scheduledExecutor);
|
|
|
+ this.echo(calledAeTitle, host, port);
|
|
|
+ } finally {
|
|
|
+ executor.shutdown();
|
|
|
+ scheduledExecutor.shutdown();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|