List of usage examples for java.lang NullPointerException getMessage
public String getMessage()
From source file:org.zaproxy.zap.extension.zest.ZestSequenceRunner.java
@Override public ZestResponse runStatement(ZestScript script, ZestStatement stmt, ZestResponse lastResponse) throws ZestAssertFailException, ZestActionFailException, ZestInvalidCommonTestException, IOException, ZestAssignFailException, ZestClientFailException { // This method makes sure each request from a Sequence Script is displayed on the Active // Scan results tab. ZestResponse response = null;/* www .ja va2 s. c om*/ try { response = super.runStatement(script, stmt, lastResponse); } catch (NullPointerException e) { logger.debug("NullPointerException occurred, while running Sequence Script: " + e.getMessage()); } try { if (stmt instanceof ZestRequest) { HttpMessage msg = ZestZapUtils.toHttpMessage((ZestRequest) stmt, response); this.currentPlugin.getParent().notifyNewMessage(msg); } } catch (Exception e) { logger.debug("Exception while trying to notify of unscanned message in a sequence."); } return response; }
From source file:org.meerkat.httpServer.CustomResourceHandler.java
@Override public final void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (response.isCommitted() || baseRequest.isHandled()) { return;// ww w.j a v a 2s . co m } else { // little cheat for common request - favicon hack if (request.getRequestURI().equals("/favicon.ico")) { response.setStatus(HttpServletResponse.SC_OK); response.setContentType("image/x-icon"); response.setContentLength(_favicon.length); response.getOutputStream().write(_favicon); baseRequest.setHandled(true); return; } else if (request.getRequestURI().contains("index.html")) { // Handle index.html String responseIndex = httpServer.getIndexPageContents(); ByteArrayISO8859Writer writer = new ByteArrayISO8859Writer(1500); //response.setContentType(MimeTypes.TEXT_HTML); response.setContentType(MimeTypes.Type.TEXT_HTML_UTF_8.asString()); response.setHeader("Cache-Control", "private, no-store, no-cache, must-revalidate"); writer.write(responseIndex); writer.flush(); response.setContentLength(writer.size()); OutputStream out = response.getOutputStream(); writer.writeTo(out); out.close(); writer.close(); baseRequest.setHandled(true); return; } else if (request.getRequestURI().contains(eventRequestID)) { // This is a request for event // Get request id String requestRef = request.getRequestURI(); requestRef = requestRef.substring(eventRequestID.length(), requestRef.length()); int id = Integer.valueOf(requestRef); WebAppEvent ev = WebAppEvent.getEventByID(id); ByteArrayISO8859Writer writer = new ByteArrayISO8859Writer(1500); //response.setContentType(MimeTypes.TEXT_HTML); response.setContentType(MimeTypes.Type.TEXT_HTML_UTF_8.asString()); if (ev != null) { response.setStatus(HttpServletResponse.SC_OK); // Escape the response String escapedResponse = escapeHtml3(ev.getCurrentResponse()); //String escapedResponse = StringUtils.replaceEach(ev.getCurrentResponse(), new String[]{"&", "\"", "<", ">"}, new String[]{"&", """, "<", ">"}); // Prettify response String prettified = HtmlOperations.addPrettifier(escapedResponse); writer.write(prettified); writer.flush(); response.setContentLength(writer.size()); OutputStream out = response.getOutputStream(); writer.writeTo(out); out.close(); writer.close(); baseRequest.setHandled(true); return; } else { writer.close(); //log.info("-- prepare to load 404 handler.."); processNotFound404(response, baseRequest); } } // Deal with request for datatables events else if (request.getRequestURI().contains(eventListRequest)) { // Get application String requestRef = request.getRequestURI(); requestRef = requestRef.substring(eventListRequest.length(), requestRef.length()); String appName = URLDecoder.decode(requestRef, "UTF-8"); // Handle paging String displayStart, displayLength; displayStart = request.getParameter("iDisplayStart"); displayLength = request.getParameter("iDisplayLength"); if (displayStart == null || displayLength == null) { displayStart = "0"; displayLength = "10"; } // Ordering String orderBy = request.getParameter("iSortCol_0"); String sortOrder = request.getParameter("sSortDir_0"); if (orderBy == null || sortOrder == null) { orderBy = "0"; sortOrder = "ASC"; } String sEcho = request.getParameter("sEcho"); if (sEcho == null) { sEcho = "1"; } // Get number of events of application WebApp webapp = wac.getWebAppByName(appName); if (webapp == null) { log.info("Application " + appName + " not present!"); webapp = new WebApp(); // prevent null in getCustomEventsList processNotFound404(response, baseRequest); } int numberEvents = 0; try { numberEvents = webapp.getNumberOfEvents(); } catch (NullPointerException e) { log.error("Failed to get number of events from app. - " + e.getMessage()); } int numberOfEventsToShow = Integer.valueOf(displayStart) + Integer.valueOf(displayLength); ArrayList<WebAppEvent> requestedEventList = webapp.getCustomEventsList(displayStart, String.valueOf(numberOfEventsToShow), orderBy, sortOrder.toUpperCase()); String returnResp = "{ \n" + "\"sEcho\": " + sEcho + ", \n" + "\"iTotalRecords\": \"" + numberEvents + "\", \n" + "\"iTotalDisplayRecords\": \"" + numberEvents + "\", \n" + "\"aaData\": [ \n"; Iterator<WebAppEvent> it = requestedEventList.iterator(); WebAppEvent ev; String jSONresponse = returnResp; while (it.hasNext()) { ev = it.next(); jSONresponse += "[\n" + "\"" + ev.getID() + "\", \n" + "\"" + ev.getDate() + "\", \n"; if (ev.getStatus()) { jSONresponse += "\"Online\", \n"; } else { jSONresponse += "\"Offline\", \n"; } jSONresponse += "\"" + ev.getAvailability() + "\", \n" + "\"" + ev.getPageLoadTime() + "\", \n" + "\"" + ev.getLatency() + "\", \n"; jSONresponse += "\"" + ev.getHttpStatusCode() + "\", \n"; jSONresponse += "\"" + ev.getDescription() + "\", \n" + "\"<a href=\\\"event-id-" + ev.getID() + "\\\" onclick=\\\"return popitup('event-id-" + +ev.getID() + "')\\\"><img src=\\\"resources/tango_edit-find.png\\\" border=\\\"0\\\" alt=\\\"\\\" /></a>\" \n" + "],"; // only the one doesnt have "," } // remove the last "," jSONresponse = jSONresponse.substring(0, jSONresponse.length() - 1); jSONresponse += "\n] \n" + "}"; ByteArrayISO8859Writer writer = new ByteArrayISO8859Writer(1500); //response.setContentType(MimeTypes.TEXT_JSON_UTF_8); response.setContentType(MimeTypes.Type.TEXT_JSON_UTF_8.asString()); response.setStatus(HttpServletResponse.SC_OK); // Disable cache response.setHeader("Cache-Control", "private, no-store, no-cache, must-revalidate"); writer.write(jSONresponse); writer.flush(); response.setContentLength(writer.size()); OutputStream out = response.getOutputStream(); writer.writeTo(out); out.close(); writer.close(); baseRequest.setHandled(true); return; } // Deal with request for Google Visualization events else if (request.getRequestURI().contains(eventListGoogleVisualizationRequest)) { // Get properties PropertiesLoader pl = new PropertiesLoader(propertiesFile); Properties prop = pl.getPropetiesFromFile(); // Get the max number of records int maxNumberRecordsToShow = Integer.valueOf(prop.getProperty("meerkat.app.timeline.maxrecords")); // Get application String requestRef = request.getRequestURI(); requestRef = requestRef.substring(eventListGoogleVisualizationRequest.length(), requestRef.length()); String appName = URLDecoder.decode(requestRef, "UTF-8"); WebApp webapp = wac.getWebAppByName(appName); WebAppEventListIterator wAppEIt = new WebAppEventListIterator(webapp); String jsonResponse = wAppEIt.getJsonFormatLastXAppEvents(maxNumberRecordsToShow); ByteArrayISO8859Writer writer = new ByteArrayISO8859Writer(1500); //response.setContentType(MimeTypes.TEXT_JSON_UTF_8); response.setContentType(MimeTypes.Type.TEXT_JSON_UTF_8.asString()); response.setStatus(HttpServletResponse.SC_OK); // Disable cache response.setHeader("Cache-Control", "private, no-store, no-cache, must-revalidate"); writer.write(jsonResponse); writer.flush(); response.setContentLength(writer.size()); OutputStream out = response.getOutputStream(); writer.writeTo(out); out.close(); writer.close(); baseRequest.setHandled(true); return; } // Otherwise return not found 404 processNotFound404(response, baseRequest); } }
From source file:com.sfs.whichdoctor.dao.BulkEmailDAOImpl.java
/** * Send an email using the supplied BulkEmailBean to * the recipient identified by the supplied EmailRecipientBean. * * @param bulkEmail the bulk email//from w ww .j a v a 2 s. c o m * @param recipient the recipient * @param preferences the preferences * @param debugMode the debug mode flag * @return true, if successful */ public final boolean sendEmail(final BulkEmailBean bulkEmail, final EmailRecipientBean recipient, final PreferencesBean preferences, final boolean debugMode) { boolean success = false; try { success = sendEmail(bulkEmail, recipient, null, preferences, debugMode); } catch (NullPointerException npe) { dataLogger.info(npe.getMessage()); } return success; }
From source file:com.sfs.whichdoctor.dao.BulkEmailDAOImpl.java
/** * Send an email using the supplied BulkEmailBean to * the recipient identified by the supplied UserBean. * * @param bulkEmail the bulk email// ww w . j a v a2s. c om * @param user the user * @param preferences the preferences * @return true, if successful */ public final boolean sendEmail(final BulkEmailBean bulkEmail, final UserBean user, final PreferencesBean preferences) { boolean success = false; try { success = sendEmail(bulkEmail, null, user, preferences, false); } catch (NullPointerException npe) { dataLogger.info(npe.getMessage()); } return success; }
From source file:com.studiostorti.ZimbraFlowHandler.java
@Override public void handleRequest(ZimbraContext zimbraContext, SoapResponse soapResponse, ZimbraExceptionContainer zimbraExceptionContainer) { String requesterId = zimbraContext.getAuthenticatedAccontId(); Mailbox mailbox = mMailboxManager.getMailboxByAccountId(requesterId); Account account = mProvisioning.getAccountById(requesterId); Map<String, String> args = new HashMap<String, String>(); if (account == null) { soapResponse.setValue("reply", "KONon e' stato possibile trovare l'account : " + requesterId); return;/*from w w w .ja v a2s . c o m*/ } OperationContext octxt = new OperationContext(account); String msgId = zimbraContext.getParameter("id", ""); String namespace = zimbraContext.getParameter("namespace", ""); String url = zimbraContext.getParameter("url", ""); String user = account.getName(); ZimbraLog.extensions .info("Azione ZimbraFlow richiesta da '" + user + "' per il messaggio: '" + msgId + "'"); args.put("cUserEmail", user); Message item; if (!msgId.contains(":")) { try { item = mailbox.getMessageById(octxt, Integer.parseInt(msgId)); } catch (Exception e) { soapResponse.setValue("reply", "KONon e' stato possibile recuperare il messaggio (" + msgId + "): " + e.getMessage()); return; } ZimbraLog.mailbox.info("ZimbraFlow mail id : " + msgId); args.put("cEmailUniqueID", account.getId() + ":" + msgId); } else { ZimbraLog.mailbox.info("ZimbraFlow il messaggio e' una cartella condivisa"); String accountId = msgId.substring(0, msgId.indexOf(':')); String itemId = msgId.substring(msgId.indexOf(':') + 1); try { Mailbox ownerMailbox = mMailboxManager.getMailboxByAccountId(accountId); item = ownerMailbox.getMessageById(octxt, Integer.parseInt(itemId)); } catch (Exception e) { soapResponse.setValue("reply", "KONon e' stato possibile recuperare il messaggio (" + msgId + "): " + e.getMessage()); return; } args.put("cEmailUniqueID", msgId); } if (item == null) { soapResponse.setValue("reply", "KONon e' stato possibile recuperare il messaggio (" + msgId + "."); return; } MimeMessage mimeMessage = null; try { mimeMessage = item.getMimeMessage(); args.put("cEmailMessageID", mimeMessage.getMessageID()); } catch (MessagingException e) { ZimbraLog.mailbox.warn("ZimbraFlow errore cEmailMessageID: " + e.getMessage()); } byte[] mime = item.getContent(); args.put("StreamBase64", Base64.encodeBase64String(mime)); String subject; subject = item.getSubject(); args.put("cSubject", subject); String body; try { body = getText(mimeMessage); } catch (MessagingException e) { ZimbraLog.mailbox.warn("ZimbraFlow errore cBody: " + e.getMessage()); body = ""; } catch (IOException e) { ZimbraLog.mailbox.warn("ZimbraFlow errore cBody: " + e.getMessage()); body = ""; } args.put("cBody", body); try { Address from = mimeMessage.getFrom()[0]; args.put("cFrom", ((InternetAddress) from).getAddress()); } catch (NullPointerException ne) { ZimbraLog.mailbox.warn("ZimbraFlow errore cFrom: " + ne.getMessage()); args.put("cFrom", ""); } catch (MessagingException e) { ZimbraLog.mailbox.warn("ZimbraFlow errore cFrom: " + e.getMessage()); args.put("cFrom", ""); } try { Address[] toRecipients = mimeMessage.getRecipients(javax.mail.Message.RecipientType.TO); String toString = ""; for (Address to : toRecipients) { toString += ((InternetAddress) to).getAddress() + ","; } if (toString.length() > 0) args.put("cTO", toString.substring(0, toString.length() - 1)); else args.put("cTO", toString); } catch (MessagingException ignored) { } catch (NullPointerException ne) { ZimbraLog.mailbox.warn("ZimbraFlow errore cTo: " + ne.getMessage()); args.put("cTO", ""); } try { Address[] ccRecipients = mimeMessage.getRecipients(javax.mail.Message.RecipientType.CC); String ccString = ""; if (ccRecipients != null) { for (Address cc : ccRecipients) { ccString += ((InternetAddress) cc).getAddress() + ","; } } if (ccString.length() > 0) args.put("cCC", ccString.substring(0, ccString.length() - 1)); else args.put("cCC", ccString); } catch (MessagingException ignored) { } catch (NullPointerException ne) { ZimbraLog.mailbox.warn("ZimbraFlow errore cCC: " + ne.getMessage()); args.put("cCC", ""); } try { Address[] bccRecipients = mimeMessage.getRecipients(javax.mail.Message.RecipientType.BCC); String bccString = ""; if (bccRecipients != null) { for (Address bcc : bccRecipients) { bccString += ((InternetAddress) bcc).getAddress() + ","; } } if (bccString.length() > 0) args.put("cCCN", bccString.substring(0, bccString.length() - 1)); else args.put("cCCN", bccString); } catch (MessagingException ignored) { } catch (NullPointerException ne) { ZimbraLog.mailbox.warn("ZimbraFlow errore cCCN: " + ne.getMessage()); args.put("cCCN", ""); } SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd hh:mm:ss"); long date = item.getDate(); args.put("cDateTime", dateFormat.format(new Date(date))); if (args.get("cDateTime") == null || args.get("cUserEmail") == null || args.get("StreamBase64") == null) { String message = "KONon sono stati trovati tutti i campi obbligatori:"; if (args.get("cDateTime") == null) message += "\nManca il campo cDateTime"; else if (args.get("cUserEmail") == null) message += "\nManca il campo cUserEmail"; else if (args.get("StreamBase64") == null) message += "\nManca il campo StreamBase64"; soapResponse.setValue("reply", message); return; } SOAPClient soapClient = new SOAPClient(url, namespace); try { String res = soapClient.sendRequest(args); soapResponse.setValue("reply", res); } catch (SOAPException e) { ZimbraLog.mailbox.error("ZimbraFlow SOAP call exception: " + e.getMessage()); soapResponse.setValue("reply", "KO" + e.getMessage()); } }
From source file:org.openo.msb.wrapper.util.MicroServiceDB.java
public void updateMicroServiceNode2Redis(String serviceName, String version, String ip, String port, int ttl) throws Exception { String serviceLBkey = MicroServiceUtil.getPrefixedKey("", serviceName, version, MicroServiceUtil.ROUTE_PATH_LOADBALANCE); Jedis jedis = null;//from ww w. java 2 s .c o m try { jedis = JedisUtil.getJedis(); String nodeKey = serviceLBkey + ":" + ip + "-" + port; Map<String, String> nodeLBmap = jedis.hgetAll(nodeKey); if (nodeLBmap.isEmpty()) { throw new NullPointerException(" MicroService Node not fond "); } nodeLBmap.put("ttl", Integer.toString(ttl)); long expiration_time = System.currentTimeMillis() + ttl * 1000; nodeLBmap.put("expiration", Long.toString(expiration_time)); nodeLBmap.put("updated_at", Long.toString(System.currentTimeMillis())); jedis.hmset(nodeKey, nodeLBmap); } catch (NullPointerException e) { throw e; } catch (Exception e) { LOGGER.error("update MicroService Node throw exception", e); throw new Exception("update MicroService Node throw exception:" + e.getMessage()); } finally { JedisUtil.returnJedisInstance(jedis); } }
From source file:com.androguide.apkreator.MainActivity.java
/** * Method to set the color scheme according to the color defined in * config.xml/*w w w . ja v a 2s .com*/ * * @param newColor : the color retrieved from config.xml */ public void changeColor(int newColor) { tabs.setIndicatorColor(newColor); Drawable colorDrawable = new ColorDrawable(newColor); Drawable bottomDrawable = getResources().getDrawable(R.drawable.actionbar_bottom); LayerDrawable ld = new LayerDrawable(new Drawable[] { colorDrawable, bottomDrawable }); if (oldBackground == null) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) ld.setCallback(drawableCallback); else getSupportActionBar().setBackgroundDrawable(ld); } else { TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, ld }); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) td.setCallback(drawableCallback); else getSupportActionBar().setBackgroundDrawable(td); td.startTransition(200); } oldBackground = ld; currentColor = newColor; /** * The following is a work-around to avoid NPE, see the following * thread: * * @see http://stackoverflow.com/questions/11002691/actionbar- * setbackgrounddrawable-nulling-background-from-thread-handler */ try { getSupportActionBar().setDisplayShowTitleEnabled(false); getSupportActionBar().setDisplayShowTitleEnabled(true); } catch (NullPointerException e) { Log.e("NPE", e.getMessage()); } }
From source file:resources.ForecastDB.ForecastDataManager.java
public ForecastTableItem findForecastItem(int columnNumb, String key) { //Making BackUP String backupLoc = makeDBbackUP(dbLocation); String col = colName[columnNumb]; System.out.println("Looking for " + key + " from Column: " + col + " in " + dbLocation); ForecastTableItem row = null;//from w w w . ja v a2s . com try { //Select Row From Main Table of DB //row = (ForecastTableItem) selectItem(mainTable, col, key); row = selectItemPrepareStatement(mainTable, col, key); //Get List of csvTable related to mainTable row List<CsvTable> csvTableList = (List<CsvTable>) (Object) selectItemListPrepareStatement(csvTable, "mainTableId", String.valueOf(row.getId())); row.setCsvTableList(csvTableList); //Get List of csvRow related to csvTables this row own for (CsvTable table : csvTableList) { List<CsvRow> cRList = new ArrayList(); cRList = (List<CsvRow>) (Object) selectItemListPrepareStatement(csvRow, "csvTableId", String.valueOf(table.getId())); table.setCsvRowList(cRList); } if (row != null) { System.out.println("Sucess! : Title is " + row.toString()); return row; } else if (columnNumb == CSVFILEPATH) { System.out.println("Unable to Find CSV File Path " + key); return new ForecastTableItem("", key); } else { System.out.println("Unable to Find Link " + key); return new ForecastTableItem(key, ""); } } catch (NullPointerException ex) { if (columnNumb == CSVFILEPATH) { System.out.println(ex.getMessage()); System.out.println("Unable to Find CSV File Path " + key); } else { System.out.println(ex.getMessage()); System.out.println("Unable to Find Link " + key); } } finally { checkNRestoreDB(dbLocation, backupLoc); if (row != null) { System.out.println("Sucess! : Title is " + row.toString()); return row; } else if (columnNumb == CSVFILEPATH) { return new ForecastTableItem("", key); } else { return new ForecastTableItem(key, ""); } } }
From source file:org.pentaho.di.job.entries.hadooptransjobexecutor.DistributedCacheUtilTest.java
@Test public void extractToTemp_missing_archive() throws Exception { DistributedCacheUtil ch = new DistributedCacheUtil(); try {/*from w ww . j a v a 2 s . c o m*/ ch.extractToTemp(null); fail("Expected exception"); } catch (NullPointerException ex) { assertEquals("archive is required", ex.getMessage()); } }
From source file:edu.hawaii.soest.hioos.storx.StorXParser.java
/** * Parses the binary STOR-X timestamp. The timestamp format is * YYYYDDD from the first 3 bytes, and HHMMSS.SSS from the last four: * Example://www. j a v a 2 s .c o m * 1E AC CC = 2010316 (year 2010, julian day 316) * 09 9D 3E 20 = 16:13:00.000 (4:13 pm) * @param timestamp - the timestamp to parse as a byte array * @return date - the timestamp as a Date object */ public Date parseTimestamp(byte[] timestamp) { Date convertedDate = new Date(0L); // initialize to the epoch try { ByteBuffer timestampBuffer = ByteBuffer.wrap(timestamp); // convert the year and day bytes int yearAndJulianDay = ((timestampBuffer.get() & 0xFF) << 16) | ((timestampBuffer.get() & 0xFF) << 8) | ((timestampBuffer.get() & 0xFF)); String yearAndJulianDayString = new Integer(yearAndJulianDay).toString(); // convert the hour, minute, second, millis bytes int hourMinuteSecondMillis = timestampBuffer.getInt(); String hourMinuteSecondMillisString = String.format("%09d", hourMinuteSecondMillis); // concatenate the strings to get the timestamp String timestampString = yearAndJulianDayString + hourMinuteSecondMillisString; // convert to a Date object FRAME_DATE_FORMAT.setTimeZone(TZ); convertedDate = FRAME_DATE_FORMAT.parse(timestampString, new ParsePosition(0)); } catch (BufferUnderflowException bue) { logger.debug( "There was a problem reading the timestamp. " + "The error message was: " + bue.getMessage()); } catch (NullPointerException npe) { logger.debug("There was a problem converting the timestamp. " + "The error message was: " + npe.getMessage()); } finally { return convertedDate; } }