Search in sources :

Example 1 with FunctionCallException

use of org.jaxen.FunctionCallException in project wso2-synapse by wso2.

the class HMACGenerateFunction method generateSignature.

/**
 * Generate the HMAC signature against the secret for given algorithm
 *
 * @param payload  The request body
 * @param secret   The secret
 * @param algorithm The algorithm to generate signature
 * @return The generated signature
 * @throws FunctionCallException On error during HMAC signature generation
 */
private String generateSignature(String payload, String secret, String algorithm) throws FunctionCallException {
    try {
        Mac mac = getMacInstance(algorithm);
        final SecretKeySpec signingKey = new SecretKeySpec(secret.getBytes(), algorithm);
        mac.init(signingKey);
        return toHexString(mac.doFinal(payload.getBytes()));
    } catch (NoSuchAlgorithmException | InvalidKeyException e) {
        String msg = "Error while generating HMAC signature";
        log.error(msg, e);
        throw new FunctionCallException(msg, e);
    }
}
Also used : FunctionCallException(org.jaxen.FunctionCallException) SecretKeySpec(javax.crypto.spec.SecretKeySpec) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) Mac(javax.crypto.Mac)

Example 2 with FunctionCallException

use of org.jaxen.FunctionCallException in project intellij-community by JetBrains.

the class BasicFileInfoFunction method call.

@Nullable
@SuppressWarnings({ "RawUseOfParameterizedType" })
public Object call(Context context, List list) throws FunctionCallException {
    final Object arg;
    if (list.size() == 0) {
        arg = context.getNodeSet().get(0);
    } else {
        final Object o = list.get(0);
        arg = o instanceof List ? ((List) o).get(0) : o;
    }
    if (!(arg instanceof PsiElement)) {
        throw new FunctionCallException("NodeSet expected");
    }
    final PsiFile psiFile = ((PsiElement) arg).getContainingFile();
    assert psiFile != null;
    return extractInfo(psiFile);
}
Also used : FunctionCallException(org.jaxen.FunctionCallException) List(java.util.List) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with FunctionCallException

use of org.jaxen.FunctionCallException in project webservices-axiom by apache.

the class JaxenXPathTestBase method getNavigator.

protected final Navigator getNavigator() {
    return new NavigatorWrapper(createNavigator()) {

        // We need to tweak the getDocument method a bit to load the document from the right
        // place.
        public Object getDocument(String uri) throws FunctionCallException {
            try {
                URL url = new URL(TESTS_ROOT + uri);
                Object document = loadDocument(url.openStream());
                documents.add(document);
                return document;
            } catch (Exception ex) {
                throw new FunctionCallException(ex);
            }
        }
    };
}
Also used : FunctionCallException(org.jaxen.FunctionCallException) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) FunctionCallException(org.jaxen.FunctionCallException)

Example 4 with FunctionCallException

use of org.jaxen.FunctionCallException in project mycore by MyCoRe-Org.

the class MCRFunctionCallJava method call.

@Override
public Object call(Context context, List args) throws FunctionCallException {
    try {
        String clazzName = (String) (args.get(0));
        String methodName = (String) (args.get(1));
        LOGGER.info("XEditor extension function calling {} {}", clazzName, methodName);
        Class[] argTypes = new Class[args.size() - 2];
        Object[] params = new Object[args.size() - 2];
        for (int i = 0; i < argTypes.length; i++) {
            argTypes[i] = args.get(i + 2).getClass();
            params[i] = args.get(i + 2);
        }
        Class clazz = ClassUtils.getClass(clazzName);
        Method method = MethodUtils.getMatchingAccessibleMethod(clazz, methodName, argTypes);
        return method.invoke(null, params);
    } catch (Exception ex) {
        LOGGER.warn("Exception in call to external java method", ex);
        return ex.getMessage();
    }
}
Also used : Method(java.lang.reflect.Method) FunctionCallException(org.jaxen.FunctionCallException)

Example 5 with FunctionCallException

use of org.jaxen.FunctionCallException in project webservices-axiom by apache.

the class DocumentNavigator method getDocument.

/**
 * Loads a document from the given URI.
 *
 * @param uri the URI of the document to load
 * @return Returns the document.
 * @throws FunctionCallException if the document could not be loaded
 */
@Override
public Object getDocument(String uri) throws FunctionCallException {
    InputStream in = null;
    try {
        if (uri.indexOf(':') == -1) {
            in = new FileInputStream(uri);
        } else {
            URL url = new URL(uri);
            in = url.openStream();
        }
        return OMXMLBuilderFactory.createOMBuilder(in).getDocument();
    } catch (Exception e) {
        if (in != null) {
            try {
                in.close();
            } catch (IOException ex) {
            // Ignore
            }
        }
        throw new FunctionCallException(e);
    }
}
Also used : FunctionCallException(org.jaxen.FunctionCallException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) URL(java.net.URL) FunctionCallException(org.jaxen.FunctionCallException) UnsupportedAxisException(org.jaxen.UnsupportedAxisException) IOException(java.io.IOException) SAXPathException(org.jaxen.saxpath.SAXPathException)

Aggregations

FunctionCallException (org.jaxen.FunctionCallException)9 InvalidKeyException (java.security.InvalidKeyException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 URL (java.net.URL)2 KeyStore (java.security.KeyStore)2 KeyStoreException (java.security.KeyStoreException)2 Certificate (java.security.cert.Certificate)2 BadPaddingException (javax.crypto.BadPaddingException)2 Cipher (javax.crypto.Cipher)2 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)2 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)2 Base64 (org.apache.commons.codec.binary.Base64)2 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Method (java.lang.reflect.Method)1 MalformedURLException (java.net.MalformedURLException)1