Calling jar from XQuery - jar

I have came across a situation where I have to call a jar with a string parameter and get the result. Is there any way i can able to do this? I came across a link where importing java:java.lang.Math namespace using Java function inside XQuery. This will help me to use library functions of Java. Is there any way I can call jar or customize function from XQuery?

MarkLogic doesn't have a way to directly call a Java method in a JAR file. The common practice is to have the required Java functionality available as a service, then call that from MarkLogic. For instance, you could set up Tomcat to host the functionality that lives in the JAR file.

Related

Call java function using XQuery in MarkLogic

Is it possible to call java function using XQuery in MarkLogic. ?
Please refer - https://stackoverflow.com/questions/65953901/calling-java-method-from-xquery
Example -
declare namespace math="java:java.lang.Math";
math:sqrt(2)
There's no way to directly call a Java function from MarkLogic XQuery. If the Java code is accessible through a web service, you can use xdmp:http-get and similar.
As noted by Martin, depending on what functionality you're trying to access, you might not need to use Java.

Does rocksdbjava api library contain the rocksdb database itself

I am very new to rockdb and will be using the rocksdb in my application as a lookup service. Does the rockDBjava library api provided contain the database itself, I mean is it not necessary to install rocksDB database separately.
I tried running the code using library and see some files created in the db path I mentioned in code, so not sure how exactly it works and if I need to install DB separately or if the library stores data in the directory and it itself acts as database?
No, you should not need to install RocksDB separately if you already have RocksJava working. They're not very clear on stating that, but if you look at the wiki in their Git repo you'll find this:
RocksJava is structured in 3 layers:
The Java classes within the org.rocksdb package which form the
RocksJava API. Java users only directly interact with this layer.
JNI code written in C++ that provides the link between the Java API
and RocksDB.
RocksDB itself written in C++ and compiled into a native library which
is used by the JNI layer.
That third point is basically their way of saying that RocksDB itself is one of the layers of RocksJava.

How to read resource bundle in java backed webscript

I want to read properties file in java-backed webscirpt. Specifically in java controller file.
I can read message.success in change-password.get_ja.properties like
msg.get("message.success");
But I don't know how to call in java-backed file.
The class you're probably looking for is I18NUtil, part of SpringSurf which is available in all WebScripts.
The Alfresco I18N wiki page has quite a bit more on it and its use. Basically though, where in your JS webscript you might have done:
msg.get("message.success");
Instead in Java you'll do:
I18NUtil.getMessage("message.success");
You can also, in java class controller, use getResources().getString("message.success");

Qt and Linking to an external DLL

I've developed a program and I am trying to make this program work with a controllable light source manufactured by some other company. I've emailed the company and they have agreed to send me their external library as a DLL.
I have developed all of my software using Qt 4.8.1 and it has been compiled using MSVC2008.
The controllable light's DLL was compiled in Visual Studio 2008 and was written in either C++ or C# (the manufacturer is uncertain). All I have been given is the DLL and a text file saying that I must:
Add the DLL as a reference to my project
Add using LightName; to the top of the class
Instantiate an instance of the object like so: LightName *ln = new LightName();
Call function void turnOn() with the newly created LightName instance.
Firstly, I find it odd that an external library requires me to instantiate an instance of their object especially when its for a simple piece of hardware.
Secondly, the other company has provided me with no interface files.
My question is:
How can I possibly link to a C++ DLL and expose the functions nested in this library without having an interface header file in a Qt environment? Is there someway to make an interface for an external library?
I have already attempted using QLibrary and doing the following:
QLibrary myLib("mylib");
typedef void (*MyPrototype)();
MyPrototype myFunction = (MyPrototype) myLib.resolve("mysymbol");
if (myFunction)
myFunction();
However, this doesn't work because the DLL I was given was not a C DLL and I have no interface so Qt doesn't have a clue about what symbols it needs to resolve.
I've attempted to display all the definitions exported from my DLL using the dumpbin /EXPORTS command. Unfortunately this was unable to produce anything. I was hoping that I would get some sort of mangled C++ from this that I could then unscramble to make my own header.
I've attempted to use the dependency walker(very useful tool) however it couldn't resolve any symbols to give me some function definitions.
QLibrary only helps you if the library has functions exported as C symbols. If that is C++ you can dump the symbol table and look if that is sufficient for you. Names must be demangled: try to look for dumpbin or similar. It is however possible that you can't do this, it depends on how the symbols have been defined. In that case you'll have to ask for the header: read this.
Well it's absolutely legal to ask you for "instantiating an instance of their object". It's been simply their design decision to make the dll interface object oriented (as contrary to plain extern "C"). QtCore.dll is just someone else's DLL too, and you are instantiating their objects all the time.
But it also means that you will have harder time to call the DLL. The symbols are not "C" symbols (you can't export class that way) so QLibrary can't do anything for you. You can try dumpbin /EXPORTS from the DLL and then tediously unmangle them to reconstruct the class declaration. Luckily there are tools to help you (even online)
But not providing a header file for such DLL is completely dumb in the first place.

WCF: Should all datacontracts use the same namespace?

I have several service contracts exposed over WCF, which use multiple datacontracts. The service is to be consumed by Adobe Flex. I've run into many problems getting Flex to consume the WSDL produced by the server. I used the procedure outlined here to squeeze the WSDL into a single file (I used FlatWsdl and not WcfExtras, if it matters).
Now I'm getting a bunch of errors when using VS2010's own wsdl.exe tool to extract my metadata. Specifically, I'm getting the following errors:
1) Schema validation warning: Schema item 'complexType' named
'ArrayOfKeyValueOfSomeKeySomeValuep1alXzIb' from namespace
'http://schemas.microsoft.com/2003/10/Serialization/Arrays' is invalid.
Namespace 'http://My/Wcf/Namespace' is not available to be referenced
in this schema.
2) Schema validation warning: Schema item 'complexType' named 'MyComplexType'
from namespace 'http://My/Wcf/Namespace' is invalid. Namespace
'http://schemas.datacontract.org/2004/07/My.Real.Namespace' is not available
to be referenced in this schema.
Now, the Dictionary ("ArrayOfKeyValueOf...") type is apparently defined in an external schema, which is not imported by my WSDL. Please note that SomeKey and SomeValue have a datacontract namespace of My/Wcf/Namespace.
As for MyComplexType, the weird thing is that if I change its Datacontract-namespace to the same namespace used by my services, servers, and bindings, then error (2) goes away. I can't figure out why.
What I'm asking boils down to two questions:
1) How can I add an import directive of an external schema to my WSDL? I saw some solutions on-line that suggested writing a wrapper class around the containers. This is something I would really like to avoid.
2) Do I really have to put all my datacontracts into a single namespace? I don't have any technical objection to doing it, but it's going to be very cumbersome to modify the namespace of all datacontracts. Perhaps there's an automated way of achieving this?
TIA!
So just in case anyone else runs into the same problem with accessing a WCF (BasicHttpBinding) server from a Flex client:
1) No, all DataContracts need not be in the same namespace (but all ServiceContracts, service implementations, and bindings do have to be in the same namespace!).
2) The crux of the problem is that Flex expects each xsd:schema to have an "xsd:import namespace" for all the namespaces it references. This import should be of the form:
<xsd:import namespace="http://schemas.datacontract.org/2004/07/SomeNamespace" />
There doesn't seem to be a way to do this with WCF, since it automatically adds an auto-generated schemaLocation attribute to this tag, which makes Flex try to fetch this schemaLocation. The only workaround appears to be manually manipulating the WSDL at the XML level (e.g. by exposing a REST endpoint for retrieving the metadata).
Thanks to Yaron Naveh in the MSDN WCF forums for his help. The discussion can be found at http://social.msdn.microsoft.com/Forums/en/wcf/thread/b9429e30-e4d5-454f-9fbd-bae39990ff33.

Resources