use of won.protocol.message.processor.exception.WonMessageProcessingException in project webofneeds by researchstudio-sat.
the class WonMessageFromHeaderToBodySerializingCamelProcessor method process.
@Override
public void process(final Exchange exchange) throws Exception {
logger.debug("processing won message");
Map headers = exchange.getIn().getHeaders();
// if the wonMessage header is there, don't change it - that way we can re-route internal messages
WonMessage wonMessage = (WonMessage) headers.get(WonCamelConstants.MESSAGE_HEADER);
if (wonMessage == null) {
throw new WonMessageProcessingException("No WonMessage found in header '" + WonCamelConstants.MESSAGE_HEADER + "'");
}
StringWriter writer = new StringWriter();
RDFDataMgr.write(writer, wonMessage.getCompleteDataset(), Lang.TRIG);
exchange.getIn().setBody(writer.toString());
logger.debug("wrote serialized wonMessage to message body");
}
use of won.protocol.message.processor.exception.WonMessageProcessingException in project webofneeds by researchstudio-sat.
the class WonMessageIntoCamelProcessor method process.
@Override
public void process(final Exchange exchange) throws Exception {
logger.debug("processing won message");
Map headers = exchange.getIn().getHeaders();
// if the wonMessage header is there, don't change it - that way we can re-route internal messages
WonMessage wonMessage = (WonMessage) headers.get(WonCamelConstants.MESSAGE_HEADER);
if (wonMessage == null) {
try {
wonMessage = WonMessageDecoder.decode(Lang.TRIG, exchange.getIn().getBody().toString());
} catch (Exception e) {
// stop the exchange in this case - maybe at some point we can return a failure response but
// currently, we would have to look into the message for doing that, and looking into
// the message is not possible if we cannot decode it.
logger.info("could not decode message as TriG, ignoring it (the offending message is logged at loglevel 'DEBUG')", e);
if (logger.isDebugEnabled()) {
logger.debug("offending message: {}", exchange.getIn().getBody().toString());
}
exchange.setProperty(Exchange.ROUTE_STOP, Boolean.TRUE);
throw new WonMessageProcessingException("Could not decode message", e);
}
}
if (wonMessage == null) {
throw new WonMessageProcessingException("No WonMessage found in header '" + WonCamelConstants.MESSAGE_HEADER + "' or in the body");
}
exchange.getIn().setHeader(WonCamelConstants.MESSAGE_TYPE_HEADER, URI.create(wonMessage.getMessageType().getResource().getURI()));
exchange.getIn().setHeader(WonCamelConstants.MESSAGE_HEADER, wonMessage);
exchange.getIn().setBody(null);
}
use of won.protocol.message.processor.exception.WonMessageProcessingException in project webofneeds by researchstudio-sat.
the class SignatureAddingWonMessageProcessor method processOnBehalfOfNeed.
public WonMessage processOnBehalfOfNeed(final WonMessage message) throws WonMessageProcessingException {
// use senderNeed key for signing
String alias = keyPairAliasDerivationStrategy.getAliasForNeedUri(message.getSenderNeedURI().toString());
PrivateKey privateKey = cryptographyService.getPrivateKey(alias);
PublicKey publicKey = cryptographyService.getPublicKey(alias);
try {
return processWithKey(message, message.getSenderNeedURI().toString(), privateKey, publicKey);
} catch (Exception e) {
logger.error("Failed to sign", e);
throw new WonMessageProcessingException("Failed to sign message " + message.getMessageURI().toString());
}
}
use of won.protocol.message.processor.exception.WonMessageProcessingException in project webofneeds by researchstudio-sat.
the class SignatureAddingWonMessageProcessor method process.
@Override
public WonMessage process(final WonMessage message) throws WonMessageProcessingException {
// use default key for signing
PrivateKey privateKey = cryptographyService.getDefaultPrivateKey();
String webId = cryptographyService.getDefaultPrivateKeyAlias();
PublicKey publicKey = cryptographyService.getPublicKey(webId);
try {
return processWithKey(message, webId, privateKey, publicKey);
} catch (Exception e) {
logger.error("Failed to sign", e);
throw new WonMessageProcessingException("Failed to sign message " + message.getMessageURI().toString());
}
}
use of won.protocol.message.processor.exception.WonMessageProcessingException in project webofneeds by researchstudio-sat.
the class SignatureCheckingWonMessageProcessor method process.
@Override
public WonMessage process(final WonMessage message) throws WonMessageProcessingException {
SignatureVerificationState result = null;
try {
// obtain public keys
Map<String, PublicKey> keys = getRequiredPublicKeys(message.getCompleteDataset());
// verify with those public keys
result = WonMessageSignerVerifier.verify(keys, message);
logger.debug("VERIFIED=" + result.isVerificationPassed() + " with keys: " + keys.values() + " for\n" + RdfUtils.writeDatasetToString(message.getCompleteDataset(), Lang.TRIG));
} catch (Exception e) {
// TODO SignatureProcessingException?
throw new WonMessageProcessingException("Could not verify message " + message.getMessageURI(), e);
}
// throw exception if the verification fails:
if (!result.isVerificationPassed()) {
// TODO SignatureProcessingException?
throw new WonMessageProcessingException(new SignatureException("Could not verify message " + message.getMessageURI() + ": " + result.getMessage()));
}
return message;
}
Aggregations