List of usage examples for java.net URL URL
public URL(String spec) throws MalformedURLException
From source file:gsonTests.jsonTojava.ParseTreeExample6.java
public static void main(String[] args) throws MalformedURLException, IOException { String url = "http://freemusicarchive.org/api/get/albums.json?api_key=60BLHNQCAOUFPIBZ&limit=5"; String json = IOUtils.toString(new URL(url)); JsonParser parser = new JsonParser(); // The JsonElement is the root node. It can be an object, array, null or // java primitive. JsonElement element = parser.parse(json); // use the isxxx methods to find out the type of jsonelement. In our // example we know that the root object is the Albums object and // contains an array of dataset objects if (element.isJsonObject()) { JsonObject albums = element.getAsJsonObject(); System.out.println(albums.get("title").getAsString()); JsonArray datasets = albums.getAsJsonArray("dataset"); for (int i = 0; i < datasets.size(); i++) { JsonObject dataset = datasets.get(i).getAsJsonObject(); System.out.println(dataset.get("album_title").getAsString()); }/*w w w.j ava2 s . c om*/ } }
From source file:ListMObjects.java
public static void main(String[] args) { System.out.println("Executing List MObjects"); try {//w w w . j a va 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 ParamsListMObjects request = new ParamsListMObjects(); SuccessListMObjects result = port.listMObjects(request, header); JAXBContext context = JAXBContext.newInstance(SuccessListMObjects.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:GetLead.java
public static void main(String[] args) { System.out.println("Executing Get Lead"); try {/*from w ww . j av a 2s . c om*/ 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 ParamsGetLead request = new ParamsGetLead(); LeadKey key = new LeadKey(); key.setKeyType(LeadKeyRef.EMAIL); key.setKeyValue("t@t.com"); request.setLeadKey(key); SuccessGetLead result = port.getLead(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:DescribeMObject.java
public static void main(String[] args) { System.out.println("Executing Describe MObject"); try {/* www . 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 ParamsDescribeMObject request = new ParamsDescribeMObject(); request.setObjectName("ActivityRecord"); SuccessDescribeMObject result = port.describeMObject(request, header); JAXBContext context = JAXBContext.newInstance(SuccessDescribeMObject.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:GetTags.java
public static void main(String[] args) { System.out.println("Executing Get Tags"); try {/*www .j av a2 s . c o m*/ URL marketoSoapEndPoint = new URL("https://100-AEK-913.mktoapi.com/soap/mktows/2_1" + "?WSDL"); String marketoUserId = "demo17_1_809934544BFABAE58E5D27"; String marketoSecretKey = "27272727aa"; 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 ParamsGetTags request = new ParamsGetTags(); ArrayOfTag tags = new ArrayOfTag(); Tag tag = new Tag(); tag.setType("Content Channel"); /* ArrayOfString values = new ArrayOfString(); values.getStringItems().add("SEM"); values.getStringItems().add("Email"); tag.setValues(values); tags.getTags().add(tag); request.setTagList(tags); */ SuccessGetTags result = port.getTags(request, header); JAXBContext context = JAXBContext.newInstance(SuccessGetTags.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:GetImportToListStatus.java
public static void main(String[] args) { System.out.println("Executing Get Import To List Status"); try {/*from www . j av a2s . c om*/ 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 ParamsGetImportToListStatus request = new ParamsGetImportToListStatus(); request.setProgramName("Trav-Demo-Program"); request.setListName("Trav-Test-List"); SuccessGetImportToListStatus result = port.getImportToListStatus(request, header); JAXBContext context = JAXBContext.newInstance(SuccessGetImportToListStatus.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:DeleteMObjects.java
public static void main(String[] args) { System.out.println("Executing Delete MObjects"); try {/*from w w w. j a v a 2s .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 ParamsDeleteMObjects request = new ParamsDeleteMObjects(); MObject mobj = new MObject(); mobj.setType("Opportunity"); mobj.setId(4); MObject mobj2 = new MObject(); mobj2.setType("Opportunity"); mobj2.setId(7); ArrayOfMObject objList = new ArrayOfMObject(); objList.getMObjects().add(mobj); objList.getMObjects().add(mobj2); request.setMObjectList(objList); SuccessDeleteMObjects result = port.deleteMObjects(request, header); JAXBContext context = JAXBContext.newInstance(SuccessDeleteMObjects.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:getMObjects.java
public static void main(String[] args) { System.out.println("Executing Get MObjects"); try {// ww w.j a v a2 s.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 ParamsGetMObjects request = new ParamsGetMObjects(); request.setType("Program"); MObjCriteria criteria = new MObjCriteria(); criteria.setAttrName("Id"); criteria.setComparison(ComparisonEnum.LE); criteria.setAttrValue("1010"); MObjCriteria criteria2 = new MObjCriteria(); criteria2.setAttrName("Name"); criteria2.setComparison(ComparisonEnum.NE); criteria2.setAttrValue("elizprogramtest"); ArrayOfMObjCriteria mObjCriteria = new ArrayOfMObjCriteria(); mObjCriteria.getMObjCriterias().add(criteria); mObjCriteria.getMObjCriterias().add(criteria2); request.setMObjCriteriaList(mObjCriteria); SuccessGetMObjects result = port.getMObjects(request, header); JAXBContext context = JAXBContext.newInstance(SuccessGetMObjects.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:MergeLeads.java
public static void main(String[] args) { System.out.println("Executing Merge Lead"); try {/* ww w. j av a2 s . 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 ParamsMergeLeads request = new ParamsMergeLeads(); ArrayOfAttribute winningLeadArray = new ArrayOfAttribute(); Attribute winner = new Attribute(); winner.setAttrName("IDNUM"); winner.setAttrValue("2"); winningLeadArray.getAttributes().add(winner); request.setWinningLeadKeyList(winningLeadArray); ArrayOfAttribute losingLeadArray = new ArrayOfAttribute(); Attribute loser = new Attribute(); loser.setAttrName("IDNUM"); loser.setAttrValue("15"); losingLeadArray.getAttributes().add(loser); ArrayOfAttribute losingLeadArray2 = new ArrayOfAttribute(); Attribute loser2 = new Attribute(); loser2.setAttrName("IDNUM"); loser2.setAttrValue("16"); losingLeadArray2.getAttributes().add(loser2); ArrayOfKeyList losingKeyList = new ArrayOfKeyList(); losingKeyList.getKeyLists().add(losingLeadArray); losingKeyList.getKeyLists().add(losingLeadArray2); request.setLosingLeadKeyLists(losingKeyList); SuccessMergeLeads result = port.mergeLeads(request, header); JAXBContext context = JAXBContext.newInstance(SuccessMergeLeads.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:SyncMObjects.java
public static void main(String[] args) { try {//w w w. j a v a2s .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 //////////////////////////////// ParamsSyncMObjects request = prepareUpdateProgramRequest(); // -or- //ParamsSyncMObjects request = prepareCreateOpptyRequest(); // -or- //ParamsSyncMObjects request = prepareCreateOpptyPersonRoleRequest(); //////////////////////////////// SuccessSyncMObjects result = port.syncMObjects(request, header); JAXBContext context = JAXBContext.newInstance(SuccessSyncMObjects.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(result, System.out); } catch (Exception e) { e.printStackTrace(); } }