Search in sources :

Example 96 with ServiceException

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);
    }
}
Also used : CacheProvider(com.adaptris.core.cache.CacheProvider) ServiceException(com.adaptris.core.ServiceException) CoreException(com.adaptris.core.CoreException) Cache(com.adaptris.core.cache.Cache) ExpiringMapCache(com.adaptris.core.cache.ExpiringMapCache)

Example 97 with ServiceException

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);
    }
}
Also used : JettyRoute(com.adaptris.core.http.jetty.JettyRouteCondition.JettyRoute) ServiceException(com.adaptris.core.ServiceException) CoreException(com.adaptris.core.CoreException)

Example 98 with ServiceException

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);
    }
}
Also used : OutputStream(java.io.OutputStream) FsWorker.isFile(com.adaptris.fs.FsWorker.isFile) File(java.io.File) FileInputStream(java.io.FileInputStream) ServiceException(com.adaptris.core.ServiceException) IOException(java.io.IOException) CoreException(com.adaptris.core.CoreException) FsException(com.adaptris.fs.FsException)

Example 99 with ServiceException

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);
        }
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) Output(com.adaptris.security.Output) ServiceException(com.adaptris.core.ServiceException) IOException(java.io.IOException) AdaptrisSecurityException(com.adaptris.security.exc.AdaptrisSecurityException)

Example 100 with ServiceException

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);
    }
}
Also used : SecretKeySpec(javax.crypto.spec.SecretKeySpec) IvParameterSpec(javax.crypto.spec.IvParameterSpec) Cipher(javax.crypto.Cipher) ServiceException(com.adaptris.core.ServiceException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) IOException(java.io.IOException) CoreException(com.adaptris.core.CoreException) InvalidKeyException(java.security.InvalidKeyException)

Aggregations

ServiceException (com.adaptris.core.ServiceException)236 Test (org.junit.Test)172 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)161 CoreException (com.adaptris.core.CoreException)45 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)26 StandaloneProducer (com.adaptris.core.StandaloneProducer)18 MetadataElement (com.adaptris.core.MetadataElement)17 ValidationStage (com.adaptris.transform.validate.ValidationStage)16 Cache (com.adaptris.core.cache.Cache)15 DefectiveMessageFactory (com.adaptris.core.stubs.DefectiveMessageFactory)13 TimeInterval (com.adaptris.util.TimeInterval)13 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)11 Connection (java.sql.Connection)10 File (java.io.File)9 IOException (java.io.IOException)9 OutputStream (java.io.OutputStream)9 SQLException (java.sql.SQLException)9 InputStream (java.io.InputStream)8 Document (org.w3c.dom.Document)8 Channel (com.adaptris.core.Channel)7