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:de.tudarmstadt.ukp.dkpro.tc.examples.io.ReutersCorpusReader.java

@Override
public Set<String> getTextClassificationOutcomes(JCas jcas) throws CollectionException {
    Set<String> outcomes = new HashSet<String>();

    DocumentMetaData dmd = DocumentMetaData.get(jcas);
    String titleWithoutExtension = FilenameUtils.removeExtension(dmd.getDocumentTitle());

    if (!goldLabelMap.containsKey(titleWithoutExtension)) {
        throw new CollectionException(new Throwable("No gold label for document: " + dmd.getDocumentTitle()));
    }// www  .j a v a  2  s.c  om

    for (String label : goldLabelMap.get(titleWithoutExtension)) {
        outcomes.add(label);
    }
    return outcomes;
}

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

@POST
@Produces(MediaType.APPLICATION_JSON)/*w  w  w . j  a  v a2s  . c o  m*/
public Response create(@FormParam("eldest") String eldest, @FormParam("youngest") String youngest,
        @FormParam("groupLevel") String groupLevel) throws WebApplicationException {
    try {
        AgeGroupDTO agDTO = ageGroupService.createAgeGroup(Date.valueOf(eldest), Date.valueOf(youngest),
                AgeGroupLevel.valueOf(groupLevel));
        AgeGroup ageGroup = AgeGroupMapping.toEntity(ageGroupService.saveAgeGroup(agDTO));
        return Response.created(URI.create(context.getAbsolutePath() + "/" + ageGroup.getId())).build();
    } catch (WebApplicationException ex) {
        throw new WebApplicationException(new Throwable("You post wrong request"), Response.Status.BAD_REQUEST);
    } catch (Exception ex) {
        throw new WebApplicationException(new Throwable("We apologize for internal server error"),
                Response.Status.INTERNAL_SERVER_ERROR);
    }
}

From source file:com.msopentech.o365.outlookServices.ODataMethodArgs.java

/**
 * Used to get parent container's type from OData path (for Attachments)
 * @param indexFromTheEnd index of container's type parameter in OData path (from the end of path)
 * @return Entity container's type ("message" or "event")
 * @throws Throwable/*from w  w  w . j  a  v  a2s.co  m*/
 */
public String parseParentTypeFromOdataPath(int indexFromTheEnd) throws Throwable {
    String type = this.parseIdFromODataPath(indexFromTheEnd).toLowerCase();
    if (type.equals("events") || type.equals("messages")) {
        return type;
    }
    throw new Throwable("Can't parse parent container type");
}

From source file:org.bpmscript.integration.internal.memory.MemoryMessageBus.java

/**
 * Starts up the bus/*from  w  ww .j av  a  2 s.  c  om*/
 */
public void afterPropertiesSet() throws Exception {
    for (int i = 0; i < threadCount; i++) {
        executor.execute(new Runnable() {

            public void run() {
                running.set(true);
                while (running.get()) {
                    try {
                        Object[] addressAndMessage;
                        addressAndMessage = queue.poll(timeoutMillis, TimeUnit.MILLISECONDS);
                        if (addressAndMessage != null) {
                            String address = (String) addressAndMessage[0];
                            // lookup endpoint and send a message to it...
                            IMessageReceiver receiver = addressRegistry.lookup(address);
                            IInternalMessage internalMessage = (IInternalMessage) addressAndMessage[1];
                            if (receiver == null) {
                                String errorMessage = "no receiver for address " + address
                                        + " not sending message " + internalMessage;
                                log.error(errorMessage, new Throwable(errorMessage));
                            } else {
                                if (log.isDebugEnabled()) {
                                    log.debug("bus sending message " + internalMessage + " to " + address);
                                }
                                receiver.onMessage(internalMessage);
                            }
                        }
                    } catch (InterruptedException e) {
                        log.warn(e, e);
                    }
                }
            }

        });
    }
}

From source file:gov.nih.nci.integration.invoker.CaTissueConsentStrategyTest.java

/**
 * Tests registerConsents using the ServiceInvocationStrategy class for the failure scenario
 * /* w w w  .j  a  v a 2 s .  c om*/
 * @throws IntegrationException - IntegrationException
 * @throws JAXBException - JAXBException
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void registerConsentsSpecimenNotExist() throws IntegrationException, JAXBException {
    final Date stTime = new Date(new java.util.Date().getTime());

    xsltTransformer.transform(null, null, null);
    EasyMock.expectLastCall().andAnswer(new IAnswer() {

        public Object answer() {
            return getRegisterConsentXMLStr();
        }
    }).anyTimes();

    final ServiceInvocationResult clientResult = new ServiceInvocationResult();
    clientResult.setDataChanged(false);

    final IntegrationException ie = new IntegrationException(IntegrationError._1090, new Throwable( //NOPMD
            "Specimen for given LABEL doesn't exist"), "Specimen for given LABEL doesn't exist");
    clientResult.setInvocationException(ie);

    EasyMock.expect(caTissueConsentClient.registerConsents((String) EasyMock.anyObject()))
            .andReturn(clientResult);
    EasyMock.replay(caTissueConsentClient);
    final ServiceInvocationMessage serviceInvocationMessage = prepareServiceInvocationMessage(REFMSGID,
            getRegisterConsentXMLStr(), stTime, caTissueConsentStrategy.getStrategyIdentifier());
    final ServiceInvocationResult strategyResult = caTissueConsentStrategy.invoke(serviceInvocationMessage);
    Assert.assertNotNull(strategyResult);
}

From source file:io.openkit.OKScore.java

public void submitScore(final ScoreRequestResponseHandler responseHandler) {
    OKUser currentUser = OKUser.getCurrentUser();
    setOKUser(currentUser);//from  w w w  . j av  a2  s .c o  m

    if (OKManager.INSTANCE.getSharedCache() == null) {
        Log.e("OpenKit", "Error: score cache came back as null");
    }

    boolean shouldSubmit = OKManager.INSTANCE.getSharedCache()
            .storeScoreInCacheIfBetterThanLocalCachedScores(this);

    if (currentUser != null && shouldSubmit) {
        submitScoreBase(new ScoreRequestResponseHandler() {

            @Override
            public void onSuccess() {
                OKManager.INSTANCE.getSharedCache().updateCachedScoreSubmitted(OKScore.this);
                responseHandler.onSuccess();
            }

            @Override
            public void onFailure(Throwable error) {
                responseHandler.onFailure(error);
            }
        });
    } else {
        OKLog.v("Score was not submitted");
        if (currentUser == null) {
            responseHandler.onFailure(new Throwable(
                    "Current user is not logged in. To submit a score, the user must be logged into OpenKit. The score was cached and will be submitted to OpenKit when the user logs in."));
        } else {
            responseHandler.onFailure(new Throwable(
                    "The score was not submitted to the OpenKit server because it is not better than previous submitted score."));
        }
    }

}

From source file:org.openmrs.module.report.web.controller.report.ReportTypeController.java

@RequestMapping(method = RequestMethod.POST)
public String onSubmit(@ModelAttribute("reportType") BirtReportType reportType, BindingResult bindingResult,
        HttpServletRequest request, SessionStatus status) {
    new BirtReportTypeValidator().validate(reportType, bindingResult);
    if (bindingResult.hasErrors()) {
        return "/module/report/report/reportType";
    } else {/*ww w. j ava  2 s.c o m*/
        BirtReportService birtReportService = Context.getService(BirtReportService.class);
        BirtReportConfig config = ReportConstants.getConfig();
        String tempPath = config.getRealPath();
        if (StringUtils.isBlank(tempPath)) {
            Throwable th = new Throwable("Not exist realpath for save file report!");

        }
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        CommonsMultipartFile file = (CommonsMultipartFile) multipartRequest.getFile("reportFile");
        if (file != null && file.getBytes() != null && file.isEmpty() == false) {
            long temp = new Date().getTime();
            //String nameReport = org.openmrs.module.report.util.StringUtils.replaceSpecialWithUnderLineCharacter(reportType.getBirtReport().getName());
            //String nameReportType = org.openmrs.module.report.util.StringUtils.replaceSpecialWithUnderLineCharacter(reportType.getName());
            String fileName = reportType.getBirtReport().getId() + "_" + temp + ".rptdesign";
            String reportFilename = tempPath + "/" + fileName;
            reportFilename = reportFilename.replaceAll("//", "/");

            try {
                FileCopyUtils.copy(file.getInputStream(), new FileOutputStream(reportFilename));
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            reportType.setPath(fileName);
        } else if (reportType.getId() != null && reportType.getId().intValue() > 0) {
            reportType.setPath(birtReportService.getBirtReportTypeById(reportType.getId()).getPath());
        }

        reportType.setCreatedBy(Context.getAuthenticatedUser().getGivenName());
        reportType.setCreatedOn(new Date());
        birtReportService.saveBirtReportType(reportType);
        status.setComplete();
        return "redirect:/module/report/reportType.form?reportId=" + reportType.getBirtReport().getId();
    }
}

From source file:org.apereo.portal.url.processing.RequestParameterProcessorInterceptor.java

/**
 * Process the request first with the dynamic processors until all are complete and then the static processors.
 * /*from w w w  . j  ava 2s .  co  m*/
 * @see org.apereo.portal.url.processing.IRequestParameterController#processParameters(org.apereo.portal.url.IWritableHttpServletRequest, javax.servlet.http.HttpServletResponse)
 */
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    final List<IRequestParameterProcessor> incompleteDynamicProcessors = new LinkedList<IRequestParameterProcessor>(
            this.dynamicRequestParameterProcessors);

    //Loop while there are still dynamic processors to execute
    int cycles = 0;
    while (incompleteDynamicProcessors.size() > 0) {
        //Run all dynamic processors that are not yet complete
        for (final Iterator<IRequestParameterProcessor> processorItr = incompleteDynamicProcessors
                .iterator(); processorItr.hasNext();) {
            final IRequestParameterProcessor requestParameterProcessor = processorItr.next();

            //If a dynamic processor completes remove it from the list.
            final boolean complete = requestParameterProcessor.processParameters(request, response);
            if (complete) {
                processorItr.remove();
            }
        }

        cycles++;

        //If the max cycle count is reached log a warning and break out of the dynamic processing loop
        if (cycles >= this.maxNumberOfProcessingCycles) {
            this.logger.warn(incompleteDynamicProcessors.size()
                    + " IDynamicRequestParameterProcessors did not complete processing after " + cycles
                    + " attempts. Execution will continue but this situation should be reviewed. Incomplete Processors="
                    + incompleteDynamicProcessors, new Throwable("Stack Trace"));
            break;
        }
    }

    return true;
}

From source file:de.tudarmstadt.ukp.experiments.ej.bills.experiment2.Exp2Reader.java

@Override
public Set<String> getTextClassificationOutcomes(JCas jcas) throws CollectionException {
    Set<String> outcomes = new HashSet<String>();

    for (Sponsor sponsor : bill.getSponsors()) {
        String sponsorName = sponsor.getName();
        outcomes.add(sponsorName);/*  w ww  .j  a v a 2s.c  o m*/
    }
    if (outcomes.size() == 0) {
        throw new CollectionException(new Throwable("No gold label for document: " + bill.getId()));
    }
    return outcomes;
}

From source file:gov.nih.nci.integration.invoker.CaTissueSpecimenStrategyTest.java

/**
 * Tests createSpecimens using the ServiceInvocationStrategy class for the failure scenario
 * /*from   ww w  .j  av  a 2 s.c o  m*/
 * @throws IntegrationException - IntegrationException
 * @throws JAXBException - JAXBException
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void createSpecimensInvalidAvailableQuantity() throws IntegrationException, JAXBException {
    final Date stTime = new Date(new java.util.Date().getTime());

    xsltTransformer.transform(null, null, null);
    EasyMock.expectLastCall().andAnswer(new IAnswer() {

        public Object answer() {
            return getSpecimenXMLStr();
        }
    }).anyTimes();

    final ServiceInvocationResult clientResult = new ServiceInvocationResult();
    clientResult.setDataChanged(false);
    clientResult.setOriginalData(getSpecimenXMLStr());

    final IntegrationException ie = new IntegrationException(IntegrationError._1085, new Throwable( // NOPMD
            "Available Quantity cannot be greater than the Initial Quantity"),
            "Available Quantity cannot be greater than the Initial Quantity");
    clientResult.setInvocationException(ie);

    EasyMock.expect(caTissueSpecimenClient.createSpecimens((String) EasyMock.anyObject()))
            .andReturn(clientResult);
    EasyMock.replay(caTissueSpecimenClient);
    final ServiceInvocationMessage serviceInvocationMessage = prepareServiceInvocationMessage(REFMSGID,
            getSpecimenXMLStr(), stTime, caTissueSpecimenStrategy.getStrategyIdentifier());
    final ServiceInvocationResult strategyResult = caTissueSpecimenStrategy.invoke(serviceInvocationMessage);
    Assert.assertNotNull(strategyResult);
}