// Extract transcoder to data directory public TranscodeService() { InputStream inputStream = null; OutputStream outputStream; // Get transcoder if (SystemUtils.IS_OS_WINDOWS) { inputStream = getClass().getResourceAsStream("ffmpeg.exe"); } else if (SystemUtils.IS_OS_LINUX) { inputStream = getClass().getResourceAsStream("ffmpeg"); } // Check we found the transcoder if (inputStream == null) { LogService.getInstance().addLogEntry(Level.ERROR, CLASS_NAME, "Transcoder not found!", null); return; } // Copy transcoder to filesystem try { LogService.getInstance().addLogEntry(Level.INFO, CLASS_NAME, "Preparing transcoder.", null); File file = new File(TRANSCODER_FILE); int readBytes; byte[] buffer = new byte[4096]; outputStream = new FileOutputStream(file); while ((readBytes = inputStream.read(buffer)) > 0) { outputStream.write(buffer, 0, readBytes); } // Close streams inputStream.close(); outputStream.close(); // Check file copied successfully if (!file.exists()) { LogService.getInstance() .addLogEntry(Level.ERROR, CLASS_NAME, "Failed to extract transcoder!", null); return; } // Make sure file is executable file.setExecutable(true); } catch (IOException ex) { LogService.getInstance() .addLogEntry(Level.ERROR, CLASS_NAME, "Failed to extract transcoder!", ex); } }
@Override public TrackingStruct addingService(ServiceReference<ResourceAnalyzer> reference) { TrackingStruct struct = new TrackingStruct(); try { String filterStr = (String) reference.getProperty(ResourceAnalyzer.FILTER); Filter filter = (filterStr != null) ? FrameworkUtil.createFilter(filterStr) : null; ResourceAnalyzer analyzer = context.getService(reference); if (analyzer == null) return null; struct = new TrackingStruct(); struct.analyzer = analyzer; struct.filter = filter; struct.valid = true; indexer.addAnalyzer(analyzer, filter); } catch (InvalidSyntaxException e) { struct.valid = false; log.log( reference, LogService.LOG_ERROR, "Ignoring ResourceAnalyzer due to invalid filter expression", e); } return struct; }
@RequestMapping(value = "/delete/{pid}", method = RequestMethod.GET) public String deletePayment(ModelMap modelMap, @PathVariable int pid) { Payment payment = paymentService.getPaymentById(pid); logService.addLog( new Log( sessionBean.getUserName(), "delete", "payment delete", "удален платеж на сумму: " + payment.getCredit() + "/ " + payment.getDebt() + " для клиента " + payment.getClientP().getName() + " " + payment.getClientP().getContractInfo() + " " + payment.getReason())); if (payment.getInvoiceP() != null || payment.getWaybill() != null) { modelMap.addAttribute("message", "unable to remove this type of payment!"); return "/auth/message"; } String message = "payment with id " + payment.getId() + " has been deleted"; paymentService.deletePayment(payment); System.out.println("deleting!!"); modelMap.addAttribute("message", message); return "/auth/message"; }
public String getLabel(String name) { try { return resources.getString(name); } catch (Exception exp) { LogService.getInstance().setMessage(exp, name); return name; } }
/** * Creates a {@link String} of the last {@value #MAX_LOGFILE_LINES} lines of the rm.log file. * * @return */ private static String getRelevantLogContent() { StringBuffer buffer = new StringBuffer(); buffer.append("Log contents:" + Tools.getLineSeparator()); buffer.append("------------" + Tools.getLineSeparator() + Tools.getLineSeparator()); BufferedReader reader = null; try { List<String> logLineList = new LinkedList<>(); reader = new BufferedReader(new FileReader(FileSystemService.getLogFile())); String line = reader.readLine(); while (line != null) { logLineList.add(line); line = reader.readLine(); // truncate list to only contain MAX_LOGFILE_LINES if (logLineList.size() > MAX_LOGFILE_LINES) { logLineList.remove(0); } } for (String lineString : logLineList) { buffer.append(lineString); buffer.append(Tools.getLineSeparator()); } } catch (IOException e) { LogService.getRoot() .log(Level.WARNING, "com.rapidminer.logservice.logfile.failed_to_read", e.getMessage()); buffer.append("Failed to read log file:"); buffer.append(e.getMessage()); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { LogService.getRoot() .log( Level.WARNING, "com.rapidminer.logservice.logfile.failed_to_close", e.getMessage()); } } } return buffer.toString(); }
/* * Returns a file reference to the transcoder. */ public File getTranscoder() { File transcoder = new File(TRANSCODER_FILE); // Check if the transcoder binary exists if (!transcoder.exists()) { LogService.getInstance().addLogEntry(Level.ERROR, CLASS_NAME, "Transcoder not found!", null); return null; } return transcoder; }
// init I18N static { ParameterService.init(); String localeLanguage = ParameterService.getParameterValue(RapidMiner.PROPERTY_RAPIDMINER_GENERAL_LOCALE_LANGUAGE); Locale locale = Locale.getDefault(); if (localeLanguage != null) { locale = new Locale(localeLanguage); Locale.setDefault(locale); LogService.getRoot().log(Level.INFO, "com.rapidminer.tools.I18N.set_locale_to", locale); } else { LogService.getRoot() .log(Level.INFO, "com.rapidminer.tools.I18N.using_default_locale", locale); } JComponent.setDefaultLocale(locale); USER_ERROR_BUNDLE = new ExtensibleResourceBundle( ResourceBundle.getBundle( "com.rapidminer.resources.i18n.UserErrorMessages", locale, I18N.class.getClassLoader())); ERROR_BUNDLE = new ExtensibleResourceBundle( ResourceBundle.getBundle( "com.rapidminer.resources.i18n.Errors", locale, I18N.class.getClassLoader())); GUI_BUNDLE = new ExtensibleResourceBundle( ResourceBundle.getBundle( "com.rapidminer.resources.i18n.GUI", locale, I18N.class.getClassLoader())); SETTINGS_BUNDLE = new ExtensibleResourceBundle( ResourceBundle.getBundle( "com.rapidminer.resources.i18n.Settings", locale, I18N.class.getClassLoader())); ResourceBundle plotterBundle = ResourceBundle.getBundle( "com.rapidminer.resources.i18n.PlotterMessages", locale, I18N.class.getClassLoader()); GUI_BUNDLE.addResourceBundle(plotterBundle); }
protected void loadResources(Class<?> clazz, Properties properties, String name) { ClassLoader loader = clazz.getClassLoader(); String locale = null; try { locale = properties.get("locale").toString(); if (locale == null || locale.trim().length() == 0) locale = "vn"; } catch (Exception exp) { LogService.getInstance().setThrowable(null, exp); locale = "vn"; } resources = ResourceBundle.getBundle("resources.i18n." + locale + "." + name, Locale.ENGLISH, loader); }
/** * Returns a message if found or the key if not found. Arguments <b>can</b> be specified which * will be used to format the String. In the {@link ResourceBundle} the String '{0}' (without ') * will be replaced by the first argument, '{1}' with the second and so on. * * <p>Catches the exception thrown by ResourceBundle in the latter case. */ public static String getMessage(ResourceBundle bundle, String key, Object... arguments) { try { if (arguments == null || arguments.length == 0) { return bundle.getString(key); } else { String message = bundle.getString(key); if (message != null) { return MessageFormat.format(message, arguments); } else { return key; } } } catch (MissingResourceException e) { LogService.getRoot().log(Level.FINE, "com.rapidminer.tools.I18N.missing_key", key); return key; } }
/** * The <code>DatabaseSessionImpl </code> is used to allow closing of a database session by the * client. This way it is possible too keep database sessions open for lazy loading support. * * @author Mostafa SkipTechnology * @version $Revision: 1.1 $, $Date: 2005/10/13 21:17:51 $ */ public class HibernateDatabaseSession implements DatabaseSessionService, LocatableService { /** The logger object. */ private static Logger log = LogService.getLogger(HibernateDatabaseSession.class); /** Default implementation for the Locatable Service interface. */ public void init() {} /** Default implementation for the Locatable Service interface. */ public void destroy() {} /** Close a database session if it is still open. */ public void close() throws GenericBusinessException { try { com.skip.HibernateSessionHelper.close(); } catch (Exception e) { log.error("Error whil closing the database connection"); throw new GenericBusinessException(e); } } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Switch mainSwitch = new Switch(this); mainSwitch.setChecked(LogService.isRunning()); mainSwitch.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { Intent intent = new Intent(MainActivity.this, LogService.class); if (b) { if (!LogService.isRunning()) { startService(intent); } } else { stopService(intent); } } }); final ActionBar bar = getActionBar(); final ActionBar.LayoutParams lp = new ActionBar.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); lp.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL; lp.rightMargin = getResources().getDimensionPixelSize(R.dimen.main_switch_margin_right); bar.setCustomView(mainSwitch, lp); bar.setDisplayShowCustomEnabled(true); mPrefs = PreferenceManager.getDefaultSharedPreferences(this); if (!mPrefs.getBoolean(PreferenceManager.KEY_HAS_SET_DEFAULT_VALUES, false)) { PreferenceManager.setDefaultValues(this, R.xml.pref_filters, true); PreferenceManager.setDefaultValues(this, R.xml.pref_appearance, true); SharedPreferences.Editor edit = mPrefs.edit(); edit.putBoolean(PreferenceManager.KEY_HAS_SET_DEFAULT_VALUES, true); edit.apply(); } }
public Result verifyCar(AdapterRequest request) { CarInfo carInfo = carService.getCarInfoById(request.getCarId()); VerifyCarRequest req = new VerifyCarRequest.Builder() .vin(carInfo.getVinString()) .ecv(carInfo.getEcvString()) .ico(icoString) .irisUser(irisUser) .irisPwd(irisPwd) .build(); Document verifyCarResult = null; Result result = Result.getInstance(request); result.setXmlInput(req.getXmlString()); try { StringWriter respWriter = new StringWriter(); ispelService.sendSourceAndReceiveToResult( new StreamSource(new StringReader(req.getXmlString())), new StreamResult(respWriter)); result.setXmlOutput(respWriter.toString()); verifyCarResult = responseResolver.getVerifyCarResult(respWriter.toString()); result.setXmlOutput(xmlOutputter.get().outputString(verifyCarResult)); carService.processVerifyCar(carInfo, verifyCarResult); } catch (Exception e) { logger.error(e); result.setProcessed(Result.UNPROCESSED); result.setErrorText(e.getMessage()); } try { logService.logResult(result); } catch (Exception e) { logger.error("Log result error."); logger.error(e); } return result; }
@Override public void modifiedService(ServiceReference<ResourceAnalyzer> reference, TrackingStruct struct) { if (struct.valid) { indexer.removeAnalyzer(struct.analyzer, struct.filter); } try { String filterStr = (String) reference.getProperty(ResourceAnalyzer.FILTER); Filter filter = (filterStr != null) ? FrameworkUtil.createFilter(filterStr) : null; struct = new TrackingStruct(); struct.filter = filter; struct.valid = true; indexer.addAnalyzer(struct.analyzer, filter); } catch (InvalidSyntaxException e) { struct.valid = false; log.log( reference, LogService.LOG_ERROR, "Ignoring ResourceAnalyzer due to invalid filter expression", e); } }
/** * Creates the BugZilla bugreport. * * @param client the logged in BugZilla client * @param exception the exception which was thrown by the bug * @param userSummary summary of the bug * @param completeDescription description of the bug * @param component the component which malfunctionied * @param version the RM version * @param severity the severity of the bug * @param platform the platform (e.g. PC or Mac) * @param os the OS * @param attachments a list of optional attachements * @param attachProcess if <code>true</code>, will attach the current process xml * @param attachSystemProps if <code>true</code>, will attach system properties * @throws Exception */ public static void createBugZillaReport( XmlRpcClient client, Throwable exception, String userSummary, String completeDescription, String component, String version, String severity, String platform, String os, File[] attachments, boolean attachProcess, boolean attachSystemProps, boolean attachLogFile) throws Exception { // create temp files with all the data we need // create process xml file for later attachement if user agreed to it File processFile = File.createTempFile("_process", ".xml"); processFile.deleteOnExit(); String xmlProcess; if (RapidMinerGUI.getMainFrame().getProcess().getProcessLocation() != null) { try { xmlProcess = RapidMinerGUI.getMainFrame().getProcess().getProcessLocation().getRawXML(); } catch (Throwable t) { xmlProcess = "could not read: " + t; } } else { xmlProcess = "no process available"; } writeFile(processFile, xmlProcess); // create system properties tempfile for later attachement if user agreed to it File propertiesFile = File.createTempFile("_properties", ".txt"); propertiesFile.deleteOnExit(); writeFile(propertiesFile, getProperties()); // create log tempfile (last MAX_LOGFILE_LINES rows) for later attachement File logTempFile = File.createTempFile("_log", ".txt"); logTempFile.delete(); writeFile(logTempFile, getRelevantLogContent()); // append the RM version to the description StringBuffer buffer = new StringBuffer(completeDescription); buffer.append(Tools.getLineSeparator()); buffer.append(Tools.getLineSeparator()); buffer.append(getStackTrace(exception)); buffer.append(Tools.getLineSeparator()); buffer.append(Tools.getLineSeparator()); buffer.append("RapidMiner: "); buffer.append(RapidMiner.getVersion()); buffer.append(Tools.getLineSeparator()); for (Plugin plugin : Plugin.getAllPlugins()) { buffer.append(plugin.getName()); buffer.append(": "); buffer.append(plugin.getVersion()); buffer.append(Tools.getLineSeparator()); } completeDescription = buffer.toString(); // call BugZilla via xml-rpc XmlRpcClient rpcClient = client; Map<String, String> bugMap = new HashMap<>(); bugMap.put("product", "RapidMiner"); bugMap.put("component", component); bugMap.put("summary", userSummary); bugMap.put("description", completeDescription); bugMap.put("version", version); bugMap.put("op_sys", os); bugMap.put("platform", platform); bugMap.put("severity", severity); bugMap.put("status", "NEW"); Map createResult = (Map) rpcClient.execute("Bug.create", new Object[] {bugMap}); // LogService.getRoot().fine("Bug submitted successfully. Bug ID: " + // createResult.get("id")); LogService.getRoot() .log(Level.FINE, "com.rapidminer.tools.BugReport.bug_submitted", createResult.get("id")); String id = String.valueOf(createResult.get("id")); Map<String, Object> attachmentMap = new HashMap<>(); FileInputStream fileInputStream = null; // add process xml file attachment if selected if (attachProcess) { attachmentMap.put("ids", new String[] {id}); // BugZilla API states Base64 encoded string is needed, but it does not work // attachmentMap.put("data", Base64.encodeFromFile(processFile.getPath())); try { fileInputStream = new FileInputStream(processFile); byte[] data = new byte[(int) processFile.length()]; fileInputStream.read(data); attachmentMap.put("data", data); attachmentMap.put("file_name", "process.xml"); attachmentMap.put("summary", "process.xml"); attachmentMap.put("content_type", "application/xml"); createResult = (Map) rpcClient.execute("Bug.add_attachment", new Object[] {attachmentMap}); attachmentMap.clear(); } finally { if (fileInputStream != null) { fileInputStream.close(); } } } // add system properties file attachment if selected if (attachSystemProps) { attachmentMap.put("ids", new String[] {id}); // BugZilla API states Base64 encoded string is needed, but it does not work // attachmentMap.put("data", Base64.encodeFromFile(propertiesFile.getPath())); try { fileInputStream = new FileInputStream(propertiesFile); byte[] data = new byte[(int) propertiesFile.length()]; fileInputStream.read(data); attachmentMap.put("data", data); attachmentMap.put("file_name", "system-properties.txt"); attachmentMap.put("summary", "system-properties.txt"); attachmentMap.put("content_type", "text/plain"); createResult = (Map) rpcClient.execute("Bug.add_attachment", new Object[] {attachmentMap}); attachmentMap.clear(); } finally { if (fileInputStream != null) { fileInputStream.close(); } } } // add rm.log file attachment if (attachLogFile) { attachmentMap.put("ids", new String[] {id}); // BugZilla API states Base64 encoded string is needed, but it does not work // attachmentMap.put("data", Base64.encodeFromFile(propertiesFile.getPath())); try { fileInputStream = new FileInputStream(logTempFile); byte[] data = new byte[(int) logTempFile.length()]; fileInputStream.read(data); attachmentMap.put("data", data); attachmentMap.put("file_name", "rm.log"); attachmentMap.put("summary", "rm.log"); attachmentMap.put("content_type", "text/plain"); createResult = (Map) rpcClient.execute("Bug.add_attachment", new Object[] {attachmentMap}); attachmentMap.clear(); } finally { if (fileInputStream != null) { fileInputStream.close(); } } } // add attachments by user for (File file : attachments) { attachmentMap.put("ids", new String[] {id}); // BugZilla API states Base64 encoded string is needed, but it does not work // attachmentMap.put("data", Base64.encodeFromFile(file.getPath())); try { fileInputStream = new FileInputStream(file); byte[] data = new byte[(int) file.length()]; fileInputStream.read(data); attachmentMap.put("data", data); attachmentMap.put("file_name", file.getName()); attachmentMap.put("summary", file.getName()); attachmentMap.put("content_type", "application/data"); createResult = (Map) rpcClient.execute("Bug.add_attachment", new Object[] {attachmentMap}); attachmentMap.clear(); } finally { if (fileInputStream != null) { fileInputStream.close(); } } } }
public static void sendEmailWithException( String address, String subject, String content, Map<String, String> headers) throws MailNotSentException { try { String method = ParameterService.getParameterValue(RapidMiner.PROPERTY_RAPIDMINER_TOOLS_MAIL_METHOD); int methodIndex = -1; if (method != null) { try { methodIndex = Integer.parseInt(method); } catch (NumberFormatException e) { methodIndex = -1; for (int i = 0; i < RapidMiner.PROPERTY_RAPIDMINER_TOOLS_MAIL_METHOD_VALUES.length; i++) { if (RapidMiner.PROPERTY_RAPIDMINER_TOOLS_MAIL_METHOD_VALUES[i].equals(method)) { methodIndex = i; break; } } } } if (methodIndex == -1) { methodIndex = RapidMiner.PROPERTY_RAPIDMINER_TOOLS_MAIL_METHOD_SMTP; } MailSender mailSender = null; switch (methodIndex) { case RapidMiner.PROPERTY_RAPIDMINER_TOOLS_MAIL_METHOD_SMTP: mailSender = new MailSenderSMTP(); break; case RapidMiner.PROPERTY_RAPIDMINER_TOOLS_MAIL_METHOD_SENDMAIL: mailSender = new MailSenderSendmail(); break; default: // LogService.getGlobal().log("Illegal send mail method: " + method + ".", // LogService.ERROR); LogService.getRoot() .log( Level.SEVERE, "com.rapidminer.tools.MailUtilities.illegal_send_mail_method", method); throw new MailNotSentException( "Illegal send mail method", "illegal_send_mail_method", method); } if (mailSender != null) { mailSender.sendEmail(address, subject, content, headers); // LogService.getRoot().info("Sent mail to "+address+" with subject "+subject); LogService.getRoot() .log( Level.INFO, "com.rapidminer.tools.MailUtilities.sent_mail_to_adress_with_subject", new Object[] {address, subject}); } } catch (Exception e) { // LogService.getGlobal().log("Cannot send mail to " + address + ": " + e, // LogService.ERROR); LogService.getRoot() .log( Level.SEVERE, "com.rapidminer.tools.MailUtilities.sending_mail_to_address_error", new Object[] {address, e}); throw new MailNotSentException( "Cannot send mail", "sending_mail_to_address_error", e, new Object[] {address, e}); } }