Example usage for java.security InvalidParameterException getMessage

List of usage examples for java.security InvalidParameterException getMessage

Introduction

In this page you can find the example usage for java.security InvalidParameterException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.nlp2rdf.webservice.NIFParameters.java

/**
 * Factory method//  w  w  w  . ja  v  a  2s . co m
 *
 * @param httpServletRequest
 * @return
 */
public static NIFParameters getInstance(HttpServletRequest httpServletRequest) {
    String requestUrl = httpServletRequest.getRequestURL().toString();
    try {

        //required Parameter input-type
        String input_type = requiredParameter("input-type", httpServletRequest, "text", "nif-owl");

        if (!isSet("input", httpServletRequest)) {
            throw new IllegalArgumentException("Missing parameter: input is required. ");
        }
        //optional parameters
        //note that nif=true is intentionally left out here, because it would be too late
        String prefix = "http://nlp2rdf.lod2.eu/nif/";
        String format = "rdfxml";
        String urirecipe = "offset";
        int contextLength = 10;
        //this is not in the nif 1.0 spec
        String output = "full";

        //prefix
        if (isSet("prefix", httpServletRequest)) {
            prefix = httpServletRequest.getParameter("prefix");
        }

        //format
        if (isSet("format", httpServletRequest)) {
            format = requiredParameter("format", httpServletRequest, "rdfxml", "turtle", "json", "ntriples",
                    "n3");
        }
        //urirecipe
        if (isSet("urirecipe", httpServletRequest)) {
            urirecipe = requiredParameter("urirecipe", httpServletRequest, "offset", "context-hash");
        }
        //contextLength
        if (isSet("context-length", httpServletRequest)) {
            contextLength = Integer.parseInt(httpServletRequest.getParameter("context-length"));
        }
        //output
        if (isSet("output", httpServletRequest)) {
            output = requiredParameter("output", httpServletRequest, "full", "diff");
        }

        Object input;
        //normalize input, i.e. fill the variables for text and model
        if (input_type.equals("text")) {
            log.trace("Handling type text");
            // read the text
            input = httpServletRequest.getParameter("input");
            //make a NIF model to work on
            //URIGenerator uriGenerator = ModelHelper.determineGenerator(urirecipe);
            //inputModel = new Text2RDF().processAsDocument(prefix, text, new FakeTokenizer(), uriGenerator);

            /**********************
             * NOTE that parsing another NIF model is a little bit harder than just the output so this reference implementation is not yet complete.
             * *********************/
        } else if (input_type.equals("nif-owl")) {
            // Read the model directly from the input
            OntModel inputModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM,
                    ModelFactory.createDefaultModel());
            ByteArrayInputStream bais = new ByteArrayInputStream(
                    httpServletRequest.getParameter("input").getBytes());
            try {
                inputModel.read(bais, "");
            } catch (JenaException e) {
                throw new InvalidParameterException(
                        "Jena could not read the presented nif-owl in RDF/XML format.\nFor the conversion of text \"input-type=text\" has to be set.");
            }
            input = inputModel;
        } else {
            throw new InvalidParameterException("third way in a binary path: maybe");
        }

        NIFParameters nifParameters = new NIFParameters(input, copyParameterMap(httpServletRequest), prefix,
                urirecipe, contextLength, format, output);
        log.trace("created NIFParameters instance from " + input_type + ": " + nifParameters.toString());
        return nifParameters;

    } catch (InvalidParameterException ipe) {
        throw new InvalidParameterException(ipe.getMessage() + getDocumentation(requestUrl));
    }
}

From source file:ch.admin.suis.msghandler.servlet.PingServlet.java

private void doProcess(HttpServletRequest request, HttpServletResponse response) throws IOException {
    try {// w ww  . j  ava 2 s . com
        response.getWriter().println(handleRequest(request, response));

    } catch (InvalidParameterException ex) {
        LOG.error("Invalid parameter: " + ex);
        response.getWriter().println(ex.getMessage());
        response.setContentType(TEXT);
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);

    } catch (IOException ex) {
        LOG.fatal("MonitorServlet: " + ex.getMessage(), ex);
        throw ex;
    }
}

From source file:net.nelz.simplesm.aop.CacheBaseTest.java

@Test
public void testBuildCacheKey() {
    try {/* www  . j a  va  2  s.com*/
        cut.buildCacheKey(null, (AnnotationData) null);
        fail("Expected exception.");
    } catch (InvalidParameterException ex) {
        assertTrue(ex.getMessage().indexOf("at least 1 character") != -1);
        System.out.println(ex.getMessage());
    }

    try {
        cut.buildCacheKey("", (AnnotationData) null);
        fail("Expected exception.");
    } catch (InvalidParameterException ex) {
        assertTrue(ex.getMessage().indexOf("at least 1 character") != -1);
        System.out.println(ex.getMessage());
    }

    final String objectId = RandomStringUtils.randomAlphanumeric(20);
    final AnnotationData annotationData = new AnnotationData();
    final String namespace = RandomStringUtils.randomAlphanumeric(12);
    annotationData.setNamespace(namespace);

    final String result = cut.buildCacheKey(objectId, annotationData);

    assertTrue(result.indexOf(objectId) != -1);
    assertTrue(result.indexOf(namespace) != -1);
}

From source file:org.flite.cach3.aop.CacheBaseTest.java

@Test
public void testBuildCacheKey() {
    final String ns = RandomStringUtils.randomAlphanumeric(235);

    try {/*w w  w  . j  av a 2  s  .c  om*/
        cut.buildCacheKey(null, ns, null);
        fail("Expected exception.");
    } catch (InvalidParameterException ex) {
        assertTrue(ex.getMessage().indexOf("at least 1 character") != -1);
    }

    try {
        cut.buildCacheKey("", ns, null);
        fail("Expected exception.");
    } catch (InvalidParameterException ex) {
        assertTrue(ex.getMessage().indexOf("at least 1 character") != -1);
    }

    final String space = RandomStringUtils.randomAlphanumeric(8) + " "
            + RandomStringUtils.randomAlphanumeric(8);
    try {
        cut.buildCacheKey(space, ns, null);
        fail("Expected exception.");
    } catch (InvalidParameterException ex) {
        assertTrue(ex.getMessage().indexOf("whitespace") != -1);
    }

    final String endline = RandomStringUtils.randomAlphanumeric(8) + "\n"
            + RandomStringUtils.randomAlphanumeric(8);
    try {
        cut.buildCacheKey(endline, ns, null);
        fail("Expected exception.");
    } catch (InvalidParameterException ex) {
        assertTrue(ex.getMessage().indexOf("whitespace") != -1);
    }

    final String tab = RandomStringUtils.randomAlphanumeric(8) + "\t" + RandomStringUtils.randomAlphanumeric(8);
    try {
        cut.buildCacheKey(tab, ns, null);
        fail("Expected exception.");
    } catch (InvalidParameterException ex) {
        assertTrue(ex.getMessage().indexOf("whitespace") != -1);
    }

    final String objectId = RandomStringUtils.randomAlphanumeric(20);
    try {
        cut.buildCacheKey(objectId, ns, null);
        fail("Expected exception.");
    } catch (InvalidParameterException ex) {
        assertTrue(ex.getMessage().indexOf("255") != -1);
        assertTrue(ex.getMessage().indexOf(objectId) != -1);
    }

    final String namespace = RandomStringUtils.randomAlphanumeric(12);

    final String result = cut.buildCacheKey(objectId, namespace, null);

    assertTrue(result.indexOf(objectId) != -1);
    assertTrue(result.indexOf(namespace) != -1);
}

From source file:com.razerzone.store.sdk.engine.gamemaker.Plugin.java

public static String init(final String secretApiKey) {

    if (sEnableLogging) {
        Log.d(TAG, "init: secretApiKey=" + secretApiKey);
    }/*  w  w  w . j  a  v  a  2 s . c  o  m*/

    final Activity activity = Plugin.getRelay().getCurrentActivity();
    if (null == activity) {
        Log.d(TAG, "Current activity is null");
        return sFalse;
    } else {
        Log.d(TAG, "Current activity is valid");
    }

    final FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content);
    if (null == content) {
        Log.d(TAG, "Content is null");
        return sFalse;
    } else {
        Runnable runnable = new Runnable() {
            public void run() {
                Log.d(TAG, "Disable screensaver");
                content.setKeepScreenOn(true);

                Log.d(TAG, "Add inputView");
                sInputView = new InputView(activity);

                Bundle developerInfo = null;
                try {
                    developerInfo = StoreFacade.createInitBundle(secretApiKey);
                } catch (InvalidParameterException e) {
                    Log.e(TAG, e.getMessage());
                    activity.finish();
                    return;
                }

                if (sEnableLogging) {
                    Log.d(TAG, "developer_id=" + developerInfo.getString(StoreFacade.DEVELOPER_ID));
                }

                if (sEnableLogging) {
                    Log.d(TAG, "developer_public_key length="
                            + developerInfo.getByteArray(StoreFacade.DEVELOPER_PUBLIC_KEY).length);
                }

                sInitCompleteListener = new CancelIgnoringResponseListener<Bundle>() {
                    @Override
                    public void onSuccess(Bundle bundle) {
                        if (sEnableLogging) {
                            Log.d(TAG, "InitCompleteListener: onSuccess");
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onSuccessInit");
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                        sInitialized = true;
                    }

                    @Override
                    public void onFailure(int errorCode, String errorMessage, Bundle optionalData) {
                        if (sEnableLogging) {
                            Log.d(TAG, "InitCompleteListener: onFailure errorCode=" + errorCode
                                    + " errorMessage=" + errorMessage);
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onFailureInit");
                            JSONObject data = new JSONObject();
                            data.put("errorCode", Integer.toString(errorCode));
                            data.put("errorMessage", errorMessage);
                            json.put("data", data);
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }
                };

                sStoreFacade = StoreFacade.getInstance();
                try {
                    sStoreFacade.init(activity, developerInfo, sInitCompleteListener);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                sRequestLoginListener = new ResponseListener<Void>() {
                    @Override
                    public void onSuccess(Void result) {
                        if (sEnableLogging) {
                            Log.d(TAG, "sRequestLoginListener: onSuccess");
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onSuccessRequestLogin");
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }

                    @Override
                    public void onFailure(int errorCode, String errorMessage, Bundle optionalData) {
                        if (sEnableLogging) {
                            Log.e(TAG, "sRequestLoginListener: onFailure errorCode=" + errorCode
                                    + " errorMessage=" + errorMessage);
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onFailureRequestLogin");
                            JSONObject data = new JSONObject();
                            data.put("errorCode", Integer.toString(errorCode));
                            data.put("errorMessage", errorMessage);
                            json.put("data", data);
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }

                    @Override
                    public void onCancel() {
                        if (sEnableLogging) {
                            Log.d(TAG, "sRequestLoginListener: onCancel");
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onCancelRequestLogin");
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }
                };

                sRequestGamerInfoListener = new ResponseListener<GamerInfo>() {
                    @Override
                    public void onSuccess(GamerInfo info) {
                        if (null == info) {
                            Log.e(TAG, "GamerInfo is null!");
                            return;
                        }
                        if (sEnableLogging) {
                            Log.d(TAG, "sRequestGamerInfoListener: onSuccess uuid=" + info.getUuid()
                                    + " username=" + info.getUsername());
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onSuccessRequestGamerInfo");
                            JSONObject data = new JSONObject();
                            data.put("uuid", info.getUuid());
                            data.put("username", info.getUsername());
                            json.put("data", data);
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }

                    @Override
                    public void onFailure(int errorCode, String errorMessage, Bundle optionalData) {
                        if (sEnableLogging) {
                            Log.e(TAG, "sRequestGamerInfoListener: onFailure errorCode=" + errorCode
                                    + " errorMessage=" + errorMessage);
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onFailureRequestGamerInfo");
                            JSONObject data = new JSONObject();
                            data.put("errorCode", Integer.toString(errorCode));
                            data.put("errorMessage", errorMessage);
                            json.put("data", data);
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }

                    @Override
                    public void onCancel() {
                        if (sEnableLogging) {
                            Log.d(TAG, "sRequestGamerInfoListener: onCancel");
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onCancelRequestGamerInfo");
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }
                };

                sRequestProductsListener = new ResponseListener<List<Product>>() {
                    @Override
                    public void onSuccess(final List<Product> products) {
                        if (null == products) {
                            Log.e(TAG, "Products are null!");
                            return;
                        }
                        if (sEnableLogging) {
                            Log.i(TAG, "sRequestProductsListener: onSuccess");
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onSuccessRequestProducts");
                            JSONArray data = new JSONArray();
                            int index = 0;
                            for (Product product : products) {
                                JSONObject item = new JSONObject();
                                try {
                                    item.put("currencyCode", product.getCurrencyCode());
                                    item.put("description", product.getDescription());
                                    item.put("identifier", product.getIdentifier());
                                    item.put("localPrice", product.getLocalPrice());
                                    item.put("name", product.getName());
                                    item.put("originalPrice", product.getOriginalPrice());
                                    item.put("percentOff", product.getPercentOff());
                                    item.put("developerName", product.getDeveloperName());
                                    data.put(index, item);
                                    ++index;
                                } catch (JSONException e2) {
                                }
                            }
                            json.put("data", data);
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }

                    @Override
                    public void onFailure(int errorCode, String errorMessage, Bundle optionalData) {
                        if (sEnableLogging) {
                            Log.e(TAG, "sRequestProductsListener: onFailure errorCode=" + errorCode
                                    + " errorMessage=" + errorMessage);
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onFailureRequestProducts");
                            JSONObject data = new JSONObject();
                            data.put("errorCode", Integer.toString(errorCode));
                            data.put("errorMessage", errorMessage);
                            json.put("data", data);
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }

                    @Override
                    public void onCancel() {
                        if (sEnableLogging) {
                            Log.i(TAG, "sRequestProductsListener: onCancel");
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onCancelRequestProducts");
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }
                };

                sRequestPurchaseListener = new ResponseListener<PurchaseResult>() {

                    @Override
                    public void onSuccess(PurchaseResult result) {
                        if (null == result) {
                            Log.e(TAG, "PurchaseResult is null!");
                            return;
                        }
                        if (sEnableLogging) {
                            Log.i(TAG, "sRequestPurchaseListener: onSuccess");
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onSuccessRequestPurchase");
                            JSONObject data = new JSONObject();
                            data.put("identifier", result.getProductIdentifier());
                            data.put("ownerId", result.getOrderId());
                            json.put("data", data);
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }

                    @Override
                    public void onFailure(int errorCode, String errorMessage, Bundle optionalData) {
                        if (sEnableLogging) {
                            Log.e(TAG, "sRequestPurchaseListener: onFailure errorCode=" + errorCode
                                    + " errorMessage=" + errorMessage);
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onFailureRequestPurchase");
                            JSONObject data = new JSONObject();
                            data.put("errorCode", Integer.toString(errorCode));
                            data.put("errorMessage", errorMessage);
                            json.put("data", data);
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }

                    @Override
                    public void onCancel() {
                        if (sEnableLogging) {
                            Log.i(TAG, "sRequestPurchaseListener: onCancel");
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onCancelRequestPurchase");
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }
                };

                sRequestReceiptsListener = new ResponseListener<Collection<Receipt>>() {

                    @Override
                    public void onSuccess(Collection<Receipt> receipts) {
                        if (null == receipts) {
                            Log.e(TAG, "Receipts are null!");
                            return;
                        }
                        if (sEnableLogging) {
                            Log.i(TAG, "requestReceipts onSuccess: received " + receipts.size() + " receipts");
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onSuccessRequestReceipts");
                            JSONArray data = new JSONArray();
                            int index = 0;
                            for (Receipt receipt : receipts) {
                                JSONObject item = new JSONObject();
                                try {
                                    item.put("identifier", receipt.getIdentifier());
                                    item.put("purchaseDate", receipt.getPurchaseDate());
                                    item.put("gamer", receipt.getGamer());
                                    item.put("uuid", receipt.getUuid());
                                    item.put("localPrice", receipt.getLocalPrice());
                                    item.put("currency", receipt.getCurrency());
                                    item.put("generatedDate", receipt.getGeneratedDate());
                                    data.put(index, item);
                                    ++index;
                                } catch (JSONException e2) {
                                }
                            }
                            json.put("data", data);
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }

                    @Override
                    public void onFailure(int errorCode, String errorMessage, Bundle optionalData) {
                        if (sEnableLogging) {
                            Log.e(TAG, "requestReceipts onFailure: errorCode=" + errorCode + " errorMessage="
                                    + errorMessage);
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onFailureRequestReceipts");
                            JSONObject data = new JSONObject();
                            data.put("errorCode", Integer.toString(errorCode));
                            data.put("errorMessage", errorMessage);
                            json.put("data", data);
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }

                    @Override
                    public void onCancel() {
                        if (sEnableLogging) {
                            Log.i(TAG, "requestReceipts onCancel");
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onCancelRequestReceipts");
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }
                };

                sShutdownListener = new CancelIgnoringResponseListener<Void>() {
                    @Override
                    public void onSuccess(Void aVoid) {
                        if (sEnableLogging) {
                            Log.i(TAG, "shutdown onSuccess");
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onSuccessShutdown");
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }

                    @Override
                    public void onFailure(int i, String s, Bundle bundle) {
                        if (sEnableLogging) {
                            Log.i(TAG, "shutdown onFailure");
                        }
                        JSONObject json = new JSONObject();
                        try {
                            json.put("method", "onFailureShutdown");
                        } catch (JSONException e1) {
                        }
                        String jsonData = json.toString();
                        sAsyncResults.add(jsonData);
                    }
                };

                Controller.init(activity);
            }
        };
        activity.runOnUiThread(runnable);
    }

    return sTrue;
}

From source file:org.onexus.resource.manager.internal.providers.AbstractProjectProvider.java

public synchronized void loadProject() {
    File projectOnx = new File(projectFolder, ONEXUS_PROJECT_FILE);

    if (!projectOnx.exists()) {
        throw new InvalidParameterException("No Onexus project in " + projectFolder.getAbsolutePath());
    }// w  w  w.ja v a2s  .com

    this.project = (Project) loadResource(projectOnx);
    this.project.setName(projectName);

    this.bundleDependencies.clear();

    if (project.getPlugins() != null) {
        for (Plugin plugin : project.getPlugins()) {

            //TODO Remove this property
            if (plugin.getParameter("location") == null && plugin.getParameters() != null) {
                plugin.getParameters().add(new Parameter("location", projectFolder.getAbsolutePath()));
            }

            try {
                long bundleId = pluginLoader.load(plugin);
                bundleDependencies.add(bundleId);
            } catch (InvalidParameterException e) {
                LOGGER.error(e.getMessage());
            }
        }
    }

    if (project.getAlias() != null && !project.getAlias().isEmpty()) {

        this.projectAlias = new Properties();
        try {
            this.projectAlias.load(new StringReader(project.getAlias()));
        } catch (IOException e) {
            LOGGER.error("Malformed project alias", e);
            this.projectAlias = null;
        }
    }

    this.resources = null;
}

From source file:org.openhab.binding.loxone.internal.core.LxWsSecurityToken.java

private boolean initialize() {
    try {/*from www. j  a va  2 s  .  co m*/
        encryptionReady = false;
        tokenRefreshRetryCount = TOKEN_REFRESH_RETRY_COUNT;
        if (Cipher.getMaxAllowedKeyLength("AES") < 256) {
            return setError(LxOfflineReason.INTERNAL_ERROR,
                    "Enable Java cryptography unlimited strength (see binding doc).");
        }
        // generate a random key for the session
        KeyGenerator aesKeyGen = KeyGenerator.getInstance("AES");
        aesKeyGen.init(256);
        aesKey = aesKeyGen.generateKey();
        // generate an initialization vector
        secureRandom = new SecureRandom();
        secureRandom.nextBytes(initVector);
        IvParameterSpec ivSpec = new IvParameterSpec(initVector);
        // initialize aes cipher for command encryption
        aesEncryptCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        aesEncryptCipher.init(Cipher.ENCRYPT_MODE, aesKey, ivSpec);
        // initialize aes cipher for response decryption
        aesDecryptCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
        aesDecryptCipher.init(Cipher.DECRYPT_MODE, aesKey, ivSpec);
        // get token value from configuration storage
        token = (String) configuration.get(SETTINGS_TOKEN);
        logger.debug("[{}] Retrieved token value: {}", debugId, token);
    } catch (InvalidParameterException e) {
        return setError(LxOfflineReason.INTERNAL_ERROR, "Invalid parameter: " + e.getMessage());
    } catch (NoSuchAlgorithmException e) {
        return setError(LxOfflineReason.INTERNAL_ERROR, "AES not supported on platform.");
    } catch (InvalidKeyException | NoSuchPaddingException | InvalidAlgorithmParameterException e) {
        return setError(LxOfflineReason.INTERNAL_ERROR, "AES cipher initialization failed.");
    }
    return true;
}

From source file:org.pentaho.platform.web.http.api.resources.FileResource.java

/**
 * Download the selected file or folder from the repository. In order to download file from the repository, the user needs to
 * have Publish action.  How the file comes down to the user and where it is saved is system and browser dependent.
 *
 * <p><b>Example Request:</b><br />
 *    GET pentaho/api/repo/files/:jmeter-test:test_file_1.xml/download?locale=de
 * </p>/*  www  .  j  av a2s . c  o m*/
 *
 * @param pathId          Colon separated path for the repository file.
 * @param strWithManifest true or false (download file with manifest).  Defaults to true  (include manifest) if this string can't be directly
 *                        parsed to 'false' (case sensitive).  This argument is only used if a directory is being downloaded.
 * @param userAgent       A string representing the type of browser to use.  Currently only applicable if contains 'FireFox' as FireFox
 *                        requires a header with encoding information (UTF-8) and a quoted filename, otherwise encoding information is not
 *                        supplied and the filename is not quoted.
 *
 * @return A jax-rs Response object with the appropriate status code, header, and body.
 *
 * <p><b>Example Response:</b></p>
 *    <pre function="syntax.xml">
 *      Encrypted file stream
 *    </pre>
 */
@GET
@Path("{pathId : .+}/download")
@Produces(WILDCARD)
@StatusCodes({ @ResponseCode(code = 200, condition = "Successful download."),
        @ResponseCode(code = 400, condition = "Usually a bad pathId."),
        @ResponseCode(code = 403, condition = "pathId points at a file the user doesn't have access to."),
        @ResponseCode(code = 404, condition = "File not found."),
        @ResponseCode(code = 500, condition = "Failed to download file for another reason.")

})
// have to accept anything for browsers to work
public Response doGetFileOrDirAsDownload(@HeaderParam("user-agent") String userAgent,
        @PathParam("pathId") String pathId, @QueryParam("withManifest") String strWithManifest) {
    FileService.DownloadFileWrapper wrapper = null;
    try {
        wrapper = fileService.doGetFileOrDirAsDownload(userAgent, pathId, strWithManifest);
        return buildZipOkResponse(wrapper);
    } catch (InvalidParameterException e) {
        logger.error(getMessagesInstance().getString("FileResource.EXPORT_FAILED", e.getMessage()), e);
        return buildStatusResponse(BAD_REQUEST);
    } catch (IllegalSelectorException e) {
        logger.error(getMessagesInstance().getString("FileResource.EXPORT_FAILED", e.getMessage()), e);
        return buildStatusResponse(FORBIDDEN);
    } catch (GeneralSecurityException e) {
        logger.error(getMessagesInstance().getString("FileResource.EXPORT_FAILED", e.getMessage()), e);
        return buildStatusResponse(FORBIDDEN);
    } catch (FileNotFoundException e) {
        logger.error(getMessagesInstance().getString("FileResource.EXPORT_FAILED", e.getMessage()), e);
        return buildStatusResponse(NOT_FOUND);
    } catch (Throwable e) {
        logger.error(
                getMessagesInstance().getString("FileResource.EXPORT_FAILED", pathId + " " + e.getMessage()),
                e);
        return buildStatusResponse(INTERNAL_SERVER_ERROR);
    }
}