List of usage examples for javax.xml.bind JAXBContext createUnmarshaller
public abstract Unmarshaller createUnmarshaller() throws JAXBException;
From source file:gov.nih.nci.cacis.sa.mirthconnect.SemanticAdapterServerSystemTest.java
@Test public void invoke() throws Exception { InputStream sampleMessageIS = FileUtils .openInputStream(new File(getClass().getClassLoader().getResource("SARequestSample.xml").toURI())); JAXBContext jc = JAXBContext.newInstance(CaCISRequest.class); final CaCISRequest request = (CaCISRequest) jc.createUnmarshaller().unmarshal(sampleMessageIS); semanticAdapter.acceptSource(request); }
From source file:org.fcrepo.integration.auth.oauth.api.TestBinding.java
@Test public void testBinding() throws JAXBException { LOGGER.trace("Executing testBinding()"); final JAXBContext context = JAXBContext.newInstance(WebAppConfig.class); final Unmarshaller u = context.createUnmarshaller(); final WebAppConfig o = (WebAppConfig) u.unmarshal(getClass().getResourceAsStream("/web.xml")); Assert.assertEquals("Fedora-on-ModeShape", o.displayName()); Assert.assertTrue(o.contextParams()// ww w .ja va 2 s.c o m .contains(new ContextParam("contextConfigLocation", "classpath:spring-test/rest.xml; " + "classpath:spring-test/repo.xml; " + "classpath:spring-test/security.xml"))); Assert.assertTrue(o.listeners() .contains(new Listener(null, "org.springframework.web.context.ContextLoaderListener"))); final ServletMapping sm = o.servletMappings("jersey-servlet").iterator().next(); Assert.assertNotNull(sm); Assert.assertEquals("/*", sm.urlPattern()); FilterMapping fm = o.filterMappings("TokenFilter").iterator().next(); Assert.assertNotNull(fm); Assert.assertEquals("/token", fm.urlPattern()); fm = o.filterMappings("OpFilter").iterator().next(); Assert.assertNotNull(fm); Assert.assertEquals("/rest/objects/authenticated/*", fm.urlPattern()); }
From source file:org.fcrepo.auth.oauth.integration.api.TestBinding.java
@Test public void testBinding() throws JAXBException { LOGGER.trace("Executing testBinding()"); final JAXBContext context = JAXBContext.newInstance(WebAppConfig.class); final Unmarshaller u = context.createUnmarshaller(); final WebAppConfig o = (WebAppConfig) u.unmarshal(getClass().getResourceAsStream("/web.xml")); assertEquals("Fedora-on-ModeShape", o.displayName()); assertTrue(o.contextParams()/* w ww.jav a 2 s.co m*/ .contains(new ContextParam("contextConfigLocation", "classpath:spring-test/rest.xml; " + "classpath:spring-test/repo.xml; " + "classpath:spring-test/security.xml"))); assertTrue(o.listeners() .contains(new Listener(null, "org.springframework.web.context.ContextLoaderListener"))); final ServletMapping sm = o.servletMappings("jersey-servlet").iterator().next(); assertNotNull(sm); assertEquals("/*", sm.urlPattern()); FilterMapping fm = o.filterMappings("TokenFilter").iterator().next(); assertNotNull(fm); assertEquals("/token", fm.urlPattern()); fm = o.filterMappings("OpFilter").iterator().next(); assertNotNull(fm); assertEquals("/rest/objects/authenticated/*", fm.urlPattern()); }
From source file:se.inera.intyg.intygstjanst.web.service.impl.SendMessageToCareServiceImplTest.java
private SendMessageToCare loadFromFile(String fileName) throws Exception { JAXBContext jaxbContext = JAXBContext.newInstance(SendMessageToCareType.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); SendMessageToCareType sendMessageToCareType = unmarshaller .unmarshal(new StreamSource(new ClassPathResource(fileName).getInputStream()), SendMessageToCareType.class) .getValue();/*ww w.j a v a 2 s . c o m*/ return new SendMessageToCareConverter().convertSendMessageToCare(sendMessageToCareType); }
From source file:org.vertx.java.http.eventbusbridge.unit.EventBusBridgeRequestTest.java
@Test public void testUnmarshallingFromXml() throws JAXBException, IOException { JAXBContext jaxbContext = JAXBContext.newInstance(EventBusBridgeRequest.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); InputStream input = getClass().getResourceAsStream("/unit/test-request.xml"); EventBusBridgeRequest request = (EventBusBridgeRequest) jaxbUnmarshaller.unmarshal(input); assertEquals("testaddress", request.getAddress()); assertEquals(Base64.decodeAsString("SGVsbG8gV29ybGQ="), new String(request.getMessage())); assertEquals("http://www.test.com/response", request.getResponseUrl()); assertEquals("String", request.getEventBusMessageType().toString()); assertEquals("application/xml", request.getResponseMediaType().toString()); }
From source file:fr.cls.atoll.motu.processor.wps.TestServiceMetadata.java
public static void testLoadOGCServiceMetadata() { // String xmlFile = // "J:/dev/atoll-v2/atoll-motu/atoll-motu-processor/src/test/resources/xml/TestServiceMetadata.xml"; String xmlFile = "C:/Documents and Settings/dearith/Mes documents/Atoll/SchemaIso/TestServiceMetadataOK.xml"; String schemaPath = "schema/iso19139"; try {//from w w w . ja v a2s. c o m List<String> errors = validateServiceMetadataFromString(xmlFile, schemaPath); if (errors.size() > 0) { StringBuffer stringBuffer = new StringBuffer(); for (String str : errors) { stringBuffer.append(str); stringBuffer.append("\n"); } throw new MotuException(String.format("ERROR - XML file '%s' is not valid - See errors below:\n%s", xmlFile, stringBuffer.toString())); } else { System.out.println(String.format("XML file '%s' is valid", xmlFile)); } } catch (MotuException e) { // TODO Auto-generated catch block e.printStackTrace(); } InputStream in = null; try { in = Organizer.getUriAsInputStream(xmlFile); } catch (MotuException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } JAXBContext jc = null; try { // jc = JAXBContext.newInstance("org.isotc211.iso19139.d_2006_05_04.srv"); // jc = JAXBContext.newInstance("org.isotc211.iso19139.d_2006_05_04.srv"); jc = JAXBContext .newInstance(new Class[] { org.isotc211.iso19139.d_2006_05_04.srv.ObjectFactory.class }); Unmarshaller unmarshaller = jc.createUnmarshaller(); Source srcFile = new StreamSource(xmlFile); JAXBElement<?> element = (JAXBElement<?>) unmarshaller.unmarshal(srcFile); // JAXBElement<?> element = (JAXBElement<?>) unmarshaller.unmarshal(in); SVServiceIdentificationType serviceIdentificationType = (SVServiceIdentificationType) element .getValue(); // serviceIdentificationType = (SVServiceIdentificationType) unmarshaller.unmarshal(in); System.out.println(serviceIdentificationType.toString()); List<SVOperationMetadataPropertyType> operationMetadataPropertyTypeList = serviceIdentificationType .getContainsOperations(); for (SVOperationMetadataPropertyType operationMetadataPropertyType : operationMetadataPropertyTypeList) { SVOperationMetadataType operationMetadataType = operationMetadataPropertyType .getSVOperationMetadata(); System.out.println("---------------------------------------------"); if (operationMetadataType == null) { continue; } System.out.println(operationMetadataType.getOperationName().getCharacterString().getValue()); System.out.println(operationMetadataType.getInvocationName().getCharacterString().getValue()); System.out.println(operationMetadataType.getOperationDescription().getCharacterString().getValue()); CIOnlineResourcePropertyType onlineResourcePropertyType = operationMetadataType.getConnectPoint() .get(0); if (onlineResourcePropertyType != null) { System.out.println(operationMetadataType.getConnectPoint().get(0).getCIOnlineResource() .getLinkage().getURL()); } List<SVParameterPropertyType> parameterPropertyTypeList = operationMetadataType.getParameters(); for (SVParameterPropertyType parameterPropertyType : parameterPropertyTypeList) { SVParameterType parameterType = parameterPropertyType.getSVParameter(); if (parameterType.getName().getAName().getCharacterString() != null) { System.out.println(parameterType.getName().getAName().getCharacterString().getValue()); } else { System.out.println("WARNING - A parameter has no name"); } if (parameterType.getDescription() != null) { if (parameterType.getDescription().getCharacterString() != null) { System.out.println(parameterType.getDescription().getCharacterString().getValue()); } else { System.out.println("WARNING - A parameter has no description"); } } else { System.out.println("WARNING - A parameter has no description"); } } } FileWriter writer = new FileWriter("c:/tempVFS/test.xml"); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(element, writer); writer.flush(); writer.close(); System.out.println("End testLoadOGCServiceMetadata"); } catch (JAXBException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.wso2telco.config.ConfigLoader.java
/** * Inits the claims config.// w w w . j a v a 2 s . c om * * @return the scope configs * @throws JAXBException the JAXB exception */ private ScopeConfigs initClaimsConfig() throws JAXBException { Unmarshaller um = null; ScopeConfigs userClaims = null; String configPath = CarbonUtils.getCarbonConfigDirPath() + File.separator + "scope-config.xml"; File file = new File(configPath); try { JAXBContext ctx = JAXBContext.newInstance(ScopeConfigs.class); um = ctx.createUnmarshaller(); userClaims = (ScopeConfigs) um.unmarshal(file); } catch (JAXBException e) { throw new JAXBException("Error unmarshalling file :" + configPath); } return userClaims; }
From source file:org.jasig.portlet.campuslife.athletics.dao.AthleticsDaoMockImpl.java
@Override public void afterPropertiesSet() throws Exception { try {/*from w w w . j av a 2s. c o m*/ JAXBContext jaxbContext = JAXBContext.newInstance(AthleticsFeed.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); this.feed = (AthleticsFeed) unmarshaller.unmarshal(mockData.getInputStream()); } catch (IOException e) { log.error("Failed to read mock data", e); } catch (JAXBException e) { log.error("Failed to unmarshall mock data", e); } }
From source file:com.photon.phresco.plugins.util.WarConfigProcessor.java
public WarConfigProcessor(File configFile) throws JAXBException, IOException { if (configFile.exists()) { JAXBContext jaxbContext = JAXBContext.newInstance(Assembly.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); assembly = (Assembly) jaxbUnmarshaller.unmarshal(configFile); } else {//from ww w .j a va 2 s .c o m configFile.createNewFile(); assembly = new Assembly(); } file = configFile; }
From source file:com.wso2telco.core.config.ConfigLoader.java
/** * Inits the loa config./*from www. j a v a 2 s . c om*/ * * @return the LOA config * @throws JAXBException the JAXB exception */ private LOAConfig initLoaConfig() throws JAXBException { String configPath = CarbonUtils.getCarbonConfigDirPath() + File.separator + "LOA.xml"; File file = new File(configPath); JAXBContext ctx = JAXBContext.newInstance(LOAConfig.class); Unmarshaller um = ctx.createUnmarshaller(); return (LOAConfig) um.unmarshal(file); }