List of usage examples for java.io IOException getMessage
public String getMessage()
From source file:net.noday.core.dnspod.Dnspod.java
/** * //from ww w . jav a2 s .com * domain_id ??ID * record_id ID * sub_domain - , www * record_type APIA * record_line API * value - , IP:200.200.200.200, CNAME: cname.dnspod.com., MX: mail.dnspod.com. * mx {1-20} - MX, MX 1-20 * ttl {1-604800} - TTL1-604800??????? */ public static String recordModify(DnsRecord obj) { try { Document doc = Jsoup.connect(urlRecordModify).data(data).data("domain_id", obj.getDnspodDomainId()) .data("record_id", obj.getDnspodRecordId()).data("sub_domain", obj.getSubDomain()) .data("record_type", obj.getRecordTypeE().name()).data("record_line", "") .data("value", obj.getValue()).data("mx", "1").data("ttl", obj.getTtl() + "") .userAgent(user_agent).post(); JSONObject o = JSON.parseObject(doc.body().text()); String code = o.getJSONObject("status").getString("code"); if (StringUtils.equals(code, "1")) { return o.getJSONObject("record").getString("id"); } throw new DnspodException(o.getJSONObject("status").getString("message")); } catch (IOException e) { throw new DnspodException(e.getMessage()); } }
From source file:com.amazonaws.apigatewaydemo.RequestRouter.java
/** * The main Lambda function handler. Receives the request as an input stream, parses the json and looks for the * "action" property to decide where to route the request. The "body" property of the incoming request is passed * to the DemoAction implementation as a request body. * * @param request The InputStream for the incoming event. This should contain an "action" and "body" properties. The * action property should contain the namespaced name of the class that should handle the invocation. * The class should implement the DemoAction interface. The body property should contain the full * request body for the action class. * @param response An OutputStream where the response returned by the action class is written * @param context The Lambda Context object * @throws BadRequestException This Exception is thrown whenever parameters are missing from the request or the action * class can't be found * @throws InternalErrorException This Exception is thrown when an internal error occurs, for example when the database * is not accessible *//*from ww w . j a v a2s. co m*/ public static void lambdaHandler(InputStream request, OutputStream response, Context context) throws BadRequestException, InternalErrorException { LambdaLogger logger = context.getLogger(); JsonParser parser = new JsonParser(); JsonObject inputObj; try { inputObj = parser.parse(IOUtils.toString(request)).getAsJsonObject(); } catch (IOException e) { logger.log("Error while reading request\n" + e.getMessage()); throw new InternalErrorException(e.getMessage()); } if (inputObj == null || inputObj.get("action") == null || inputObj.get("action").getAsString().trim().equals("")) { logger.log("Invald inputObj, could not find action parameter"); throw new BadRequestException("Could not find action value in request"); } String actionClass = inputObj.get("action").getAsString(); DemoAction action; try { action = DemoAction.class.cast(Class.forName(actionClass).newInstance()); } catch (final InstantiationException e) { logger.log("Error while instantiating action class\n" + e.getMessage()); throw new InternalErrorException(e.getMessage()); } catch (final IllegalAccessException e) { logger.log("Illegal access while instantiating action class\n" + e.getMessage()); throw new InternalErrorException(e.getMessage()); } catch (final ClassNotFoundException e) { logger.log("Action class could not be found\n" + e.getMessage()); throw new InternalErrorException(e.getMessage()); } if (action == null) { logger.log("Action class is null"); throw new BadRequestException("Invalid action class"); } JsonObject body = null; if (inputObj.get("body") != null) { body = inputObj.get("body").getAsJsonObject(); } String output = action.handle(body, context); try { IOUtils.write(output, response); } catch (final IOException e) { logger.log("Error while writing response\n" + e.getMessage()); throw new InternalErrorException(e.getMessage()); } }
From source file:com.dattack.naming.standalone.StandaloneContextFactory.java
private static Context createInitialContext(final File dir, final Map<?, ?> environment, final CompositeConfiguration configuration) throws NamingException { LOGGER.debug("Scanning directory '{}' for JNDI resources.", dir); try {//from w ww. j av a 2s . c o m final StandaloneContext ctx = new StandaloneContext(environment); final NamingLoader loader = new NamingLoader(); final Collection<File> extraClasspath = FilesystemUtils .locateFiles(configuration.getList(CLASSPATH_DIRECTORY_PROPERTY)); loader.loadDirectory(dir, ctx, extraClasspath); LOGGER.debug("JNDI context is ready"); return ctx; } catch (final IOException e) { throw (NamingException) new NamingException(e.getMessage()).initCause(e); } }
From source file:org.dataconservancy.ui.it.support.BaseIT.java
/** * Util method creating a small file for deposit. For the purposes of this test, the content of the file * does not matter. This file can be re-used for all of the tests. * * @return the file to deposit//from w ww . j a v a2s.c o m */ protected static File createSampleDataFile(String namePrefix, String fileNameExtenstion) { File sampleDataFile = null; if (namePrefix == null) { namePrefix = ""; } if (fileNameExtenstion == null) { fileNameExtenstion = ""; } try { sampleDataFile = java.io.File.createTempFile(namePrefix, fileNameExtenstion); FileOutputStream tmpFileOut = new FileOutputStream(sampleDataFile); Random random = new Random(); final int lineCount = 10; for (int i = 0; i < lineCount; i++) { IOUtils.write("This is a line of content.", tmpFileOut); } tmpFileOut.close(); return sampleDataFile; } catch (IOException e) { throw new RuntimeException("Error creating test Data File: " + e.getMessage(), e); } }
From source file:cf.funge.aworldofplants.RequestRouter.java
/** * The main Lambda function handler. Receives the request as an input stream, parses the json and looks for the * "action" property to decide where to route the request. The "body" property of the incoming request is passed * to the Action implementation as a request body. * * @param request The InputStream for the incoming event. This should contain an "action" and "body" properties. The * action property should contain the namespaced name of the class that should handle the invocation. * The class should implement the Action interface. The body property should contain the full * request body for the action class. * @param response An OutputStream where the response returned by the action class is written * @param context The Lambda Context object * @throws BadRequestException This Exception is thrown whenever parameters are missing from the request or the action * class can't be found * @throws InternalErrorException This Exception is thrown when an internal error occurs, for example when the database * is not accessible *//*from www . j av a 2 s. c om*/ public static void lambdaHandler(InputStream request, OutputStream response, Context context) throws BadRequestException, InternalErrorException { LambdaLogger logger = context.getLogger(); JsonParser parser = new JsonParser(); JsonObject inputObj; try { inputObj = parser.parse(IOUtils.toString(request)).getAsJsonObject(); } catch (IOException e) { logger.log("Error while reading request\n" + e.getMessage()); throw new InternalErrorException(e.getMessage()); } if (inputObj == null || inputObj.get("action") == null || inputObj.get("action").getAsString().trim().equals("")) { logger.log("Invald inputObj, could not find action parameter"); throw new BadRequestException("Could not find action value in request"); } String actionClass = inputObj.get("action").getAsString(); Action action; try { action = Action.class.cast(Class.forName(actionClass).newInstance()); } catch (final InstantiationException e) { logger.log("Error while instantiating action class\n" + e.getMessage()); throw new InternalErrorException(e.getMessage()); } catch (final IllegalAccessException e) { logger.log("Illegal access while instantiating action class\n" + e.getMessage()); throw new InternalErrorException(e.getMessage()); } catch (final ClassNotFoundException e) { logger.log("Action class could not be found\n" + e.getMessage()); throw new InternalErrorException(e.getMessage()); } if (action == null) { logger.log("Action class is null"); throw new BadRequestException("Invalid action class"); } JsonObject body = null; if (inputObj.get("body") != null) { body = inputObj.get("body").getAsJsonObject(); } String output = action.handle(body, context); try { IOUtils.write(output, response); } catch (final IOException e) { logger.log("Error while writing response\n" + e.getMessage()); throw new InternalErrorException(e.getMessage()); } }
From source file:Main.java
public static FileVisitor<Path> getFileVisitor() { class DeleteDirVisitor extends SimpleFileVisitor<Path> { @Override/*from w ww.j a v a 2 s.c om*/ public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException { FileVisitResult result = FileVisitResult.CONTINUE; if (e != null) { System.out.format("Error deleting %s. %s%n", dir, e.getMessage()); result = FileVisitResult.TERMINATE; } else { Files.delete(dir); System.out.format("Deleted directory %s%n", dir); } return result; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); System.out.format("Deleted file %s%n", file); return FileVisitResult.CONTINUE; } } FileVisitor<Path> visitor = new DeleteDirVisitor(); return visitor; }
From source file:com.microsoft.azuretools.hdinsight.util.HDInsightJobViewUtils.java
private static void extractJobViewResource() { URL url = HDInsightJobViewUtils.class.getResource("/resources/" + HTML_ZIP_FILE_NAME); URL hdinsightJobViewJarUrl = HDInsightJobViewUtils.class .getResource("/resources/" + HDINSIGHT_JOB_VIEW_JAR_NAME); if (url == null || hdinsightJobViewJarUrl == null) { DefaultLoader.getUIHelper().showError("Cann't find Spark job view resources", "Job view"); return;//from ww w . j av a 2 s . c o m } File indexRootFile = new File(PluginUtil.pluginFolder, HDINSIGIHT_FOLDER_NAME); if (indexRootFile.exists()) { FileUtils.deleteQuietly(indexRootFile); } File htmlRootFile = new File(indexRootFile.getPath(), "html"); htmlRootFile.mkdirs(); File htmlToFile = new File(htmlRootFile.getAbsolutePath(), HTML_ZIP_FILE_NAME); File hdinsightJobViewToFile = new File(indexRootFile, HDINSIGHT_JOB_VIEW_JAR_NAME); try { FileUtils.copyURLToFile(url, htmlToFile); FileUtils.copyURLToFile(hdinsightJobViewJarUrl, hdinsightJobViewToFile); HDInsightJobViewUtils.unzip(htmlToFile.getAbsolutePath(), htmlToFile.getParent()); DefaultLoader.getIdeHelper().setProperty(HDINSIGHT_JOBVIEW_EXTRACT_FLAG, "true"); } catch (IOException e) { DefaultLoader.getUIHelper().showError("Extract Job View Folder error:" + e.getMessage(), "Job view"); } }
From source file:com.streamsets.pipeline.stage.processor.statsaggregation.ConfigHelper.java
public static RuleDefinitionsJson readRulesDefinition(String ruleDefinitionsJson, Stage.Context context, List<Stage.ConfigIssue> issues) { RuleDefinitionsJson ruleDefJson = null; if (ruleDefJson != null) { try {/*from w w w . j av a2s . com*/ ruleDefJson = ObjectMapperFactory.get() .readValue(new String(Base64.decodeBase64(ruleDefinitionsJson)), RuleDefinitionsJson.class); } catch (IOException ex) { issues.add(context.createConfigIssue(Groups.STATS.getLabel(), "ruleDefinitionsJson", Errors.STATS_01, ex.getMessage(), ex)); } } return ruleDefJson; }
From source file:GitHubApiTest.java
/** * It's not possible to store username/password in the test file, * this cretentials are stored in a properties file * under user home directory./*from w w w .jav a 2 s. c om*/ * * This method would be used to fetch parameters for the test * and allow to avoid committing createntials with source file. * @return username, repo, password */ @NotNull public static Properties readGitHubAccount() { File propsFile = new File(System.getenv("USERPROFILE"), ".github.test.account"); System.out.println("Loading properites from: " + propsFile); try { if (!propsFile.exists()) { FileUtil.createParentDirs(propsFile); Properties ps = new Properties(); ps.setProperty(URL, "https://api.github.com"); ps.setProperty(USERNAME, "jonnyzzz"); ps.setProperty(REPOSITORY, "TeamCity.GitHub"); ps.setProperty(PASSWORD_REV, rewind("some-password-written-end-to-front")); PropertiesUtil.storeProperties(ps, propsFile, "mock properties"); return ps; } else { return PropertiesUtil.loadProperties(propsFile); } } catch (IOException e) { throw new RuntimeException("Could not read Amazon Access properties: " + e.getMessage(), e); } }
From source file:se.ginkou.interfaceio.InterfaceServer.java
public static void startServer() throws Exception { // HTTP parameters for the server HttpParams params = new SyncBasicHttpParams(); params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true) .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1"); // Create HTTP protocol processing chain HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpResponseInterceptor[] { // Use standard server-side protocol interceptors new ResponseDate(), new ResponseServer(), new ResponseContent(), new ResponseConnControl() }); // Set up request handlers HttpAsyncRequestHandlerRegistry reqistry = new HttpAsyncRequestHandlerRegistry(); reqistry.register("*/datatables", new DataTablesHandler()); reqistry.register("*/loginmodules", new RuleFileHandler()); reqistry.register("*/login", new LoginHandler()); reqistry.register("*", new HttpFileHandler(new File("website"))); reqistry.register("*/ping", new TestHandler()); // Create server-side HTTP protocol handler HttpAsyncService protocolHandler = new HttpAsyncService(httpproc, new DefaultConnectionReuseStrategy(), reqistry, params) {/*ww w . j a v a2 s . c o m*/ @Override public void connected(final NHttpServerConnection conn) { System.out.println(conn + ": connection open"); super.connected(conn); } @Override public void closed(final NHttpServerConnection conn) { System.out.println(conn + ": connection closed"); super.closed(conn); } }; // Create HTTP connection factory NHttpConnectionFactory<DefaultNHttpServerConnection> connFactory; // // Initialize SSL context // ClassLoader cl = NHttpServer.class.getClassLoader(); // URL url = cl.getResource("my.keystore"); // if (url == null) { // System.out.println("Keystore not found"); // System.exit(1); // } // KeyStore keystore = KeyStore.getInstance("jks"); // keystore.load(url.openStream(), "secret".toCharArray()); // KeyManagerFactory kmfactory = KeyManagerFactory.getInstance( // KeyManagerFactory.getDefaultAlgorithm()); // kmfactory.init(keystore, "secret".toCharArray()); // KeyManager[] keymanagers = kmfactory.getKeyManagers(); // SSLContext sslcontext = SSLContext.getInstance("TLS"); // sslcontext.init(keymanagers, null, null); // connFactory = new SSLNHttpServerConnectionFactory(sslcontext, null, params); connFactory = new DefaultNHttpServerConnectionFactory(params); // Create server-side I/O event dispatch IOEventDispatch ioEventDispatch = new DefaultHttpServerIODispatch(protocolHandler, connFactory); // Create server-side I/O reactor ListeningIOReactor ioReactor = new DefaultListeningIOReactor(); try { // Listen of the given port ioReactor.listen(new InetSocketAddress(PORT)); // Ready to go! ioReactor.execute(ioEventDispatch); } catch (InterruptedIOException ex) { System.err.println("Interrupted"); } catch (IOException e) { System.err.println("I/O error: " + e.getMessage()); } System.out.println("Shutdown"); }