I am using the library com.thoughtworks.xstream:xstream:1.4.5 to transfer Java object between two machines.
The first one is running Windows 8.1 with Java Hotspot Client VM 1.7.0_51
The second one is running Ubuntu Linux 12.04 with Java HotSpot 64bit Server VM 1.7.0_51
I am transfering a TestNG testcase from the Windows machine to the Linux machine thus requiring XStream for deserialization. When a result is returned from Linux to Windows there is a problem deserializing the XML on the Windows machine.
Obviously the java.lang.UNIX ** classes are not available on the Windows JVM. How do I suppress this exception. These classes are not required for further processing, but could be ignored.
com.thoughtworks.xstream.converters.ConversionException: java.lang.UNIXProcess$ProcessPipeInputStream : java.lang.UNIXProcess$ProcessPipeInputStream
---- Debugging information ----
message : java.lang.UNIXProcess$ProcessPipeInputStream
cause-exception : com.thoughtworks.xstream.mapper.CannotResolveClassException
cause-message : java.lang.UNIXProcess$ProcessPipeInputStream
class : org.apache.commons.exec.StreamPumper
required-type : org.apache.commons.exec.StreamPumper
converter-type : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path : /org.testng.internal.TestResult/m_testClass/m_beforeTestMethods/org.testng.internal.ConfigurationMethod/m_instance/driver/executor/connection/process/process/process/executor/streamHandler/outputThread/target/is
line number : 107
class[1] : java.lang.Thread
class[2] : org.apache.commons.exec.PumpStreamHandler
class[3] : org.apache.commons.exec.DefaultExecutor
class[4] : org.openqa.selenium.os.UnixProcess
class[5] : org.openqa.selenium.os.CommandLine
class[6] : org.openqa.selenium.firefox.FirefoxBinary
class[7] : org.openqa.selenium.firefox.internal.NewProfileExtensionConnection
class[8] : org.openqa.selenium.firefox.FirefoxDriver$LazyCommandExecutor
class[9] : org.openqa.selenium.firefox.FirefoxDriver
class[10] : my.work.selenium.MySeleniumTest
class[11] : org.testng.internal.ConfigurationMethod
class[12] : [Lorg.testng.ITestNGMethod;
converter-type[1] : com.thoughtworks.xstream.converters.collections.ArrayConverter
class[13] : org.testng.TestClass
class[14] : org.testng.internal.TestResult
version : 1.4.5
-------------------------------
I found the solution after some further research...
XStream allow to intercept the (un-)marshalling processes by adding converter. Hence I registered the following converter which stop (un-)marshalling as soon as a FirefoxDriver class is identified.
import org.openqa.selenium.firefox.FirefoxDriver;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
public class CutoffConverter implements Converter{
#SuppressWarnings("unchecked")
public boolean canConvert(Class type) {
return type.equals(FirefoxDriver.class);
}
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
}
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
return null;
}
}
Registering it at the XStream instance is simple:
XStream xstream = new XStream();
xstream.registerConverter(new CutoffConverter());
Maybe someone finds this helpful.
Related
I am launching a model that was created with an old version of repast (RepastSimphony 1.2.0) and I am trying to run it an the latest version of Repast.
I have imported manually the scenarios files to the best of my abilities (I am a beginner with Repast).
Now, when I launch the model in Repast, it has en error because it cannot find a certain file/library/module (I am unsure).
Now, I am not sure whether this is a Repast internal library or some piece of code that I should have been given and that is missing...
Any insight about this error will be welcome !
The error is this one:
WARN [AWT-EventQueue-0] 13:20:38,158 ObjectActionLoader - Error loading information from data. Continuing with model loading.
com.thoughtworks.xstream.converters.ConversionException: repast.score.impl.SGeographyImpl : repast.score.impl.SGeographyImpl
---- Debugging information ----
message : repast.score.impl.SGeographyImpl
cause-exception : com.thoughtworks.xstream.mapper.CannotResolveClassException
cause-message : repast.score.impl.SGeographyImpl
class : java.util.ArrayList
required-type : java.util.ArrayList
converter-type : com.thoughtworks.xstream.converters.collections.CollectionConverter
path : /repast.simphony.visualization.engine.DefaultDisplayDescriptor/projections/repast.score.impl.SGeographyImpl
line number : 61
class[1] : repast.simphony.visualization.engine.DefaultDisplayDescriptor
converter-type[1] : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
version :
I traced that the attempt to load something from the scenario description:
<repast.score.impl.SGeographyImpl>
<name>PeopleGeography</name>
</repast.score.impl.SGeographyImpl>
</projections>
<valueLayers/>
<projectionDescriptors>
<entry>
<string>PeopleGeography</string>
<repast.simphony.visualization.engine.DefaultProjectionDescriptor>
<proj class="repast.score.impl.SGeographyImpl" reference="../../../../projections/repast.score.impl.SGeographyImpl"/>
<props/>
</repast.simphony.visualization.engine.DefaultProjectionDescriptor>
</entry>
</projectionDescriptors>
Incidentally, I tried to run a model from the model library (zombies) and it launches and works properly.
From https://www.blazemeter.com/blog/5-ways-launch-jmeter-test-without-using-jmeter-gui, I have this test file:
public class JMeterTests {
StandardJMeterEngine jmeter;
HashTree testPlanTree;
#BeforeEach
void init() throws Exception {
// JMeter Engine
jmeter = new StandardJMeterEngine();
// Initialize Properties, logging, locale, etc.
JMeterUtils.loadJMeterProperties("src/test/java/com/tests/JMeterTests.java");
JMeterUtils.setJMeterHome("/usr/local/Cellar/jmeter/5.4.1");
JMeterUtils.initLocale();
// Initialize JMeter SaveService
SaveService.loadProperties();
// Load existing .jmx Test Plan
FileInputStream in = new FileInputStream("src/test/jmeter/my.jmx");
testPlanTree = SaveService.loadTree(in); // <-- testPlanTree is null, did not load
in.close();
}
#Test
void fromExistingJmx() throws MalformedURLException {
// Run JMeter Test
jmeter.configure(testPlanTree); // <-- Fails since testPlanTree is null
jmeter.run();
}
}
As a result, I get this error:
ERROR 2021-10-19 13:29:31.301 [jmeter.s] (): Conversion error com.thoughtworks.xstream.converters.ConversionException: org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor : org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor
---- Debugging information ----
message : org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor
cause-exception : com.thoughtworks.xstream.mapper.CannotResolveClassException
cause-message : org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor
class : org.apache.jorphan.collections.ListedHashTree
required-type : org.apache.jorphan.collections.ListedHashTree
converter-type : org.apache.jmeter.save.converters.HashTreeConverter
path : /jmeterTestPlan/hashTree/hashTree/hashTree[4]/hashTree/JSONPostProcessor
line number : 207
I've already confirmed my.jmx works in GUI mode.
From https://www.blazemeter.com/blog/5-ways-launch-jmeter-test-without-using-jmeter-gui, you have the following statement:
Have the required JMeter jars from /lib and especially /lib/ext folders of your JMeter installation in your project or module class path.
If it is not clear enough get Apache JMeter Components ยป 5.4.1 library in your project classpath
Also you made a mistake in copying and pasting this line:
JMeterUtils.loadJMeterProperties("src/test/java/com/tests/JMeterTests.java");
it should point to jmeter.properties file, preferably the original one.
I have a local jBPM 7.33 with a simple process. At one point in the process, I need to generate a PDF file.
I want to do it by creating a very basic Java class that is run in a Task. The class would get variables from the process scope, generate the PDF and save the generated blob (or filesystem path) as a process variable.
How do I add a custom class and then call that class?
that's what we call it WorkItemHandler , your java class will be a customized jbpm task
First of all install jbpm in eclipse
Create a jBPM project in eclipse (tick Build the project using Maven)
create a java class that implements WorkItemHandler. it will be in this format.
package com.example;
import org.kie.api.runtime.process.WorkItem;
import java.util.HashMap;
import java.util.Map;
import org.drools.core.process.instance.WorkItemHandler;
import org.kie.api.runtime.process.WorkItemManager;
public class WorkItemTest implements WorkItemHandler {
#Override
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
workItem.getParameters().toString();
/**Input Variables***/
String stringVar = (String) workItem.getParameter("stringVar");
/***
*
*
* YOUR CODE
*
*/
String msg = "done";
/**Output Variables in a HashMap***/
Map<String, Object> resultMap = new HashMap<String, Object>();
resultMap.put("Result", msg); //("name of variable", value)
manager.completeWorkItem(workItem.getId(), resultMap);
}
#Override
public void abortWorkItem(WorkItem workItem, WorkItemManager manager) {
System.out.println("Aborted ! ");
}
}
Build a jar file of this project (with maven).
From the workbench, go to Artifact, upload the jar
click on this icon, then artifacts
from the settings of your project, go to dependencies, and add from repository the uploaded artifact
from the settings of your project, go to Deployments / Work Item Handler and add a new work Item Handler : type its name and how to instantiate it (new com.example.WorkItemTest())
Finally, go to the Asset "WorkDefinitions" , define your work item (so you can see it in the workflow designer tool) as follow
[
"name" : "WorkItemTest",
"parameters" : [ //inputs
"stringVar " : new StringDataType(),
],
"results" : [ //outputs
"Result" : new ObjectDataType(),
],
"displayName" : "WorkItemTest",
"icon" : "defaultservicenodeicon.png"
]
you can now find this task in "service tasks" of your workflow designer tool (refresh before)
CONTEXT :
I need to call a "file.py", where is implement my class "myClass", by the Python language OR the JAVA language through Jython.
I do in my "file.py" :
try :
# Jython source file
from com.local.mylocal.jython import ImyClass
except :
ImyClass = None
from threading import Thread
class myClassMetaClass(type) :
def __new__() :
if IClient is None :
bases = (Thread,)
else :
bases = (Thread, ImyClass,)
return type.__new__(metacls, nom, bases, dict)
class myClass(metaclass=myClassMetaClass) :
pass
When I run my PYTHON code, my class : myClass is instance with all metaclass she need. My code run.
When I run my JAVA code who call my PY class through Jython, my code error is :
Exception in thread "main" SyntaxError: ("mismatched input '='
expecting RPAREN", ('../file.py', 52, 22, 'class
myClass(metaclass=myClassMetaClass) :\n')) Blockquote
INVESTIGATION :
I see in "https://github.com/jython/jython3" isaiah solved my probleme.
PROBLEME :
I can't compile the source code on my Windows environement (need : POSIX ...).
I need the "jython3.jar" file.
REQUEST :
How compile jython3 souces on my Windows environement ?
Is it possible to acces to a "jython3.jar" file ?
[EDITED]
The project i'm working on is a 3 folder project in Java J2EE with servlets and Hibernate for the persistance. The structure is as follow: - Admin -> the main program with the beans and HTML/CSS - Jar -> with the jars, Hibernate tools and classes - War -> with the Servlets
Between them, I use Xstream to share the classes and important info.
I'm using Eclipse and Tomcat 7.
Hope that with this all of you get the global idea.
This what the Xstream debugger said:
Caused by: com.thoughtworks.xstream.converters.ConversionException: satdata.musicoterapia.hibernate.Terapeuta0 : satdata.musicoterapia.hibernate.Terapeuta0
---- Debugging information ----
message : satdata.musicoterapia.hibernate.Terapeuta0
cause-exception : com.thoughtworks.xstream.mapper.CannotResolveClassException
cause-message : satdata.musicoterapia.hibernate.Terapeuta0
class : satdata.musicoterapia.hibernate.Usuario
required-type : satdata.musicoterapia.hibernate.Usuario
converter-type : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path : /list/Usuario[2]/terapeuta
class[1] : java.util.ArrayList
converter-type[1] : com.thoughtworks.xstream.converters.collections.CollectionConverter
version : null
Links (I don't have enough reputiation for have more than 2 links):
Complete StackTrace: http://pastebin.com/6vXyD6hC
XML: http://pastebin.com/YM9q3uvq
Servlet: below, in the comment
Where the problem occurs: below, in the comment
Java classes: below, in the comment
If something is missing, ask and I'll put it here. Thanks for all!!!
In your servlet code you are are mentioning :
xstream.alias("Terapeuta", Terapeuta.class);
In XML file it is given as:
<terapeuta class="satdata.musicoterapia.hibernate.Terapeuta0" resolves-to="Terapeuta">
So in logs you are getting error as:
The exception in logs says:
com.thoughtworks.xstream.mapper.CannotResolveClassException:
satdata.musicoterapia.hibernate.Terapeuta0
it seems your class namein MXL should be satdata.musicoterapia.hibernate.Terapeuta
satdata.musicoterapia.hibernate.Terapeuta0