Example usage for com.liferay.portal.kernel.util StackTraceUtil getStackTrace

List of usage examples for com.liferay.portal.kernel.util StackTraceUtil getStackTrace

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util StackTraceUtil getStackTrace.

Prototype

public static String getStackTrace(Throwable t) 

Source Link

Usage

From source file:com.liferay.alloy.mvc.AlloyDataRequestHandler.java

License:Open Source License

public static void processRequest(ActionRequest actionRequest, ActionResponse actionResponse,
        Map<String, BaseAlloyControllerImpl> alloyControllers) throws Exception {

    String jsonString = null;/*from www  .jav a2 s.  c  o  m*/

    String controller = ParamUtil.getString(actionRequest, "controller");

    BaseAlloyControllerImpl baseAlloyControllerImpl = alloyControllers.get(controller);

    if (baseAlloyControllerImpl == null) {
        throw new Exception("Unable to find controller " + controller);
    }

    String action = ParamUtil.getString(actionRequest, "action");

    try {
        if (action.equals("custom")) {
            jsonString = baseAlloyControllerImpl.processDataRequest(actionRequest);
        } else if (action.equals("dynamicQuery")) {
            jsonString = executeDynamicQuery(baseAlloyControllerImpl, actionRequest);
        } else if (action.equals("search")) {
            jsonString = executeSearch(baseAlloyControllerImpl, actionRequest);
        }
    } catch (Exception e) {
        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

        jsonObject.put("error", "An unexpected exception occurred: " + e.getMessage());
        jsonObject.put("stacktrace", StackTraceUtil.getStackTrace(e));

        jsonString = jsonObject.toString();
    }

    if (jsonString != null) {
        writeJSON(actionRequest, actionResponse, jsonString);
    }
}

From source file:com.liferay.alloy.mvc.AlloyDataRequestProcessor.java

License:Open Source License

public static void process(ActionRequest actionRequest, ActionResponse actionResponse,
        Map<String, BaseAlloyControllerImpl> alloyControllers) throws Exception {

    String jsonString = null;/*from w w w.j av  a  2 s  . com*/

    String controller = ParamUtil.getString(actionRequest, "controller");

    BaseAlloyControllerImpl baseAlloyControllerImpl = alloyControllers.get(controller);

    if (baseAlloyControllerImpl == null) {
        throw new Exception("Unable to find controller " + controller);
    }

    String action = ParamUtil.getString(actionRequest, "action");

    try {
        if (action.equals("custom")) {
            Class<?> clazz = BaseAlloyControllerImpl.class;

            Method method = clazz.getDeclaredMethod("processDataRequest",
                    new Class<?>[] { ActionRequest.class });

            jsonString = (String) ServiceBeanMethodInvocationFactoryUtil.proceed(baseAlloyControllerImpl, clazz,
                    method, new Object[] { actionRequest }, new String[] { "transactionAdvice" });
        } else if (action.equals("dynamicQuery")) {
            jsonString = executeDynamicQuery(baseAlloyControllerImpl, actionRequest);
        } else if (action.equals("search")) {
            jsonString = executeSearch(baseAlloyControllerImpl, actionRequest);
        }
    } catch (Exception e) {
        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

        String message = e.getMessage();

        if (Validator.isNull(message)) {
            message = baseAlloyControllerImpl.translate("an-unexpected-error-occurred");
        }

        jsonObject.put("message", message);

        jsonObject.put("stacktrace", StackTraceUtil.getStackTrace(e));
        jsonObject.put("success", false);

        jsonString = jsonObject.toString();
    }

    if (jsonString != null) {
        writeJSON(actionRequest, actionResponse, jsonString);
    }
}

From source file:com.liferay.portlet.documentlibrary.service.DLAppServiceTest.java

License:Open Source License

public void testAddNullFileEntry() throws Exception {
    long folderId = _folder.getFolderId();
    String description = StringPool.BLANK;
    String changeLog = StringPool.BLANK;

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);

    try {//from  w  w  w .ja va  2 s  . c  o  m
        String name = "Bytes-null.txt";
        byte[] bytes = null;

        FileEntry fileEntry = DLAppServiceUtil.addFileEntry(TestPropsValues.getGroupId(), folderId, name,
                ContentTypes.TEXT_PLAIN, name, description, changeLog, bytes, serviceContext);

        DLAppServiceUtil.updateFileEntry(fileEntry.getFileEntryId(), name, ContentTypes.TEXT_PLAIN, name,
                description, changeLog, true, bytes, serviceContext);

        String newName = "Bytes-changed.txt";

        bytes = _CONTENT.getBytes();

        DLAppServiceUtil.updateFileEntry(fileEntry.getFileEntryId(), newName, ContentTypes.TEXT_PLAIN, newName,
                description, changeLog, true, bytes, serviceContext);
    } catch (Exception e) {
        fail("Unable to pass null byte[] " + StackTraceUtil.getStackTrace(e));
    }

    try {
        String name = "File-null.txt";
        File file = null;

        FileEntry fileEntry = DLAppServiceUtil.addFileEntry(TestPropsValues.getGroupId(), folderId, name,
                ContentTypes.TEXT_PLAIN, name, description, changeLog, file, serviceContext);

        DLAppServiceUtil.updateFileEntry(fileEntry.getFileEntryId(), name, ContentTypes.TEXT_PLAIN, name,
                description, changeLog, true, file, serviceContext);

        try {
            String newName = "File-changed.txt";

            file = FileUtil.createTempFile(_CONTENT.getBytes());

            DLAppServiceUtil.updateFileEntry(fileEntry.getFileEntryId(), newName, ContentTypes.TEXT_PLAIN,
                    newName, description, changeLog, true, file, serviceContext);
        } finally {
            FileUtil.delete(file);
        }
    } catch (Exception e) {
        fail("Unable to pass null File " + StackTraceUtil.getStackTrace(e));
    }

    try {
        String name = "IS-null.txt";
        InputStream is = null;

        FileEntry fileEntry = DLAppServiceUtil.addFileEntry(TestPropsValues.getGroupId(), folderId, name,
                ContentTypes.TEXT_PLAIN, name, description, changeLog, is, 0, serviceContext);

        DLAppServiceUtil.updateFileEntry(fileEntry.getFileEntryId(), name, ContentTypes.TEXT_PLAIN, name,
                description, changeLog, true, is, 0, serviceContext);

        try {
            String newName = "IS-changed.txt";

            is = new ByteArrayInputStream(_CONTENT.getBytes());

            DLAppServiceUtil.updateFileEntry(fileEntry.getFileEntryId(), newName, ContentTypes.TEXT_PLAIN,
                    newName, description, changeLog, true, is, 0, serviceContext);
        } finally {
            if (is != null) {
                is.close();
            }
        }
    } catch (Exception e) {
        fail("Unable to pass null InputStream " + StackTraceUtil.getStackTrace(e));
    }
}

From source file:com.liferay.server.manager.internal.servlet.ServerManagerServlet.java

License:Open Source License

@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws IOException {

    if (!isValidUser(request)) {
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);

        return;//w w w. ja v a 2 s.c o  m
    }

    JSONObject responseJSONObject = JSONFactoryUtil.createJSONObject();

    responseJSONObject.put(JSONKeys.ERROR, StringPool.BLANK);
    responseJSONObject.put(JSONKeys.OUTPUT, StringPool.BLANK);
    responseJSONObject.put(JSONKeys.STATUS, 0);

    try {
        execute(request, responseJSONObject, request.getPathInfo());
    } catch (Exception e) {
        responseJSONObject.put(JSONKeys.ERROR, StackTraceUtil.getStackTrace(e));
        responseJSONObject.put(JSONKeys.STATUS, 1);
    }

    String format = ParamUtil.getString(request, "format");

    if (format.equals("raw")) {
        response.setContentType(ContentTypes.TEXT_PLAIN);

        String outputStream = responseJSONObject.getString(JSONKeys.OUTPUT);

        ServletResponseUtil.write(response, outputStream);
    } else {
        response.setContentType(ContentTypes.APPLICATION_JSON);

        ServletResponseUtil.write(response, responseJSONObject.toString());
    }
}

From source file:com.liferay.servermanager.servlet.ServerManagerServlet.java

License:Open Source License

@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws IOException {

    if (!isValidUser(request)) {
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);

        return;//  ww w. j  av a2s . co m
    }

    JSONObject responseJSONObject = JSONFactoryUtil.createJSONObject();

    responseJSONObject.put(JSONKeys.ERROR, StringPool.BLANK);
    responseJSONObject.put(JSONKeys.OUTPUT, StringPool.BLANK);
    responseJSONObject.put(JSONKeys.STATUS, 0);

    try {
        Queue<String> arguments = new LinkedList<String>();

        String path = request.getPathInfo();

        path = StringUtil.toLowerCase(path);

        if (path.startsWith(StringPool.SLASH)) {
            path = path.substring(1);
        }

        String[] pathParts = StringUtil.split(path, StringPool.SLASH);

        for (String pathPart : pathParts) {
            arguments.add(pathPart);
        }

        execute(request, responseJSONObject, arguments);
    } catch (Exception e) {
        responseJSONObject.put(JSONKeys.ERROR, StackTraceUtil.getStackTrace(e));
        responseJSONObject.put(JSONKeys.STATUS, 1);
    }

    String format = ParamUtil.getString(request, "format");

    if (format.equals("raw")) {
        response.setContentType(ContentTypes.TEXT_PLAIN);

        String outputStream = responseJSONObject.getString(JSONKeys.OUTPUT);

        ServletResponseUtil.write(response, outputStream);
    } else {
        response.setContentType(ContentTypes.APPLICATION_JSON);

        ServletResponseUtil.write(response, responseJSONObject.toString());
    }
}

From source file:it.infn.ct.security.liferay.openidconnect.OpenIdConnectAutoLogin.java

License:Apache License

@Override
public String[] login(HttpServletRequest request, HttpServletResponse response) throws AutoLoginException {

    if (request.getParameter("openIdLogin") != null
            && request.getParameter("openIdLogin").equalsIgnoreCase("true")) {
        _log.debug("OpenID Connect auth request");
        Authenticator authZ = new Authenticator();

        try {//from   www.  java 2  s. c  o m
            request.getSession().setAttribute("LOGIN", authZ.getState());
            response.sendRedirect(authZ.getAuthRequestURL());
            return null;
        } catch (IOException ex) {
            _log.error(ex);
        }
    }

    _log.debug("Check if the session is for login: " + request.getSession().getAttribute("LOGIN"));
    if (request.getSession().getAttribute("LOGIN") != null) {
        _log.debug("Remote Authentication performed. Retrieve the token");
        State state = (State) request.getSession().getAttribute("LOGIN");

        if (request.getParameter("error") != null) {
            try {
                response.sendRedirect("/web/guest/not-authorized");
                return null;
            } catch (IOException ex) {
                _log.error(ex);
            }
        }

        if (request.getParameter("code") != null && request.getParameter("state") != null) {
            request.getSession().removeAttribute("LOGIN");

            Authenticator authZ = new Authenticator(state);

            UserInfo userInfo = null;
            try {
                userInfo = authZ.getUserInfo(request);
                if (!(userInfo.getStringListClaim("edu_person_entitlements")
                        .contains("urn:mace:egi.eu:aai.egi.eu:member@vo.access.egi.eu")
                        && userInfo.getStringListClaim("edu_person_entitlements")
                                .contains("urn:mace:egi.eu:aai.egi.eu:vm_operator@vo.access.egi.eu"))) {
                    try {
                        response.sendRedirect("/web/guest/not-authorized");
                        return null;
                    } catch (IOException ex) {
                        _log.error(ex);
                    }
                }
            } catch (AuthException ex) {
                _log.error(ex);
                return null;
            }

            String[] credentials = null;
            long companyId = 0;

            try {
                companyId = PortalUtil.getCompany(request).getCompanyId();

                String mail = userInfo.getEmail().toString();
                _log.info("Check the mail: " + mail);

                User user = null;
                try {
                    user = UserLocalServiceUtil.getUserByEmailAddress(companyId, mail);
                } catch (NoSuchUserException ex) {

                    String givenName;
                    String familyName;

                    if (userInfo.getGivenName() == null || userInfo.getGivenName().isEmpty()) {
                        givenName = userInfo.getName();
                    } else {
                        givenName = userInfo.getGivenName();
                    }

                    if (givenName != null && !givenName.isEmpty()) {
                        if (userInfo.getFamilyName() != null && !userInfo.getFamilyName().isEmpty()) {
                            familyName = userInfo.getFamilyName();
                        } else {
                            if (givenName.contains(" ")) {
                                String[] names = givenName.split(" ");
                                givenName = "";
                                for (int i = 0; i < names.length - 1; i++) {
                                    givenName += names[i];
                                    if (1 < names.length - 2)
                                        givenName += " ";
                                }
                                familyName = names[names.length - 1];
                            } else {
                                familyName = givenName;
                            }
                        }
                    } else {
                        givenName = "EGI";
                        familyName = "USER " + (int) (10000 * Math.random());
                    }

                    _log.info("New user " + givenName + " " + familyName + " " + mail + " (id "
                            + userInfo.getStringClaim("sub") + ")");
                    SecureRandom random = new SecureRandom();
                    String pass = new BigInteger(130, random).toString(32);
                    UserGroup uGroup = UserGroupLocalServiceUtil.getUserGroup(companyId, "EGIUsers");
                    long[] userGroupIds = new long[1];
                    userGroupIds[0] = uGroup.getUserGroupId();
                    user = UserLocalServiceUtil.addUser(0, companyId, true, null, null, false,
                            userInfo.getStringClaim("sub").replace('@', '-'), mail, 0,
                            userInfo.getStringClaim("sub"), Locale.ENGLISH, givenName, StringPool.BLANK,
                            familyName, 0, 0, true, 1, 1, 1970, StringPool.BLANK, null, null, null,
                            userGroupIds, false, null);
                }
                credentials = new String[3];

                credentials[0] = String.valueOf(user.getUserId());
                credentials[1] = user.getPassword();
                credentials[2] = Boolean.TRUE.toString();

                return credentials;

            } catch (Exception e) {
                _log.error(StackTraceUtil.getStackTrace(e));
                throw new AutoLoginException(e);
            }
        }
    }
    return null;
}