List of usage examples for java.net URL URL
public URL(String spec) throws MalformedURLException
From source file:ImportToList.java
public static void main(String[] args) { System.out.println("Executing Import To List"); try {/*from w ww. j a v a 2s . co m*/ URL marketoSoapEndPoint = new URL("CHANGE ME" + "?WSDL"); String marketoUserId = "CHANGE ME"; String marketoSecretKey = "CHANGE ME"; QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService"); MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName); MktowsPort port = service.getMktowsApiSoapPort(); // Create Signature DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); String text = df.format(new Date()); String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22); String encryptString = requestTimestamp + marketoUserId; SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1"); Mac mac = Mac.getInstance("HmacSHA1"); mac.init(secretKey); byte[] rawHmac = mac.doFinal(encryptString.getBytes()); char[] hexChars = Hex.encodeHex(rawHmac); String signature = new String(hexChars); // Set Authentication Header AuthenticationHeader header = new AuthenticationHeader(); header.setMktowsUserId(marketoUserId); header.setRequestTimestamp(requestTimestamp); header.setRequestSignature(signature); // Create Request ParamsImportToList request = new ParamsImportToList(); request.setProgramName("Trav-Demo-Program"); request.setCampaignName("Batch Campaign Example"); request.setImportFileHeader("Last Name,First Name,Job Title,Company Name,Email Address"); ArrayOfString rows = new ArrayOfString(); rows.getStringItems().add("Awesomesauce,Developer,Code Slinger,Marketo,dawesomesauce@marketo.com"); rows.getStringItems().add("Doe,Jane,VP Marketing,Jane Consulting,jdoe@janeconsulting.com"); request.setImportFileRows(rows); request.setImportListMode(ImportToListModeEnum.UPSERTLEADS); request.setListName("Trav-Test-List"); request.setClearList(false); SuccessImportToList result = port.importToList(request, header); JAXBContext context = JAXBContext.newInstance(SuccessImportToList.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(result, System.out); } catch (Exception e) { e.printStackTrace(); } }
From source file:ScheduleCampaign.java
public static void main(String[] args) { System.out.println("Executing Schedule Campaign"); try {//from w w w . jav a 2 s . c o m URL marketoSoapEndPoint = new URL("CHANGE ME" + "?WSDL"); String marketoUserId = "CHANGE ME"; String marketoSecretKey = "CHANGE ME"; QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService"); MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName); MktowsPort port = service.getMktowsApiSoapPort(); // Create Signature DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); String text = df.format(new Date()); String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22); String encryptString = requestTimestamp + marketoUserId; SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1"); Mac mac = Mac.getInstance("HmacSHA1"); mac.init(secretKey); byte[] rawHmac = mac.doFinal(encryptString.getBytes()); char[] hexChars = Hex.encodeHex(rawHmac); String signature = new String(hexChars); // Set Authentication Header AuthenticationHeader header = new AuthenticationHeader(); header.setMktowsUserId(marketoUserId); header.setRequestTimestamp(requestTimestamp); header.setRequestSignature(signature); // Create Request ParamsScheduleCampaign request = new ParamsScheduleCampaign(); request.setProgramName("Trav-Demo-Program"); request.setCampaignName("Batch Campaign Example"); // Create setCampaignRunAt timestamp GregorianCalendar gc = new GregorianCalendar(); gc.setTimeInMillis(new Date().getTime()); DatatypeFactory factory = DatatypeFactory.newInstance(); ObjectFactory objectFactory = new ObjectFactory(); JAXBElement<XMLGregorianCalendar> setCampaignRunAtValue = objectFactory .createParamsScheduleCampaignCampaignRunAt(factory.newXMLGregorianCalendar(gc)); request.setCampaignRunAt(setCampaignRunAtValue); request.setCloneToProgramName("TestProgramCloneFromSOAP"); ArrayOfAttrib aoa = new ArrayOfAttrib(); Attrib attrib = new Attrib(); attrib.setName("{{my.message}}"); attrib.setValue("Updated message"); aoa.getAttribs().add(attrib); JAXBElement<ArrayOfAttrib> arrayOfAttrib = objectFactory .createParamsScheduleCampaignProgramTokenList(aoa); request.setProgramTokenList(arrayOfAttrib); SuccessScheduleCampaign result = port.scheduleCampaign(request, header); JAXBContext context = JAXBContext.newInstance(SuccessScheduleCampaign.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(result, System.out); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { URL url = new URL("http://www.java2s.com/style/download.png"); final BufferedImage bi = ImageIO.read(url); SwingUtilities.invokeLater(new Runnable() { @Override// w ww. j a v a2 s. c om public void run() { int strokeWidth = 12; int pad = 50; Shape shape = new Rectangle(pad, pad, bi.getWidth() - (2 * pad), bi.getHeight() - (2 * pad)); Image i = getStrokedImage(bi, shape, strokeWidth); JOptionPane.showMessageDialog(null, new JLabel(new ImageIcon(i))); } }); }
From source file:Main.java
public static void main(String[] args) throws Exception { JFrame Main = new JFrame("Gradient Mask"); JLabel imageLayer = new JLabel(); JLabel maskLayer = new JLabel(); BufferedImage image = ImageIO.read(new URL("http://www.java2s.com/style/download.png")); BufferedImage gradientMask = new GradientImage(image.getWidth(), image.getHeight(), new Color[] { new Color(255, 255, 255, 125), Color.BLACK }, GradientImage.RADIAL_FROM_CENTER) .getImage();/* w w w .jav a 2s . com*/ Main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Main.setBounds(100, 50, image.getWidth(), image.getHeight()); imageLayer.setBounds(0, 0, Main.getWidth(), Main.getHeight()); maskLayer.setBounds(0, 0, Main.getWidth(), Main.getHeight()); imageLayer.setIcon(new ImageIcon((Image) image)); maskLayer.setIcon(new ImageIcon((Image) gradientMask)); Main.getContentPane().add(imageLayer); imageLayer.add(maskLayer); Main.setVisible(true); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { ParserGetter kit = new ParserGetter(); HTMLEditorKit.Parser parser = kit.getParser(); String encoding = "ISO-8859-1"; URL url = new URL("http://www.java2s.com"); InputStream in = url.openStream(); InputStreamReader r = new InputStreamReader(in, encoding); // parse once just to detect the encoding HTMLEditorKit.ParserCallback doNothing = new HTMLEditorKit.ParserCallback(); parser.parse(r, doNothing, false);//from w w w . ja va 2 s. c om parse(url, encoding); }
From source file:Main.java
public static void main(String[] args) throws Exception { URLLabel label = new URLLabel(new URL("http://java2s.com")); JOptionPane.showMessageDialog(null, label); }
From source file:GetMultipleLeads.java
public static void main(String[] args) { System.out.println("Executing GetMultipleLeads"); try {//from w w w.ja v a2 s. c o m URL marketoSoapEndPoint = new URL("CHANGE ME" + "?WSDL"); String marketoUserId = "CHANGE ME"; String marketoSecretKey = "CHANGE ME"; QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService"); MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName); MktowsPort port = service.getMktowsApiSoapPort(); // Create Signature DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); String text = df.format(new Date()); String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22); String encryptString = requestTimestamp + marketoUserId; SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1"); Mac mac = Mac.getInstance("HmacSHA1"); mac.init(secretKey); byte[] rawHmac = mac.doFinal(encryptString.getBytes()); char[] hexChars = Hex.encodeHex(rawHmac); String signature = new String(hexChars); // Set Authentication Header AuthenticationHeader header = new AuthenticationHeader(); header.setMktowsUserId(marketoUserId); header.setRequestTimestamp(requestTimestamp); header.setRequestSignature(signature); // Create Request ParamsGetMultipleLeads request = new ParamsGetMultipleLeads(); // Request Using LeadKey Selector //////////////////////////////////////////////////////// LeadKeySelector keySelector = new LeadKeySelector(); keySelector.setKeyType(LeadKeyRef.EMAIL); ArrayOfString aos = new ArrayOfString(); aos.getStringItems().add("formtest1@marketo.com"); aos.getStringItems().add("joe@marketo.com"); keySelector.setKeyValues(aos); request.setLeadSelector(keySelector); /* // Request Using LastUpdateAtSelector //////////////////////////////////////////////////////// LastUpdateAtSelector leadSelector = new LastUpdateAtSelector(); GregorianCalendar gc = new GregorianCalendar(); gc.setTimeInMillis(new Date().getTime()); gc.add( GregorianCalendar.DAY_OF_YEAR, -2); DatatypeFactory factory = DatatypeFactory.newInstance(); ObjectFactory objectFactory = new ObjectFactory(); JAXBElement<XMLGregorianCalendar> until =objectFactory.createLastUpdateAtSelectorLatestUpdatedAt(factory.newXMLGregorianCalendar(gc)); GregorianCalendar since = new GregorianCalendar(); since.setTimeInMillis(new Date().getTime()); since.add( GregorianCalendar.DAY_OF_YEAR, -5); leadSelector.setOldestUpdatedAt(factory.newXMLGregorianCalendar(since)); leadSelector.setLatestUpdatedAt(until); request.setLeadSelector(leadSelector); */ /* // Request Using StaticList Selector //////////////////////////////////////////////////////// StaticListSelector staticListSelector = new StaticListSelector(); //staticListSelector.setStaticListId(value) ObjectFactory objectFactory = new ObjectFactory(); JAXBElement<String> listName = objectFactory.createStaticListSelectorStaticListName("SMSProgram.listForTesting"); staticListSelector.setStaticListName(listName); // JAXBElement<Integer> listId = objectFactory.createStaticListSelectorStaticListId(6926); // staticListSelector.setStaticListId(listId); request.setLeadSelector(staticListSelector); */ ArrayOfString attributes = new ArrayOfString(); attributes.getStringItems().add("FirstName"); attributes.getStringItems().add("AnonymousIP"); attributes.getStringItems().add("Company"); request.setIncludeAttributes(attributes); JAXBElement<Integer> batchSize = new ObjectFactory().createParamsGetMultipleLeadsBatchSize(10); request.setBatchSize(batchSize); SuccessGetMultipleLeads result = port.getMultipleLeads(request, header); JAXBContext context = JAXBContext.newInstance(SuccessGetLead.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(result, System.out); } catch (Exception e) { e.printStackTrace(); } }
From source file:icevaluation.BingAPIAccess.java
public static void main(String[] args) { String searchText = "arts site:wikipedia.org"; searchText = searchText.replaceAll(" ", "%20"); // String accountKey="jTRIJt9d8DR2QT/Z3BJCAvY1BfoXj0zRYgSZ8deqHHo"; String accountKey = "JfeJSA3x6CtsyVai0+KEP0A6CYEUBT8VWhZmm9CS738"; byte[] accountKeyBytes = Base64.encodeBase64((accountKey + ":" + accountKey).getBytes()); String accountKeyEnc = new String(accountKeyBytes); URL url;/* w w w . ja va 2s .c o m*/ try { url = new URL("https://api.datamarket.azure.com/Bing/Search/v1/Composite?Sources=%27Web%27&Query=%27" + searchText + "%27&$format=JSON"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("Authorization", "Basic " + accountKeyEnc); BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); StringBuilder sb = new StringBuilder(); String output; System.out.println("Output from Server .... \n"); //write json to string sb int c = 0; if ((output = br.readLine()) != null) { System.out.println("Output is: " + output); sb.append(output); c++; //System.out.println("C:"+c); } conn.disconnect(); //find webtotal among output int find = sb.indexOf("\"WebTotal\":\""); int startindex = find + 12; System.out.println("Find: " + find); int lastindex = sb.indexOf("\",\"WebOffset\""); System.out.println(sb.substring(startindex, lastindex)); } catch (MalformedURLException e1) { e1.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) throws AWTException { Runnable r = new Runnable() { @Override// www . ja v a 2s . c o m public void run() { try { URL url = new URL("http://www.java2s.com/style/download.png"); BufferedImage bi = ImageIO.read(url); JPanel gui = new JPanel(new GridLayout(1, 2, 2, 2)); gui.add(new JLabel(new ImageIcon(bi))); gui.add(new JLabel(new ImageIcon(getFlippedImage(bi)))); JOptionPane.showMessageDialog(null, gui); } catch (Exception e) { e.printStackTrace(); } } }; SwingUtilities.invokeLater(r); }
From source file:bonapetit.ParseJson1.java
public static void main(String[] args) { String url = "http://freemusicarchive.org/api/get/genres.json?api_key=60BLHNQCAOUFPIBZ&limit=2"; /*/*w w w . j a v a 2 s .c o m*/ * {"title":"Free Music Archive - Genres","message":"","errors":[],"total" : "161","total_pages":81,"page":1,"limit":"2", * "dataset": * [{"genre_id": "1","genre_parent_id":"38","genre_title":"Avant-Garde" ,"genre_handle": "Avant-Garde","genre_color":"#006666"}, * {"genre_id":"2","genre_parent_id" :null,"genre_title":"International","genre_handle":"International","genre_color":"#CC3300"}]} */ try { String genreJson = IOUtils.toString(new URL(url)); JSONObject genreJsonObject = (JSONObject) JSONValue.parseWithException(genreJson); // get the title System.out.println(genreJsonObject.get("title")); // get the data JSONArray genreArray = (JSONArray) genreJsonObject.get("dataset"); // get the first genre JSONObject firstGenre = (JSONObject) genreArray.get(0); System.out.println(firstGenre.get("genre_title")); } catch (IOException | ParseException e) { e.printStackTrace(); } }