Impossible classname for ExtensionObjects - opc-ua

I am using Milo to browse the capabilities of servers.
This also involves decoding ExtensionObjects (which works fine for the UnifiedAutomationReadCustomDataTypeExample).
On open62541 and milo servers it fails strangely, as ExtensionObjects cannot be cast to ExtensionObjects - please note the "[L" in the following exception:
java.lang.ClassCastException: [Lorg.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject; cannot be cast to org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject
Is this a bug in Milo or am I missing something?
I am using the latest Eclipse to compile both Server and Client.
I am using Milo 0.2.3 from Maven.

The issue was produced by casting an Object[] to an Object. The code below now works properly.
if(rd.getDisplayName().getText().equals("OutputArguments")) {
DataValue readServiceResult = client.readValue(100, TimestampsToReturn.Both, rd.getNodeId().local().get()).get();
Variant args =readServiceResult.getValue();
NodeId ni = args.getDataType().get();
Object[] oVal = (Object[])args.getValue();
Object val = oVal[0];
if(val instanceof ExtensionObject) {
ExtensionObject eo = (ExtensionObject)oVal[0];
Object o = eo.decode();
System.out.println(o);
}
}

Related

Wicket configuration for nashorn

I recently upgraded my java version from java 1.7 to java 1.8. After the upgrade i am getting this error.
Caused by: ECMAScript Exception: Type Error: Can not find a common class loader for ScriptObject and My Interface.
Which version of wicket do i need to use which supports java 1.8 and nashorn script engine. Also do i need to configure anything related to Script Engine for wicket.
I have tried adding this dependency
<dependency>
<groupId>org.wicketstuff</groupId>
<artifactId>wicketstuff-nashorn</artifactId>
<version>7.4.0</version>
</dependency>
and ScriptEngineManager sem = new ScriptEngineManager();
engine = sem.getEngineByName("nashorn");
but i am still getting the same issue.
Please help me fix this issue.
Below is my method
private final ScriptEngine engine;
ScriptEngineManager sem = new ScriptEngineManager();
engine = sem.getEngineByName("nashorn");
public <K> K getNewInterface(MyScript myScript){
ScriptContext ctx = new SimpleScriptContext();
String script = myScript.getScript();
if(Strings.isEmpty(script)) {markInvalid(myScript, "Script is empty", null); return null;}
script += " (function(){return this;})();";
Object thiz;
try{
thiz = engine.eval(script, ctx);
} catch (ScriptException e){
markInvalid(myScript, "Can't execute script", e);
return null;
}
if(thiz==null) {markInvalid(myScript, "Script executed, but context is null", null); return null;}
K ret = (K) ((Invocable)engine).getInterface(thiz, myScript.getScriptInterfaceClass());
if(ret==null) {
markInvalid(myScript, "Script executed, but it's incompatible with required interface", null);
return null;
}else{
myScript.setValid(true);
return ret;
}
}
Wicket doesn't need Nashorn. You can use Wicket 1.5/6.x/7.x/8.x with Java 8.
wicketstuff-nashorn is definitely not needed to run Wicket application.
Without the actual error it is hard for us to tell why it is failing.
Update: why do you use new ScriptEngineManager(null), i.e. null ClassLoader. Better use new ScriptEngineManager() and it will use the context class loader which most probably knows about both classes. Or use new ScriptEngineManager(YourInterface.class.getClassLoader())

Delete all messages in queue Websphere 8.5 SIB via JMX

I want to delete all the messages in a queue configured in Websphere 8.5 SIB. Below are two approaches I tried, but none of them seem to be working and each throws a different exception. Can someone please advise on what is the correct way to achieve this.
Approach 1
MBeanServerConnection connection = getServerConnection();
connection.invoke(new ObjectName("WebSphere:*,type=SIBQueuePoint,name=jms.queue.MY_QUEUE"), "deleteAllQueuedMessages", null, null);
This approach throws the below exception.
javax.management.InstanceNotFoundException: WebSphere:type=SIBQueuePoint,name=jms.queue.MY_QUEUE
Approach 2
MBeanServerConnection connection = getServerConnection();
ObjectName objQueue = new ObjectName(WAS85_RESOURCE_URL + ",type=SIBQueuePoint");
Set<ObjectName> objNames = connection.queryNames(objQueue, null);
for(ObjectName objName: objNames) {
String qName = connection.getAttribute(objName,"identifier").toString();
if(qName.equals("jms.queue.MY_QUEUE")) {
connection.invoke(objName, "deleteAllQueuedMessages", null, null);
}
}
This approach throws the below exception.
javax.management.ReflectionException: Target method not found: com.ibm.ws.sib.admin.impl.JsQueuePoint.deleteAllQueuedMessages
Figured out the issue.
The 2nd approach works. The issue was with my invocation of the deleteAllQueuedMessages message. The method takes a boolean argument which indicates the messages should be moved to the Exception Destination. I was not passing this argument !!!
I corrected the implementation as below and it works now.
connection.invoke(objName, "deleteAllQueuedMessages", new Object[]{false}, new String[]{"java.lang.Boolean"});
A better way to delete all Messages is something like that:
String queryString = "WebSphere:*,type=JMSAdministration";
ObjectName queryServer = new ObjectName(queryString);
String serverStr = "";
Set pet = aClient.queryNames(queryServer, null);
Iterator itsServer = pet.iterator();
if (itsServer.hasNext())
serverStr = itsServer.next().toString();
ObjectName obj = new ObjectName(serverStr);
Object param[] = { "jms/messageQueue","jms/messageCF" };
String signature[] = { "java.lang.String","java.lang.String" };
aClient.invoke(obj, "clear", param, signature);
Using MBean JMSAdministration is better because you can set Query exacly.

FOP/ikvm: error "Provider com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl not found"

I have produced a fop.dll from fop-1.0 with ikvm:
ikvmc -target:library -reference:IKVM.OpenJDK.Core.dll -recurse:{myPathToJars}\*.jar -version:1.0 -out:{myPathToJars}\fop.dll
If I use my fop.dll in a Windows Application, everything works perfect.
If I use it in a Class Library, I get the following error:
"Provider com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl not found" at javax.xml.transform.TransformerFactory.newInstance()
The code line is: TransformerFactory factory = TransformerFactory.newInstance();
Here is the code of method:
public static void xmlToPDF(String xmlPath, String xslPath, SortedList arguments, String destPdfPath)
{
java.io.File xmlfile = new java.io.File(xmlPath);
java.io.File pdffile = new java.io.File(destPdfPath);
try
{
// configure fopFactory as desired
FopFactory fopFactory = FopFactory.newInstance();
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
// configure foUserAgent as desired
// Setup output
OutputStream outputStream = new java.io.FileOutputStream(pdffile);
outputStream = new java.io.BufferedOutputStream(outputStream);
try
{
// Construct fop with desired output format
Fop fop = fopFactory.newFop("application/pdf" /*MimeConstants.MIME_PDF*/, foUserAgent, outputStream);
// Setup XSLT
TransformerFactory factory = TransformerFactory.newInstance();
java.io.File xsltfile = new java.io.File(xslPath);
Transformer transformer = factory.newTransformer(new StreamSource(xsltfile.getAbsoluteFile()));
// Set the value of a in the stylesheet
if (arguments != null)
{
IList keys = arguments.GetKeyList();
foreach (var key in keys)
{
Object value = arguments[key];
transformer.setParameter(key.ToString(), value);
}
}
// Setup input for XSLT transformation
Source src = new StreamSource(xmlfile);
// Resulting SAX events (the generated FO) must be piped through to FOP
Result res = new SAXResult(fop.getDefaultHandler());
// Start XSLT transformation and FOP processing
transformer.transform(src, res);
}
catch (Exception e1)
{
System.Console.WriteLine(e1.Message);
}
finally
{
outputStream.close();
}
}
catch (Exception ex)
{
System.Console.WriteLine(ex.Message);
}
}
I used ikvm-0.46.0.1 to make my fop.dll (based on fop 1.0). I included the following jars:
avalon-framework-4.2.0.jar
batik-all-1.7.jar
commons-io-1.3.1.jar
commons-logging-1.0.4.jar
fop.jar
serializer-2.7.0.jar
xalan-2.7.0.jar
xercesImpl-2.7.1.jar
xml-apis-1.3.04.jar
xml-apis-ext-1.3.04.jar
xmlgraphics-commons-1.4.jar
Any idea why this error occurs? Why is the behaviour different between Windows Application and Class Library?
Addition 10/19/11:
I managed to get working the following:
MyMainPrg (a Windows Forms Application)
MyFopWrapper (a Class Library that calls fop.dll)
But for my case this is not the solution, because in my target project, I have the following structure:
MainCmdLinePrg (a Console Application; calls DLL_1)
DLL_1 (calls DLLsharedFop) {there are several DLLs that can call DLLsharedFop}
DLLsharedFop (calls directly fop.dll; or - I don't care - might call MyFopWrapper)
Unfortunately this construct results in the error.
You can shorten to a pair (ACmdLinePrg,MyFopWrapper): already this does not work! But (MyMainPrg,MyFopWrapper) does...
Here is how I got that error and how I resolved:
My solultion looks like this:
ClientApp (references)--> ClassLibrary1
My ClassLibrary1 public functions are using, but not exposing any IKVM related objects, therefore the caller (ClientApp) did not have to add IKVM references. All is good in compile time.
However in runtime, the situation is different. I got the same exception and realized that ClientApp also needed to reference the correct IKVM dll (IKVM.OpenJDK.XML.Transform.dll) that contains "com.sun.org.apache.xalan.#internal.xsltc.trax" namespace.
I resolved a similar problem by adding the following before the problematic line:
var s = new com.sun.org.apache.xerces.#internal.jaxp.SAXParserFactoryImpl();
var t = new com.sun.org.apache.xalan.#internal.xsltc.trax.TransformerFactoryImpl();
As described here
Do you have the dll with the missing class in your working directory?
If you have the dll then it is a classloader problem. Look in the IKVM wiki. Often the BootClassPathAssemby help.
I was using NuGet Packages of FOP.dll v1.1.0 and IKVM pacakges of v7.1.45 in C#.NET app. I got this issue on Windows 2016 x64 server with error messages like:
------------------------------ Fop.cs (111): Provider com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl
not found - at javax.xml.transform.TransformerFactory.newInstance()
Fop.cs (125): Provider
com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl not found
- at javax.xml.parsers.SAXParserFactory.newInstance()\r\n at org.apache.avalon.framework.configuration.DefaultConfigurationBuilder..ctor(Boolean
enableNamespaces)\r\n at
org.apache.avalon.framework.configuration.DefaultConfigurationBuilder..ctor()\r\n
I resolved the problem by adding those two lines at begins of procedure
com.sun.org.apache.xerces.#internal.jaxp.SAXParserFactoryImpl s = new com.sun.org.apache.xerces.#internal.jaxp.SAXParserFactoryImpl();
com.sun.org.apache.xalan.#internal.xsltc.trax.TransformerFactoryImpl t = new com.sun.org.apache.xalan.#internal.xsltc.trax.TransformerFactoryImpl();
helpful link:
https://github.com/KevM/tikaondotnet/issues/21

Eclipse IDE doesnt allow me to give the input while running groovy script

I tried to run the groovy script. But unfortunately the script does not ask me for the input and through null pointer exceptions. Please help me what I need to do for this.
static startShell() {
client = new Client()
// TODO add Windows compatibility check
def historyFile = new File(System.getProperty("user.home"), "kitty.history")
historyFile.createNewFile()
def history = new History(historyFile)
def reader = new ConsoleReader()
reader.setBellEnabled(false)
reader.setUseHistory(true)
reader.setDefaultPrompt(PROMPT)
reader.setHistory(history)
reader.addCompletor(new SimpleCompletor(commands as String[]))
LOOP: while (true) {
def input = reader?.readLine().trim()
if (input.length() == 0)
continue
if (["exit", "quit"].contains(input.tokenize().get(0)))
break LOOP
try {
inputHandler(input)
}
catch (Exception e) {
println e.getMessage()
}
I also tried by replacing the reader? with reader also.
Error:
kitty> Caught: java.lang.NullPointerException: Cannot invoke method trim() on null object
at org.apache.kitty.CmdShell.startShell(CmdShell.groovy:100)
at org.apache.kitty.CmdShell.main(CmdShell.groovy:79)
Please Help
I believe this is related to this question:
java.io.Console support in Eclipse IDE
Essentially, Eclipse does not support Console Reader for running applications - though I'm confused as to how Andrew Eisenberg got a working result in Eclipse if that is the case.
Can you simplify your program into something that I can run? I tried something very simple and I was able to have it run both on the command line and inside Eclipse.
Here's the script I created:
import jline.ConsoleReader
def reader = new ConsoleReader()
LOOP: while (true) {
def input = reader?.readLine().trim()
if (input.length() == 0)
continue
if (["exit", "quit"].contains(input.tokenize().get(0)))
break LOOP
println "You said: " + input
}
Can you try running this and see if this works for you?

XmlDeserialization fails in medium trust level

We have our site hosted in medium trust level and the hosting provider has refused to give us full trust. Our code tries to deserialize code using following code snippet but fails with the reflectionpermission error. Upon debug I get "There is an error in XML document (71, 6)." error. It works perfectly fine in full trust. Please someone advice how I can solve this problem before we decide to move to full trust hosting provider.
public static T Decrypt<T>(Stream stream)
{
Rijndael rij = Rijndael.Create();
rij.Key = key;
rij.IV = iv;
T obj = default(T); // assigns null if T is a reference type, or 0 (zero) for value types
using (CryptoStream cs = new CryptoStream(stream, rij.CreateDecryptor(), CryptoStreamMode.Read))
{
using (GZipStream zs = new GZipStream(cs, CompressionMode.Decompress))
{
XmlSerializer xs = new XmlSerializer(typeof(T));
obj = (T)xs.Deserialize(zs);
zs.Close();
}
cs.Close();
}
return obj;
}
Open the project properties and set "Generate serialization assembly" to "on". This will make the compiler generate serialization assemblies at compile-time instead of on the fly. Just make sure to deploy the serialization assemblies.