List of usage examples for javax.crypto Mac init
public final void init(Key key) throws InvalidKeyException
From source file:GetChannels.java
public static void main(String[] args) { System.out.println("Executing Get Channels"); try {/*from w ww. j av a 2 s .c o m*/ URL marketoSoapEndPoint = new URL("CHANGEME" + "?WSDL"); String marketoUserId = "CHANGEME"; String marketoSecretKey = "CHANGEME"; QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService"); MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName); // 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 ParamsGetChannels params = new ParamsGetChannels(); Tag tags = new Tag(); ArrayOfString tagArray = new ArrayOfString(); tagArray.getStringItems().add("Webinar"); tagArray.getStringItems().add("Blog"); tagArray.getStringItems().add("Tradeshow"); tags.setValues(tagArray); MktowsPort port = service.getMktowsApiSoapPort(); SuccessGetChannels result = port.getChannels(params, 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:GetCustomObjects.java
public static void main(String[] args) { System.out.println("Executing Get Custom Objects"); try {//from w ww . 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 ParamsGetCustomObjects request = new ParamsGetCustomObjects(); request.setObjTypeName("RoadShow"); ArrayOfAttribute arrayOfAttribute = new ArrayOfAttribute(); Attribute attr = new Attribute(); attr.setAttrName("MKTOID"); attr.setAttrValue("1090177"); arrayOfAttribute.getAttributes().add(attr); JAXBElement<ArrayOfAttribute> attributes = new ObjectFactory() .createParamsGetCustomObjectsCustomObjKeyList(arrayOfAttribute); request.setCustomObjKeyList(attributes); SuccessGetCustomObjects result = port.getCustomObjects(request, header); JAXBContext context = JAXBContext.newInstance(SuccessGetCustomObjects.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 va 2 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 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:GetTags.java
public static void main(String[] args) { System.out.println("Executing Get Tags"); try {/*w w w .java2 s.co 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:ImportToList.java
public static void main(String[] args) { System.out.println("Executing Import To List"); try {//w w w . ja v a 2 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 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:DeleteCustomObjects.java
public static void main(String[] args) { System.out.println("Executing Delete Custom Objects"); try {//w w w . ja 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 ParamsDeleteCustomObjects request = new ParamsDeleteCustomObjects(); request.setObjTypeName("RoadShow"); ArrayOfAttribute arrayOfAttribute = new ArrayOfAttribute(); Attribute attr = new Attribute(); attr.setAttrName("MKTOID"); attr.setAttrValue("1090177"); arrayOfAttribute.getAttributes().add(attr); Attribute attr2 = new Attribute(); attr2.setAttrName("rid"); attr2.setAttrValue("123456"); arrayOfAttribute.getAttributes().add(attr2); ArrayOfKeyList keyList = new ArrayOfKeyList(); keyList.getKeyLists().add(arrayOfAttribute); request.setCustomObjKeyLists(keyList); SuccessDeleteCustomObjects result = port.deleteCustomObjects(request, header); JAXBContext context = JAXBContext.newInstance(SuccessDeleteCustomObjects.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 {/*from w w w .ja va 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 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:GetLeadActivity.java
public static void main(String[] args) { System.out.println("Executing Get Lead Activity"); try {//from w w w . j a va2 s. com 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 ParamsGetLeadActivity request = new ParamsGetLeadActivity(); LeadKey key = new LeadKey(); key.setKeyType(LeadKeyRef.EMAIL); key.setKeyValue("t@t.com"); request.setLeadKey(key); ObjectFactory objectFactory = new ObjectFactory(); JAXBElement<Integer> batchSize = objectFactory.createParamsGetLeadActivityBatchSize(10); request.setBatchSize(batchSize); ActivityTypeFilter atv = new ActivityTypeFilter(); ArrayOfActivityType aatt = new ArrayOfActivityType(); aatt.getActivityTypes().add(ActivityType.VISIT_WEBPAGE); aatt.getActivityTypes().add(ActivityType.FILL_OUT_FORM); atv.setIncludeTypes(aatt); JAXBElement<ActivityTypeFilter> typeFilter = objectFactory .createParamsGetLeadActivityActivityFilter(atv); request.setActivityFilter(typeFilter); SuccessGetLeadActivity result = port.getLeadActivity(request, header); JAXBContext context = JAXBContext.newInstance(SuccessGetLeadActivity.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:RequestCampaign.java
public static void main(String[] args) { System.out.println("Executing Request Campaign"); try {//from w ww .j av 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 ParamsRequestCampaign request = new ParamsRequestCampaign(); request.setSource(ReqCampSourceType.MKTOWS); ObjectFactory objectFactory = new ObjectFactory(); JAXBElement<Integer> campaignId = objectFactory.createParamsRequestCampaignCampaignId(4496); request.setCampaignId(campaignId); ArrayOfLeadKey leadKeyList = new ArrayOfLeadKey(); LeadKey key = new LeadKey(); key.setKeyType(LeadKeyRef.EMAIL); key.setKeyValue("lead@company.com"); LeadKey key2 = new LeadKey(); key2.setKeyType(LeadKeyRef.EMAIL); key2.setKeyValue("anotherlead@company.com"); leadKeyList.getLeadKeies().add(key); leadKeyList.getLeadKeies().add(key2); JAXBElement<ArrayOfLeadKey> arrayOfLeadKey = objectFactory .createParamsRequestCampaignLeadList(leadKeyList); request.setLeadList(arrayOfLeadKey); SuccessRequestCampaign result = port.requestCampaign(request, header); JAXBContext context = JAXBContext.newInstance(SuccessRequestCampaign.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:ListOperation.java
public static void main(String[] args) { System.out.println("Executing List Operation"); try {/* w ww. 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 ParamsListOperation request = new ParamsListOperation(); request.setListOperation(ListOperationType.ISMEMBEROFLIST); ListKey listKey = new ListKey(); listKey.setKeyType(ListKeyType.MKTOLISTNAME); listKey.setKeyValue("Trav-Test-List"); request.setListKey(listKey); LeadKey key = new LeadKey(); key.setKeyType(LeadKeyRef.IDNUM); key.setKeyValue("87710"); LeadKey key2 = new LeadKey(); key2.setKeyType(LeadKeyRef.IDNUM); key2.setKeyValue("1089946"); ArrayOfLeadKey leadKeys = new ArrayOfLeadKey(); leadKeys.getLeadKeies().add(key); leadKeys.getLeadKeies().add(key2); request.setListMemberList(leadKeys); JAXBElement<Boolean> strict = new ObjectFactory().createParamsListOperationStrict(false); request.setStrict(strict); SuccessListOperation result = port.listOperation(request, header); JAXBContext context = JAXBContext.newInstance(SuccessListOperation.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(result, System.out); } catch (Exception e) { e.printStackTrace(); } }