How to use libpostal in my java code? - java

AddressExpander expander = AddressExpander.getInstance();
ExpanderOptions options = new ExpanderOptions.Builder().build();

Have a read on the section "Installation (Windows)" of the C library documentation in order to install it under windows (https://github.com/openvenues/libpostal#installation-windows); once installed use the JNDI binding in order to make the calls between your java application and libpostal(https://github.com/openvenues/jpostal).
#dunni already answered this for you.

Related

Support for setting ACL in Linux

I understand from Java 7 onwards I can use a code like the below to set ACL for a file:
java.nio.file.Path file = Paths.get(filePath);
java.nio.file.attribute.GroupPrincipal joe = file.getFileSystem().getUserPrincipalLookupService()
.lookupPrincipalByGroupName(groupid);
AclFileAttributeView view = Files.getFileAttributeView(file, AclFileAttributeView.class);
java.nio.file.attribute.AclEntry entry = java.nio.file.attribute.AclEntry.newBuilder()
.setType(AclEntryType.ALLOW)
.setPrincipal(joe)
.setPermissions(aclEntryPermissions)
.build();
List<java.nio.file.attribute.AclEntry> acl = view.getAcl();
acl.add(entry);
view.setAcl(acl);
But this code wont run for Linux (runs fine for Windows and Solaris). And the reason seems to be because AclFileAttributeView is not supported in Linux.
My questions are:
Is there some version of Java where AclFileAttributeView is supported in Linux?
If answer to 1 is no, then can someone share a sample JNA code, or give me some pointers to the Native API I need to use in Linux, to get this running.
In effect I want the functionality similar to the setfacl and getfacl command lines.

Where to copy "initialization patameter file" using oracle database?

I'm compltely new in Oracle database now I'm trying to copy a intilization parameter file from this link. But Question is: Where to save init.ora file in which directory?.. please help?
Depends on the OS.
For Unix/Linux, by default it is $ORACLE_HOME/dbs
For Windows,
Default location for spfile in a windows platform is here:
%ORACLE_HOME%\database\spfile%ORACLE_SID%.ora
For a pfile, path is the same:
%ORACLE_HOME%\database\init%ORACLE_SID%.ora
as per oracle flexible architecture we put pfile in
$ORACLE_BASE/admin/database_name/pfile/
and spfile is present in
$ORACLE_HOME/dbs

Setting up New Relic for Railo 4.x on Windows

I will like to setup performance monitoring on an application running on Railo 4 using New Relic. I have consulted the java docs on Railo, Railo google groups, etc but no one seems to have a perfect step by step.
Here is what I have done so far:
Extracted newrelic into Railo's install folder.
Added this line to setenv.sh
export JAVA_OPTS="$JAVA_OPTS -javaagent:c/railo/newrelic/newrelic.jar"
Restarted the Railo-Tomcat service
Added this line to the onapplicationstart function
application.NewRelic = createObject( "java", "com.newrelic.api.agent.NewRelic" );
Added this line to the onrequeststart function
if ( structKeyExists( application, "NewRelic" ) ) {
application.NewRelic.setTransactionName( "CFML", CGI.SCRIPT_NAME );
}
My application is still not sending metrics to New Relic. I will appreciate a step by step instruction of what to do as I can't seem to find that anywhere else and I have no idea what to do.
You can't use setenv.sh on Windows. Instead modify the catalina.bat file, or use the Configure Tomcat utility in the Start Menu to set the javaagent option. These steps can be found in more detail in the New Relic documentation
We have more detailed instructions for installing with our supported platforms and frameworks in our documentation. To see a list of the supported frameworks we are compatible with check out https://docs.newrelic.com/docs/java/new-relic-for-java#h2-compatibility
We may be able to work with the Tomcat portion of your environment and you can find helpful installation information at https://docs.newrelic.com/docs/java/java-agent-manual-installation
Should you run into any obstacles, I suggest opening a ticket at http://support.newrelic.com

Java Stored Procedure using MQ

I need to create a Java stored procedure in Oracle. I have used IBM's sample class for creating an MQ message from a simple class outside of Java EE environment. I have tested the class by itself and it is working.
My Oracle vesrion is 11i.
When I am trying to add the jars used in the simple application to load to Oralce along with my simple class, I am getting errors about class not found, even if same jars work with the test case. I am stuck with this for over a week and am desperately hoping that someone would be able to help me with it.
Kinds of errors I am getting are like this from -v flag with loadjava utility on the client
on line 326 / 327, you see this:
creating : class com/ibm/mq/jms/admin/AP loading : class
com/ibm/mq/jms/admin/AP
and then at the end starting from line 6224 to end, it indicates that the above class can’t be resolved:
com/ibm/mq/jms/admin/APRCXI: ORA-29534: referenced object
xxxx.com/ibm/mq/jms/admin/AP could not be resolved
com/ibm/mq/jms/admin/APSDX: ORA-29534: referenced object xxxx.com/ibm/mq/jms/admin/AP could not be resolved exiting : errors
resolving class com/ibm/mq/jms/admin/AP
the command I used is:
c:\Oracle\product\11.2.0\client_1\bin\loadjava.bat -f -jarsasdbobjects
-prependjarnames -stoponerror -u xxxx/yyyy#SID -v -resolve lib\jms.jar lib\com.ibm.mqjms.jar lib\com.ibm.mq.jmqi.jar lib\dhbcore.jar
lib\fscontext.jar src\com\test\javasp\mq\JmsProducer.java
I also tried with -genmissing option with some additional jars ( list I found here ), but still get similar error for a different class.
Other issue with this that I am facing is that if I get an error and try to use the dropjava command from Oracle, it doesn't work either.
I also saw from this link, that this person was successful, but unfortunately, he/she didn't indicate how they used loadjava to load the jars.
If i can provide any other information, please let me know.
If anyoneone has any idea on how to get the Java Stored Procedure to use IBM MQ working with Oracle 11i, I would really appreciate the help.
Found a detailed answer in this blog entry. I tried it and it worked for me.
In Oracle there is no concept of CLASSPATH, so the standard MQ Client install is useless. You can only load the jars reference by your app within the database schema. Classes are resolved when loaded with the -r option. You can further on specify your own resolved using -r -Resolver (schemas). (check Oracle docs for exact format). So in effect the database schemas becomes the classpath.
Using Websphere MQ classes for Java poses a number of problems, you have to ensure that the Oracle JDK version is at an appropriate support level to connect to the chosen MQ server version. Check the system requirements for websphere MQ Vx.x. You should find IBM's web references. check the support for MQ classed for java.
I have such an issue at the moment trying to connect to Mq using Oracle 10 and JDK 1.4.2. I had to recompile my Java code using JDK 1.4.x. This does not work and I assume it is because I connect to MQ 7.0.1.7 which requires JRE 1.7 as minimum.

Working with Php-Java Bridge

I am having trouble setting up the Php-Java Bridge setup properly.
I will explain what I have done.
My site is in pure php
For our payment transaction process we need to set up a php-java bridge
I followed this link to setup the bridge PHP-JAVA BRIDGE INSTALATION.
Here I learned that I need to have a private jvm to install the bridge.
So 1st i installed apache-tomcat-6.0.14 in Private JVM using my c-panel. After instalation it asked me to Map a domain to private JVM. So I mapped my domain example.com (which is the only option available) to it.
Then it asked to enable a traffic redirection from Apache web server to my Java application server (there was a check box and i clicked it)
Finally it asked me to deploy the WAR File (JavaBridge.WAR was my file) and everthing seems fine
Now when i go to http://example.com/JavaBridge/ I could see the javabridge examples and it works fine.
SO FAR SO GOOD
Now my problem starts here when I try to access a java class file from php. A sample test.php is what I create and put the following code into it.
<?php
require_once("http://example.com:portnumber/JavaBridge/java/Java.inc");
$System = java("java.lang.System");
echo $System->getProperties(); //This Part echo's correctly and shows the data so it means i can access Java.inc Correctly
$path_e24class = getcwd(). '/e24PaymentPipe.class'; //This part fails both test.php and java class file e24PaymentPipe.class are in the same directory in publich_html folder
java_require($path_e24class);
$pipe = new Java("e24PaymentPipe");
$pipe->setAction("1");
?>
My site contents reside in the public_html folder and the WAR file are deployed in private jvm.
These are the error message am getting.
1) Warning: java_require() not supported anymore. Please use tomcat or jee hot deployment instead
Fatal error: Uncaught [[o:Exception]:"java.lang.Exception: CreateInstance failed: new e24PaymentPipe. Cause: java.lang.ClassNotFoundException: e24PaymentPipe VM: 1.6.0_22#http://java.sun.com/" at: #-10
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358) #-9
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204) #-8
java.lang.Class.forName0(Native Method) #-7
java.lang.Class.forName(Class.java:247) #-6
php.java.bridge.Util.classForName(Util.java:1518) #-5
php.java.bridge.JavaBridge.CreateObject(JavaBridge.java:445) #-4
php.java.bridge.Request.handleRequest(Request.java:458) #-3
php.java.bridge.Request.handleRequests(Request.java:500) #-2
php.java.bridge.http.ContextRunner.run(ContextRunner.java:145) #-1
php.java.bridge.ThreadPool$Delegate.run(ThreadPool.java:60) #0
http://example.com:portnumber/JavaBridge/java/Java.inc(232): java_ThrowExceptionProxyFactory->getProxy(3, 'java.util.Prope...', 'T', false) #1
Finally I don't know much about the java. So am stuck here not knowing what to do.
Here is a great step by step tutorial you can follow, which shows everything required! It is a little old (2007) but helped me a while ago.
There is also another option. You can install Apache Tomcat and deploy your war there. You can have even multiple tomcat instances simultaneously with your httpd running at the same time on the same machine, as long as you respect the port settings. You can even front them with Apache httpd.
you can try this:
package your code to jar, and copy it to java.ext.dirs which you can found in JavaBridge.log
copy the related class libraries to java.ext.dirs
restart the service of JavaBridge
good luck!
<?php require_once("JavaBridge/java/Java.inc");
try {
$hd = new java("hdfs.HDFS");
$hd->get("hdfs://master:9000/user/hadoop/test-in/logo_cn.png", "/home/hadoop/1.png");
} catch (JavaException $ex) { echo "An exception occured: "; echo $ex; echo "<br>\n";}
?>
You can use this php implementation on github that works with php 5.3.
See credits on the git readme for more information.
You can try this; put the JavaBridge.jar in tomcat's lib folder e.g. apache-tomcat-7.0.12/lib.
Restart tomcat server and then,
$pipe = new java("com.aciworldwide.commerce.gateway.plugins.e24PaymentPipe");
$pipe->setAction("1");
This way I created the php version of the object.
Why don't you put the e24PaymentPipe class in your Java application's classpath and skip the two lines below:
// $path_e24class = getcwd(). '/e24PaymentPipe.class';
// java_require($path_e24class);
$pipe = new java("fully.qualified.classpath.e24PaymentPipe");
You are mixing PHP side and Java side operations. in theory the java_require (which is deprecated) was designed to work on the Java side. You are specifying a PHP side path.
You can save yourself a lot of grief by using a pure PHP implementation of the e24PaymentPipe library.
Disclaimer
The link is to my github repo of the library, but I did not write it. See the readme in for original credits.

Categories