* @param clazz the clazz
* @return the xml from object
* @throws JAXBException the JAXB exception
+ * @throws IOException
*/
- public <T> String getXmlFromObject(T clazz) throws JAXBException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- JAXBContext jc = JAXBContext.newInstance(clazz.getClass().getPackage().getName());
-
- Marshaller marshaller = jc.createMarshaller();
- marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
- marshaller.marshal(clazz, baos);
-
- return baos.toString();
+ public <T> String getXmlFromObject(T clazz) throws JAXBException, IOException {
+ try(ByteArrayOutputStream baos = new ByteArrayOutputStream()){
+ JAXBContext jc = JAXBContext.newInstance(clazz.getClass().getPackage().getName());
+
+ Marshaller marshaller = jc.createMarshaller();
+ marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+ marshaller.marshal(clazz, baos);
+ return baos.toString();
+ }
}
/**
try {
init();
} catch(Exception e) {
- logger.error( "Error initializing " + this.getClass());
+ logger.error( "Error initializing " + this.getClass(),e);
throw e;
}
pathSb.append(getDocumentHeader());
results.get(key).stream().filter((i) -> (i.getFrom().equals(xmlRootElementName) && (! i.isPrivateEdge() && i.getPreventDelete().equals("OUT")))).forEach((i) ->{ preventDelete.add(i.getTo().toUpperCase());} );
}
} catch(Exception e) {
- logger.debug("xmlRootElementName: "+xmlRootElementName+"\n"+e);
+ logger.debug("xmlRootElementName: "+xmlRootElementName+"\n",e);
}
try {
EdgeRuleQuery q1 = new EdgeRuleQuery.Builder(xmlRootElementName).version(v).toOnly().build();
results.get(key).stream().filter((i) -> (i.getTo().equals(xmlRootElementName) && (! i.isPrivateEdge() && i.getPreventDelete().equals("IN")))).forEach((i) ->{ preventDelete.add(i.getFrom().toUpperCase());} );
}
} catch(Exception e) {
- logger.debug("xmlRootElementName: "+xmlRootElementName+"\n"+e);
+ logger.debug("xmlRootElementName: "+xmlRootElementName+"\n",e);
}
if(preventDelete.size() > 0) {
prevent = xmlRootElementName.toUpperCase()+" cannot be deleted if related to "+String.join(",",preventDelete);
javaTypeDefinitions.put(xmlRootElementName, definitionsLocalSb.toString());
}
} catch (Exception e) {
- e.printStackTrace();
+ logger.error("Exception adding in javaTypeDefinitions",e);
}
if ( xmlRootElementName.equals("inventory") ) {
logger.trace("skip xmlRootElementName(2)="+xmlRootElementName);
try {
outfile.createNewFile();
} catch (IOException e) {
- logger.error( "Exception creating output file " + outfileName);
- e.printStackTrace();
+ logger.error( "Exception creating output file " + outfileName,e);
}
- BufferedWriter bw = null;
try {
Charset charset = Charset.forName("UTF-8");
Path path = Paths.get(outfileName);
- bw = Files.newBufferedWriter(path, charset);
- bw.write(fileContent);
- if ( bw != null ) {
- bw.close();
+ try(BufferedWriter bw = Files.newBufferedWriter(path, charset)){
+ bw.write(fileContent);
}
} catch ( IOException e) {
- logger.error( "Exception writing output file " + outfileName);
- e.printStackTrace();
+ logger.error( "Exception writing output file " + outfileName,e);
}
}
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import java.io.IOException;
import java.time.LocalDateTime;
import java.time.Month;
import java.util.ArrayList;
}
@Test
- public void testGetXmlFromObject() throws JAXBException {
+ public void testGetXmlFromObject() throws JAXBException, IOException {
NotificationEvent notificationEvent = new NotificationEvent();
notificationEvent.setCambriaPartition("partition");