use of com.adaptris.core.ServiceException in project interlok by adaptris.
the class GetAndCacheOauthToken method doService.
@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
try {
Cache cache = getConnection().retrieveConnection(CacheProvider.class).retrieveCache();
String key = msg.resolve(getCacheKey());
AccessToken token = (AccessToken) cache.get(key);
if (token == null) {
log.trace("[{}] not found in cache; requesting new token", key);
token = getAccessTokenBuilder().build(msg);
addToCache(cache, key, token);
} else {
log.trace("[{}] found in cache", key);
}
tokenWriterToUse().apply(token, msg);
} catch (Exception e) {
throw ExceptionHelper.wrapServiceException(e);
}
}
use of com.adaptris.core.ServiceException in project interlok by adaptris.
the class JettyRoutingService method doService.
@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
try {
String method = msg.getMetadataValue(HTTP_METHOD);
String uri = msg.getMetadataValue(JETTY_URI);
boolean matched = false;
for (JettyRouteSpec route : routes) {
JettyRoute m = route.build(method, uri);
if (m.matches()) {
log.trace("[{}][{}], matched by {}", method, uri, route);
msg.setMetadata(m.metadata());
msg.setNextServiceId(route.getServiceId());
matched = true;
break;
}
}
if (!matched) {
log.debug("No Matches from configured routes, using {}", getDefaultServiceId());
msg.setNextServiceId(getDefaultServiceId());
}
} catch (Exception e) {
throw ExceptionHelper.wrapServiceException(e);
}
}
use of com.adaptris.core.ServiceException in project interlok by adaptris.
the class ReadFileService method doService.
@Override
public void doService(final AdaptrisMessage message) throws ServiceException {
try {
final File file = convertToFile(message.resolve(getFilePath()));
log.trace("Reading file : {}", file.getCanonicalPath());
try (FileInputStream in = new FileInputStream(file);
OutputStream out = message.getOutputStream()) {
copy(in, out);
}
if (isNotBlank(getContentTypeMetadataKey())) {
message.addMetadata(getContentTypeMetadataKey(), probeContentType(file));
}
} catch (Exception e) {
throw ExceptionHelper.wrapServiceException(e);
}
}
use of com.adaptris.core.ServiceException in project interlok by adaptris.
the class EncryptionService method doService.
/**
* @see com.adaptris.core.Service#doService(AdaptrisMessage)
*/
@Override
public final void doService(AdaptrisMessage m) throws ServiceException {
try {
Output output = doEncryption(addLength(m), retrieveRemotePartner(m));
m.setPayload(output.getBytes());
if (branchingEnabled) {
m.setNextServiceId(getSuccessId());
}
} catch (Exception e) {
if (branchingEnabled) {
m.setNextServiceId(getFailId());
m.getObjectHeaders().put(CoreConstants.OBJ_METADATA_EXCEPTION, e);
} else {
throw new ServiceException(e);
}
}
}
use of com.adaptris.core.ServiceException in project interlok by adaptris.
the class SymmetricKeyCryptographyService method doService.
@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
try {
String algToUse = msg.resolve(getAlgorithm());
String cipherToUse = msg.resolve(getCipherTransformation());
byte[] keyBytes = Conversion.base64StringToByteArray(Password.decode(ExternalResolver.resolve(getKey().extract(msg))));
byte[] initialVectorBytes = Conversion.base64StringToByteArray(getInitialVector().extract(msg));
Cipher cipher = Cipher.getInstance(cipherToUse);
SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, algToUse);
IvParameterSpec ivParameterSpec = new IvParameterSpec(initialVectorBytes);
getOperationMode().execute(cipher, secretKeySpec, ivParameterSpec, source().wrap(msg), target().wrap(msg));
} catch (Exception e) {
throw ExceptionHelper.wrapServiceException(e);
}
}
Aggregations