List of usage examples for javax.xml.bind Marshaller marshal
public void marshal(Object jaxbElement, javax.xml.stream.XMLEventWriter writer) throws JAXBException;
From source file:Main.java
public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Field.class); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); Field field = new Field(); field.name = "myField"; marshaller.marshal(field, System.out); field.status = "citizen"; field.country = "England"; marshaller.marshal(field, System.out); field.status = null;/*from w w w.j a v a 2s . co m*/ marshaller.marshal(field, System.out); }
From source file:GetTags.java
public static void main(String[] args) { System.out.println("Executing Get Tags"); try {//from w w w. jav a 2s .com 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:Main.java
public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(A.class, B.class); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); A a = new A(); a.setFoo("Hello World"); marshaller.marshal(a, System.out); B b = new B(); b.setFoo("Hello World"); marshaller.marshal(b, System.out); }
From source file:ImportToList.java
public static void main(String[] args) { System.out.println("Executing Import To List"); try {//from ww w. java2 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 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:Main.java
public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(BarX.class, BarY.class); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); BarX barX = new BarX(); barX.setXThing("XThing"); marshaller.marshal(barX, System.out); BarY barY = new BarY(); barY.setYBlah("YBlah"); marshaller.marshal(barY, System.out); }
From source file:DeleteCustomObjects.java
public static void main(String[] args) { System.out.println("Executing Delete Custom Objects"); try {/*from w w w . jav a2 s. 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 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 ww. java2 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:GetLeadActivity.java
public static void main(String[] args) { System.out.println("Executing Get Lead Activity"); try {//from w w w .ja va2s. 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 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:Main.java
public static void main(String[] args) throws Exception { Company company = new Company(); Employee employee1 = new Employee(); employee1.setId("1"); employee1.setName("Jane Doe"); company.getEmployees().add(employee1); Employee employee2 = new Employee(); employee2.setId("2"); employee2.setName("John Smith"); employee2.setManager(employee1);//from ww w .ja v a2 s. com employee1.getReports().add(employee2); company.getEmployees().add(employee2); Employee employee3 = new Employee(); employee3.setId("3"); employee3.setName("Anne Jones"); employee3.setManager(employee1); employee1.getReports().add(employee3); company.getEmployees().add(employee3); JAXBContext jc = JAXBContext.newInstance(Company.class); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(company, System.out); }
From source file:RequestCampaign.java
public static void main(String[] args) { System.out.println("Executing Request Campaign"); try {//w w w . jav a2 s . 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 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(); } }