List of usage examples for javax.xml.bind JAXBContext createUnmarshaller
public abstract Unmarshaller createUnmarshaller() throws JAXBException;
From source file:esg.node.components.registry.IdpWhitelistGleaner.java
public synchronized IdpWhitelistGleaner loadMyIdpWhitelist() { log.info("Loading my IDP Whitelist info from " + idpWhitelistPath + idpWhitelistFile); try {/*from ww w. j a v a2 s . c om*/ JAXBContext jc = JAXBContext.newInstance(IdpWhitelist.class); Unmarshaller u = jc.createUnmarshaller(); JAXBElement<IdpWhitelist> root = u .unmarshal(new StreamSource(new File(idpWhitelistPath + idpWhitelistFile)), IdpWhitelist.class); idps = root.getValue(); } catch (Exception e) { log.error(e); } return this; }
From source file:esg.node.components.registry.LasSistersGleaner.java
public LasServers createLasServersFromString(String lasServersContentString) { log.info("Loading my LAS LasServers info from \n" + lasServersContentString + "\n"); LasServers fromContentLasServers = null; try {/*from w w w . j a v a 2s . c o m*/ JAXBContext jc = JAXBContext.newInstance(LasServers.class); Unmarshaller u = jc.createUnmarshaller(); JAXBElement<LasServers> root = u.unmarshal(new StreamSource(new StringReader(lasServersContentString)), LasServers.class); fromContentLasServers = root.getValue(); } catch (Exception e) { log.error(e); } return fromContentLasServers; }
From source file:zerogame.info.javapay.web.MMIAPApiController.java
@RequestMapping(value = "mmiap", method = RequestMethod.POST, consumes = "application/xml") @ResponseBody/*w w w. j ava 2 s . c o m*/ protected SyncAppOrderResp mmiap(@RequestBody String resultString, HttpServletRequest request, HttpServletResponse response, Map<String, Object> model) throws Exception { if (null == resultString || "".equals(resultString)) { response.setStatus(400); return null; } JAXBContext context = JAXBContext.newInstance(SyncAppOrderReq.class); Unmarshaller unmarshaller = context.createUnmarshaller(); SyncAppOrderReq result = (SyncAppOrderReq) unmarshaller .unmarshal(new ByteArrayInputStream(resultString.getBytes())); logger.info(String.format( "cmcc pay order MsgType=%s, Version=%s,OrderID=%s,CheckID=%s,TradeID=%s,Price=%s,ActionTime=%s," + "ActionID=%s,MSISDN=%s,FeeMSISDN=%s,AppID=%s,ProgramID=%s,PayCode=%s,TotalPrice=%s,SubsNumb=%s,SubsSeq=%s," + "ChannelID=%s,ExData=%s", result.getMsgType(), result.getVersion(), result.getOrderID(), result.getCheckID(), result.getTradeID(), result.getPrice(), result.getActionTime(), result.getActionID(), result.getMSISDN(), result.getFeeMSISDN(), result.getAppID(), result.getProgramID(), result.getPayCode(), result.getTotalPrice(), result.getSubsNumb(), result.getSubsSeq(), result.getChannelID(), result.getExData())); //log.info(JSONObject.fromObject(result).toString()); SyncAppOrderResp syncAppOrderResp = new SyncAppOrderResp(); syncAppOrderResp.setMsgType("SyncAppOrderResp"); syncAppOrderResp.setVersion("1.0.0"); String[] billNos = result.getExData().split("-"); String accountId = billNos[0]; String goodId = billNos[1]; Player player = userDao.getPlayer(CHANNEL_CMCC, accountId, "1"); if (player == null) { logger.warn("no user"); syncAppOrderResp.sethRet(1); return syncAppOrderResp; } PayOrder payorder = addPayOrder(player.getUin(), accountId, result.getOrderID(), goodId, Integer.valueOf(Integer.valueOf(result.getPrice()) / 100), CHANNEL_CMCC, Integer.valueOf("1"), PAY_ORDER_TYPE_COMMON, 0, player.getLevel(), player.getVip()); if (payorder == null) { logger.warn("add payorder fail!"); syncAppOrderResp.sethRet(1); return syncAppOrderResp; } MultiKeyCommands jedis = jedisPool.getResource(); jedis.publish("tap_hero_1_1", "{\"type\":101,\"uin\":\"" + String.valueOf(player.getUin()) + "\"}"); jedisPool.returnResource(jedis); syncAppOrderResp.sethRet(0); return syncAppOrderResp; }
From source file:esg.node.components.registry.AzsWhitelistGleaner.java
public AzsWhitelist createAzsWhitelistFromString(String azsWhitelistContentString) { log.info("Loading my AZS Whitelist info from \n" + azsWhitelistContentString + "\n"); AzsWhitelist fromContentAzsWhitelist = null; try {// w w w . j a va2s .c om JAXBContext jc = JAXBContext.newInstance(AzsWhitelist.class); Unmarshaller u = jc.createUnmarshaller(); JAXBElement<AzsWhitelist> root = u .unmarshal(new StreamSource(new StringReader(azsWhitelistContentString)), AzsWhitelist.class); fromContentAzsWhitelist = root.getValue(); } catch (Exception e) { log.error(e); } return fromContentAzsWhitelist; }
From source file:esg.node.components.registry.IdpWhitelistGleaner.java
public IdpWhitelist createIdpWhitelistFromString(String idpWhitelistContentString) { log.info("Loading my IDP Whitelist info from \n" + idpWhitelistContentString + "\n"); IdpWhitelist fromContentIdpWhitelist = null; try {//from ww w . j a va2s.co m JAXBContext jc = JAXBContext.newInstance(IdpWhitelist.class); Unmarshaller u = jc.createUnmarshaller(); JAXBElement<IdpWhitelist> root = u .unmarshal(new StreamSource(new StringReader(idpWhitelistContentString)), IdpWhitelist.class); fromContentIdpWhitelist = root.getValue(); } catch (Exception e) { log.error(e); } return fromContentIdpWhitelist; }
From source file:com.github.jrrdev.mantisbtsync.core.common.auth.PortalAuthBuilder.java
/** * Build the portal authentication manager from an XML file * describing the sequence of requests to be sent. * * @param filepath/*from w w w. j a v a 2s .co m*/ * File path of the XML file. The file is loaded through Spring resource loader, so * the file path can contain definition like "classpath:" * @return the portal authentication manager * @throws JAXBException * If an error occurs during the XML unmarshalling * @throws IOException * if the resource cannot be resolved as absolute file path, i.e. if the resource is * not available in a file system */ public PortalAuthManager buildAuthManager(final String filepath) throws JAXBException, IOException { final PortalAuthManager mgr = new PortalAuthManager(); if (filepath != null && !filepath.isEmpty()) { if (LOGGER.isInfoEnabled()) { LOGGER.info("Loading portal authentication configuration from file : " + filepath); } final File file = resourceLoader.getResource(filepath).getFile(); if (file.exists() && file.isFile() && file.canRead()) { final JAXBContext jaxbContext = JAXBContext.newInstance(AuthSequenceBean.class); final Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); final AuthSequenceBean sequence = (AuthSequenceBean) jaxbUnmarshaller.unmarshal(file); if (sequence != null) { mgr.setFirstRequest(buildRequest(sequence.getFirstRequest())); } if (LOGGER.isInfoEnabled()) { LOGGER.info("Portal authentication configuration loaded"); } } else { if (LOGGER.isErrorEnabled()) { LOGGER.error( "Portal authentication configuration loading failed, file may not exists or can't be read"); throw new IOException( "Portal authentication configuration loading failed, file may not exists or can't be read : " + filepath); } } } else if (LOGGER.isInfoEnabled()) { LOGGER.info("No portal authentication configuration file specified"); } return mgr; }
From source file:com.dalendev.meteotndata.servlet.UpdateStationDataServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// w w w. j a va 2 s. c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { InputStream inputStream = request.getInputStream(); ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream(); int length; byte[] buffer = new byte[1024]; while ((length = inputStream.read(buffer)) >= 0) { byteArrayStream.write(buffer, 0, length); } if (byteArrayStream.size() > 0) { Station station = SerializationUtils.deserialize(byteArrayStream.toByteArray()); Logger.getLogger(UpdateStationDataServlet.class.getName()).log(Level.INFO, station.getCode()); JAXBContext jc; try { jc = JAXBContext.newInstance(MeasurementList.class); Unmarshaller u = jc.createUnmarshaller(); URL url = new URL( "http://dati.meteotrentino.it/service.asmx/ultimiDatiStazione?codice=" + station.getCode()); StreamSource src = new StreamSource(url.openStream()); JAXBElement je = u.unmarshal(src, MeasurementList.class); MeasurementList measurementList = (MeasurementList) je.getValue(); MeasurmentSamplerService mss = new MeasurmentSamplerService(); mss.mergeMeasurment(station, measurementList); List<Measurement> sampledList = mss.getSampledMeasurementList(); MeasurementDAO.storeStation(sampledList); if (sampledList.size() > 0) { Measurement lastMeasurement = sampledList.get(sampledList.size() - 1); station.setLastUpdate(lastMeasurement.getTimestamp()); StationDAO.storeStation(station); } Logger.getLogger(UpdateStationDataServlet.class.getName()).log(Level.INFO, "Station {0} has {1} new measurements", new Object[] { station.getCode(), sampledList.size() }); } catch (JAXBException ex) { Logger.getLogger(UpdateStationDataServlet.class.getName()).log(Level.SEVERE, null, ex); } response.setStatus(200); } else { Logger.getLogger(UpdateStationDataServlet.class.getName()).log(Level.INFO, "Cannot retrieve Station's serialization"); } }
From source file:org.jasig.portlet.degreeprogress.dao.mock.MockDegreeProgressDaoImpl.java
@Override public void afterPropertiesSet() throws Exception { try {// w ww. j ava2 s .com JAXBContext jaxbContext = JAXBContext .newInstance(org.jasig.portlet.degreeprogress.model.xml.DegreeProgressReport.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); this.report = (DegreeProgressReport) unmarshaller.unmarshal(mockData.getInputStream()); for (DegreeRequirementSection section : report.getDegreeRequirementSections()) { for (JAXBElement<? extends GeneralRequirementType> requirement : section.getGeneralRequirements()) { GeneralRequirementType req = requirement.getValue(); if (req instanceof GpaRequirement) { section.setRequiredGpa(((GpaRequirement) req).getRequiredGpa()); } } for (CourseRequirement req : section.getCourseRequirements()) { for (Course course : req.getCourses()) { StudentCourseRegistration registration = new StudentCourseRegistration(); registration.setCredits(course.getCredits()); registration.setSource(course.getSource()); registration.setSemester(course.getSemester()); registration.setCourse(course); Grade grade = new Grade(); grade.setCode(course.getGrade().getCode()); registration.setGrade(grade); req.getRegistrations().add(registration); } } this.report.addSection(section); } } 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:org.jasig.portlet.announcements.Importer.java
private void importTopics() { try {/*from www . j a va 2 s .com*/ JAXBContext jc = JAXBContext.newInstance(Topic.class); Unmarshaller unmarshaller = jc.createUnmarshaller(); File[] files = dataDirectory.listFiles(new TopicImportFileFilter()); if (files == null) { errors.add("Directory " + dataDirectory + " is not a valid directory"); } else { for (File f : files) { log.info("Processing file " + f.toString()); StreamSource xmlFile = new StreamSource(f.getAbsoluteFile()); try { JAXBElement<Topic> je1 = unmarshaller.unmarshal(xmlFile, Topic.class); Topic topic = je1.getValue(); if (StringUtils.isBlank(topic.getTitle())) { String msg = "Error parsing file " + f.toString() + "; did not get valid record:\n" + topic.toString(); log.error(msg); errors.add(msg); } else { announcementService.addOrSaveTopic(topic); log.info("Successfully imported topic '" + topic.getTitle() + "'"); } } catch (JAXBException e) { String msg = "JAXB exception " + e.getCause().getMessage() + " processing file " + f.toString(); log.error(msg, e); errors.add(msg + ". See stack trace"); } catch (HibernateException e) { String msg = "Hibernate exception " + e.getCause().getMessage() + " processing file " + f.toString(); log.error(msg, e); errors.add(msg + ". See stack trace"); } } } } catch (JAXBException e) { String msg = "Fatal JAXBException in importTopics - no topics imported"; log.fatal(msg, e); errors.add(msg + ". See stack trace"); } }
From source file:gov.nih.nci.cacis.ip.mirthconnect.CanonicalModelProcessorMCIntegrationTest.java
@Test public void invokeJaxWS() throws Exception { final JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.setServiceClass(CanonicalModelProcessorPortType.class); // specify the URL. We are using the in memory test container factory.setAddress(ADDRESS);/*from www .ja va 2s . c o m*/ final JAXBContext jc = JAXBContext.newInstance(CaCISRequest.class); final InputStream is = getClass().getClassLoader().getResourceAsStream("CMP_valid_CR.xml"); final CaCISRequest request = (CaCISRequest) jc.createUnmarshaller().unmarshal(is); final CanonicalModelProcessorPortType client = (CanonicalModelProcessorPortType) factory.create(); client.acceptCanonical(request); }