List of usage examples for java.net URL URL
public URL(String spec) throws MalformedURLException
From source file:gcm.play.android.samples.com.gcmquickstart.GcmSender.java
public static void main(String[] args) throws JSONException { if (args.length < 1 || args.length > 2 || args[0] == null) { System.err.println("usage: ./gradlew run -Pargs=\"MESSAGE[,DEVICE_TOKEN]\""); System.err.println(""); System.err.println(//from w ww. j a v a 2s . c o m "Specify a test message to broadcast via GCM. If a device's GCM registration token is\n" + "specified, the message will only be sent to that device. Otherwise, the message \n" + "will be sent to all devices subscribed to the \"global\" topic."); System.err.println(""); System.err.println( "Example (Broadcast):\n" + "On Windows: .\\gradlew.bat run -Pargs=\"<Your_Message>\"\n" + "On Linux/Mac: ./gradlew run -Pargs=\"<Your_Message>\""); System.err.println(""); System.err.println("Example (Unicast):\n" + "On Windows: .\\gradlew.bat run -Pargs=\"<Your_Message>,<Your_Token>\"\n" + "On Linux/Mac: ./gradlew run -Pargs=\"<Your_Message>,<Your_Token>\""); System.exit(1); } try { // Prepare JSON containing the GCM message content. What to send and where to send. JSONObject jGcmData = new JSONObject(); JSONObject jData = new JSONObject(); jData.put("message", args[0].trim()); // Where to send GCM message. if (args.length > 1 && args[1] != null) { jGcmData.put("to", args[1].trim()); } else { jGcmData.put("to", "/topics/global"); } // What to send in GCM message. jGcmData.put("data", jData); // Create connection to send GCM Message request. URL url = new URL("https://android.googleapis.com/gcm/send"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestProperty("Authorization", "key=" + API_KEY); conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestMethod("POST"); conn.setDoOutput(true); // Send GCM message content. OutputStream outputStream = conn.getOutputStream(); outputStream.write(jGcmData.toString().getBytes()); // Read GCM response. InputStream inputStream = conn.getInputStream(); String resp = IOUtils.toString(inputStream); System.out.println(resp); System.out.println("Check your device/emulator for notification or logcat for " + "confirmation of the receipt of the GCM message."); } catch (IOException e) { System.out.println("Unable to send GCM message."); System.out.println("Please ensure that API_KEY has been replaced by the server " + "API key, and that the device's registration token is correct (if specified)."); e.printStackTrace(); } }
From source file:com.adobe.aem.demo.Analytics.java
public static void main(String[] args) { String hostname = null;/*from w ww . j a va 2 s.c om*/ String url = null; String eventfile = null; // Command line options for this tool Options options = new Options(); options.addOption("h", true, "Hostname"); options.addOption("u", true, "Url"); options.addOption("f", true, "Event data file"); CommandLineParser parser = new BasicParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("u")) { url = cmd.getOptionValue("u"); } if (cmd.hasOption("f")) { eventfile = cmd.getOptionValue("f"); } if (cmd.hasOption("h")) { hostname = cmd.getOptionValue("h"); } if (eventfile == null || hostname == null || url == null) { System.out.println("Command line parameters: -h hostname -u url -f path_to_XML_file"); System.exit(-1); } } catch (ParseException ex) { logger.error(ex.getMessage()); } URLConnection urlConn = null; DataOutputStream printout = null; BufferedReader input = null; String u = "http://" + hostname + "/" + url; String tmp = null; try { URL myurl = new URL(u); urlConn = myurl.openConnection(); urlConn.setDoInput(true); urlConn.setDoOutput(true); urlConn.setUseCaches(false); urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); printout = new DataOutputStream(urlConn.getOutputStream()); String xml = readFile(eventfile, StandardCharsets.UTF_8); printout.writeBytes(xml); printout.flush(); printout.close(); input = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); logger.debug(xml); while (null != ((tmp = input.readLine()))) { logger.debug(tmp); } printout.close(); input.close(); } catch (Exception ex) { logger.error(ex.getMessage()); } }
From source file:com.krawler.runtime.utils.URLClassLoaderUtil.java
public static void main(String[] args) { try {//from w w w .ja v a 2 s . c om URLClassLoaderUtil urlcu = new URLClassLoaderUtil( new URL[] { new URL("file:///home/krawler/KrawlerJsonLib.jar") }); urlcu.addFile("/home/krawler/KrawlerJsonLib.jar"); Class c = Class.forName("com.krawler.utils.json.base.JSONObject"); System.out.print(c.getCanonicalName()); } catch (Exception ex) { Logger.getLogger(URLClassLoaderUtil.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.yufei.dataget.dataretriver.HttpDataRetriverUsingFirefoxDriverWithTimeOut.java
public static void main(String[] args) throws MalformedURLException { DataRetrieverFeatures dataRetrieverFeatures = new DataRetrieverFeatures(Boolean.TRUE, null, 10L * 1000, 3 * 1000);/* www . j a va 2 s .co m*/ HttpDataRetriverUsingFirefoxDriverWithTimeOut hdrufdwto = new HttpDataRetriverUsingFirefoxDriverWithTimeOut( dataRetrieverFeatures); String url = "http://www.baidu.com/tools?url=http%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3DO0urTq_fyCkG3Rd2veZDQm7TLJ50XyUOeeoybddPUG6zBjpgh37XHtMM_oXKe4nQxM-q5IEVjldslw0tbkMfvK&jump=http%3A%2F%2Fkoubei.baidu.com%2Fwomc%2Fp%2Fsentry%3Ftitle%3D%012014%01-%012015%01%E5%B9%B4%E5%BA%A6%01QS%01%E4%B8%96%E7%95%8C%01%E6%8E%92%E5%90%8D%01%3A%01%E6%BE%B3%E5%A4%A7%E5%88%A9%E4%BA%9A%01%E5%A4%A7%E5%AD%A6%0123%01%E6%89%80%01%E9%AB%98%E6%A0%A1%01%E8%BF%9B%E5%85%A5%02TOP%01500%03-%01%E7%95%99%E5%AD%A6%01-%01...%26q%3Dtop%20500%20university&key=surl"; hdrufdwto.setUrl(new URL(url)); hdrufdwto.connect(); System.out.print(hdrufdwto.getHtmlContent()); hdrufdwto.disconnect(); }
From source file:org.wrml.runtime.format.application.schema.json.JsonSchemaLoader.java
public static void main(final String[] args) throws Exception { final String wrmlConfigFilePath = args[0]; final EngineConfiguration config = EngineConfiguration.load(wrmlConfigFilePath); final Engine engine = new DefaultEngine(); engine.init(config);// w w w. ja va 2 s . co m final String urlString = args[1]; final URL jsonSchemaId = new URL(urlString); final SchemaLoader schemaLoader = engine.getContext().getSchemaLoader(); final JsonSchemaLoader jsonSchemaLoader = schemaLoader.getJsonSchemaLoader(); final JsonSchema downloadedJsonSchema = jsonSchemaLoader.load(jsonSchemaId); System.out.println("Downloaded JSON schema:\n" + downloadedJsonSchema); final Schema schema = schemaLoader.load(downloadedJsonSchema, schemaLoader.getDocumentSchemaUri()); System.out.println("Generated WRML schema:\n" + schema); final Schema docSchema = schemaLoader.load(schemaLoader.getDocumentSchemaUri()); final JsonSchema docJsonSchema = jsonSchemaLoader.load(docSchema); System.out.println("Generated WRML's Document schema as a JSON schema:\n" + docJsonSchema); }
From source file:org.eclipse.swt.snippets.Snippet317.java
public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 317"); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 2;/*from w w w . ja v a2 s. c om*/ shell.setLayout(gridLayout); final Text location = new Text(shell, SWT.BORDER); GridData data = new GridData(); data.horizontalAlignment = GridData.FILL; data.grabExcessHorizontalSpace = true; location.setLayoutData(data); Button go = new Button(shell, SWT.PUSH); go.setText("Go"); final Browser browser; try { browser = new Browser(shell, SWT.NONE); } catch (SWTError e) { System.out.println("Could not instantiate Browser: " + e.getMessage()); display.dispose(); return; } data = new GridData(); data.horizontalAlignment = data.verticalAlignment = GridData.FILL; data.grabExcessHorizontalSpace = data.grabExcessVerticalSpace = true; data.horizontalSpan = 2; browser.setLayoutData(data); browser.setUrl("eclipse.org"); browser.addLocationListener(new LocationAdapter() { @Override public void changed(LocationEvent event) { location.setText(event.location); } }); Listener navigateListener = event -> browser.setUrl(location.getText()); go.addListener(SWT.Selection, navigateListener); location.addListener(SWT.DefaultSelection, navigateListener); browser.addAuthenticationListener(event -> { try { URL url = new URL(event.location); if (url.getHost().equals(KNOWN_HOST)) { event.user = KNOWN_USER; event.password = KNOWN_PASSWORD; } else { /* do nothing, let default prompter run */ } } catch (MalformedURLException e) { /* should not happen, let default prompter run */ } }); shell.setBounds(10, 10, 500, 500); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:com.cloudbees.tftwoway.Client.java
public static void main(String[] args) throws Exception { URL url = new URL(SERVER_ADDRESS); HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); SSLContext sslContext = createSSLContext(); connection.setSSLSocketFactory(sslContext.getSocketFactory()); connection.connect();/*from w w w .ja v a 2 s . co m*/ int responseCode = connection.getResponseCode(); String response = IOUtils.toString(connection.getInputStream(), connection.getContentEncoding()); System.out.println(responseCode); System.out.println(response); }
From source file:com.pinch.console.GcmSender.java
public static void main(String[] args) { // if (args.length < 1 || args.length > 2 || args[0] == null) { // System.err.println("usage: ./gradlew run -Pmsg=\"MESSAGE\" [-Pto=\"DEVICE_TOKEN\"]"); // System.err.println(""); // System.err.println("Specify a test message to broadcast via GCM. If a device's GCM registration token is\n" + // "specified, the message will only be sent to that device. Otherwise, the message \n" + // "will be sent to all devices subscribed to the \"global\" topic."); // System.err.println(""); // System.err.println("Example (Broadcast):\n" + // "On Windows: .\\gradlew.bat run -Pmsg=\"<Your_Message>\"\n" + // "On Linux/Mac: ./gradlew run -Pmsg=\"<Your_Message>\""); // System.err.println(""); // System.err.println("Example (Unicast):\n" + // "On Windows: .\\gradlew.bat run -Pmsg=\"<Your_Message>\" -Pto=\"<Your_Token>\"\n" + // "On Linux/Mac: ./gradlew run -Pmsg=\"<Your_Message>\" -Pto=\"<Your_Token>\""); // System.exit(1); // }//from w ww . j a va2 s.c o m try { // Prepare JSON containing the GCM message content. What to send and where to send. JSONObject jGcmData = new JSONObject(); JSONObject jData = new JSONObject(); jData.put("message", "Saurabh Garg signed up!!"); jData.put("title", "New sign up!"); // Where to send GCM message. //if (args.length > 1 && args[1] != null) { jGcmData.put("to", "dOEmVpNPTCY:APA91bEkeYfFMhAraF4d87SJu12oxDElUp6KW1r710KSKeuDpW31Cd5_WExUxT16KNquJ69wwDMlxd-3qoEIeDNJNU1XjyXiXztOqlKglB-zdOlszoXhX9zIYmYNV8d4vWkM0oPwjlk9"); // } else { // jGcmData.put("to", "/topics/global"); // } // What to send in GCM message. jGcmData.put("data", jData); // Create connection to send GCM Message request. URL url = new URL("https://android.googleapis.com/gcm/send"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestProperty("Authorization", "key=" + API_KEY); conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestMethod("POST"); conn.setDoOutput(true); // Send GCM message content. OutputStream outputStream = conn.getOutputStream(); outputStream.write(jGcmData.toString().getBytes()); // Read GCM response. InputStream inputStream = conn.getInputStream(); String resp = IOUtils.toString(inputStream); System.out.println(resp); System.out.println("Check your device/emulator for notification or logcat for " + "confirmation of the receipt of the GCM message."); } catch (IOException e) { System.out.println("Unable to send GCM message."); System.out.println("Please ensure that API_KEY has been replaced by the server " + "API key, and that the device's registration token is correct (if specified)."); e.printStackTrace(); } }
From source file:com.pixa.gcmsender.GcmSender.java
public static void main(String[] args) { if (args.length < 1 || args.length > 2 || args[0] == null) { System.err.println("usage: ./gradlew run -Pmsg=\"MESSAGE\" [-Pto=\"DEVICE_TOKEN\"]"); System.err.println(""); System.err.println(/* w w w . j av a2s. c om*/ "Specify a test message to broadcast via GCM. If a device's GCM registration token is\n" + "specified, the message will only be sent to that device. Otherwise, the message \n" + "will be sent to all devices subscribed to the \"global\" topic."); System.err.println(""); System.err.println( "Example (Broadcast):\n" + "On Windows: .\\gradlew.bat run -Pmsg=\"<Your_Message>\"\n" + "On Linux/Mac: ./gradlew run -Pmsg=\"<Your_Message>\""); System.err.println(""); System.err.println("Example (Unicast):\n" + "On Windows: .\\gradlew.bat run -Pmsg=\"<Your_Message>\" -Pto=\"<Your_Token>\"\n" + "On Linux/Mac: ./gradlew run -Pmsg=\"<Your_Message>\" -Pto=\"<Your_Token>\""); System.exit(1); } try { // Prepare JSON containing the GCM message content. What to send and where to send. JSONObject jGcmData = new JSONObject(); JSONObject jData = new JSONObject(); jData.put("message", args[0].trim()); // Where to send GCM message. if (args.length > 1 && args[1] != null) { jGcmData.put("to", args[1].trim()); } else { jGcmData.put("to", "/topics/global"); } // What to send in GCM message. jGcmData.put("data", jData); // Create connection to send GCM Message request. URL url = new URL("https://android.googleapis.com/gcm/send"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestProperty("Authorization", "key=" + API_KEY); conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestMethod("POST"); conn.setDoOutput(true); // Send GCM message content. OutputStream outputStream = conn.getOutputStream(); outputStream.write(jGcmData.toString().getBytes()); // Read GCM response. InputStream inputStream = conn.getInputStream(); String resp = IOUtils.toString(inputStream); System.out.println(resp); System.out.println("Check your device/emulator for notification or logcat for " + "confirmation of the receipt of the GCM message."); } catch (IOException e) { System.out.println("Unable to send GCM message."); System.out.println("Please ensure that API_KEY has been replaced by the server " + "API key, and that the device's registration token is correct (if specified)."); e.printStackTrace(); } }
From source file:com.ebay.spine.Launcher.java
public static void main(String[] args) throws Exception { // not using the default parsing for the hub. Creating a simple one from the default. GridHubConfiguration config = new GridHubConfiguration(); // adding the VNC capable servlet. List<String> servlets = new ArrayList<String>(); servlets.add("web.ConsoleVNC"); config.setServlets(servlets);// w w w . j a va 2s . c o m // capabilities are dynamic for VMs. config.setThrowOnCapabilityNotPresent(false); // forcing the host from command line param as the hub gets confused by all the VMWare network interfaces. for (int i = 0; i < args.length; i++) { if (args[i].startsWith("hubhost=")) { config.setHost(args[i].replace("hubhost=", "")); } } Hub h = new Hub(config); h.start(); // and the nodes. // load the node templates. Map<String, JSONObject> templatesByNameMap = getTemplates("eugrid.json"); // get the template to use for each VM Map<String, String> vmsMapping = getVMtoTemplateMapping("nodes.properties"); // register each node using its template. for (String id : vmsMapping.keySet()) { String templateName = vmsMapping.get(id); JSONObject request = templatesByNameMap.get(templateName); request.getJSONObject("configuration").put("vm", id); BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("POST", "http://" + hub + "/grid/register/"); r.setEntity(new StringEntity(request.toString())); DefaultHttpClient client = new DefaultHttpClient(); URL hubURL = new URL("http://" + hub); HttpHost host = new HttpHost(hubURL.getHost(), hubURL.getPort()); HttpResponse response = client.execute(host, r); } }