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.da.img.BoradList.java

protected void executeURL(String p_page) throws IOException, ClientProtocolException, URISyntaxException {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    try {//from  ww  w . ja v  a2s  .  co  m
        HttpGet httpget = executeLogin(httpclient);
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        String responseBody = "";
        // /bank/story_mn.php?p_userid=bluesman&p_snum=201&p_num=35788
        // String strUrl = "http://story.soraspace.info/bank/story_mn.php?p_userid=bluesman&p_snum=201&p_num=35821";
        //  : http://photo.soraspace.info/album/theme/pic_list.php?p_anum=173&p_ix=3&p_gnum=351
        // http://photo.soraspace.info/album/theme/pic_list.php?p_page=1&p_sort=D&p_anum=173&p_gnum=351&p_soption=&p_stxt=
        // http://photo.soraspace.info/album/theme/pic_list.php?p_page=2&p_sort=D&p_anum=173&p_gnum=351&p_soption=&p_stxt=
        // http://photo.soraspace.info/album/theme/pic_list.php?p_page=3&p_sort=D&p_anum=173&p_gnum=351&p_soption=&p_stxt=
        // http://photo.soraspace.info/album/theme/pic_list.php?p_page=3&p_sort=D&p_anum=351&p_gnum=351&p_soption=&p_stxt=

        String imgUrl;
        // 351 : mom , 481: lip
        String SaveFilePath = "c:/temp/173";
        String p_gnum = "351";
        List<ImageVo> lst = null;
        int max_page = 10000;
        String output = "";
        InputStream istream;
        int init_page = 1;
        if (!"".equals(StringUtils.stripToEmpty(p_page))) {
            init_page = Integer.parseInt(p_page);
        }
        for (int i = init_page; i < max_page; i++) {
            lst = getBoardList(httpclient, httpget, responseHandler, p_gnum, String.valueOf(i));
            for (ImageVo vo : lst) {
                // continue;
                imgUrl = vo.getImgUrl(); //"http://photo2.soraspace.info/thumbnail.php?p_imgwidth=1104&p_imgheight=1104&p_width=1104&p_height=1104&p_imgfile=%2F%2F201205%2F22%2Fsk650%2F%2F1501694.jpg&verify=%2F%90%F9%B7%D6%D0%12%0EF%17%B8M%DA%A4L%C4";
                istream = getDownloadUrlInputStream(httpclient, httpget, imgUrl);
                // System.out.println("result = " + istream.toString());
                output = SaveFilePath + "/" + p_gnum + "/"
                        + org.apache.commons.lang.StringUtils.leftPad(String.valueOf(i), 4, "0") + "/"
                        + vo.getFileName();
                fileDownCopy(output, istream);
                if (istream != null) {
                    istream.close();
                }
            }
        }

    } catch (Exception ex) {
        System.out.println("ERROR: " + ex.getLocalizedMessage());
    } finally {
        // When HttpClient instance is no longer needed,
        // shut down the connection manager to ensure
        // immediate deallocation of all system resources
        httpclient.getConnectionManager().shutdown();
    }
}

From source file:com.comcast.viper.flume2storm.spout.FlumeSpout.java

/**
 * @see backtype.storm.spout.ISpout#nextTuple()
 *///from   ww  w  . j  ava2s.  c  om
@Override
public void nextTuple() {
    try {
        if (collector != null) {
            // Emit any events we have queued
            for (final EventReceptor<CP> eventReceptor : eventReceptors.values()) {
                List<F2SEvent> events = eventReceptor.getEvents();
                for (final F2SEvent event : events) {
                    LOG.trace("Received F2S event: {}", event);
                    for (final F2SEventEmitter emitter : emitters) {
                        emitter.emitEvent(event, collector);
                    }
                }
                // Removing EventReceptor if:
                // - it's disconnected from the EventSender
                // - the associated ServiceProvider is not registered
                // - it does not have queued up events
                if (!eventReceptor.getStats().isConnected()
                        && !locationService
                                .containsServiceProvider(eventReceptor.getConnectionParameters().getId())
                        && events.isEmpty()) {
                    removeServiceProvider(eventReceptor.getConnectionParameters().getId());
                }
            }
        }
    } catch (final Exception ex) {
        LOG.error("There was a problem emitting events: " + ex.getLocalizedMessage(), ex);
        collector.reportError(ex);
    }
    // TODO remove: this is not needed since storm 0.8.1
    // Always sleep for a little bit
    try {
        Thread.sleep(SPOUT_SLEEP_TIME);
    } catch (final InterruptedException ex) {
        LOG.warn("Thread interupted: " + ex.getLocalizedMessage());
    }
}

From source file:com.norconex.collector.core.AbstractCollectorLauncher.java

public void launch(String[] args) {
    CommandLine cmd = parseCommandLineArguments(args);
    String action = cmd.getOptionValue(ARG_ACTION);
    File configFile = new File(cmd.getOptionValue(ARG_CONFIG));
    File varFile = null;//  www.  j a  v a2  s .  c  om
    if (cmd.hasOption(ARG_VARIABLES)) {
        varFile = new File(cmd.getOptionValue(ARG_VARIABLES));
    }

    try {
        if (!configFile.isFile()) {
            System.err.println("Invalid configuration file path: " + configFile.getAbsolutePath());
            System.exit(-1);
        }
        if (varFile != null && !varFile.isFile()) {
            System.err.println("Invalid variable file path: " + configFile.getAbsolutePath());
            System.exit(-1);
        }

        ICollectorConfig config = new CollectorConfigLoader(getCollectorConfigClass())
                .loadCollectorConfig(configFile, varFile);
        ICollector collector = createCollector(config);
        if (ARG_ACTION_START.equalsIgnoreCase(action)) {
            collector.start(false);
        } else if (ARG_ACTION_RESUME.equalsIgnoreCase(action)) {
            collector.start(true);
        } else if (ARG_ACTION_STOP.equalsIgnoreCase(action)) {
            collector.stop();
        }
    } catch (Exception e) {
        PrintStream err = System.err;
        File errorFile = new File("./error-" + System.currentTimeMillis() + ".log");
        err.println("\n\nAn ERROR occured:\n\n" + e.getLocalizedMessage());
        err.println("\n\nDetails of the error has been stored at: " + errorFile.getAbsolutePath() + "\n\n");
        try {
            PrintWriter w = new PrintWriter(errorFile, CharEncoding.UTF_8);
            e.printStackTrace(w);
            w.flush();
            w.close();
        } catch (FileNotFoundException | UnsupportedEncodingException e1) {
            err.println("\n\nCannot write error file. " + e1.getLocalizedMessage());
        }
        System.exit(-1);
    }
}

From source file:com.sun.socialsite.web.rest.core.GroupsHandler.java

private Future<?> getAPublicGroup(String viewerId, String grpHandle, String userId) throws SocialSpiException {
    ResponseItem res = null;//  w w w  .j ava  2s  .  c om
    try {
        GroupManager gmgr = Factory.getSocialSite().getGroupManager();
        Group grp = gmgr.getGroupByHandle(grpHandle);
        if (grp == null) {
            String msg = "Unable to find group : " + grpHandle;
            throw new SocialSpiException(ResponseError.BAD_REQUEST, msg);
        }
        return ImmediateFuture.newInstance(grp.toJSON(Group.Format.OPENSOCIAL, viewerId));

    } catch (Exception ex) {
        String msg = String.format("Error while getting group : " + ex.getLocalizedMessage());
        log.error(msg, ex);
        throw new SocialSpiException(ResponseError.INTERNAL_ERROR, msg, ex);
    }
}

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

@Path("/schema/{type}")
@GET/* w w w.  j a  va 2  s .  c  o  m*/
@Produces(MediaType.APPLICATION_JSON)
public JResponse<DALResponse> schema(@Context HttpServletRequest req,
        @DefaultValue(ServerConfig._EMPTY_PATH_ELEMENT_) @PathParam("type") String type) throws Exception {
    try {
        Timer timer = new Timer();

        log.debug("[SESSIONID:" + req.getSession().getId() + "]");

        List<StructEntityReflect> types = null;
        if (type.compareTo(ServerConfig._EMPTY_PATH_ELEMENT_) == 0) {
            types = ReflectionUtils.get().getAllMetadata();
        } else {
            String[] names = type.split(",");
            if (names != null && names.length > 0) {
                types = new ArrayList<StructEntityReflect>();
                for (String name : names) {
                    StructEntityReflect enref = ReflectionUtils.get().getEntityMetadata(name);
                    if (enref != null && !types.contains(enref))
                        types.add(enref);

                }
            }
        }
        DALResponse response = new DALResponse();
        response.setMessage("[TYPES:" + type + "]");
        if (types != null && types.size() > 0) {
            List<EntitySchema> schema = new ArrayList<EntitySchema>();
            List<String> packages = DataManager.get().getEntityPackages();

            for (StructEntityReflect enref : types) {
                if (!showSchema(enref, packages))
                    continue;

                EntitySchema es = EntitySchema.loadSchema(enref);
                schema.add(es);
            }
            response.setState(EnumResponseState.Success);
            response.setData(schema);
        } else {
            response.setState(EnumResponseState.NoData);
        }
        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:com.wonders.bud.freshmommy.web.asq.controller.AsqResultController.java

@RequestMapping(value = "/update", method = RequestMethod.POST)
@ResponseBody/*  ww w  .  ja  v  a2 s  . c  o  m*/
public RestMsg<Object> update(HttpServletRequest request) {
    RestMsg<Object> rm = new RestMsg<Object>();

    String rId = request.getParameter("rId");
    String qType = request.getParameter("q_Type");
    String month = request.getParameter("b_Month");
    String rDesc = request.getParameter("r_rDesc");
    ;
    try {

        if (StringUtils.isBlank(qType)) {
            rm.errorMsg("?");
            return rm;
        }
        if (StringUtils.isBlank(month)) {
            rm.errorMsg("???");
            return rm;
        }
        if (StringUtils.isBlank(rDesc)) {
            rm.errorMsg("??");
            return rm;
        }
        // 

        if (StringUtils.isBlank(rId)) {
            rm.errorMsg("?");
            return rm;
        }

        AsqResultPO po = new AsqResultPO();
        po.setrId(rId);
        po.setqType(Integer.valueOf(qType));
        po.setMonth(Integer.valueOf(month));
        po.setrDesc(rDesc);
        po.setStatus(1);
        po = asqResultService.update(po);
        rm.successMsg("??");
    } catch (Exception e) {
        rm.errorMsg("?");
        log.error(e.getLocalizedMessage());
    }
    return rm;
}

From source file:com.jaxio.celerio.maven.plugin.dbmetadata.DbMetadataMojo.java

public void execute() throws MojoExecutionException {
    try {//from   w ww .j  a v a 2s .  co  m
        process();
    } catch (Exception e) {
        getLog().error(e.getMessage(), e);
        throw new MojoExecutionException(e.getLocalizedMessage(), e);
    }
}

From source file:com.tribalyte.plugin.myo.MyoEventController.java

private void callHandler(String evType, Myo myo, long timestamp, Object[] extras) {
    CallbackContext cbc = null;//from w  w w  .  ja  v a  2 s. com
    synchronized (mHandlersLock) {
        cbc = mEvHandlers.get(evType);
    }
    if (cbc != null) {
        //logd("Sending event " + evType + " to registered caller");
        MyoWithJson myoWithJson = mMyoMap.get(myo.getMacAddress());
        if (myoWithJson != null) {
            try {
                JSONObject res = new JSONObject();
                res.put("eventName", evType);
                res.put("myo", myoWithJson.myoJson);
                res.put("timestamp", Long.valueOf(timestamp));
                for (int i = 0; extras != null && i < extras.length; i += 2) {
                    res.put((String) extras[i], extras[i + 1]);
                }
                PluginResult pResult = new PluginResult(PluginResult.Status.OK, res);
                pResult.setKeepCallback(true);
                cbc.sendPluginResult(pResult);
            } catch (Exception e) {
                loge("Exception while calling handler: ", e);
                cbc.error(e.getLocalizedMessage());
            }
        } else {
            loge("ERROR: JSON Myo not found for MAC " + myo.getMacAddress(), null);
        }
    }
}

From source file:net.zorgblub.typhon.catalog.LoadOPDSTask.java

@Override
public Option<Feed> doInBackground(String... params) {

    String baseUrl = params[0];/*from   w w w. j  ava  2  s  .  c  o m*/

    if (baseUrl == null || baseUrl.trim().length() == 0) {
        return none();
    }

    boolean isBaseFeed = baseUrl.equals(config.getBaseOPDSFeed());

    baseUrl = baseUrl.trim();

    try {

        HttpGet currentRequest = new HttpGet(baseUrl);
        currentRequest.setHeader("User-Agent", config.getUserAgent());
        currentRequest.setHeader("Accept-Language", config.getLocale().getLanguage());
        HttpResponse response = httpClient.execute(currentRequest);

        LOG.debug("Starting download of " + baseUrl);

        if (response.getStatusLine().getStatusCode() != 200) {
            this.errorMessage = "HTTP " + response.getStatusLine().getStatusCode() + ": "
                    + response.getStatusLine().getReasonPhrase();
            return none();
        }

        InputStream stream = response.getEntity().getContent();
        Feed feed = Nucular.readAtomFeedFromStream(stream);
        feed.setURL(baseUrl);
        feed.setDetailFeed(asDetailsFeed);
        feed.setSearchFeed(asSearchFeed);

        for (Entry entry : feed.getEntries()) {
            entry.setBaseURL(baseUrl);
        }

        if (isBaseFeed) {
            addCustomSitesEntry(feed);
        }

        if (isCancelled()) {
            return none();
        }

        Option<Link> searchLinkOption = feed.findByRel(AtomConstants.REL_SEARCH);

        if (!isEmpty(searchLinkOption)) {

            Link searchLink = searchLinkOption.unsafeGet();

            URL mBaseUrl = new URL(baseUrl);
            URL mSearchUrl = new URL(mBaseUrl, searchLink.getHref());
            searchLink.setHref(mSearchUrl.toString());

            LOG.debug("Got searchLink of type " + searchLink.getType() + " with href=" + searchLink.getHref());

            /*
            Some sites report the search as OpenSearch, but still have the
            searchTerms in the URL. If the URL already contains searchTerms,
            we ignore the reported type and treat it as Atom
             */
            if (searchLink.getHref().contains(AtomConstants.SEARCH_TERMS)) {
                searchLink.setType(AtomConstants.TYPE_ATOM);
            }

            if (AtomConstants.TYPE_OPENSEARCH.equals(searchLink.getType())) {

                String searchURL = searchLink.getHref();

                LOG.debug("Attempting to download OpenSearch description from " + searchURL);

                try {
                    currentRequest = new HttpGet(searchURL);
                    InputStream searchStream = httpClient.execute(currentRequest).getEntity().getContent();

                    SearchDescription desc = Nucular.readOpenSearchFromStream(searchStream);

                    desc.getSearchLink().forEach(l -> searchLink.setHref(l.getHref()));

                    searchLink.setType(AtomConstants.TYPE_ATOM);

                } catch (Exception searchIO) {
                    LOG.error("Could not get search info", searchIO);
                }
            }

            LOG.debug("Using searchURL " + searchLink.getHref());
        }

        return some(feed);
    } catch (Exception e) {
        this.errorMessage = e.getLocalizedMessage();
        LOG.error("Download failed for url: " + baseUrl, e);
        return none();
    }

}

From source file:org.addhen.smssync.net.MessageSyncHttpClient.java

private void initRequest(Message message, String toNumber, String deviceId) {

    SyncScheme syncScheme = syncUrl.getSyncScheme();
    SyncMethod method = syncScheme.getMethod();
    SyncDataFormat format = syncScheme.getDataFormat();

    setHeader("Content-Type", syncScheme.getContentType());
    addParam(syncScheme.getKey(SyncDataKey.SECRET), syncUrl.getSecret());
    addParam(syncScheme.getKey(SyncDataKey.FROM), message.getPhoneNumber());
    addParam(syncScheme.getKey(SyncDataKey.MESSAGE), message.getBody());
    if (message.getDate() != null) {
        addParam(syncScheme.getKey(SyncDataKey.SENT_TIMESTAMP), String.valueOf(message.getDate().getTime()));
    }/*from  w  w  w.  java  2s  .com*/
    addParam(syncScheme.getKey(SyncDataKey.SENT_TO), toNumber);
    addParam(syncScheme.getKey(SyncDataKey.MESSAGE_ID), message.getUuid());
    addParam(syncScheme.getKey(SyncDataKey.DEVICE_ID), deviceId);
    try {
        setHttpEntity(format);
    } catch (Exception e) {
        log("Failed to set request body", e);
        setClientError("Failed to format request body" + e.getLocalizedMessage());
    }

    try {
        switch (method) {
        case POST:
            setMethod(HttpMethod.POST);
            break;
        case PUT:
            setMethod(HttpMethod.PUT);
            break;
        default:
            log("Invalid server method");
            setClientError("Failed to set request method.");
        }
    } catch (Exception e) {
        log("failed to set request method.", e);
        setClientError("Failed to set request method.");
    }

}