Example usage for java.lang Throwable Throwable

List of usage examples for java.lang Throwable Throwable

Introduction

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

Prototype

public Throwable(Throwable cause) 

Source Link

Document

Constructs a new throwable with the specified cause and a detail message of (cause==null ?

Usage

From source file:io.openkit.user.OKUserUtilities.java

public static void updateOKUser(final OKUser user, final CreateOrUpdateOKUserRequestHandler requestHandler) {
    //Setup the request parameters
    JSONObject requestParams = new JSONObject();
    try {/*from   w  w w  .  j av  a2s.c o  m*/
        JSONObject userDict = getJSONRepresentationOfUser(user);
        requestParams.put("app_key", OpenKit.getAppKey());
        requestParams.put("user", userDict);

    } catch (JSONException e) {
        Log.e("OpenKit", "Error creating JSON request for updating user nick: " + e);
        requestHandler.onFail(e);
    }

    String requestPath = "/users/" + Integer.toString(user.getOKUserID());

    OKHTTPClient.putJSON(requestPath, requestParams, new OKJsonHttpResponseHandler() {

        @Override
        public void onSuccess(JSONObject object) {
            OKUser responseUser = new OKUser(object);

            if (responseUser.getOKUserID() != 0) {
                requestHandler.onSuccess(responseUser);
                OKLog.v("Succesfully updated OKUser");
            } else {
                requestHandler.onFail(new Throwable(
                        "Unknown error from OpenKit when trying to update user. No userID returned"));
            }
        }

        @Override
        public void onSuccess(JSONArray array) {
            requestHandler.onFail(new Throwable("Received a JSON array when expecting a JSON object"));
        }

        @Override
        public void onFailure(Throwable error, String content) {
            requestHandler.onFail(error);
            checkIfErrorIsUnsubscribedUserError(error);
        }

        @Override
        public void onFailure(Throwable e, JSONArray errorResponse) {
            requestHandler.onFail(e);
            checkIfErrorIsUnsubscribedUserError(e);
        }

        @Override
        public void onFailure(Throwable e, JSONObject errorResponse) {
            requestHandler.onFail(e);
            checkIfErrorIsUnsubscribedUserError(e);
        }
    });
}

From source file:fi.jumi.core.api.StackTraceTest.java

@Test
public void provides_the_name_of_the_original_exception_class() {
    Throwable original = new Throwable("original message");

    StackTrace copy = StackTrace.from(original);

    assertThat(copy.getExceptionClass(), is("java.lang.Throwable"));
}

From source file:io.confluent.connect.elasticsearch.internals.Response.java

public Response(BulkResult result) {
    this.result = result;
    Throwable firstException = null;
    for (BulkResultItem bulkResultItem : result.getFailedItems()) {
        ObjectNode obj = parseError(bulkResultItem.error);
        String exceptionType = obj.get("type").asText();
        if (exceptionType.equals(nonRetriableError)) {
            throwable = new Throwable(exceptionType);
            break;
        } else {/*from w  w w . ja  v a2  s.c o  m*/
            if (firstException == null) {
                firstException = new Throwable(bulkResultItem.error);
            }
        }
    }
    if (throwable == null) {
        throwable = firstException;
    }
}

From source file:io.openkit.OKAchievementScore.java

public void submitAchievementScore(final AchievementScoreRequestResponseHandler responseHandler) {
    OKUser currentUser = OKUser.getCurrentUser();
    if (currentUser == null) {
        responseHandler.onFailure(new Throwable(
                "Current user is not logged in. To submit an achievement score, the user must be logged into OpenKit"));
        return;/*from  www . j  a va2 s  .c  om*/
    }

    try {
        JSONObject achievementScoreJSON = getAchievementScoreAsJSON();

        JSONObject requestParams = new JSONObject();
        requestParams.put("app_key", OpenKit.getAppKey());
        requestParams.put("achievement_score", achievementScoreJSON);

        OKHTTPClient.postJSON("/achievement_scores", requestParams, new OKJsonHttpResponseHandler() {

            @Override
            public void onSuccess(JSONObject object) {
                responseHandler.onSuccess();
            }

            @Override
            public void onSuccess(JSONArray array) {
                //This should not be called, submitting an achievementScore should
                // not return an array, so this is an errror case
                responseHandler.onFailure(new Throwable(
                        "Unknown error from OpenKit servers. Received an array when expecting an object"));
            }

            @Override
            public void onFailure(Throwable error, String content) {
                OKUserUtilities.checkIfErrorIsUnsubscribedUserError(error);
                responseHandler.onFailure(error);
            }

            @Override
            public void onFailure(Throwable e, JSONArray errorResponse) {
                OKUserUtilities.checkIfErrorIsUnsubscribedUserError(e);
                responseHandler.onFailure(new Throwable(errorResponse.toString()));
            }

            @Override
            public void onFailure(Throwable e, JSONObject errorResponse) {
                OKUserUtilities.checkIfErrorIsUnsubscribedUserError(e);
                responseHandler.onFailure(new Throwable(errorResponse.toString()));
            }
        });

    } catch (JSONException e) {
        responseHandler.onFailure(new Throwable("OpenKit JSON parsing error"));
    }

}

From source file:cz.muni.fi.sport.club.sport.club.rest.AgeGroupsResource.java

@GET
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)//from   w  w w. j a v  a2 s  . c o  m
public AgeGroup getById(@PathParam("id") String id) throws WebApplicationException {
    try {
        AgeGroup ag = AgeGroupMapping.toEntity(ageGroupService.getAgeGroupById(Long.parseLong(id)));
        if (ag == null) {
            throw new IllegalArgumentException();
        }
        return ag;
    } catch (NumberFormatException ex) {
        throw new WebApplicationException(new Throwable("You put wrong request"), Response.Status.BAD_REQUEST);
    } catch (IllegalArgumentException ex) {
        throw new WebApplicationException(new Throwable("Age Group was not found"), Response.Status.NOT_FOUND);
    } catch (Exception ex) {
        throw new WebApplicationException(new Throwable("We apologize for internal server error"),
                Response.Status.INTERNAL_SERVER_ERROR);
    }
}

From source file:de.kp.ames.semantic.service.SearchImpl.java

public void processRequest(RequestContext ctx) {

    String methodName = this.method.getName();
    if (!(methodName.equals("get") || methodName.equals("apply"))) {
        this.sendBadRequest(ctx, new Throwable("[SearchImpl] only method=get & apply supported"));
    }//from  ww  w.j a  va2  s  . c o m

    /*
     * set search use case by source: wn or scm 
     */
    String source = this.method.getAttribute("source");

    if (source == null || !(source.equals("wn") || source.equals("scm"))) {
        System.out.println("====> processRequest: source not set or not scm | wn: " + source);
        this.sendNotImplemented(ctx);
    }

    String type = this.method.getAttribute("type");
    System.out.println("====> processRequest: " + type);

    if (type.equals("suggest")) {

        /*
         * Call suggest method
         */
        String query = this.method.getAttribute("query");
        String start = this.method.getAttribute("_startRow");
        String end = this.method.getAttribute("_endRow");

        if ((!methodName.equals("get")) || (query == null) || (start == null) || (end == null)) {
            this.sendNotImplemented(ctx);

        } else {

            try {
                /*
                 * JSON response
                 */
                String content = suggest(source, query, start, end);
                this.sendJSONResponse(content, ctx.getResponse());

            } catch (Exception e) {
                this.sendBadRequest(ctx, e);

            }
        }
    } else if (type.equals("search")) {
        /*
         * Call searchmethod
         */
        String query = this.method.getAttribute("query");
        String start = this.method.getAttribute("_startRow");
        String end = this.method.getAttribute("_endRow");

        if ((!methodName.equals("get")) || (query == null) || (start == null) || (end == null)) {
            this.sendNotImplemented(ctx);

        } else {

            try {
                /*
                 * JSON response
                 */
                String content = getResult(source, query, start, end);
                this.sendJSONResponse(content, ctx.getResponse());

            } catch (Exception e) {
                this.sendBadRequest(ctx, e);

            }
        }
    } else if (type.equals("similar")) {
        String query = this.method.getAttribute("query");
        String name = this.method.getAttribute("name");
        if ((!methodName.equals("get")) || (query == null) || (name == null)) {
            this.sendNotImplemented(ctx);

        } else {
            try {
                /*
                 * JSON response
                 */

                String content = getSimilar(source, query, name);
                this.sendJSONResponse(content, ctx.getResponse());

            } catch (Exception e) {
                this.sendBadRequest(ctx, e);

            }
        }
    } else if (type.equals("checkout")) {

        // access post data
        String data = this.getRequestData(ctx);

        System.out.println("====> SearchImpl.checkout> data.len: " + data.length());

        if ((!methodName.equals("apply")) || (data == null)) {
            this.sendNotImplemented(ctx);

        } else {
            try {
                /*
                 * JSON response
                 */

                String content = getCheckout(source, data);
                this.sendJSONResponse(content, ctx.getResponse());

            } catch (Exception e) {
                this.sendBadRequest(ctx, e);

            }
        }
    } else if (type.equals("download")) {

        // access post data when send with doApply
        //   String data = this.getRequestData(ctx);

        // access post data, from named FORM field
        String data = ctx.getRequest().getParameter("hiddenField");

        System.out.println("====> SearchImpl.download> data.len: " + data.length());

        if ((!methodName.equals("apply")) || (data == null)) {
            this.sendNotImplemented(ctx);

        } else {
            try {
                /*
                 * JSON response
                 */

                byte[] bytes = getDownload(source, data);
                this.sendZIPResponse(bytes, ctx.getResponse());

            } catch (Exception e) {
                this.sendBadRequest(ctx, e);

            }
        }
    }
}

From source file:cn.edu.szjm.service.PostRecordTask.java

protected Integer doInBackground(Object... params) {

    requestListener.onRequestStart();//  w  w w. jav a  2s.com

    if ((activity == null) || (!(in == null) && (news == null)))
        requestListener.onRequestFault(new Throwable(new NullPointerException().getMessage()));

    Kaixin kaixin = Kaixin.getInstance();

    try {

        Bundle bundle = new Bundle();
        bundle.putByteArray("content", news.getBytes());

        Map<String, Object> photoes = new HashMap<String, Object>();
        photoes.put("filename", in);

        String jsonResult = kaixin.uploadContent(activity, RESTAPI_INTERFACE_POSTRECORD, bundle, photoes);

        if (TextUtils.isEmpty(jsonResult)) {

            requestListener.onRequestFault(new KaixinError(Constant.RESULT_FAILED_REQUEST_ERR,
                    "/", "", ""));

        } else {

            KaixinError kaixinError = Util.parseRequestError(jsonResult);

            if (kaixinError != null) {

                requestListener.onRequestError(kaixinError);

            } else {

                long rid = getRecordID(jsonResult);

                if (rid < 0)
                    requestListener.onRequestError(new KaixinError(Constant.RESULT_POST_RECORD_FAILED,
                            "/???", "", jsonResult));
                else
                    requestListener.onRequestComplete(jsonResult);
            }

        }

    } catch (IOException e) {
        requestListener
                .onRequestFault(new KaixinError(Constant.RESULT_FAILED_NETWORK_ERR, e.getMessage(), "", ""));
    } catch (JSONException e) {
        requestListener
                .onRequestError(new KaixinError(Constant.RESULT_FAILED_JSON_PARSE_ERR, e.getMessage(), "", ""));
    }
    return params.length;
}

From source file:org.sonatype.siesta.webapp.test.TestResource.java

@Inject
public TestResource() {
    if (log.isTraceEnabled()) {
        log.trace("Created", new Throwable("MARKER"));
    } else {// w ww  .j  a  v a2s. com
        log.debug("Created");
    }
}

From source file:de.kp.ames.web.function.scm.ScmServiceImpl.java

public void processRequest(RequestContext ctx) {

    String methodName = this.method.getName();
    if (!(methodName.equals("get") || methodName.equals("apply"))) {
        this.sendBadRequest(ctx, new Throwable("[ScmServiceImpl] only method=get & apply supported"));
    }// ww  w  . ja  va  2s.  c o m

    String type = this.method.getAttribute("type");

    if (type.equals("suggest")) {

        /*
         * Call suggest method
         */
        String query = this.method.getAttribute("query");
        String start = this.method.getAttribute("_startRow");
        String end = this.method.getAttribute("_endRow");

        if ((!methodName.equals("get")) || (query == null) || (start == null) || (end == null)) {
            this.sendNotImplemented(ctx);

        } else {

            try {
                /*
                 * JSON response
                 */
                String content = suggest(query, start, end);
                this.sendJSONResponse(content, ctx.getResponse());

            } catch (Exception e) {
                this.sendBadRequest(ctx, e);

            }
        }
    } else if (type.equals("search")) {
        /*
         * Call searchmethod
         */
        String query = this.method.getAttribute("query");
        String start = this.method.getAttribute("_startRow");
        String end = this.method.getAttribute("_endRow");

        if ((!methodName.equals("get")) || (query == null) || (start == null) || (end == null)) {
            this.sendNotImplemented(ctx);

        } else {

            try {
                /*
                 * JSON response
                 */
                String content = getResult(query, start, end);
                this.sendJSONResponse(content, ctx.getResponse());

            } catch (Exception e) {
                this.sendBadRequest(ctx, e);

            }
        }
    } else if (type.equals("similar")) {
        String query = this.method.getAttribute("query");
        String name = this.method.getAttribute("name");
        if ((!methodName.equals("get")) || (query == null) || (name == null)) {
            this.sendNotImplemented(ctx);

        } else {
            try {
                /*
                 * JSON response
                 */

                String content = getSimilar(query, name);
                this.sendJSONResponse(content, ctx.getResponse());

            } catch (Exception e) {
                this.sendBadRequest(ctx, e);

            }
        }
    } else if (type.equals("checkout")) {

        // access post data
        String data = this.getRequestData(ctx);

        if ((!methodName.equals("apply")) || (data == null)) {
            this.sendNotImplemented(ctx);

        } else {
            try {
                /*
                 * JSON response
                 */

                String content = getCheckout(data);
                this.sendJSONResponse(content, ctx.getResponse());

            } catch (Exception e) {
                this.sendBadRequest(ctx, e);

            }
        }
    } else if (type.equals("download")) {

        // access post data when send with doApply
        //   String data = this.getRequestData(ctx);

        // access post data, from named FORM field
        String data = ctx.getRequest().getParameter("hiddenField");

        if ((!methodName.equals("apply")) || (data == null)) {
            this.sendNotImplemented(ctx);

        } else {
            try {
                /*
                 * JSON response
                 */

                byte[] bytes = getDownload(data);
                this.sendZIPResponse(bytes, ctx.getResponse());

            } catch (Exception e) {
                this.sendBadRequest(ctx, e);

            }
        }
    }
}

From source file:org.starfishrespect.myconsumption.server.business.controllers.UserController.java

@RequestMapping(value = "/{name}", method = RequestMethod.POST)
public SimpleResponseDTO put(@PathVariable String name,
        @RequestParam(value = "password", defaultValue = "") String password) throws DaoException {

    if (mUserRepository.getUser(name) != null) {
        return new SimpleResponseDTO(SimpleResponseDTO.STATUS_ALREADY_EXISTS, "User already exists");
    }//from ww w  . j  ava2  s .  c  o  m
    if (password.equals("")) {
        throw new BadRequestException(new Throwable("Password is empty"));
    }
    if (mUserRepository.insertUser(new User(name, password))) {
        return new SimpleResponseDTO(true, "user created");
    } else {
        return new SimpleResponseDTO(false, "Error while creating user");
    }
}