List of usage examples for java.lang Exception getStackTrace
public StackTraceElement[] getStackTrace()
From source file:org.alfresco.repo.content.AbstractContentAccessor.java
/** * Derived classes can call this method to ensure that necessary trace logging is performed * when the IO Channel is opened.// www. j a v a 2 s. c o m */ protected final void channelOpened() { // trace debug if (loggerTrace.isDebugEnabled()) { Exception e = new Exception(); e.fillInStackTrace(); traceLoggerChannelAssignTrace = e.getStackTrace(); } }
From source file:Thumbnail.java
/** * Reads an image in a file and creates a thumbnail in another file. * largestDimension is the largest dimension of the thumbnail, the other dimension is scaled accordingly. * Utilises weighted stepping method to gradually reduce the image size for better results, * i.e. larger steps to start with then smaller steps to finish with. * Note: always writes a JPEG because GIF is protected or something - so always make your outFilename end in 'jpg'. * PNG's with transparency are given white backgrounds *//*from ww w .ja v a 2s . c o m*/ public String createThumbnail(String inFilename, String outFilename, int largestDimension) { try { double scale; int sizeDifference, originalImageLargestDim; if (!inFilename.endsWith(".jpg") && !inFilename.endsWith(".jpeg") && !inFilename.endsWith(".gif") && !inFilename.endsWith(".png")) { return "Error: Unsupported image type, please only either JPG, GIF or PNG"; } else { Image inImage = Toolkit.getDefaultToolkit().getImage(inFilename); if (inImage.getWidth(null) == -1 || inImage.getHeight(null) == -1) { return "Error loading file: \"" + inFilename + "\""; } else { //find biggest dimension if (inImage.getWidth(null) > inImage.getHeight(null)) { scale = (double) largestDimension / (double) inImage.getWidth(null); sizeDifference = inImage.getWidth(null) - largestDimension; originalImageLargestDim = inImage.getWidth(null); } else { scale = (double) largestDimension / (double) inImage.getHeight(null); sizeDifference = inImage.getHeight(null) - largestDimension; originalImageLargestDim = inImage.getHeight(null); } //create an image buffer to draw to BufferedImage outImage = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); //arbitrary init so code compiles Graphics2D g2d; AffineTransform tx; if (scale < 1.0d) //only scale if desired size is smaller than original { int numSteps = sizeDifference / 100; int stepSize = sizeDifference / numSteps; int stepWeight = stepSize / 2; int heavierStepSize = stepSize + stepWeight; int lighterStepSize = stepSize - stepWeight; int currentStepSize, centerStep; double scaledW = inImage.getWidth(null); double scaledH = inImage.getHeight(null); if (numSteps % 2 == 1) //if there's an odd number of steps centerStep = (int) Math.ceil((double) numSteps / 2d); //find the center step else centerStep = -1; //set it to -1 so it's ignored later Integer intermediateSize = originalImageLargestDim, previousIntermediateSize = originalImageLargestDim; Integer calculatedDim; for (Integer i = 0; i < numSteps; i++) { if (i + 1 != centerStep) //if this isn't the center step { if (i == numSteps - 1) //if this is the last step { //fix the stepsize to account for decimal place errors previously currentStepSize = previousIntermediateSize - largestDimension; } else { if (numSteps - i > numSteps / 2) //if we're in the first half of the reductions currentStepSize = heavierStepSize; else currentStepSize = lighterStepSize; } } else //center step, use natural step size { currentStepSize = stepSize; } intermediateSize = previousIntermediateSize - currentStepSize; scale = (double) intermediateSize / (double) previousIntermediateSize; scaledW = (int) scaledW * scale; scaledH = (int) scaledH * scale; outImage = new BufferedImage((int) scaledW, (int) scaledH, BufferedImage.TYPE_INT_RGB); g2d = outImage.createGraphics(); g2d.setBackground(Color.WHITE); g2d.clearRect(0, 0, outImage.getWidth(), outImage.getHeight()); g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); tx = new AffineTransform(); tx.scale(scale, scale); g2d.drawImage(inImage, tx, null); g2d.dispose(); inImage = new ImageIcon(outImage).getImage(); previousIntermediateSize = intermediateSize; } } else { //just copy the original outImage = new BufferedImage(inImage.getWidth(null), inImage.getHeight(null), BufferedImage.TYPE_INT_RGB); g2d = outImage.createGraphics(); g2d.setBackground(Color.WHITE); g2d.clearRect(0, 0, outImage.getWidth(), outImage.getHeight()); tx = new AffineTransform(); tx.setToIdentity(); //use identity matrix so image is copied exactly g2d.drawImage(inImage, tx, null); g2d.dispose(); } //JPEG-encode the image and write to file. OutputStream os = new FileOutputStream(outFilename); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(os); encoder.encode(outImage); os.close(); } } } catch (Exception ex) { String errorMsg = ""; errorMsg += "<br>Exception: " + ex.toString(); errorMsg += "<br>Cause = " + ex.getCause(); errorMsg += "<br>Stack Trace = "; StackTraceElement stackTrace[] = ex.getStackTrace(); for (int traceLine = 0; traceLine < stackTrace.length; traceLine++) { errorMsg += "<br>" + stackTrace[traceLine]; } return errorMsg; } return ""; //success }
From source file:edu.cornell.mannlib.vitro.webapp.controller.jena.JenaXMLFileUpload.java
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (!isAuthorizedToDisplayPage(request, response, SimplePermission.USE_ADVANCED_DATA_TOOLS_PAGES.ACTION)) { return;/* ww w. ja va2s . c o m*/ } VitroRequest vreq = new VitroRequest(request); //make a form for uploading a file request.setAttribute("title", "Upload file and convert to RDF"); request.setAttribute("bodyJsp", "/jenaIngest/xmlFileUpload.jsp"); request.setAttribute("modelNames", getModelMaker(vreq).listModels().toList()); request.setAttribute("models", null); RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP); request.setAttribute("css", "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + vreq.getAppBean().getThemeDir() + "css/edit.css\"/>"); try { rd.forward(request, response); } catch (Exception e) { System.out.println(this.getClass().getName() + " could not forward to view."); System.out.println(e.getMessage()); System.out.println(e.getStackTrace()); } }
From source file:com.daro.persistence.generic.dao.GenericDaoImpl.java
/** * Get Current Session from Session Factory. * //from w w w .j a v a 2s . c o m * @return Session Session instance * @throws PersistenceException */ protected Session getCurrentSession() throws PersistenceException { Session session = null; try { session = this.sessionFactory.getCurrentSession(); } catch (java.lang.NullPointerException nullPpointEx) { logger.error("Persistence layer error: " + nullPpointEx.getStackTrace()); throw new PersistenceException(PersistenceError.SESSION_FACTORY_NULL, nullPpointEx.getCause()); } catch (Exception ex) { logger.error("Persistence layer error: " + ex.getStackTrace()); PersistenceError error = PersistenceError.PERSISTENCE_INTERNAL_ERROR; throw new PersistenceException(error, ex.getCause()); } return session; }
From source file:com.music.web.util.ExceptionResolver.java
@Override public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { // the stacktrace will be printed by spring's DispatcherServlet // we are only logging the request url and headeres here logger.warn("An exception occurred when invoking the following URL: " + request.getRequestURL() + " . Requester IP is " + request.getRemoteAddr() + ", User-Agent: " + request.getHeader("User-Agent") + "; Message=" + ex.getMessage() + ": " + ex.getStackTrace()[0].getMethodName()); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return null;//w ww .j a va 2 s. c o m }
From source file:com.quinsoft.zeidon.dbhandler.MysqlJdbcHandler.java
@Override protected void releaseGenkeyLock() { for (int tries = 0; tries < 5; tries++) { try {/*from w w w . j av a 2 s . co m*/ executeSql("UNLOCK TABLES;"); return; } catch (Exception e) { // Danger danger Will Robinson! We couldn't delete the lock, which will // prevent anybody else from creating new entities. Log a warning and try again. getTask().log().warn("Exception attempting to execute UNLOCK TABLES: %s\n %s", e.getMessage(), StringUtils.join(e.getStackTrace(), "\n ")); } try { Thread.sleep(tries * tries * 100); } catch (InterruptedException e2) { // Ignore this error. If we somehow get a crazy error here we still want // to try and unlock the tables. } getTask().log().warn("Attempting to UNLOCK genkey tables again #%d.", tries); } // If we get here then we didn't acquire the lock. throw new GenkeyLockException("Unable to UNLOCK GENKEY lock. See logs for possible explanation."); }
From source file:com.esri.ges.solutions.processor.geometry.RangeFanProcessor.java
private void constructVisibility(GeoEvent ge, String gpservice, String imageservice, double range, String unit, double elevation, String units_elev, Geometry mask, int wkid) throws FieldException, ConfigurationException, GeometryException { try {/* www. j a va 2 s . c o m*/ UnitConverter uc = new UnitConverter(); range = uc.Convert(range, unit, srBuffer); String procUnitName = srBuffer.getUnit().getName(); // normalize horizontal and vertical units to z-factor = 1 //double inElev = elevation; if (procUnitName.equals("Meter")) { if (units_elev.equals("Feet")) { elevation = elevation * 0.3048; } } else { if (units_elev.equals("Meters")) { elevation = elevation * 3.28084; } } Geoprocessor gp = new Geoprocessor(gpservice); List<GPParameter> parameters = new ArrayList<GPParameter>(); com.esri.ges.spatial.Point eventGeo = (com.esri.ges.spatial.Point) ge.getGeometry(); // Set params Double x = (Double) eventGeo.getX(); Double y = (Double) eventGeo.getY(); Point center = new Point(); center.setX(x); center.setY(y); Point centerProj = (Point) GeometryEngine.project(center, srIn, srBuffer); String cx = ((Double) centerProj.getX()).toString(); String cy = ((Double) centerProj.getY()).toString(); String obs = cx + " " + cy; GPString paramObserver = new GPString(); paramObserver.setParamName("observers"); paramObserver.setValue(obs); parameters.add(paramObserver); GPString paramIS = new GPString(); paramIS.setParamName("image_service_url"); paramIS.setValue(imageservice); parameters.add(paramIS); GPDouble paramRadius = new GPDouble(); paramRadius.setParamName("radius"); paramRadius.setValue(range); parameters.add(paramRadius); GPDouble paramHeight = new GPDouble(); paramHeight.setParamName("height"); paramHeight.setValue(elevation); parameters.add(paramHeight); String json = GeometryEngine.geometryToJson(srBuffer, mask); GPString paramMask = new GPString(); paramMask.setParamName("json_mask"); paramMask.setValue(json); parameters.add(paramMask); GPLong paramWkid = new GPLong(); paramWkid.setParamName("wkid"); paramWkid.setValue(wkid); parameters.add(paramWkid); com.esri.ges.spatial.Geometry visible = null; com.esri.ges.spatial.Geometry nonvisible = null; GPParameter[] result = null; try { result = gp.execute(parameters); } catch (Exception ex) { LOG.error(ex.getMessage()); LOG.error(ex.getStackTrace()); gp.cancelJob(); } if (result != null) { for (GPParameter outputParameter : result) { if (outputParameter instanceof GPFeatureRecordSetLayer) { GPFeatureRecordSetLayer gpResults = (GPFeatureRecordSetLayer) outputParameter; for (Graphic graphic : gpResults.getGraphics()) { int code = (Integer) graphic.getAttributes().get("gridcode"); // com.esri.ges.spatial.Geometry tmpgesVis = null; // com.esri.ges.spatial.Geometry tmpgesNonVis = // null; if (code == 0) { Geometry tmpvis = graphic.getGeometry(); Geometry vis = GeometryEngine.project(tmpvis, srBuffer, srOut); json = GeometryEngine.geometryToJson(srOut, vis); visible = spatial.fromJson(json); } else { Geometry tmpnonvis = graphic.getGeometry(); Geometry nonvis = GeometryEngine.project(tmpnonvis, srBuffer, srOut); json = GeometryEngine.geometryToJson(srOut, nonvis); nonvisible = spatial.fromJson(json); } } } } } else { NullPointerException e = new NullPointerException(); throw e; } /*ArrayList<FieldDefinition> augmentList = new ArrayList<FieldDefinition>(); ArrayList<String> tagTypes = new ArrayList<String>(); tagTypes.add("Geometry"); Tag visTag = tagMgr.createNewTag("VISIBLE", "Visible polygons returned from visibility analysis", tagTypes); tagMgr.addTag(visTag); Tag nonvisTag = tagMgr.createNewTag("NONVISIBLE", "Visible polygons returned from visibility analysis", tagTypes); tagMgr.addTag(nonvisTag); addToAugmentList(augmentList, "elevation", FieldType.Double, (String) null); addToAugmentList(augmentList, "elev_units", FieldType.String, (String) null); addToAugmentList(augmentList, "gridcode", FieldType.Short, (String) null); addToAugmentList(augmentList, "visible", FieldType.Geometry, visTag.getName()); addToAugmentList(augmentList, "nonvisible", FieldType.Geometry, nonvisTag.getName()); GeoEventDefinition geDef = ge.getGeoEventDefinition(); geDef.augment(augmentList);*/ ge.setField("visible", visible); ge.setField("nonvisible", nonvisible); //ge.setField("elevation", inElev); //ge.setField("elevUnits", units_elev); } catch (Exception e) { } }
From source file:edu.cornell.mannlib.vitro.webapp.controller.edit.VclassEditController.java
public void doPost(HttpServletRequest req, HttpServletResponse response) { if (!isAuthorizedToDisplayPage(req, response, SimplePermission.EDIT_ONTOLOGY.ACTION)) { return;/* w w w . ja va 2 s.co m*/ } VitroRequest request = new VitroRequest(req); EditProcessObject epo = super.createEpo(request, FORCE_NEW); request.setAttribute("epoKey", epo.getKey()); VClassDao vcwDao = ModelAccess.on(getServletContext()).getWebappDaoFactory(ASSERTIONS_ONLY).getVClassDao(); VClass vcl = (VClass) vcwDao.getVClassByURI(request.getParameter("uri")); if (vcl == null) { vcl = request.getUnfilteredWebappDaoFactory().getVClassDao().getTopConcept(); } request.setAttribute("VClass", vcl); ArrayList results = new ArrayList(); results.add("class"); // 1 results.add("class label"); // 2 results.add("class group"); // 3 results.add("ontology"); // 4 results.add("RDF local name"); // 5 results.add("short definition"); // 6 results.add("example"); // 7 results.add("editor description"); // 8 //results.add("curator comments"); results.add("display level"); // 9 results.add("update level"); // 10 results.add("display rank"); // 11 results.add("custom entry form"); // 12 results.add("URI"); // 13 results.add("publish level"); // 14 String ontologyName = null; if (vcl.getNamespace() != null) { Ontology ont = request.getUnfilteredWebappDaoFactory().getOntologyDao() .getOntologyByURI(vcl.getNamespace()); if ((ont != null) && (ont.getName() != null)) { ontologyName = ont.getName(); } } WebappDaoFactory wadf = request.getUnfilteredWebappDaoFactory(); String groupURI = vcl.getGroupURI(); String groupName = "none"; if (groupURI != null) { VClassGroupDao groupDao = wadf.getVClassGroupDao(); VClassGroup classGroup = groupDao.getGroupByURI(groupURI); if (classGroup != null) { groupName = classGroup.getPublicName(); } } String shortDef = (vcl.getShortDef() == null) ? "" : vcl.getShortDef(); String example = (vcl.getExample() == null) ? "" : vcl.getExample(); String description = (vcl.getDescription() == null) ? "" : vcl.getDescription(); boolean foundComment = false; StringBuffer commSb = null; for (Iterator<String> commIt = request.getUnfilteredWebappDaoFactory().getCommentsForResource(vcl.getURI()) .iterator(); commIt.hasNext();) { if (commSb == null) { commSb = new StringBuffer(); foundComment = true; } commSb.append(commIt.next()).append(" "); } if (!foundComment) { commSb = new StringBuffer("no comments yet"); } String hiddenFromDisplay = (vcl.getHiddenFromDisplayBelowRoleLevel() == null ? "(unspecified)" : vcl.getHiddenFromDisplayBelowRoleLevel().getDisplayLabel()); String ProhibitedFromUpdate = (vcl.getProhibitedFromUpdateBelowRoleLevel() == null ? "(unspecified)" : vcl.getProhibitedFromUpdateBelowRoleLevel().getUpdateLabel()); String hiddenFromPublish = (vcl.getHiddenFromPublishBelowRoleLevel() == null ? "(unspecified)" : vcl.getHiddenFromPublishBelowRoleLevel().getDisplayLabel()); String customEntryForm = (vcl.getCustomEntryForm() == null ? "(unspecified)" : vcl.getCustomEntryForm()); //String lastModified = "<i>not implemented yet</i>"; // TODO String uri = (vcl.getURI() == null) ? "" : vcl.getURI(); results.add(vcl.getPickListName()); // 1 results.add(vcl.getName() == null ? "(no public label)" : vcl.getName()); // 2 results.add(groupName); // 3 results.add(ontologyName == null ? "(not identified)" : ontologyName); // 4 results.add(vcl.getLocalName()); // 5 results.add(shortDef); // 6 results.add(example); // 7 results.add(description); // 8 //results.add(commSb.toString()); // results.add(hiddenFromDisplay); // 9 results.add(ProhibitedFromUpdate); // 10 results.add(String.valueOf(vcl.getDisplayRank())); // 11 results.add(customEntryForm); // 12 results.add(uri); // 13 results.add(hiddenFromPublish); // 14 request.setAttribute("results", results); request.setAttribute("columncount", NUM_COLS); request.setAttribute("suppressquery", "true"); epo.setDataAccessObject(vcl); FormObject foo = new FormObject(); HashMap OptionMap = new HashMap(); HashMap formSelect = new HashMap(); // tells the JSP what select lists are populated, and thus should be displayed request.setAttribute("formSelect", formSelect); // if supported, we want to show only the asserted superclasses and subclasses. VClassDao vcDao = ModelAccess.on(getServletContext()).getWebappDaoFactory(ASSERTIONS_ONLY).getVClassDao(); VClassDao displayVcDao = ModelAccess.on(getServletContext()).getWebappDaoFactory().getVClassDao(); List<VClass> superVClasses = getVClassesForURIList(vcDao.getSuperClassURIs(vcl.getURI(), false), displayVcDao); sortForPickList(superVClasses, request); request.setAttribute("superclasses", superVClasses); List<VClass> subVClasses = getVClassesForURIList(vcDao.getSubClassURIs(vcl.getURI()), displayVcDao); sortForPickList(subVClasses, request); request.setAttribute("subclasses", subVClasses); List<VClass> djVClasses = getVClassesForURIList(vcDao.getDisjointWithClassURIs(vcl.getURI()), displayVcDao); sortForPickList(djVClasses, request); request.setAttribute("disjointClasses", djVClasses); List<VClass> eqVClasses = getVClassesForURIList(vcDao.getEquivalentClassURIs(vcl.getURI()), displayVcDao); sortForPickList(eqVClasses, request); request.setAttribute("equivalentClasses", eqVClasses); // add the options foo.setOptionLists(OptionMap); epo.setFormObject(foo); boolean instantiable = (vcl.getURI().equals(OWL.Nothing.getURI())) ? false : true; RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP); request.setAttribute("epoKey", epo.getKey()); request.setAttribute("vclassWebapp", vcl); request.setAttribute("instantiable", instantiable); request.setAttribute("bodyJsp", "/templates/edit/specific/classes_edit.jsp"); request.setAttribute("title", "Class Control Panel"); //request.setAttribute("css", "<link rel=\"stylesheet\" type=\"text/css\" href=\""+request.getAppBean().getThemeDir()+"css/edit.css\"/>"); try { rd.forward(request, response); } catch (Exception e) { log.error("VclassEditController could not forward to view."); log.error(e.getMessage()); log.error(e.getStackTrace()); } }
From source file:org.apache.pig.impl.logicalLayer.LOLoad.java
public void setInputFile(FileSpec inputFileSpec) throws IOException { try {/* www . j a va 2s . com*/ mLoadFunc = (LoadFunc) PigContext.instantiateFuncFromSpec(inputFileSpec.getFuncSpec()); } catch (ClassCastException cce) { log.error(inputFileSpec.getFuncSpec() + " should implement the LoadFunc interface."); IOException ioe = new IOException(cce.getMessage()); ioe.setStackTrace(cce.getStackTrace()); throw ioe; } catch (Exception e) { IOException ioe = new IOException(e.getMessage()); ioe.setStackTrace(e.getStackTrace()); throw ioe; } mInputFileSpec = inputFileSpec; }
From source file:py.edu.ucsa.voto.ws.service.VotoEndpoint.java
@PayloadRoot(localPart = CONSULTAR_REQUEST, namespace = NAMESPACE) public ConsultarResponse consultarTransaccion(ConsultarRequest request) { //Date fecha = consultarTransaccionRequestDAO.getDataBaseTime(); //se obtiene la fecha //request.setFchins(fecha); //se setea la fecha ConsultarResponse response = new ConsultarResponse(); try {/* ww w.ja va 2 s . co m*/ // enviar a cola request // String idMessageRequest = gfvJmsMessageManager // .enviarObjectMessage(request); // recibir response consultarRequestDAO.saveOrUpdate(request); response.setCodigo(new BigDecimal(_CODIGO_OK)); response.setDescripcion(_CONSULTA_OK_DESCRIPCION); response.setConsultarRequest(request); } catch (Exception e) { logger.error(e.getStackTrace(), e); response.setCodigo(new BigDecimal(_CODIGO_OK)); response.setDescripcion(_CONSULTA_OK_DESCRIPCION); response.setConsultarRequest(request); } consultarResponseDAO.saveOrUpdate(response); return response; }