List of usage examples for javax.xml.bind Marshaller setProperty
public void setProperty(String name, Object value) throws PropertyException;
From source file:Main.java
public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Customer.class); Customer customer = new Customer(); customer.setFirstName("Jane"); customer.setLastName("Doe"); PhoneNumber workPhone = new PhoneNumber(); workPhone.setType("work"); workPhone.setNumber("555-1111"); customer.getPhoneNumbers().add(workPhone); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); JAXBElement<Customer> rootElement = new JAXBElement<Customer>(new QName("customer"), Customer.class, customer);//from ww w.j av a2 s .c o m marshaller.marshal(rootElement, System.out); }
From source file:org.jasig.portlet.data.Exporter.java
public static void main(String[] args) throws Exception { String dir = args[0];/* ww w. j a v a2 s. c om*/ String importExportContext = args[1]; String sessionFactoryBeanName = args[2]; String modelClassName = args[3]; String serviceBeanName = args[4]; String serviceBeanMethodName = args[5]; ApplicationContext context = PortletApplicationContextLocator.getApplicationContext(importExportContext); SessionFactory sessionFactory = context.getBean(sessionFactoryBeanName, SessionFactory.class); Class<?> modelClass = Class.forName(modelClassName); Object service = context.getBean(serviceBeanName); Session session = sessionFactory.getCurrentSession(); Transaction transaction = session.beginTransaction(); JAXBContext jc = JAXBContext.newInstance(modelClass); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); Method method = service.getClass().getMethod(serviceBeanMethodName); List<?> objects = (List<?>) method.invoke(service, null); for (Object o : objects) { session.lock(o, LockMode.NONE); JAXBElement je2 = new JAXBElement(new QName(modelClass.getSimpleName().toLowerCase()), modelClass, o); String output = dir + File.separator + UUID.randomUUID().toString() + ".xml"; try { marshaller.marshal(je2, new FileOutputStream(output)); } catch (Exception exception) { exception.printStackTrace(); } } transaction.commit(); }
From source file:ListMObjects.java
public static void main(String[] args) { System.out.println("Executing List MObjects"); try {//from w w w . ja v a 2s . 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 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:org.jasig.portlet.announcements.Exporter.java
public static void main(String[] args) throws Exception { String dir = args[0];/*from ww w. ja v a 2 s. c om*/ ApplicationContext context = PortletApplicationContextLocator .getApplicationContext(PortletApplicationContextLocator.DATABASE_CONTEXT_LOCATION); SessionFactory sessionFactory = context.getBean(SESSION_FACTORY_BEAN_NAME, SessionFactory.class); IAnnouncementService announcementService = context.getBean(ANNOUNCEMENT_SVC_BEAN_NAME, IAnnouncementService.class); Session session = sessionFactory.getCurrentSession(); Transaction transaction = session.beginTransaction(); JAXBContext jc = JAXBContext.newInstance(Topic.class); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); List<Topic> topics = announcementService.getAllTopics(); for (Topic topic : topics) { if (topic.getSubscriptionMethod() == 4) { continue; } session.lock(topic, LockMode.NONE); JAXBElement<Topic> je2 = new JAXBElement<Topic>(new QName("topic"), Topic.class, topic); String output = dir + File.separator + UUID.randomUUID().toString() + ".xml"; System.out.println("Exporting Topic " + topic.getId() + " to file " + output); try { marshaller.marshal(je2, new FileOutputStream(output)); } catch (Exception exception) { exception.printStackTrace(); } } transaction.commit(); }
From source file:DescribeMObject.java
public static void main(String[] args) { System.out.println("Executing Describe MObject"); 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 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:Main.java
public static void main(String[] args) throws Exception { JAXBContext context = JAXBContext.newInstance(Disk.class, MyStatus.class, MyDisk.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); Disk disk = new Disk(); disk.setStatus("attached"); disk.setSize(10000000000L);//ww w . jav a 2 s.c o m disk.setFreeSpace(25600000L); disk.setId("1"); m.marshal(disk, System.out); m.marshal(new MyStatus(disk), System.out); m.marshal(new MyDisk(disk), System.out); }
From source file:GetImportToListStatus.java
public static void main(String[] args) { System.out.println("Executing Get Import To List Status"); try {/* 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 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:GetLead.java
public static void main(String[] args) { System.out.println("Executing Get Lead"); try {//w w w . j a v a2 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 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:Main.java
public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Note.class); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(new Note(), System.out); }
From source file:BarAdapter.java
public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Foo.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); File xml = new File("data.xml"); Foo foo = (Foo) unmarshaller.unmarshal(xml); Marshaller marshaller = jc.createMarshaller(); marshaller.setAdapter(new BarAdapter()); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(foo, System.out); }