Example usage for java.lang Exception getLocalizedMessage

List of usage examples for java.lang Exception getLocalizedMessage

Introduction

In this page you can find the example usage for java.lang Exception getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:com.sqewd.open.dal.services.DataServices.java

@Path("/save/{type}")
@POST/* w  ww  .  ja  v a 2s  .  c  o  m*/
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public JResponse<DALResponse> save(@Context HttpServletRequest req, @PathParam("type") String type, String data,
        @DefaultValue("off") @QueryParam("d") String debugs) throws Exception {
    try {
        Timer timer = new Timer();

        log.debug("[ENTITY TYPE:" + type + "]");

        boolean debug = false;
        if (debugs.compareToIgnoreCase("on") == 0)
            debug = true;

        DataManager dm = DataManager.get();

        StructEntityReflect enref = ReflectionUtils.get().getEntityMetadata(type);
        if (enref == null)
            throw new Exception("No entity found for type [" + type + "]");
        Class<?> typec = Class.forName(enref.Class);

        ObjectMapper mapper = new ObjectMapper();
        AbstractEntity entity = (AbstractEntity) mapper.readValue(data, typec);
        if (debug)
            log.debug(entity.toString());

        DALResponse response = new DALResponse();

        OperationResponse or = dm.save(entity);
        response.setMessage("SAVE");
        response.setData(or);

        response.setTimetaken(timer.stop());

        return JResponse.ok(response).build();
    } catch (Exception e) {
        LogUtils.stacktrace(log, e);
        log.error(e.getLocalizedMessage());

        DALResponse response = new DALResponse();
        response.setState(EnumResponseState.Exception);
        response.setMessage(e.getLocalizedMessage());
        return JResponse.ok(response).build();
    }
}

From source file:ratpack.codahale.metrics.internal.WebSocketReporter.java

@SuppressWarnings("rawtypes")
private void writeGauges(JsonGenerator json, SortedMap<String, Gauge> gauges) throws IOException {
    json.writeArrayFieldStart("gauges");
    for (Map.Entry<String, Gauge> entry : gauges.entrySet()) {
        Gauge gauge = entry.getValue();/*from   www.ja  va2  s  .c o m*/

        json.writeStartObject();
        json.writeStringField("name", entry.getKey());
        try {
            json.writeFieldName("value");
            json.writeObject(gauge.getValue());
        } catch (Exception e) {
            LOGGER.log(Level.FINE, "Exception encountered while reporting [" + entry.getKey() + "]: "
                    + e.getLocalizedMessage());
            json.writeNull();
        }
        json.writeEndObject();

    }
    json.writeEndArray();
}

From source file:com.ibm.mil.LoyaltyUserAdapterResource.java

/**
 * Retrieve the Watson personality insights for a user. You would normally
 * take a users Twitter feed and supply it to the Watson personality
 * insights service and leverage the results to make informed decisions
 * about what types of offers to make to the user based on their
 * personality./*from  w  w  w.  j a va  2s . c o  m*/
 * 
 * For this simple application we are hard coding the "Twitter feed" that we
 * are suppling the Watson service and are NOT using the results to generate
 * the custom offers we provide for the user as this logic would be very
 * specific to the industry the application is rolled into and the specific
 * business owners needs.
 * 
 * @return The Watson personality insights response as a JSON string.
 */
@GET
@Path("/watson-data")
@Produces(MediaType.APPLICATION_JSON)
public Response getUserWatsonData() {
    // log message to server log
    logger.info(messages.getMessage("MSG0006"));

    Response srvrResponse;
    try {
        HttpPost httpPost = getHttpPost();
        String result = execute(httpPost);

        srvrResponse = Response.ok(result, MediaType.APPLICATION_JSON).build();

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        srvrResponse = Response.serverError().entity(
                messages.getMessage("MSG0005") + System.getProperty("line.separator") + e.getLocalizedMessage())
                .build();
    } catch (Exception ex) {
        ex.printStackTrace();
        srvrResponse = Response.serverError().entity(ex.getLocalizedMessage()).build();
    }
    return srvrResponse;
}

From source file:com.amalto.workbench.actions.XSDSetAnnotationForeignKeyInfoAction.java

@Override
public IStatus doAction() {
    try {// w w  w . j a va 2  s.com
        IStructuredSelection selection = (TreeSelection) page.getTreeViewer().getSelection();
        XSDComponent xSDCom = null;
        if (selection.getFirstElement() instanceof Element) {
            TreePath tPath = ((TreeSelection) selection).getPaths()[0];
            for (int i = 0; i < tPath.getSegmentCount(); i++) {
                if (tPath.getSegment(i) instanceof XSDAnnotation) {
                    xSDCom = (XSDAnnotation) (tPath.getSegment(i));
                }
            }
        } else {
            xSDCom = (XSDComponent) selection.getFirstElement();
        }
        XSDAnnotationsStructure struc = new XSDAnnotationsStructure(xSDCom);
        if (struc.getAnnotation() == null) {
            throw new RuntimeException(
                    Messages.bind(Messages.UnableEditAnnotationType, xSDCom.getClass().getName()));
        }

        dlg = getNewAnnotaionOrderedListsDialog(struc.getForeignKeyInfos().values());

        dlg.setLock(true);
        dlg.setRetrieveFKinfos(struc.getRetrieveFKinfos());
        dlg.setFormatFKInfo(struc.getFormatForeignKeyInfo());
        dlg.setBlockOnOpen(true);
        int ret = dlg.open();
        if (ret == Window.CANCEL) {
            return Status.CANCEL_STATUS;
        }

        struc.setForeignKeyInfos(dlg.getXPaths());
        struc.setRetrieveFKinfos(dlg.isRetrieveFKinfos());
        struc.setFormatForeignKeyInfo(dlg.getFormatFKInfo());
        if (struc.hasChanged()) {
            page.refresh();
            page.getTreeViewer().expandToLevel(xSDCom, 2);
            page.markDirty();
        }

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error,
                Messages.bind(Messages.ErrorForeignKey, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}

From source file:com.jkoolcloud.tnt4j.streams.configure.sax.WsConfigParserHandler.java

@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
    super.endElement(uri, localName, qName);

    try {//from   ww w  .  jav a2  s  .  c  om
        if (SCENARIO_ELMT.equals(qName)) {
            if (currScenario.isEmpty()) {
                throw new SAXException(StreamsResources.getStringFormatted(
                        StreamsResources.RESOURCE_BUNDLE_NAME, "WsConfigParserHandler.element.must.have.one",
                        SCENARIO_ELMT, STEP_ELMT, getLocationInfo()));
            }

            ((AbstractWsStream) currStream).addScenario(currScenario);
            currScenario = null;
        } else if (STREAM_ELMT.equals(qName)) {
            if (currStream instanceof AbstractWsStream) {
                if (CollectionUtils.isEmpty(((AbstractWsStream) currStream).getScenarios())) {
                    throw new SAXException(
                            StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                                    "WsConfigParserHandler.element.must.have.one", STREAM_ELMT, SCENARIO_ELMT,
                                    getLocationInfo()));
                }
            }
        } else if (STEP_ELMT.equals(qName)) {
            if (StringUtils.isEmpty(currStep.getRequest()) && StringUtils.isEmpty(currStep.getUrlStr())) {
                throw new SAXParseException(
                        StreamsResources.getStringFormatted(StreamsResources.RESOURCE_BUNDLE_NAME,
                                "ConfigParserHandler.must.contain", STEP_ELMT, URL_ATTR, REQ_ELMT),
                        currParseLocation);
            }

            currScenario.addStep(currStep);
            currStep = null;
        } else if (REQ_ELMT.equals(qName)) {
            if (elementData != null) {
                currStep.setRequest(getElementData());
                elementData = null;
            }
        }
    } catch (SAXException exc) {
        throw exc;
    } catch (Exception e) {
        throw new SAXException(e.getLocalizedMessage() + getLocationInfo(), e);
    }
}

From source file:com.amalto.workbench.actions.XSDEditComplexTypeAction.java

@Override
public IStatus doAction() {
    try {/*from  w w  w.ja v a 2s  .  c o m*/
        ISelection selection = page.getTreeViewer().getSelection();
        IStructuredContentProvider provider = (IStructuredContentProvider) page.getSchemaContentProvider();
        XSDComplexTypeDefinition decl = (XSDComplexTypeDefinition) ((IStructuredSelection) selection)
                .getFirstElement();

        String oldName = decl.getName();
        InputDialog id = new InputDialog(page.getSite().getShell(),
                Messages.XSDEditComplexTypeAction_EditComplexType,
                Messages.XSDEditComplexTypeAction_EnterNameForEntity, oldName, new IInputValidator() {

                    public String isValid(String newText) {
                        if ((newText == null) || "".equals(newText)) //$NON-NLS-1$
                            return Messages.XSDEditComplexTypeAction_ComplexTypeCannotBeEmpty;

                        if (Pattern.compile("^\\s+\\w+\\s*").matcher(newText).matches()//$NON-NLS-1$
                                || newText.trim().replaceAll("\\s", "").length() != newText.trim().length())//$NON-NLS-1$//$NON-NLS-2$
                            return Messages.XSDEditComplexTypeAction_NameCannotContainEmpty;
                        if (!XSDUtil.isValidatedXSDName(newText)) {
                            return Messages.InvalidName_Message;
                        }
                        EList list = schema.getTypeDefinitions();
                        for (Iterator iter = list.iterator(); iter.hasNext();) {
                            Object d = iter.next();
                            if (d instanceof XSDComplexTypeDefinition) {
                                XSDComplexTypeDefinition type = (XSDComplexTypeDefinition) d;
                                if (type.getName().equals(newText.trim()))
                                    return Messages.XSDEditComplexTypeAction_ComplexAlreadyExists;
                            }
                        }
                        return null;
                    };
                });

        id.setBlockOnOpen(true);
        int ret = id.open();
        if (ret == Dialog.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        decl.setName(id.getValue().trim());

        Util.updateReferenceToXSDTypeDefinition(page.getSite(), decl, provider);
        page.refresh();
        page.markDirty();

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error,
                Messages.XSDEditComplexTypeAction_ErrorEditEntity + e.getLocalizedMessage());
        return Status.CANCEL_STATUS;
    }

    return Status.OK_STATUS;
}

From source file:com.amalto.workbench.actions.XSDEditIdentityConstraintAction.java

public IStatus doAction() {
    try {/*w  w w.jav a2  s . com*/

        ISelection selection = page.getTreeViewer().getSelection();
        constraint = (XSDIdentityConstraintDefinition) ((IStructuredSelection) selection).getFirstElement();
        String oldName = constraint.getName();

        InputDialog id = new InputDialog(page.getSite().getShell(), Messages.XSDEditIdentityXX_EditKey,
                Messages.XSDEditIdentityXX_EnterANameForKey, oldName,
                new EditXSDIdentityConstraintNameValidator(constraint)
        // new IInputValidator() {
        // public String isValid(String newText) {
        // if ((newText==null) || "".equals(newText)) return "The Entity Name cannot be empty";
        // XSDSchema schema = XSDEditIdentityConstraintAction.this.constraint.getSchema();
        // EList list = schema.getIdentityConstraintDefinitions();
        // for (Iterator iter = list.iterator(); iter.hasNext(); ) {
        // XSDIdentityConstraintDefinition icd = (XSDIdentityConstraintDefinition) iter.next();
        // if (icd.getName().equals(newText)) return "This Key already exists";
        // }
        // return null;
        // };
        // }
        );

        id.setBlockOnOpen(true);
        int ret = id.open();
        if (ret == Dialog.CANCEL) {
            return Status.CANCEL_STATUS;
        }

        if (XSDIdentityConstraintCategory.UNIQUE_LITERAL.equals(constraint.getIdentityConstraintCategory())
                && !((XSDElementDeclaration) constraint.getContainer()).getName().equals(id.getValue())) {

            MessageDialog.openWarning(page.getSite().getShell(), Messages.Warning,
                    Messages.XSDEditIdentityXX_WarningMsg);
            return Status.CANCEL_STATUS;
        }

        constraint.setName(id.getValue());
        constraint.updateElement();

        page.refresh();
        page.markDirty();

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error,
                Messages.bind(Messages.XSDEditIdentityXX_ErrorEditEntity, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}

From source file:com.amalto.workbench.actions.XSDSetAnnotationFKFilterAction.java

@Override
public IStatus doAction() {
    try {/* w  w  w  .java  2s  .  com*/
        IStructuredSelection selection = (TreeSelection) page.getTreeViewer().getSelection();
        XSDComponent xSDCom = null;
        String conceptName = null;
        if (selection.getFirstElement() instanceof Element) {
            TreePath tPath = ((TreeSelection) selection).getPaths()[0];
            for (int i = 0; i < tPath.getSegmentCount(); i++) {
                if (tPath.getSegment(i) instanceof XSDAnnotation) {
                    xSDCom = (XSDAnnotation) (tPath.getSegment(i));
                }
            }
        } else {
            xSDCom = (XSDComponent) selection.getFirstElement();
        }
        if (xSDCom instanceof XSDElementDeclaration) {
            conceptName = xSDCom.getElement().getAttributes().getNamedItem("name").getNodeValue();//$NON-NLS-1$
        }
        if (xSDCom instanceof XSDParticle) {
        }
        XSDAnnotationsStructure struc = null;
        if (xSDCom != null) {
            struc = new XSDAnnotationsStructure(xSDCom);
        }
        if (struc == null || struc.getAnnotation() == null) {
            throw new RuntimeException(
                    Messages.bind(Messages.UnableEditAnnotationType, xSDCom.getClass().getName()));
        }

        fkd = getNewFKFilterDialog(page.getSite().getShell(), struc.getFKFilter(), page, conceptName);
        fkd.setDataModel(dataModelName);
        fkd.setLock(true);
        fkd.setBlockOnOpen(true);
        int ret = fkd.open();
        if (ret == Window.CANCEL) {
            return Status.CANCEL_STATUS;
        }

        String fkfilter = fkd.getFilter();
        struc.setFKFilter(fkfilter);

        if (struc.hasChanged()) {
            page.refresh();
            page.getTreeViewer().expandToLevel(xSDCom, 2);
            page.markDirty();
        }

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error,
                Messages.bind(Messages.ErrorFKFilter, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}

From source file:com.amalto.workbench.editors.JobMainPage.java

public void checkServiceStatus() {
    try {//
        if (jobName.endsWith(".zip")) {//$NON-NLS-1$
            statusLabel.setText(Messages.JobMainPage_Ready);
            return;
        }//from   ww  w.  jav  a  2s  . c o m
        String job = this.jobName.substring(0, this.jobName.lastIndexOf("_"));//$NON-NLS-1$
        String jobversion = this.jobName.substring(0, this.jobName.lastIndexOf("."));//$NON-NLS-1$
        String URLPath = "http://" + getXObject().getEndpointHost() + ":" + getXObject().getEndpointPort() + "/" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
                + jobversion + "/services/" + job;//$NON-NLS-1$
        HttpClientUtil.getStringContentByHttpget(URLPath);
        statusLabel.setText(Messages.JobMainPage_Ready);
    } catch (XtentisException ex) {
        // if the http response status is not 200
        statusLabel.setText(Messages.JobMainPage_Fail);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(this.getSite().getShell(), Messages._Error,
                Messages.bind(Messages.JobMainPage_ErrorMsg, e.getLocalizedMessage()));
    }
}

From source file:io.getlime.security.powerauth.app.server.service.controller.RESTResponseExceptionResolver.java

@Override
protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response,
        Object handler, Exception exception) {
    try {//from   w  ww.j a  v  a 2 s .c  o m
        // Build the error list
        RESTErrorModel error = new RESTErrorModel();
        error.setCode("ERR_SPRING_JAVA");
        error.setMessage(exception.getMessage());
        error.setLocalizedMessage(exception.getLocalizedMessage());
        List<RESTErrorModel> errorList = new LinkedList<>();
        errorList.add(error);

        // Prepare the response
        RESTResponseWrapper<List<RESTErrorModel>> errorResponse = new RESTResponseWrapper<>("ERROR", errorList);

        // Write the response in JSON and send it
        ObjectMapper mapper = new ObjectMapper();
        String responseString = mapper.writeValueAsString(errorResponse);
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        response.setCharacterEncoding(StandardCharsets.UTF_8.name());
        response.setContentType(MediaType.APPLICATION_JSON_VALUE);
        response.getOutputStream().print(responseString);
        response.flushBuffer();
    } catch (IOException e) {
        // Response object does have an output stream here
    }
    return new ModelAndView();
}