List of usage examples for javax.xml.bind JAXBException getMessage
public String getMessage()
From source file:net.itransformers.idiscover.discoverylisteners.XmlTopologyDeviceLogger.java
public void handleDevice(String deviceName, RawDeviceData rawData, DiscoveredDeviceData discoveredDeviceData, Resource resource) {// ww w . jav a 2s.co m ByteArrayOutputStream graphMLOutputStream = new ByteArrayOutputStream(); ByteArrayOutputStream os = new ByteArrayOutputStream(); try { JaxbMarshalar.marshal(discoveredDeviceData, os, "DiscoveredDevice"); } catch (JAXBException e) { logger.error(e.getMessage(), e); } XsltTransformer transformer = new XsltTransformer(); try { transformer.transformXML(new ByteArrayInputStream(os.toByteArray()), xsltFileName, graphMLOutputStream, null, null); } catch (Exception e) { logger.error(e.getMessage(), e); } try { final String fileName = "node-" + deviceName + ".graphml"; // String fullFileName = path + File.separator + fileName; final File nodeFile = new File(deviceCentricPath, fileName); String graphml = null; try { graphml = new XmlFormatter().format(new String(graphMLOutputStream.toByteArray())); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } FileUtils.writeStringToFile(nodeFile, graphml); try { final File networkGraphml = new File(networkCentricPath + File.separator + "network.graphml"); if (networkGraphml.exists()) { Map<String, String> edgesTypes = new HashMap<String, String>(); edgesTypes.put("name", "string"); edgesTypes.put("method", "string"); edgesTypes.put("dataLink", "string"); edgesTypes.put("ipLink", "string"); edgesTypes.put("IPv4Forwarding", "string"); edgesTypes.put("IPv6Forwarding", "string"); edgesTypes.put("InterfaceNameA", "string"); edgesTypes.put("InterfaceNameB", "string"); edgesTypes.put("IPv4AddressA", "string"); edgesTypes.put("IPv4AddressB", "string"); edgesTypes.put("edgeTooltip", "string"); edgesTypes.put("diff", "string"); edgesTypes.put("diffs", "string"); edgesTypes.put("bgpAutonomousSystemA", "string"); edgesTypes.put("bgpAutonomousSystemB", "string"); Map<String, String> vertexTypes = new HashMap<String, String>(); vertexTypes.put("deviceModel", "string"); vertexTypes.put("deviceType", "string"); vertexTypes.put("nodeInfo", "string"); vertexTypes.put("hostname", "string"); vertexTypes.put("deviceStatus", "string"); vertexTypes.put("DiscoveredIPv4Address", "string"); vertexTypes.put("geoCoordinates", "string"); vertexTypes.put("SubnetPrefix", "string"); vertexTypes.put("site", "string"); vertexTypes.put("diff", "string"); vertexTypes.put("diffs", "string"); vertexTypes.put("diffs", "string"); vertexTypes.put("IPv6Forwarding", "string"); vertexTypes.put("IPv4Forwarding", "string"); vertexTypes.put("bgpLocalAS", "string"); Map<String, MergeConflictResolver> edgeConflictResolver = new HashMap<String, MergeConflictResolver>(); Map<String, MergeConflictResolver> nodeConflictResolver = new HashMap<String, MergeConflictResolver>(); edgeConflictResolver.put("method", new MergeConflictResolver() { @Override public Object resolveConflict(Object srcValue, Object targetValue) { // if (srcValue instanceof String && targetValue instanceof String) { String[] srcArray = ((String) srcValue).split(","); String[] targetArray = ((String) targetValue).split(","); String[] both = (String[]) ArrayUtils.addAll(srcArray, targetArray); Arrays.sort(both); LinkedHashSet<String> m = new LinkedHashSet<String>(); Collections.addAll(m, both); return StringUtils.join(m, ','); } }); new GrahmlMerge(nodeConflictResolver, edgeConflictResolver).merge(nodeFile, networkGraphml, networkGraphml, vertexTypes, edgesTypes, graphtType); } else { //networkGraphml.createNewFile(); FileUtils.writeStringToFile(networkGraphml, graphml); // new GrahmlMerge().merge(nodeFile, networkGraphml, networkGraphml); } //TODO remove when you have some time and do the diff in the correct way! // File networkGraphmls = new File(labelPath,graphtType+".graphmls"); // if (!networkGraphmls.exists()){ // FileWriter writer = new FileWriter(networkGraphmls); // writer.write("network.graphml\n"); // writer.close(); // } } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } } catch (IOException e) { e.printStackTrace(); } }
From source file:org.geosdi.geoplatform.connector.server.request.GPPostConnectorRequest.java
@Override public String getResponseAsString() throws ServerInternalFault, IOException, IllegalParameterFault { Writer writer = new StringWriter(); try {/* ww w .j a v a 2 s . co m*/ HttpResponse httpResponse = super.securityConnector.secure(this, this.getPostMethod()); HttpEntity responseEntity = httpResponse.getEntity(); if (responseEntity != null) { InputStream is = responseEntity.getContent(); char[] buffer = new char[1024]; Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); int n; while ((n = reader.read(buffer)) != -1) { writer.write(buffer, 0, n); } EntityUtils.consume(responseEntity); } else { throw new ServerInternalFault("Connector Server Error: Connection " + "problem"); } } catch (JAXBException ex) { logger.error("\n@@@@@@@@@@@@@@@@@@ JAXBException *** {} ***", ex.getMessage()); throw new ServerInternalFault("*** JAXBException ***"); } catch (ClientProtocolException ex) { logger.error("\n@@@@@@@@@@@@@@@@@@ ClientProtocolException *** {} ***", ex.getMessage()); throw new ServerInternalFault("*** ClientProtocolException ***"); } return writer.toString(); }
From source file:org.geosdi.geoplatform.connector.server.request.GPPostConnectorRequest.java
@Override public T getResponse() throws IllegalParameterFault, ServerInternalFault, IOException { T response = null;// w ww. j a va 2 s. c om try { HttpResponse httpResponse = super.securityConnector.secure(this, this.getPostMethod()); HttpEntity responseEntity = httpResponse.getEntity(); if (responseEntity != null) { InputStream is = responseEntity.getContent(); Unmarshaller unmarshaller = getUnmarshaller(); Object content = unmarshaller.unmarshal(is); if (!(content instanceof JAXBElement)) { // ExceptionReport logger.error("\n#############\n{}\n#############", content); throw new ServerInternalFault("Connector Server Error: incorrect responce"); } JAXBElement<T> elementType = (JAXBElement<T>) content; response = elementType.getValue(); EntityUtils.consume(responseEntity); } else { throw new ServerInternalFault("Connector Server Error: Connection " + "problem"); } } catch (JAXBException ex) { logger.error("\n@@@@@@@@@@@@@@@@@@ JAXBException *** {} ***", ex.getMessage()); throw new ServerInternalFault("*** JAXBException ***" + ex); } catch (ClientProtocolException ex) { logger.error("\n@@@@@@@@@@@@@@@@@@ ClientProtocolException *** {} ***", ex.getMessage()); throw new ServerInternalFault("*** ClientProtocolException ***"); } return response; }
From source file:com.cws.esolutions.security.listeners.SecurityServiceListener.java
/** * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent) *//*from w w w . j ava2 s .co m*/ public void contextInitialized(final ServletContextEvent sContextEvent) { final String methodName = SecurityServiceListener.CNAME + "#contextInitialized(final ServletContextEvent sContextEvent)"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("ServletContextEvent: {}", sContextEvent); } URL xmlURL = null; JAXBContext context = null; Unmarshaller marshaller = null; SecurityConfigurationData configData = null; final ServletContext sContext = sContextEvent.getServletContext(); final ClassLoader classLoader = SecurityServiceListener.class.getClassLoader(); if (DEBUG) { DEBUGGER.debug("ServletContext: {}", sContext); DEBUGGER.debug("ClassLoader: {}", classLoader); } try { if (sContext != null) { if (StringUtils.isBlank(SecurityServiceListener.INIT_SYSLOGGING_FILE)) { System.err.println("Logging configuration not found. No logging enabled !"); } else { DOMConfigurator.configure(Loader .getResource(sContext.getInitParameter(SecurityServiceListener.INIT_SYSLOGGING_FILE))); } if (StringUtils.isBlank(SecurityServiceListener.INIT_SYSCONFIG_FILE)) { xmlURL = classLoader .getResource(sContext.getInitParameter(SecurityServiceListener.INIT_SYSCONFIG_FILE)); } else { ERROR_RECORDER.error("System configuration not found. Shutting down !"); throw new SecurityServiceException( "System configuration file location not provided by application. Cannot continue."); } if (DEBUG) { DEBUGGER.debug("xmlURL: {}", xmlURL); } if (xmlURL != null) { context = JAXBContext.newInstance(SecurityConfigurationData.class); marshaller = context.createUnmarshaller(); configData = (SecurityConfigurationData) marshaller.unmarshal(xmlURL); SecurityServiceListener.svcBean.setConfigData(configData); Context initContext = new InitialContext(); Context envContext = (Context) initContext.lookup(SecurityServiceConstants.DS_CONTEXT); DAOInitializer.configureAndCreateAuthConnection( new FileInputStream(FileUtils.getFile(configData.getSecurityConfig().getAuthConfig())), false, SecurityServiceListener.svcBean); Map<String, DataSource> dsMap = new HashMap<String, DataSource>(); for (DataSourceManager mgr : configData.getResourceConfig().getDsManager()) { dsMap.put(mgr.getDsName(), (DataSource) envContext.lookup(mgr.getDataSource())); } SecurityServiceListener.svcBean.setDataSources(dsMap); } else { throw new SecurityServiceException("Unable to load configuration. Cannot continue."); } } else { throw new SecurityServiceException("Unable to load configuration. Cannot continue."); } } catch (NamingException nx) { ERROR_RECORDER.error(nx.getMessage(), nx); } catch (SecurityServiceException ssx) { ERROR_RECORDER.error(ssx.getMessage(), ssx); } catch (JAXBException jx) { ERROR_RECORDER.error(jx.getMessage(), jx); } catch (FileNotFoundException fnfx) { ERROR_RECORDER.error(fnfx.getMessage(), fnfx); } }
From source file:gov.hhs.fha.nhinc.lift.clientController.SocketClientManagerController.java
@Override public final void run() { while (true) { Socket socket = null;//from w w w . j a va 2 s . co m InputStream in = null; URI writtenFile = null; String errorMesg = null; LiftMessage mesg = null; try { socket = server.accept(); while (socket == null) { socket = server.accept(); } in = socket.getInputStream(); log.debug("Server " + server.getInetAddress() + " connecting to socket " + socket.getInetAddress() + ": " + socket.getPort()); InterProcessSocketProtocol processSocket = new InterProcessSocketProtocol(); String message = processSocket.readData(in); log.info("SocketClientManagerController received message: " + message); if (message != null) { mesg = (LiftMessage) JaxbUtil.unmarshalFromReader(new StringReader(message), LiftMessage.class); System.out.println("Setting " + mesg.getRequest().getRequest() + " to in progress"); mesgState.add(mesg.getRequest().getRequest()); writtenFile = manager.startClient(mesg, this); } } catch (JAXBException ex) { errorMesg = "Client is unable to process LiftMessage " + ex.getMessage(); log.error(errorMesg); } catch (IOException e) { errorMesg = "Client is unable to process incoming socket information " + e.getMessage(); log.error(errorMesg); } finally { if (socket != null) { try { log.debug("Closing socket " + socket); socket.close(); } catch (IOException ex) { log.warn("Unable to close socket " + socket); } } if (writtenFile != null) { reportSuccess(mesg.getRequest().getRequest(), writtenFile); } else { if (mesg != null && mesg.getRequest() != null && mesg.getRequest().getRequest() != null) { reportFailure(mesg.getRequest().getRequest(), errorMesg); } else { reportFailure(null, errorMesg); } } } } }
From source file:org.jasig.portlet.courses.dao.xml.Jaxb2CourseSummaryHttpMessageConverter.java
/** * Creates a new {@link Marshaller} for the given class. * * @param clazz the class to create the marshaller for * @return the {@code Marshaller}/*from w w w .ja va 2s. c o m*/ * @throws HttpMessageConversionException in case of JAXB errors */ protected final Marshaller createWrapperMarshaller(Class clazz) { try { JAXBContext jaxbContext = getJaxbContext(clazz); return jaxbContext.createMarshaller(); } catch (JAXBException ex) { throw new HttpMessageConversionException( "Could not create Marshaller for class [" + clazz + "]: " + ex.getMessage(), ex); } }
From source file:hermes.browser.dialog.DestinationPropertyConfigPanel.java
public void doOK() { if (beanPropertyPanel != null) { log.debug("config=" + config); beanPropertyPanel.doOK();/* w ww. j av a 2 s . c o m*/ if (beanPropertyPanel.getChanges().size() > 0) { if (config.getProperties() == null) { // @@TODO Fix. config.setProperties(new PropertySetConfig()); } try { HermesBrowser.getConfigDAO().updatePropertySet(config.getProperties(), beanPropertyPanel.getChanges()); } catch (JAXBException e) { log.error(e.getMessage(), e); } } } for (Iterator iter = onOK.iterator(); iter.hasNext();) { Runnable r = (Runnable) iter.next(); r.run(); } }
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}/*from www . j a va 2s . c om*/ * @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:hermes.browser.dialog.HermesAdminFactoryConfigPanel.java
public void updateModel() { if (propertyTableModel != null && config != null) { try {/*from w ww. j a v a 2 s. c om*/ config.setClassName( HermesBrowser.getConfigDAO().getAdminClassForPlugIn(afCombo.getSelectedItem().toString())); config.getProperties().getProperty().clear(); config.getProperties().getProperty().addAll(propertyTableModel.getProperties()); } catch (JAXBException e) { log.error(e.getMessage(), e); } } }
From source file:com.jaspersoft.jasperserver.rest.services.RESTPermission.java
private String generatePermissionUsingJaxb(List<ObjectPermission> permissions) { try {//from w w w . ja va 2s . c om StringWriter sw = new StringWriter(); JAXBList<ObjectPermission> lst; lst = new JAXBList<ObjectPermission>(permissions); Marshaller m = restUtils.getMarshaller(JAXBList.class, ObjectPermissionImpl.class, UserImpl.class, RoleImpl.class); m.marshal(lst, sw); if (log.isDebugEnabled()) { log.debug("finished marshaling permissions: " + lst.size()); } return sw.toString(); } catch (JAXBException e) { throw new ServiceException(e.getMessage()); } }