use of org.nhindirect.xd.soap.ThreadData in project nhin-d by DirectProject.
the class DocumentRepositoryAbstract method getHeaderData.
/**
* Extract header values from a ThreadData object.
*/
protected void getHeaderData() {
Long threadId = new Long(Thread.currentThread().getId());
LOGGER.info("DTHREAD ID " + threadId);
ThreadData threadData = new ThreadData(threadId);
this.endpoint = threadData.getReplyAddress();
this.messageId = threadData.getMessageId();
this.to = threadData.getTo();
this.thisHost = threadData.getThisHost();
this.remoteHost = threadData.getRemoteHost();
this.pid = threadData.getPid();
this.action = threadData.getAction();
this.from = threadData.getFrom();
this.directTo = threadData.getDirectTo();
this.directFrom = threadData.getDirectFrom();
LOGGER.info(threadData.toString());
}
use of org.nhindirect.xd.soap.ThreadData in project nhin-d by DirectProject.
the class DocumentRepositoryAbstract method setHeaderData.
/**
* Build a ThreadData object with header information.
*/
protected void setHeaderData() {
Long threadId = new Long(Thread.currentThread().getId());
LOGGER.info("THREAD ID " + threadId);
ThreadData threadData = new ThreadData(threadId);
threadData.setTo(this.to);
threadData.setMessageId(this.messageId);
threadData.setRelatesTo(this.relatesTo);
threadData.setAction(this.action);
threadData.setThisHost(this.thisHost);
threadData.setRemoteHost(this.remoteHost);
threadData.setPid(this.pid);
threadData.setFrom(this.from);
threadData.setDirectTo(this.directTo);
threadData.setDirectFrom(this.directFrom);
LOGGER.info(threadData.toString());
}
use of org.nhindirect.xd.soap.ThreadData in project nhin-d by DirectProject.
the class DocumentRepositoryAbstract method provideAndRegisterDocumentSet.
/**
* Handle an incoming ProvideAndRegisterDocumentSetRequestType object and
* transform to XDM or relay to another XDR endponit.
*
* @param prdst
* The incoming ProvideAndRegisterDocumentSetRequestType object
* @return a RegistryResponseType object
* @throws Exception
*/
protected RegistryResponseType provideAndRegisterDocumentSet(ProvideAndRegisterDocumentSetRequestType prdst) throws Exception {
RegistryResponseType resp = null;
try {
getHeaderData();
@SuppressWarnings("unused") InitialContext ctx = new InitialContext();
DirectDocuments documents = xdsDirectDocumentsTransformer.transform(prdst);
List<String> forwards = new ArrayList<String>();
// Get endpoints (first check direct:to header, then go to intendedRecipients)
if (StringUtils.isNotBlank(directTo))
forwards = Arrays.asList((new URI(directTo).getSchemeSpecificPart()));
else {
forwards = ParserHL7.parseRecipients(documents);
}
messageId = UUID.randomUUID().toString();
// TODO patID and subsetId
String patId = "PATID TBD";
String subsetId = "SUBSETID";
getAuditMessageGenerator().provideAndRegisterAudit(messageId, remoteHost, endpoint, to, thisHost, patId, subsetId, pid);
// Send to SMTP endpoints
if (getResolver().hasSmtpEndpoints(forwards)) {
// Get a reply address (first check direct:from header, then go to authorPerson)
if (StringUtils.isNotBlank(directFrom))
replyEmail = (new URI(directFrom)).getSchemeSpecificPart();
else {
replyEmail = documents.getSubmissionSet().getAuthorPerson();
replyEmail = StringUtils.splitPreserveAllTokens(replyEmail, "^")[0];
replyEmail = StringUtils.contains(replyEmail, "@") ? replyEmail : "nhindirect@nhindirect.org";
}
LOGGER.info("SENDING EMAIL TO " + getResolver().getSmtpEndpoints(forwards) + " with message id " + messageId);
// Construct message wrapper
DirectMessage message = new DirectMessage(replyEmail, getResolver().getSmtpEndpoints(forwards));
message.setSubject("XD* Originated Message");
message.setBody("Please find the attached XDM file.");
message.setDirectDocuments(documents);
// Send mail
MailClient mailClient = getMailClient();
mailClient.mail(message, messageId, suffix);
}
// Send to XD endpoints
for (String reqEndpoint : getResolver().getXdEndpoints(forwards)) {
String endpointUrl = getResolver().resolve(reqEndpoint);
String to = StringUtils.remove(endpointUrl, "?wsdl");
Long threadId = new Long(Thread.currentThread().getId());
LOGGER.info("THREAD ID " + threadId);
ThreadData threadData = new ThreadData(threadId);
threadData.setTo(to);
List<Document> docs = prdst.getDocument();
// Make a copy of the original documents
List<Document> originalDocs = new ArrayList<Document>();
for (Document d : docs) originalDocs.add(d);
// Clear document list
docs.clear();
// Re-add documents
for (Document d : originalDocs) {
Document doc = new Document();
doc.setId(d.getId());
DataHandler dh = d.getValue();
ByteArrayOutputStream buffOS = new ByteArrayOutputStream();
dh.writeTo(buffOS);
byte[] buff = buffOS.toByteArray();
DataSource source = new ByteArrayDataSource(buff, documents.getDocument(d.getId()).getMetadata().getMimeType());
DataHandler dhnew = new DataHandler(source);
doc.setValue(dhnew);
docs.add(doc);
}
LOGGER.info(" SENDING TO ENDPOINT " + to);
DocumentRepositoryProxy proxy = new DocumentRepositoryProxy(endpointUrl, new DirectSOAPHandlerResolver());
RegistryResponseType rrt = proxy.provideAndRegisterDocumentSetB(prdst);
String test = rrt.getStatus();
if (test.indexOf("Failure") >= 0) {
String error = "";
try {
error = rrt.getRegistryErrorList().getRegistryError().get(0).getCodeContext();
} catch (Exception x) {
}
throw new Exception("Failure Returned from XDR forward:" + error);
}
getAuditMessageGenerator().provideAndRegisterAuditSource(messageId, remoteHost, endpoint, to, thisHost, patId, subsetId, pid);
}
resp = getRepositoryProvideResponse(messageId);
relatesTo = messageId;
action = "urn:ihe:iti:2007:ProvideAndRegisterDocumentSet-bResponse";
to = endpoint;
setHeaderData();
} catch (Exception e) {
e.printStackTrace();
throw (e);
}
return resp;
}
use of org.nhindirect.xd.soap.ThreadData in project nhin-d by DirectProject.
the class DocumentRepository method setHeaderData.
/**
* Set header data.
*
* TODO: Investigate the usefulness of this method. It sets null known null
* values.
*/
protected void setHeaderData() {
Long threadId = Long.valueOf(Thread.currentThread().getId());
LOGGER.info("THREAD ID " + threadId);
ThreadData threadData = new ThreadData(threadId);
threadData.setTo(this.to);
threadData.setMessageId(this.messageId);
threadData.setAction(this.action);
threadData.setDirectTo(this.directTo);
threadData.setDirectFrom(this.directFrom);
LOGGER.info(threadData.toString());
}
use of org.nhindirect.xd.soap.ThreadData in project nhin-d by DirectProject.
the class ThreadDataTest method testThreadData.
/**
* Test methods in the ThreadData class.
*/
public void testThreadData() {
Map<Long, Map<String, String>> map = ThreadData.getThreadMapView();
// Compare against current size (which may affected by previous tests)
int mapSize = map.size();
ThreadData t1 = new ThreadData(new Long(99991));
t1.setAction("action.1");
t1.setFrom("from.1");
t1.setMessageId("messageId.1");
t1.setPid("pid.1");
t1.setRelatesTo("relatesTo.1");
t1.setRemoteHost("remoteHost.1");
t1.setReplyAddress("replyAddress.1");
t1.setThisHost("thisHost.1");
t1.setTo("to.1");
assertEquals("Map size does not match expected value.", mapSize + 1, map.size());
assertEquals("Map does not contain specific key.", true, map.containsKey(new Long(99991)));
assertEquals("Map value does not match expected.", "action.1", map.get(new Long(99991)).get(ThreadData.ACTION));
assertEquals("Map value does not match expected.", "from.1", map.get(new Long(99991)).get(ThreadData.FROM));
assertEquals("Map value does not match expected.", "messageId.1", map.get(new Long(99991)).get(ThreadData.MESSAGE));
assertEquals("Map value does not match expected.", "pid.1", map.get(new Long(99991)).get(ThreadData.PID));
assertEquals("Map value does not match expected.", "relatesTo.1", map.get(new Long(99991)).get(ThreadData.RELATESTO));
assertEquals("Map value does not match expected.", "remoteHost.1", map.get(new Long(99991)).get(ThreadData.REMOTEHOST));
assertEquals("Map value does not match expected.", "replyAddress.1", map.get(new Long(99991)).get(ThreadData.REPLY));
assertEquals("Map value does not match expected.", "thisHost.1", map.get(new Long(99991)).get(ThreadData.THISHOST));
assertEquals("Map value does not match expected.", "to.1", map.get(new Long(99991)).get(ThreadData.TO));
assertEquals("Instance value does not match expected.", "action.1", t1.getAction());
assertEquals("Instance value does not match expected.", "from.1", t1.getFrom());
assertEquals("Instance value does not match expected.", "messageId.1", t1.getMessageId());
assertEquals("Instance value does not match expected.", "pid.1", t1.getPid());
assertEquals("Instance value does not match expected.", "relatesTo.1", t1.getRelatesTo());
assertEquals("Instance value does not match expected.", "remoteHost.1", t1.getRemoteHost());
assertEquals("Instance value does not match expected.", "replyAddress.1", t1.getReplyAddress());
assertEquals("Instance value does not match expected.", "thisHost.1", t1.getThisHost());
assertEquals("Instance value does not match expected.", "to.1", t1.getTo());
t1.setTo("to.1.1");
assertEquals("Map value does not match expected.", "to.1.1", map.get(new Long(99991)).get(ThreadData.TO));
ThreadData t2 = new ThreadData(new Long(99992));
t2.setAction("action.2");
t2.setFrom("from.2");
t2.setMessageId("messageId.2");
t2.setPid("pid.2");
t2.setRelatesTo("relatesTo.2");
t2.setRemoteHost("remoteHost.2");
t2.setReplyAddress("replyAddress.2");
t2.setThisHost("thisHost.2");
t2.setTo("to.2");
assertEquals("Map size does not match expected value.", mapSize + 2, map.size());
assertEquals("Map does not contain specific key.", true, map.containsKey(new Long(99992)));
ThreadData.clean(new Long(99991));
assertTrue("Key,value was not removed from map", map.get(new Long(99991)) == null);
String out = t1.toString();
assertTrue("toString() output does not contain expected value", StringUtils.containsIgnoreCase(out, "No map found"));
out = t2.toString();
assertTrue("toString() output does not contain expected value", StringUtils.contains(out, "99992"));
}
Aggregations