List of usage examples for javax.xml.bind JAXBContext createUnmarshaller
public abstract Unmarshaller createUnmarshaller() throws JAXBException;
From source file:org.jasig.portlet.blackboardvcportlet.dao.ws.impl.PresentationWSDaoImplTest.java
@SuppressWarnings("unchecked") private JAXBElement<BlackboardPresentationResponseCollection> getSinglePresentation() throws JAXBException { final JAXBContext context = JAXBContext.newInstance("com.elluminate.sas"); final Unmarshaller unmarshaller = context.createUnmarshaller(); JAXBElement<BlackboardPresentationResponseCollection> response = (JAXBElement<BlackboardPresentationResponseCollection>) unmarshaller .unmarshal(this.getClass() .getResourceAsStream("/data/singleListRepositoryPresentationResponseCollection.xml")); return response; }
From source file:org.jasig.portlet.courses.dao.xml.Jaxb2CourseSummaryHttpMessageConverter.java
/** * Creates a new {@link Unmarshaller} for the given class. * * @param clazz the class to create the unmarshaller for * @return the {@code Unmarshaller}// w w w. j av a2 s . c o m * @throws HttpMessageConversionException in case of JAXB errors */ protected final Unmarshaller createWrapperUnmarshaller(Class clazz) throws JAXBException { try { JAXBContext jaxbContext = getJaxbContext(clazz); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); unmarshaller.setProperty("com.sun.xml.bind.ObjectFactory", new ObjectFactoryWrapper()); return unmarshaller; } catch (JAXBException ex) { throw new HttpMessageConversionException( "Could not create Unmarshaller for class [" + clazz + "]: " + ex.getMessage(), ex); } }
From source file:com.netscape.cmstools.system.KRAConnectorAddCLI.java
public void execute(String[] args) throws Exception { // Always check for "--help" prior to parsing if (Arrays.asList(args).contains("--help")) { printHelp();/*from ww w . j ava 2 s.c om*/ return; } CommandLine cmd = parser.parse(options, args); String[] cmdArgs = cmd.getArgs(); if (cmdArgs.length != 0) { throw new Exception("Too many arguments specified."); } String kraHost = cmd.getOptionValue("host"); String kraPort = cmd.getOptionValue("port"); String inputFile = cmd.getOptionValue("input-file"); KRAConnectorClient kraConnectorClient = kraConnectorCLI.getKRAConnectorClient(); //check if connector exists boolean connectorExists = true; try { @SuppressWarnings("unused") KRAConnectorInfo info = kraConnectorClient.getConnectorInfo(); } catch (ConnectorNotFoundException e) { connectorExists = false; } if (inputFile != null) { if (connectorExists) { throw new Exception( "Cannot add new connector from file. " + "Delete the existing connector first"); } FileInputStream fis = new FileInputStream(inputFile); JAXBContext context = JAXBContext.newInstance(KRAConnectorInfo.class); Unmarshaller unmarshaller = context.createUnmarshaller(); KRAConnectorInfo info = (KRAConnectorInfo) unmarshaller.unmarshal(fis); kraConnectorClient.addConnector(info); MainCLI.printMessage("Added KRA connector"); } else { if (!connectorExists) { throw new Exception( "Cannot add new host to existing connector. " + "No connector currently exists"); } kraConnectorClient.addHost(kraHost, kraPort); MainCLI.printMessage("Added KRA host \"" + kraHost + ":" + kraPort + "\""); } }
From source file:org.jasig.portlet.blackboardvcportlet.dao.ws.impl.GlobalSettingsWSDaoTest.java
private BlackboardGetServerQuotasResponseCollection getServerQuotaMock() throws JAXBException { final JAXBContext context = JAXBContext.newInstance(BlackboardGetServerQuotasResponseCollection.class); final Unmarshaller unmarshaller = context.createUnmarshaller(); final BlackboardGetServerQuotasResponseCollection result = (BlackboardGetServerQuotasResponseCollection) unmarshaller .unmarshal(this.getClass().getResourceAsStream("/data/serverQuotaResponse.xml")); return result; }
From source file:org.apache.cxf.systest.jaxrs.JAXRSClientServerUserResourceAsteriskTest.java
private Chapter readChapter(InputStream is) throws Exception { JAXBContext c = JAXBContext.newInstance(new Class[] { Chapter.class }); Unmarshaller u = c.createUnmarshaller(); return (Chapter) u.unmarshal(is); }
From source file:org.jasig.portlet.blackboardvcportlet.dao.ws.impl.GlobalSettingsWSDaoTest.java
private BlackboardGetServerVersionResponseCollection getServerVersionsMock() throws JAXBException { final JAXBContext context = JAXBContext.newInstance(BlackboardGetServerVersionResponseCollection.class); final Unmarshaller unmarshaller = context.createUnmarshaller(); final BlackboardGetServerVersionResponseCollection result = (BlackboardGetServerVersionResponseCollection) unmarshaller .unmarshal(this.getClass().getResourceAsStream("/data/serverVersionsResponse.xml")); return result; }
From source file:in.gov.uidai.auth.aua.httpclient.BfdClient.java
private BfdRes parseBfdResponseXML(String xmlToParse) throws JAXBException { //Create an XMLReader to use with our filter try {/*from ww w .j a v a 2 s . co m*/ //Prepare JAXB objects JAXBContext jc = JAXBContext.newInstance(BfdRes.class); Unmarshaller u = jc.createUnmarshaller(); XMLReader reader; reader = XMLReaderFactory.createXMLReader(); //Create the filter (to add namespace) and set the xmlReader as its parent. NamespaceFilter inFilter = new NamespaceFilter( "http://www.uidai.gov.in/authentication/uid-bfd-response/1.0", true); inFilter.setParent(reader); //Prepare the input, in this case a java.io.File (output) InputSource is = new InputSource(new StringReader(xmlToParse)); //Create a SAXSource specifying the filter SAXSource source = new SAXSource(inFilter, is); //Do unmarshalling BfdRes res = u.unmarshal(source, BfdRes.class).getValue(); return res; } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:com.eventestimator.mvc.ContactCollectionController.java
@RequestMapping(value = "/json.j", method = RequestMethod.GET) protected ResponseEntity<Object> getContacts(Model model, HttpServletRequest request) throws Exception { HttpSession session = request.getSession(); String userName = (String) session.getAttribute("userName"); String accessToken = (String) session.getAttribute("accessToken"); String contactUrl = WS_URL_PREFIX + userName + "/contacts?access_token=" + accessToken; Feed contactSource = restTemplate.getForObject(contactUrl, Feed.class); List<Entry> contacts = contactSource.getEntries(); List<Contact> contactObjects = new ArrayList<Contact>(contacts.size()); for (Entry contact : contacts) { Link link = (Link) contact.getOtherLinks().get(0); String linkHref = link.getHref(); String contentXML = restTemplate.getForObject(WS_DOMAIN + linkHref + "?access_token=" + accessToken, String.class); // List<Content> contactContents = contactEntry.getBody().getContents(); // List<Content> contactContents = contactEntry.getContents(); ///*from w ww .j av a 2 s . c om*/ // Content contactContent = contactContents.get(0); // String contentXML = contactContent.getValue(); final SAXParserFactory sax = SAXParserFactory.newInstance(); sax.setNamespaceAware(false); final XMLReader reader; try { reader = sax.newSAXParser().getXMLReader(); } catch (SAXException e) { throw new RuntimeException(e); } InputSource is = new InputSource(new StringReader(contentXML)); SAXSource source = new SAXSource(reader, is); JAXBContext context = JAXBContext.newInstance(ContactEntry.class); javax.xml.bind.Unmarshaller unmarshaller = context.createUnmarshaller(); JAXBElement<ContactEntry> contactEntry = (JAXBElement<ContactEntry>) unmarshaller.unmarshal(source, ContactEntry.class); Contact contactObject = contactEntry.getValue().getContent().getContact(); contactObjects.add(contactObject); } ResponseEntity<Object> response = new ResponseEntity<Object>(contactObjects, HttpStatus.OK); return response; }
From source file:org.springframework.hateoas.VndErrorsMarshallingTest.java
@Before public void setUp() throws Exception { jackson2Mapper = new com.fasterxml.jackson.databind.ObjectMapper(); jackson2Mapper.registerModule(new Jackson2HalModule()); jackson2Mapper.setHandlerInstantiator(new Jackson2HalModule.HalHandlerInstantiator(relProvider, null)); jackson2Mapper.configure(SerializationFeature.INDENT_OUTPUT, true); JAXBContext context = JAXBContext.newInstance(VndErrors.class); marshaller = context.createMarshaller(); unmarshaller = context.createUnmarshaller(); VndError error = new VndError("42", "Validation failed!", // new Link("http://...", "describes"), new Link("http://...", "help")); errors = new VndErrors(error, error, error); }