Search in sources :

Example 1 with AddonSelector

use of org.openecard.addon.AddonSelector in project open-ecard by ecsec.

the class ActivationController method activate.

/**
 * Performs an activation according to BSI TR-03124-1, but does not perform the return to web session part.
 * A result containing the outcome of the
 *
 * @param url
 * @return
 */
public ActivationResult activate(String url) {
    // create request uri and extract query strings
    URI requestURI = URI.create(url);
    String path = requestURI.getPath();
    // remove leading '/'
    String resourceName = path.substring(1, path.length());
    // find suitable addon
    String failureMessage;
    AddonManager manager = sctx.getManager();
    AddonSelector selector = new AddonSelector(manager);
    try {
        if (manager == null || selector == null) {
            throw new IllegalStateException("Addon initialization failed.");
        } else {
            AppPluginAction action = selector.getAppPluginAction(resourceName);
            String rawQuery = requestURI.getRawQuery();
            Map<String, String> queries = new HashMap<>(0);
            if (rawQuery != null) {
                queries = HttpRequestLineUtils.transform(rawQuery);
            }
            BindingResult result = action.execute(null, queries, null, null);
            return createActivationResult(result);
        }
    } catch (AddonNotFoundException ex) {
        failureMessage = ex.getMessage();
        LOG.info("Addon not found.", ex);
    } catch (UnsupportedEncodingException ex) {
        failureMessage = "Unsupported encoding.";
        LOG.warn(failureMessage, ex);
    } catch (Exception ex) {
        failureMessage = ex.getMessage();
        LOG.warn(ex.getMessage(), ex);
    }
    LOG.info("Returning error as INTERRUPTED result.");
    return new ActivationResult(INTERRUPTED, failureMessage);
}
Also used : AddonSelector(org.openecard.addon.AddonSelector) BindingResult(org.openecard.addon.bind.BindingResult) HashMap(java.util.HashMap) AddonNotFoundException(org.openecard.addon.AddonNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AppPluginAction(org.openecard.addon.bind.AppPluginAction) URI(java.net.URI) AddonNotFoundException(org.openecard.addon.AddonNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AddonManager(org.openecard.addon.AddonManager)

Example 2 with AddonSelector

use of org.openecard.addon.AddonSelector in project open-ecard by ecsec.

the class TinySAL method setAddonManager.

public void setAddonManager(AddonManager manager) {
    protocolSelector = new AddonSelector(manager);
    protocolSelector.setStrategy(new HighestVersionSelector());
}
Also used : AddonSelector(org.openecard.addon.AddonSelector) HighestVersionSelector(org.openecard.addon.HighestVersionSelector)

Aggregations

AddonSelector (org.openecard.addon.AddonSelector)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1 AddonManager (org.openecard.addon.AddonManager)1 AddonNotFoundException (org.openecard.addon.AddonNotFoundException)1 HighestVersionSelector (org.openecard.addon.HighestVersionSelector)1 AppPluginAction (org.openecard.addon.bind.AppPluginAction)1 BindingResult (org.openecard.addon.bind.BindingResult)1