use of com.thoughtworks.xstream.converters.ConversionException in project jmeter by apache.
the class JMeter method startGui.
/**
* Starts up JMeter in GUI mode
*/
private void startGui(String testFile) {
//NOSONAR
System.out.println("================================================================================");
//NOSONAR
System.out.println("Don't use GUI mode for load testing, only for Test creation and Test debugging !");
//NOSONAR
System.out.println("For load testing, use NON GUI Mode:");
//NOSONAR
System.out.println(" jmeter -n -t [jmx file] -l [results file] -e -o [Path to output folder]");
//NOSONAR
System.out.println("& adapt Java Heap to your test requirements:");
//NOSONAR
System.out.println(" Modify HEAP=\"-Xms512m -Xmx512m\" in the JMeter batch file");
//NOSONAR
System.out.println("================================================================================");
SplashScreen splash = new SplashScreen();
splash.showScreen();
String jMeterLaf = LookAndFeelCommand.getJMeterLaf();
try {
UIManager.setLookAndFeel(jMeterLaf);
} catch (Exception ex) {
log.warn("Could not set LAF to: {}", jMeterLaf, ex);
}
splash.setProgress(10);
JMeterUtils.applyHiDPIOnFonts();
PluginManager.install(this, true);
JMeterTreeModel treeModel = new JMeterTreeModel();
splash.setProgress(30);
JMeterTreeListener treeLis = new JMeterTreeListener(treeModel);
final ActionRouter instance = ActionRouter.getInstance();
instance.populateCommandMap();
splash.setProgress(60);
treeLis.setActionHandler(instance);
GuiPackage.initInstance(treeLis, treeModel);
splash.setProgress(80);
MainFrame main = new MainFrame(treeModel, treeLis);
splash.setProgress(100);
ComponentUtil.centerComponentInWindow(main, 80);
main.setVisible(true);
instance.actionPerformed(new ActionEvent(main, 1, ActionNames.ADD_ALL));
if (testFile != null) {
try {
File f = new File(testFile);
log.info("Loading file: {}", f);
FileServer.getFileServer().setBaseForScript(f);
HashTree tree = SaveService.loadTree(f);
GuiPackage.getInstance().setTestPlanFile(f.getAbsolutePath());
Load.insertLoadedTree(1, tree);
} catch (ConversionException e) {
log.error("Failure loading test file", e);
JMeterUtils.reportErrorToUser(SaveService.CEtoString(e));
} catch (Exception e) {
log.error("Failure loading test file", e);
JMeterUtils.reportErrorToUser(e.toString());
}
} else {
JTree jTree = GuiPackage.getInstance().getMainFrame().getTree();
TreePath path = jTree.getPathForRow(0);
jTree.setSelectionPath(path);
FocusRequester.requestFocus(jTree);
}
splash.setProgress(100);
splash.close();
}
use of com.thoughtworks.xstream.converters.ConversionException in project ddf by codice.
the class XStreamAttributeCopier method copyXml.
/**
* Copies the entire XML element {@code reader} is currently at into {@code writer} and returns
* a new reader ready to read the copied element. After the call, {@code reader} will be at the
* end of the element that was copied.
* <p>
* If {@code attributeMap} is provided, the attributes will be added to the copy.
*
* @param reader the reader currently at the XML element you want to copy
* @param writer the writer that the element will be copied into
* @param attributeMap the map of attribute names to values that will be added as attributes of
* the copy, may be null
* @return a new reader ready to read the copied element
* @throws ConversionException if a parser to use for the new reader can't be created
*/
public static HierarchicalStreamReader copyXml(HierarchicalStreamReader reader, StringWriter writer, Map<String, String> attributeMap) {
copyElementWithAttributes(reader, new CompactWriter(writer, new NoNameCoder()), attributeMap);
XmlPullParser parser;
try {
parser = XmlPullParserFactory.newInstance().newPullParser();
} catch (XmlPullParserException e) {
throw new ConversionException("Unable to create XmlPullParser, cannot parse XML.", e);
}
try {
// encoding will be used which will not always work
return new XppReader(new InputStreamReader(IOUtils.toInputStream(writer.toString(), StandardCharsets.UTF_8.name())), parser);
} catch (IOException e) {
LOGGER.debug("Unable create reader with UTF-8 encoding, Exception {}", e);
return new XppReader(new InputStreamReader(IOUtils.toInputStream(writer.toString())), parser);
}
}
use of com.thoughtworks.xstream.converters.ConversionException in project ddf by codice.
the class TransactionRequestConverter method getElementFromXml.
private <T> T getElementFromXml(String xml, Class<T> clazz) {
JAXBElement<T> root;
try {
JAXBContext jaxbContext = getJaxBContext();
XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();
xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
xmlInputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, false);
XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(new StringReader(xml));
root = jaxbContext.createUnmarshaller().unmarshal(xmlStreamReader, clazz);
} catch (JAXBException | XMLStreamException e) {
throw new ConversionException(e);
}
return root.getValue();
}
use of com.thoughtworks.xstream.converters.ConversionException in project hudson-2.x by hudson.
the class RobustReflectionConverter method doUnmarshal.
public Object doUnmarshal(final Object result, final HierarchicalStreamReader reader, final UnmarshallingContext context) {
final SeenFields seenFields = new SeenFields();
Iterator it = reader.getAttributeNames();
// Remember outermost Saveable encountered, for reporting below
if (result instanceof Saveable && context.get("Saveable") == null)
context.put("Saveable", result);
// Process attributes before recursing into child elements.
while (it.hasNext()) {
String attrAlias = (String) it.next();
String attrName = mapper.attributeForAlias(attrAlias);
Class classDefiningField = determineWhichClassDefinesField(reader);
boolean fieldExistsInClass = fieldDefinedInClass(result, attrName);
if (fieldExistsInClass) {
Field field = reflectionProvider.getField(result.getClass(), attrName);
SingleValueConverter converter = mapper.getConverterFromAttribute(field.getDeclaringClass(), attrName, field.getType());
Class type = field.getType();
if (converter == null) {
converter = mapper.getConverterFromItemType(type);
}
if (converter != null) {
Object value = converter.fromString(reader.getAttribute(attrAlias));
if (type.isPrimitive()) {
type = Primitives.box(type);
}
if (value != null && !type.isAssignableFrom(value.getClass())) {
throw new ConversionException("Cannot convert type " + value.getClass().getName() + " to type " + type.getName());
}
reflectionProvider.writeField(result, attrName, value, classDefiningField);
seenFields.add(classDefiningField, attrName);
}
}
}
Map implicitCollectionsForCurrentObject = null;
while (reader.hasMoreChildren()) {
reader.moveDown();
try {
String fieldName = mapper.realMember(result.getClass(), reader.getNodeName());
boolean implicitCollectionHasSameName = mapper.getImplicitCollectionDefForFieldName(result.getClass(), reader.getNodeName()) != null;
Class classDefiningField = determineWhichClassDefinesField(reader);
boolean fieldExistsInClass = !implicitCollectionHasSameName && fieldDefinedInClass(result, fieldName);
Class type = determineType(reader, fieldExistsInClass, result, fieldName, classDefiningField);
final Object value;
if (fieldExistsInClass) {
Field field = reflectionProvider.getField(result.getClass(), fieldName);
value = unmarshalField(context, result, type, field);
// TODO the reflection provider should have returned the proper field in first place ....
Class definedType = reflectionProvider.getFieldType(result, fieldName, classDefiningField);
if (!definedType.isPrimitive()) {
type = definedType;
}
} else {
value = context.convertAnother(result, type);
}
if (value != null && !type.isAssignableFrom(value.getClass())) {
LOGGER.warning("Cannot convert type " + value.getClass().getName() + " to type " + type.getName());
// behave as if we didn't see this element
} else {
if (fieldExistsInClass) {
reflectionProvider.writeField(result, fieldName, value, classDefiningField);
seenFields.add(classDefiningField, fieldName);
} else {
implicitCollectionsForCurrentObject = writeValueToImplicitCollection(context, value, implicitCollectionsForCurrentObject, result, fieldName);
}
}
} catch (NonExistentFieldException e) {
LOGGER.log(WARNING, "Skipping a non-existent field " + e.getFieldName());
addErrorInContext(context, e);
} catch (CannotResolveClassException e) {
LOGGER.log(WARNING, "Skipping a non-existent type " + e.getMessage());
addErrorInContext(context, e);
} catch (LinkageError e) {
LOGGER.log(WARNING, "Failed to resolve a type " + e.getMessage());
addErrorInContext(context, e);
}
reader.moveUp();
}
// Report any class/field errors in Saveable objects
if (context.get("ReadError") != null && context.get("Saveable") == result) {
OldDataMonitor.report((Saveable) result, (ArrayList<Throwable>) context.get("ReadError"));
context.put("ReadError", null);
}
return result;
}
use of com.thoughtworks.xstream.converters.ConversionException in project hudson-2.x by hudson.
the class RobustReflectionConverterTest method testIfWeNeedWorkaround.
public void testIfWeNeedWorkaround() {
try {
read(new XStream());
fail();
} catch (ConversionException e) {
// expected
assertTrue(e.getMessage().contains("z"));
}
}
Aggregations