use of org.w3._2007.rif.If in project arctic-sea by 52North.
the class Soap12Encoder method createSOAP12FaultFromExceptionResponse.
// see
// http://www.angelikalanger.com/GenericsFAQ/FAQSections/ProgrammingIdioms.html#FAQ300
// for more details
private XmlObject createSOAP12FaultFromExceptionResponse(final OwsExceptionReport owsExceptionReport) throws EncodingException {
final FaultDocument faultDoc = FaultDocument.Factory.newInstance();
final Fault fault = faultDoc.addNewFault();
final Faultcode code = fault.addNewCode();
code.setValue(SOAPConstants.SOAP_SENDER_FAULT);
// 19.2.3 SOAP 1.2 Fault Binding
if (!owsExceptionReport.getExceptions().isEmpty()) {
final CodedException firstException = owsExceptionReport.getExceptions().get(0);
final Subcode subcode = code.addNewSubcode();
QName qName;
if (firstException.getCode() != null) {
qName = OwsHelper.getQNameForLocalName(firstException.getCode().toString());
} else {
qName = OwsHelper.getQNameForLocalName(OwsExceptionCode.NoApplicableCode.name());
}
subcode.setValue(qName);
final Reasontext addNewText = fault.addNewReason().addNewText();
addNewText.setLang(Locale.ENGLISH.getLanguage());
addNewText.setStringValue(SoapHelper.getSoapFaultReasonText(firstException.getCode()));
fault.addNewDetail().set(encodeObjectToXml(OWSConstants.NS_OWS, firstException, EncodingContext.of(XmlBeansEncodingFlags.ENCODE_OWS_EXCEPTION_ONLY)));
}
return faultDoc;
}
use of org.w3._2007.rif.If in project nhin-d by DirectProject.
the class XDClient method send.
public void send(String endpoint, DirectDocuments documents) throws Exception {
ProvideAndRegisterDocumentSetRequestType request = documents.toProvideAndRegisterDocumentSetRequestType();
String response;
try {
response = forward(endpoint, request);
} catch (Exception e) {
throw new Exception("Unable to send message " + this.messageId, e);
}
if (StringUtils.contains(response, "Failure"))
LOGGER.warn("Endpoint returned a failure for message " + this.messageId);
}
use of org.w3._2007.rif.If 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.w3._2007.rif.If in project nhin-d by DirectProject.
the class DefaultMimeXdsTransformer method transform.
/*
* (non-Javadoc)
*
* @see org.nhindirect.transform.MimeXdsTransformer#transform(javax.mail.internet.MimeMessage)
*/
@Override
public ProvideAndRegisterDocumentSetRequestType transform(MimeMessage mimeMessage) throws TransformationException {
ProvideAndRegisterDocumentSetRequestType request;
DirectDocuments documents = new DirectDocuments();
byte[] xdsDocument = null;
String xdsMimeType = null;
FormatCodeEnum xdsFormatCode = null;
DirectDocumentType documentType = null;
try {
Date sentDate = mimeMessage.getSentDate();
String subject = mimeMessage.getSubject();
String from = mimeMessage.getFrom()[0].toString();
Address[] recipients = mimeMessage.getAllRecipients();
// Plain mail (no attachments)
if (MimeType.TEXT_PLAIN.matches(mimeMessage.getContentType())) {
LOGGER.info("Handling plain mail (no attachments) - " + mimeMessage.getContentType());
// Get the document type
documentType = DirectDocumentType.lookup(mimeMessage);
// Get the format code and MIME type
xdsFormatCode = documentType.getFormatCode();
xdsMimeType = documentType.getMimeType().getType();
// Get the contents
xdsDocument = ((String) mimeMessage.getContent()).getBytes();
// Add document to the collection of documents
documents.getDocuments().add(getDocument(sentDate, from, xdsMimeType, xdsFormatCode, xdsDocument, documentType));
documents.setSubmissionSet(getSubmissionSet(subject, sentDate, from, recipients, xdsDocument, documentType));
} else // Multipart/mixed (attachments)
if (MimeType.MULTIPART.matches(mimeMessage.getContentType())) {
LOGGER.info("Handling multipart/mixed - " + mimeMessage.getContentType());
MimeMultipart mimeMultipart = (MimeMultipart) mimeMessage.getContent();
BodyPart xdmBodyPart = null;
for (int i = 0; i < mimeMultipart.getCount(); i++) {
//check for XDM
BodyPart bodyPart = mimeMultipart.getBodyPart(i);
documentType = DirectDocumentType.lookup(bodyPart);
if (DirectDocumentType.XDM.equals(documentType)) {
xdmBodyPart = bodyPart;
}
}
// For each BodyPart
for (int i = 0; i < mimeMultipart.getCount(); i++) {
/*
* Special handling for XDM attachments.
*
* Spec says if XDM package is present, this will be the
* only attachment.
*
* Overwrite all documents with XDM content and then break
*/
if (xdmBodyPart != null) {
XdmPackage xdmPackage = XdmPackage.fromXdmZipDataHandler(xdmBodyPart.getDataHandler());
// Spec says if XDM package is present, this will be the only attachment
// Overwrite all documents with XDM content and then break
System.out.println("XDM FILE FOUND");
documents = xdmPackage.getDocuments();
break;
}
BodyPart bodyPart = mimeMultipart.getBodyPart(i);
// Skip empty BodyParts
if (bodyPart.getSize() <= 0) {
LOGGER.warn("Empty body, skipping");
continue;
}
// Get the document type
documentType = DirectDocumentType.lookup(bodyPart);
if (LOGGER.isInfoEnabled()) {
LOGGER.info("File name: " + bodyPart.getFileName());
}
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Content type: " + bodyPart.getContentType());
}
if (LOGGER.isInfoEnabled()) {
LOGGER.info("DocumentType: " + documentType.toString());
}
// Get the format code and MIME type
xdsFormatCode = documentType.getFormatCode();
xdsMimeType = documentType.getMimeType().getType();
// Best guess for UNKNOWN MIME type
if (DirectDocumentType.UNKNOWN.equals(documentType)) {
xdsMimeType = bodyPart.getContentType();
}
// Get the contents
xdsDocument = read(bodyPart);
// Add the document to the collection of documents
documents.getDocuments().add(getDocument(sentDate, from, xdsMimeType, xdsFormatCode, xdsDocument, documentType));
documents.setSubmissionSet(getSubmissionSet(subject, sentDate, from, recipients, xdsDocument, documentType));
}
} else {
if (LOGGER.isWarnEnabled()) {
LOGGER.warn("Message content type (" + mimeMessage.getContentType() + ") is not supported, skipping");
}
}
} catch (MessagingException e) {
if (LOGGER.isErrorEnabled()) {
LOGGER.error("Unexpected MessagingException occured while handling MimeMessage", e);
}
throw new TransformationException("Unable to complete transformation.", e);
} catch (IOException e) {
if (LOGGER.isErrorEnabled()) {
LOGGER.error("Unexpected IOException occured while handling MimeMessage", e);
}
throw new TransformationException("Unable to complete transformation.", e);
} catch (Exception e) {
if (LOGGER.isErrorEnabled()) {
LOGGER.error("Unexpected Exception occured while handling MimeMessage", e);
}
throw new TransformationException("Unable to complete transformation", e);
}
try {
request = documents.toProvideAndRegisterDocumentSetRequestType();
} catch (IOException e) {
if (LOGGER.isErrorEnabled()) {
LOGGER.error("Unexpected IOException occured while transforming to ProvideAndRegisterDocumentSetRequestType", e);
}
throw new TransformationException("Unable to complete transformation", e);
}
return request;
}
use of org.w3._2007.rif.If in project nhin-d by DirectProject.
the class DefaultXdmXdsTransformer method getDocName.
public String getDocName(File file) throws TransformationException {
LOGGER.trace("Begin transformation of XDM to XDS (file)");
ZipFile zipFile = null;
String objectId = null;
ProvideAndRegisterDocumentSetRequestType prsr = new ProvideAndRegisterDocumentSetRequestType();
try {
zipFile = new ZipFile(file, ZipFile.OPEN_READ);
Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();
ZipEntry zipEntry = null;
// load the ZIP archive into memory
while (zipEntries.hasMoreElements()) {
zipEntry = zipEntries.nextElement();
String zname = zipEntry.getName();
LOGGER.trace("Processing a ZipEntry " + zname);
if (!zipEntry.isDirectory()) {
String subsetDirspec = getSubmissionSetDirspec(zipEntry.getName());
// Read metadata
if (matchName(zname, subsetDirspec, XDM_FILENAME_METADATA)) {
ByteArrayOutputStream byteArrayOutputStream = readData(zipFile, zipEntry);
SubmitObjectsRequest submitObjectRequest = (SubmitObjectsRequest) XmlUtils.unmarshal(byteArrayOutputStream.toString(), oasis.names.tc.ebxml_regrep.xsd.lcm._3.ObjectFactory.class);
prsr.setSubmitObjectsRequest(submitObjectRequest);
objectId = getDocName(submitObjectRequest);
}
// Read data
}
}
zipFile.close();
} catch (Exception e) {
if (LOGGER.isErrorEnabled()) {
LOGGER.error("Unable to complete getObjectId.", e);
}
throw new TransformationException("Unable to complete getObjectId.", e);
}
return objectId;
}
Aggregations