use of org.w3._2007.rif.Document in project poi by apache.
the class TestSignatureInfo method sign.
private void sign(OPCPackage pkgCopy, String alias, String signerDn, int signerCount) throws Exception {
initKeyPair(alias, signerDn);
SignatureConfig signatureConfig = new SignatureConfig();
signatureConfig.setKey(keyPair.getPrivate());
signatureConfig.setSigningCertificateChain(Collections.singletonList(x509));
signatureConfig.setExecutionTime(cal.getTime());
signatureConfig.setDigestAlgo(HashAlgorithm.sha1);
signatureConfig.setOpcPackage(pkgCopy);
SignatureInfo si = new SignatureInfo();
si.setSignatureConfig(signatureConfig);
Document document = DocumentHelper.createDocument();
// operate
DigestInfo digestInfo = si.preSign(document, null);
// verify
assertNotNull(digestInfo);
LOG.log(POILogger.DEBUG, "digest algo: " + digestInfo.hashAlgo);
LOG.log(POILogger.DEBUG, "digest description: " + digestInfo.description);
assertEquals("Office OpenXML Document", digestInfo.description);
assertNotNull(digestInfo.hashAlgo);
assertNotNull(digestInfo.digestValue);
// setup: key material, signature value
byte[] signatureValue = si.signDigest(digestInfo.digestValue);
// operate: postSign
si.postSign(document, signatureValue);
// verify: signature
si.getSignatureConfig().setOpcPackage(pkgCopy);
List<X509Certificate> result = new ArrayList<X509Certificate>();
for (SignaturePart sp : si.getSignatureParts()) {
if (sp.validate()) {
result.add(sp.getSigner());
}
}
assertEquals(signerCount, result.size());
}
use of org.w3._2007.rif.Document in project hale by halestudio.
the class TestModelRifToRifTranslator method testTranslateExample3CPSimpleFilter.
/**
* Tests that it is possible to translate the example 3 CP source dataset,
* including a simple predicate filter.
*
* @throws TranslationException
* if any errors occurred during the translation
* @throws JAXBException
* if unable to write out a DOM document containing the RIF-PRD
*/
@Test
public void testTranslateExample3CPSimpleFilter() throws TranslationException, JAXBException {
URL url = getClass().getClassLoader().getResource(// $NON-NLS-1$
"com/onespatial/jrc/tnstg/proto/oml_to_rif/alignments/example3_cp_filter.goml");
org.w3._2007.rif.Document doc = translator.translate(url);
assertNotNull(doc);
assertNotNull(doc.getPayload());
assertNotNull(doc.getPayload().getGroup());
assertNotNull(doc.getPayload().getGroup().getSentence());
assertThat(doc.getPayload().getGroup().getSentence().size(), is(1));
assertNotNull(doc.getPayload().getGroup().getSentence().get(0));
checkJavaBindings(doc);
writeDom(getDomFromRif(doc), System.out);
}
use of org.w3._2007.rif.Document in project hale by halestudio.
the class TestModelRifToRifTranslator method testTranslateExample3CPComplexFilter.
/**
* Tests that it is possible to translate the example 3 CP source dataset,
* including a slightly more complex predicate filter.
*
* @throws TranslationException
* if any errors occurred during the translation
* @throws JAXBException
* if unable to write out a DOM document containing the RIF-PRD
*/
@Test
public void testTranslateExample3CPComplexFilter() throws TranslationException, JAXBException {
URL url = getClass().getClassLoader().getResource(// $NON-NLS-1$
"com/onespatial/jrc/tnstg/proto/oml_to_rif/alignments/example3_complex_logical_filter.goml");
org.w3._2007.rif.Document doc = translator.translate(url);
assertNotNull(doc);
assertNotNull(doc.getPayload());
assertNotNull(doc.getPayload().getGroup());
assertNotNull(doc.getPayload().getGroup().getSentence());
assertThat(doc.getPayload().getGroup().getSentence().size(), is(1));
assertNotNull(doc.getPayload().getGroup().getSentence().get(0));
checkJavaBindings(doc);
writeDom(getDomFromRif(doc), System.out);
}
use of org.w3._2007.rif.Document in project hale by halestudio.
the class ModelRifToRifTranslator method translate.
/**
* @see com.onespatial.jrc.tns.oml_to_rif.api.Translator#translate(Object)
* which this method implements.
* @param source
* {@link ModelRifDocument}
* @return {@link Document}
* @throws TranslationException
* if any exceptions are thrown during translation.
*/
@Override
public Document translate(ModelRifDocument source) throws TranslationException {
final Document document = factory.createDocument();
Payload payload = factory.createPayload();
document.setPayload(payload);
GroupContents group = factory.createGroupContents();
payload.setGroup(group);
for (ModelSentence s : source.getSentences()) {
group.getSentence().add(buildSentence(s));
}
return document;
}
use of org.w3._2007.rif.Document 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;
}
Aggregations