Requesting association to dcm4chee-arc-light5 from Java application

236 views
Skip to first unread message

Fabrício H. Simozo

unread,
Oct 18, 2018, 4:30:55 PM10/18/18
to dcm...@googlegroups.com
Hello, everyone.

I'm trying to write a Java application to query/retrieve DICOM images from my dcm4chee archive.

The archive is installed in a Linux Mint 19 Virtual Machine, configured with bridge connection.

I am able to connect with this archive without any problems with Weasis and dcm4che tools from my Windows host, but I receive an exception when trying to perform an association with the archive from a Java application using dcm4che core.

This is my code:

 Device device = new Device("device");
 
ApplicationEntity localAE = new ApplicationEntity("DEVICEAE");
 
Connection conn = new Connection();
 
Connection remote = new Connection();
 
AAssociateRQ rq = new AAssociateRQ();
 
 device
.addConnection(conn);
 device
.addApplicationEntity(localAE);
 localAE
.addConnection(conn);
 
 conn
.setCommonName("loc_conn");
 conn
.setHostname("localhost");
 conn
.setPort(localPort);
 conn
.setProtocol(Connection.Protocol.DICOM);
 conn
.setInstalled(true);
 localAE
.addConnection(conn);
 
 
ApplicationEntity remAE = new ApplicationEntity();
 remAE
.setAETitle(remoteAE);
 
 remote
.setCommonName("rem_conn");
 remote
.setHostname(remoteIP);
 remote
.setPort(remotePort);
 remote
.setProtocol(Connection.Protocol.DICOM);
 remote
.setInstalled(true);
 remAE
.addConnection(remote);
 
 rq
.setCalledAET(remAE.getAETitle());
 rq
.setCallingAET(localAE.getAETitle());
 rq
.setApplicationContext("1.2.840.10008.3.1.1.1");
 rq
.setImplClassUID("1.2.40.0.13.1.1");
 rq
.setImplVersionName("dcm4che-5.14.1");
 rq
.setMaxPDULength(16384);
 rq
.setMaxOpsInvoked(0);
 rq
.setMaxOpsPerformed(0);
 rq
.addPresentationContext(new PresentationContext(
     
1, "1.2.840.10008.1.1", "1.2.840.10008.1.2"));


 
Executor exec = (Runnable command) -> {};
 device
.setExecutor(exec);


 
try {
 
Association assoc = localAE.connect(conn, remote, rq);
 
} catch (IOException | InterruptedException | IncompatibleConnectionException | GeneralSecurityException e) {
 
// TODO Auto-generated catch block
 e
.printStackTrace();
 
}



And this is the exception I receive when running it:
java.net.SocketException: Network is unreachable: connect
 at java
.net.DualStackPlainSocketImpl.connect0(Native Method)
 at java
.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
 at java
.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
 at java
.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
 at java
.net.AbstractPlainSocketImpl.connect(Unknown Source)
 at java
.net.PlainSocketImpl.connect(Unknown Source)
 at java
.net.SocksSocketImpl.connect(Unknown Source)
 at java
.net.Socket.connect(Unknown Source)
 at org
.dcm4che3.net.Connection.connect(Connection.java:965)
 at org
.dcm4che3.net.ApplicationEntity.connect(ApplicationEntity.java:609)
 at com
.ciaware.dicom.test.ConnectionTest.main(ConnectionTest.java:96)


With this code, I receive "ONLINE", meaning it is possible to reach my VirtualMachine from the Java application.
 try {
 
while (true) {
 SocketAddress sockaddr = new InetSocketAddress(remoteIP, remotePort);
 Socket socket = new Socket();
 boolean online = true;
 try {
 socket.connect(sockaddr, 10000);
 }
 catch (IOException IOException) {
 online = false;
 }
 if(!online){
 System.out.println("OFFLINE");
 }
 if(online){
 System.out.println("ONLINE");
 }
 Thread.sleep(1 * 1000);
 }}
}
 catch (InterruptedException e) {
 e.printStackTrace();
 }



If I use "dcmqrscp" in Windows, and then try to connect to it from my Java application, the association is completed with success.

19:14:49,541 DEBUG - DCMQRSCP<-DEVICEAE(2): enter state: Sta6 - Association established and ready for data transfer


I'm not entirely sure this problem is related to dcm4che, but the fact that I can connect with the archive without using it seems to be indicating I'm missing something when configuring the connection.

I appreciate any kind of help. I am still new to all of this, and the lack of documentation is really discouraging.

Thank you in advance!
Fabrício.

Fabrício H. Simozo

unread,
Oct 19, 2018, 11:37:53 AM10/19/18
to dcm...@googlegroups.com
With a little bit more digging, I think I found the answer to it.

The problem is that I was defining the host name for the local connection with "conn.setHostname("localhost");"
When performing the connection between the local and remote addresses, the class Connection binds the socket instance to its defined hostname (in this case, "localhost"). Hence, it was impossible to connect to anything out of the loopback.

Changing it to  "conn.setHostname(localIP);" apparently did the trick, and I can now succesfuly perform the association with the archive.

----- EDIT -----

The association is still not complete. If I try to either connect to my archive or to the localhost dcmqrscp, the java application hangs in

DEBUG org.dcm4che3.net.Association  - DEVICEAE->DCMQRSCP(1): enter state: Sta5 - Awaiting A-ASSOCIATE-AC or A-ASSOCIATE-RJ PDU

 even though the server is sending the A-ASSOCIATE-AC message and waits on 

DEBUG - DCMQRSCP<-DEVICEAE(3): enter state: Sta6 - Association established and ready for data transfer 

Java application log:
 [main] INFO org.dcm4che3.net.Connection  - Initiate connection from 0.0.0.0/0.0.0.0:0 to localhost:11112
8 [main] INFO org.dcm4che3.net.Connection  - Established connection Socket[addr=localhost/127.0.0.1,port=11112,localport=50101]
19 [main] DEBUG org.dcm4che3.net.Association  - /127.0.0.1:50101->localhost/127.0.0.1:11112(1): enter state: Sta4 - Awaiting transport connection opening to complete
19 [main] INFO org.dcm4che3.net.Association  - DEVICEAE->DCMQRSCP(1) << A-ASSOCIATE-RQ
27 [main] DEBUG org.dcm4che3.net.Association  - A-ASSOCIATE-RQ[
  calledAET
: DCMQRSCP
  callingAET
: DEVICEAE
  applicationContext
: 1.2.840.10008.3.1.1.1 - DICOM Application Context Name
  implClassUID
: 1.2.40.0.13.1.3
  implVersionName
: dcm4che-5.14.1
  maxPDULength
: 16378
  maxOpsInvoked
/maxOpsPerformed: 1/1
 
PresentationContext[id: 1
   
as: 1.2.840.10008.5.1.4.1.2.2.1 - Study Root Query/Retrieve Information Model - FIND
    ts
: 1.2.840.10008.1.2 - Implicit VR Little Endian
 
]
]
27 [main] DEBUG org.dcm4che3.net.Association  - DEVICEAE->DCMQRSCP(1): enter state: Sta5 - Awaiting A-ASSOCIATE-AC or A-ASSOCIATE-RJ PDU

DCMRQSCP log:
19:11:29,397 INFO  - Accept connection Socket[addr=/127.0.0.1,port=50101,localport=11112]
19:11:29,397 DEBUG - /
127.0.0.1:11112<-/127.0.0.1:50101(3): enter state: Sta2 - Transport connection open
19:11:29,416 INFO  - DCMQRSCP<-DEVICEAE(3) >> A-ASSOCIATE-RQ
19:11:29,416 DEBUG - A-ASSOCIATE-RQ[
 calledAET
: DCMQRSCP
 callingAET
: DEVICEAE
 applicationContext
: 1.2.840.10008.3.1.1.1 - DICOM Application Context Name
 implClassUID
: 1.2.40.0.13.1.3
 implVersionName
: dcm4che-5.14.1
 maxPDULength
: 16378
 maxOpsInvoked
/maxOpsPerformed: 1/1
 
PresentationContext[id: 1
 
as: 1.2.840.10008.5.1.4.1.2.2.1 - Study Root Query/Retrieve Information Model - FIND
 ts
: 1.2.840.10008.1.2 - Implicit VR Little Endian
 
]
]
19:11:29,419 DEBUG - DCMQRSCP<-DEVICEAE(3): enter state: Sta3 - Awaiting local A-ASSOCIATE response primitive
19:11:29,419 INFO  - DCMQRSCP<-DEVICEAE(3) << A-ASSOCIATE-AC
19:11:29,419 DEBUG - A-ASSOCIATE-AC[
 calledAET
: DCMQRSCP
 callingAET
: DEVICEAE
 applicationContext
: 1.2.840.10008.3.1.1.1 - DICOM Application Context Name
 implClassUID
: 1.2.40.0.13.1.3
 implVersionName
: dcm4che-5.14.1
 maxPDULength
: 16378
 maxOpsInvoked
/maxOpsPerformed: 1/1
 
PresentationContext[id: 1
 result
: 0 - acceptance
 ts
: 1.2.840.10008.1.2 - Implicit VR Little Endian
 
]
]
19:11:29,427 DEBUG - DCMQRSCP<-DEVICEAE(3): enter state: Sta6 - Association established and ready for data transfer


Em quinta-feira, 18 de outubro de 2018 17:30:55 UTC-3, Fabrício H. Simozo escreveu:
Hello, everyone.

 ...
Reply all
Reply to author
Forward
0 new messages