private void init(String sealAlgorithm, int sealKeySize) { if (sealAlgorithm == null || sealKeySize < 1) { return; } _sealAlgorithm = sealAlgorithm; try { KeyGenerator keyGenerator = KeyGenerator.getInstance(_sealAlgorithm); keyGenerator.init(sealKeySize); _secretKey = keyGenerator.generateKey(); } catch (NoSuchAlgorithmException nsae) { throw new SwitchYardException(nsae); } }
/** * Validate the current message on the exchange. * @param exchange exchange * @throws HandlerException handler exception */ @Override public void handleMessage(Exchange exchange) throws HandlerException { Validator<?> validator = get(exchange); if (validator != null) { try { ValidationResult result = applyValidator(exchange, validator); if (!result.isValid()) { throw RuntimeMessages.MESSAGES.validatorFailed(validator.getClass().getName(), result.getDetail()); } } catch (SwitchYardException syEx) { // Validators which throw SwitchYardException should be reported as HandlerException throw new HandlerException(syEx.getMessage()); } } }
/** * Validate the current message on the exchange. * @param exchange exchange * @throws ValidationFailureException validation failure exception */ @Override public void handleMessage(Exchange exchange) throws ValidationFailureException { Validator<?> validator = get(exchange); if (validator != null) { try { ValidationResult result = applyValidator(exchange, validator); if (!result.isValid()) { String msg = RuntimeMessages.MESSAGES.validatorFailed( validator.getClass().getName(), validator.getType().getName(), validator.getName().toString(), result.getDetail()); throw new ValidationFailureException(validator, result, msg); } } catch (SwitchYardException e) { // Validators which throw SwitchYardException should be reported as a ValidationFailureException String msg = RuntimeMessages.MESSAGES.validatorFailed( validator.getClass().getName(), validator.getType().getName(), validator.getName().toString(), e); throw new ValidationFailureException(validator, e.getCause() != null ? e.getCause() : e, msg); } } }
throw new HandlerException(syEx.getMessage());
private void init(String sealAlgorithm, int sealKeySize) { if (sealAlgorithm == null || sealKeySize < 1) { return; } _sealAlgorithm = sealAlgorithm; try { KeyGenerator keyGenerator = KeyGenerator.getInstance(_sealAlgorithm); keyGenerator.init(sealKeySize); _secretKey = keyGenerator.generateKey(); } catch (NoSuchAlgorithmException nsae) { throw new SwitchYardException(nsae); } }
throw new HandlerException(syEx.getMessage());
private String getTransactionManagerName(URI uri) { try { final Map<String, Object> parseParameters = URISupport.parseParameters(uri); String name = (String) parseParameters.get("transactionManager"); if (name != null) { name = name.replace("#", ""); } return name; } catch (URISyntaxException e) { throw new SwitchYardException(e); } }
private String getTransactionManagerName(URI uri) { try { final Map<String, Object> parseParameters = URISupport.parseParameters(uri); String name = (String) parseParameters.get("transactionManager"); if (name != null) { name = name.replace("#", ""); } return name; } catch (URISyntaxException e) { throw new SwitchYardException(e); } }
/** * Seals the specified object. * @param object the object * @return the sealed object */ public SealedObject seal(Serializable object) { try { Cipher cipher = Cipher.getInstance(_sealAlgorithm); cipher.init(Cipher.ENCRYPT_MODE, _secretKey); return new SealedObject(object, cipher); } catch (Exception e) { throw new SwitchYardException(e); } }
/** * Unseals the specified sealed object. * @param object the sealed object * @return the unsealed object */ public Serializable unseal(SealedObject object) { try { Cipher cipher = Cipher.getInstance(_sealAlgorithm); cipher.init(Cipher.DECRYPT_MODE, _secretKey); return (Serializable)object.getObject(cipher); } catch (Exception e) { throw new SwitchYardException(e); } }
/** * Seals the specified object. * @param object the object * @return the sealed object */ public SealedObject seal(Serializable object) { try { Cipher cipher = Cipher.getInstance(_sealAlgorithm); cipher.init(Cipher.ENCRYPT_MODE, _secretKey); return new SealedObject(object, cipher); } catch (Exception e) { throw new SwitchYardException(e); } }
/** * Unseals the specified sealed object. * @param object the sealed object * @return the unsealed object */ public Serializable unseal(SealedObject object) { try { Cipher cipher = Cipher.getInstance(_sealAlgorithm); cipher.init(Cipher.DECRYPT_MODE, _secretKey); return (Serializable)object.getObject(cipher); } catch (Exception e) { throw new SwitchYardException(e); } }
/** * Initialize new instance of mixin and read configuration. * * @throws Exception In case of initialization failure. */ public AMQPMixIn() throws Exception { _properties = new Properties(); InputStream is = this.getClass().getResourceAsStream(AMQP_PROPERTIES_FILE); try { _properties.load(is); _qpidConnectionFactory = _properties.getProperty(AMQP_PROPS_QPID_CONNECTIONFACTORY); } finally { is.close(); } if (_qpidConnectionFactory == null) { throw new SwitchYardException("No connection factory configured. Please set "+ AMQP_PROPS_QPID_CONNECTIONFACTORY + " in the "+AMQP_PROPERTIES_FILE+" file found in the class path of your application"); } _qpidQueueExchange = _properties.getProperty(AMQP_PROPS_QUEUE_EXCHANGE); _qpidTopicExchange = _properties.getProperty(AMPQ_PROPS_TOPIC_EXCHANGE); if (_qpidQueueExchange == null && _qpidTopicExchange == null) { throw new SwitchYardException("No topic or queue configured. Please set either one by using " + AMQP_PROPS_QUEUE_EXCHANGE + " or " + AMPQ_PROPS_TOPIC_EXCHANGE + " in your " + AMQP_PROPERTIES_FILE + " properties file."); } }
private UriBuilder createUriBuilder(URI baseUri, Class<?> resourceClass, Method method) { UriBuilder builder = null; try { builder = (UriBuilder)URIBUILDER_CLASS.newInstance(); } catch (Exception ie) { throw new SwitchYardException(ie); } builder.uri(baseUri); if (resourceClass.isAnnotationPresent(Path.class)) { builder.path(resourceClass); } if (_method.isAnnotationPresent(Path.class)) { builder.path(method); } return builder; }
/** * Initialize new instance of mixin and read configuration. * * @throws Exception In case of initialization failure. */ public AMQPMixIn() throws Exception { _properties = new Properties(); InputStream is = this.getClass().getResourceAsStream(AMQP_PROPERTIES_FILE); try { _properties.load(is); _qpidConnectionFactory = _properties.getProperty(AMQP_PROPS_QPID_CONNECTIONFACTORY); } finally { is.close(); } if (_qpidConnectionFactory == null) { throw new SwitchYardException("No connection factory configured. Please set "+ AMQP_PROPS_QPID_CONNECTIONFACTORY + " in the "+AMQP_PROPERTIES_FILE+" file found in the class path of your application"); } _qpidQueueExchange = _properties.getProperty(AMQP_PROPS_QUEUE_EXCHANGE); _qpidTopicExchange = _properties.getProperty(AMPQ_PROPS_TOPIC_EXCHANGE); if (_qpidQueueExchange == null && _qpidTopicExchange == null) { throw new SwitchYardException("No topic or queue configured. Please set either one by using " + AMQP_PROPS_QUEUE_EXCHANGE + " or " + AMPQ_PROPS_TOPIC_EXCHANGE + " in your " + AMQP_PROPERTIES_FILE + " properties file."); } }
/** * Get a JMS Session from an ActiveMQ connection. * @return JMS Session */ public Session getSession() { ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(_url); try { if (_connection == null) { _connection = connectionFactory.createConnection(_user, _passwd); _connection.start(); } return _connection.createSession(false, Session.AUTO_ACKNOWLEDGE); } catch (JMSException e) { throw new SwitchYardException(e); } }
/** * Get a JMS Session from an ActiveMQ connection. * @return JMS Session */ public Session getSession() { ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(_url); try { if (_connection == null) { _connection = connectionFactory.createConnection(_user, _passwd); _connection.start(); } return _connection.createSession(false, Session.AUTO_ACKNOWLEDGE); } catch (JMSException e) { throw new SwitchYardException(e); } }
private void init(String keyStoreLocation, String keyStoreType, char[] keyStorePassword, String keyAlias, char[] keyPassword, String keyTransformation) { if (keyStoreLocation == null) { return; } KeyStorePuller keyStorePuller = new KeyStorePuller(keyStoreType, keyStorePassword); KeyStore keyStore = keyStorePuller.pullPath(keyStoreLocation, getClass(), PathType.values()); try { Certificate certificate = keyStore.getCertificate(keyAlias); _publicKey = certificate.getPublicKey(); _keyTransformation = keyTransformation != null ? keyTransformation : _publicKey.getAlgorithm(); } catch (KeyStoreException kse) { throw new SwitchYardException(kse); } }
private void init(String keyStoreLocation, String keyStoreType, char[] keyStorePassword, String keyAlias, char[] keyPassword, String keyTransformation) { if (keyStoreLocation == null) { return; } KeyStorePuller keyStorePuller = new KeyStorePuller(keyStoreType, keyStorePassword); KeyStore keyStore = keyStorePuller.pullPath(keyStoreLocation, getClass(), PathType.values()); try { Certificate certificate = keyStore.getCertificate(keyAlias); _publicKey = certificate.getPublicKey(); _keyTransformation = keyTransformation != null ? keyTransformation : _publicKey.getAlgorithm(); } catch (KeyStoreException kse) { throw new SwitchYardException(kse); } }