Calling JNI from my servlet
Hai,
I am using a servlet and I am calling the JNI method, but it is throwing an error like
"java.lang.UnsatisfiedLinkError: check_file". (check_file is my JNI method.)
I have checked the included header file name and function name, they are proper and correct. Can any one tell me some solution forthis problem. Thanks in advance.
Bala
Hai ,
I found the solution for this query from jguru forum. I thought it will be helpful for persons like me, so i am posting it here. Consider the flg. example.
All programs are under package "com.myprogram"
MyServlet.java (My servlet program)
GetInfo.java (My Java link program)
GetInfofromCLib.c(My JNI interface program)
MyServlet.java ---> Servlet that calls the get_info() native method of GetInfo.java
******GetInfo.java*****
public class GetInfo
public native void get_info();
static{
System.load("/usr/home/com/myprogram/mylib.so");
so now if u create "javah -jni GetInfo"
it will create the function name like
Java_get_1info(JNIEnv*, jobject);
but we need to rewrite this function name, so that it is representing the total path as
Java_com_myprogram_get_1nfo(....);
And also in the GetInfofromCLib.c we need to refer this way. Hope this will help others......
Thanks,
Bala....
Similar Messages
-
Problem Calling JNI from a servlet
Hi guys,
How can I trace a C program called from a servlet using JNI ? The problem is a cant see the standard output of the C program because I call it from an applet, not from the console. I would preffer not to generate an error output from the C program, only see the text output this program outputs to the console.
Thanks.Have you tried adding a pipe to the calling command?
For example:
Process p = Runtime.getRuntime().exec("myutil.exe > output.txt");
p.waitFor();
Once the program has finished, the output from the myutil.exe can be found in the file output.txt.
HTH -
Couldn't Load DLL and Call JNI in Portal Servlet !!!
Hello,
I'm trying to write a small test servlet in portal which will call functions in a DLL using JNI. Here is my source code. I put my DLL in \Window\system32, usr/sap/J2E/JC01/j2ee/os_libs, even included into my portal project \PORTAL-INF\lib. But everytime when I try to preview my page, I got the following error and I couldn't find the log file specified in the error message. Please help me out. Thanks a lot!
Portal Runtime Error
An exception occurred while processing a request for :
iView : N/A
Component Name : N/A
MyTestDLL.
Exception id: 12:25_23/12/06_0029_11241950
See the details for the exception ID in the log file
Source Code:
import com.sapportals.portal.prt.component.*;
public class CIViewTest extends AbstractPortalComponent
public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)
response.write("Hello From Java Servlet!!!\n");
static {
try {
Runtime.getRuntime().loadLibrary("MyTestDLL");
// I've also tried System.LoadLibrary("MyTestDLL");
} catch (UnsatisfiedLinkError ule) {
throw ule;Nobody used JNI in Portal Servlet??? Please advice. Thanks!
-
Calling XSQL from java servlet
I'm able to call XSQL, process the page, and display it. But, how do I set the stylesheet from within my java servlet.
I tried params.put( "xml-stylesheet", "[path to sheet]" ), and then passing that to process(), but it just ignores it. I want to be able to set the stylesheet dynamicaly like when you call XSQL from the command line or from the XSQL servlet.
XSQLRequest req = new XSQLRequest( xsql );
Hashtable params = new Hashtable(2);
params.put( "mths", "6");
params.put( "run_id", "30");
params.put( "grade", "A" );
params.put( "xml-stylesheet", xsl ); <-- just seems to ignore this.
ByteArrayOutputStream ostr = new ByteArrayOutputStream(2048);
req.process( params, ostr, new PrintWriter(System.err) );Thanks for the help Steve (and thanks for a really nice book by the way.)
To answer your first question, I have implemented a report caching servlet. In the application we're writing, reports are generated in HTML or PDF (using XSQL) on demand. However, the data really only changes once a day at most so I wanted to have a way to store the reports once they were generated. So this servlet basically gets the request for a report, checks to see if the report has already been generated and, if not, generates the report using XSQLRequest. Finally it returns the report to the user.
One benefit to doing this is that it masks the generation process from the user (ie, they can just hit a link like http://somehost/path/to/report.pdf and they get a pdf report.) Of course the other benefit is that reports only need to be generated once, reducing server load.
I will definitely try your suggestion and just redirect to the XSQL servlet. I guess I was thinking about it too hard, this is a simple solution which will probably address the problem with a minimum of fuss. ;o) Using XSQLRequest directly works, it's just that I want to be able to reference external images using relative paths... it's funny that relative references to XSL pages works though.
Thanks again,
Van
null -
Calling application from a servlet
Hi,
I am having trouble sending automated email messages from a servlet. Someone else in this office has had luck with getting an application to send email. I was wondering if my servlet could call the application .class file? It is possible for a servlet to call an application and if so how do I do it?
Thanks// you need activation.jar in you class path
// also note that your SMTP host may have to allow relaying from your
/ ip address
import java.io.*;
import java.net.InetAddress;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
* @author Scott Shaver
* @version
public class EMailMessage {
private static String mailHost = null;
private static String to = null;
private static String subject = null;
private static String from = null;
private static String text = null;
private static String cc = null;
private static String bcc = null;
private Vector attachments = new Vector(2);
private boolean bodyIsHTML = false;
/** Creates new Message */
public EMailMessage() {
/** Creates new Message */
public EMailMessage(String to, String from, String subject, String text) {
setTo(to);
setFrom(from);
setSubject(subject);
setText(text);
/** Creates new Message */
public EMailMessage(String to, String from, String subject, String text, String host) {
setTo(to);
setFrom(from);
setSubject(subject);
setText(text);
setMailHost(host);
public void sendNoExceptions() {
try
send();
catch(Exception x)
public void send() throws AddressException, MessagingException {
try
Properties props = System.getProperties();
props.put("mail.smtp.host", mailHost);
MimeBodyPart msgTextBP = null;
Multipart content = new MimeMultipart();
Session session = Session.getInstance(props, null);
javax.mail.Message msg = new javax.mail.internet.MimeMessage(session);
if(from!=null)
msg.setFrom(new InternetAddress(from));
if(to!=null)
msg.setRecipients(javax.mail.Message.RecipientType.TO,InternetAddress.parse(to, false));
if(cc!=null)
msg.setRecipients(javax.mail.Message.RecipientType.CC,InternetAddress.parse(cc, false));
if(bcc!=null)
msg.setRecipients(javax.mail.Message.RecipientType.BCC,InternetAddress.parse(bcc, false));
if(subject!=null)
msg.setSubject(subject);
if(text!=null)
msgTextBP = new MimeBodyPart();
if(bodyIsHTML)
msgTextBP.setContent(text, "text/html");
else
msgTextBP.setText(text);
content.addBodyPart(msgTextBP);
//msg.setText(text);
msg.setHeader("X-Mailer", "EMailMessage");
msg.setSentDate(new Date());
int fac = attachments.size();
for(int loop=0;loop<fac;loop++)
File file = (File)attachments.elementAt(loop);
DataSource source = new FileDataSource(file);
MimeBodyPart bp = new MimeBodyPart();
bp.setDataHandler(new DataHandler(source));
bp.setFileName(file.getName());
content.addBodyPart(bp);
msg.setContent(content);
Transport.send(msg);
catch(AddressException ax)
System.out.println("EMailMessage.send() AddressException");
System.out.println(ax);
ax.printStackTrace();
catch(MessagingException mx)
System.out.println("EMailMessage.send() MessagingException");
System.out.println(mx);
mx.printStackTrace();
public void addAttachment(File a) {
attachments.addElement(a);
public void setMailHost(String host) {
mailHost = host;
public String getMailHost() {
return mailHost;
public void setTo(String to) {
this.to = to;
public String getTo() {
return to;
public void setSubject(String subject) {
this.subject = subject;
public String getSubject() {
return subject;
public void setFrom(String from) {
this.from = from;
public String getFrom() {
return from;
public void setBodyIsHTML() {
bodyIsHTML = true;
public void setText(String text) {
this.text = text;
public String getText() {
return text;
public void setCC(String cc) {
this.cc = cc;
public String getCC() {
return cc;
public void setBCC(String bcc) {
this.bcc = bcc;
public String getBCC() {
return bcc;
public static void main(String[] args) {
/*EMailMessage m = new EMailMessage(
"[email protected]",
"[email protected]",
"This is the subject of a test message.",
"This is the text of the message.\nThis is another line.",
"mail");
try{
m.send();
catch(Exception x)
x.printStackTrace(); -
How can I call EJB from JSP/Servlets in iWS?
Hi!!
My JSP/Servlets are on iWS, and I deploy EJB on iAS.
In this case, I don't know how JSP/Servlet call EJb on iAS.
I'd like to know how I can set JNDI name in JSP/Servlet on iWS.
I will thank you if you give me a simple example source using JSP/Servlet
and EJB.
Thanks in advance!!!
- Park-Park,
Why Are you running your JSP/Servlets in iWS instead of iAS? For whatever
reason,
look at the Converter sample from iAS. You will be doing RMI/IIOP in this
case and the sample explains in detail what to do.
hth,
-robert
"SungHyun, Park" <[email protected]> wrote in message
news:9jpfmt$[email protected]..
Hi!!
My JSP/Servlets are on iWS, and I deploy EJB on iAS.
In this case, I don't know how JSP/Servlet call EJb on iAS.
I'd like to know how I can set JNDI name in JSP/Servlet on iWS.
I will thank you if you give me a simple example source using JSP/Servlet
and EJB.
Thanks in advance!!!
- Park- -
Calling JNI from a java sp.
I read in 8.1.5 docs that JNI is not enabled in the Oracle JVM (for customers)
Still the case in in 8.1.7?
Has anyone (Brian?) had success when making RMI calls from the Oracle JVM?
Thanks,
Matt
[email protected]Well, the problem with JNI, is a difficult issue. See, the C code would have to be linked with the Oracle executable itself and if not functionning properly (er, say core-dumping, or referencing random places in memory) could corrupt the quality of your precious data in the database. (For example, bogus code could overwrite data in the buffer caches). So JNI is indeed here and used in-house for most natives but is not available for customers. Sigh.
Now, doing an RMI callout to a standalone RMI server that uses JNI is a GOOD IDEA. It's functional and recommended.
The issues about RMI and scalability is when you want to use oracle itself as an RMI server. Not when you want to do RMI callouts.
Hope this helps,
matthieu -
Calling ApplicationModule from a servlet (Standalone WL)
Hi,
I have to use a servlet call into my Oracle Fusion application (ADF Faces 11g)
Into the servlet I have to access the DB so I am calling the ApplicationModule as following:
String amDef = "hod.tasdeeq.workspace.service.TasdeeqServiceAM";
String config = "TasdeeqServiceAMLocal";
ApplicationModule am = Configuration.createRootApplicationModule(amDef,config);
ViewObject vo = am.findViewObject("CertifiedDocPDFVO");
It is working well using the embedded WL (Debug and Run).
After deploying the application to the standalone WL I have an exception when calling the servlet.
Seems a connection pool exception...
Any idea?
Thank you
Jamil
oracle.jbo.DMLException: JBO-26061: Error while opening JDBC connection.
at oracle.jbo.server.ConnectionPool.createConnection(ConnectionPool.java:205)
at oracle.jbo.server.ConnectionPool.instantiateResource(ConnectionPool.java:164)
at oracle.jbo.pool.ResourcePool.createResource(ResourcePool.java:589)
at oracle.jbo.pool.ResourcePool.useResource(ResourcePool.java:322)
at oracle.jbo.server.ConnectionPool.getConnectionInternal(ConnectionPool.java:100)
at oracle.jbo.server.ConnectionPool.getConnection(ConnectionPool.java:66)
at oracle.jbo.server.ConnectionPoolManagerImpl.getConnection(ConnectionPoolManagerImpl.java:52)
at oracle.jbo.server.URLConnectionHelper.getConnection(URLConnectionHelper.java:129)
at oracle.jbo.server.DBTransactionImpl.establishNewConnection(DBTransactionImpl.java:935)
at oracle.jbo.server.DBTransactionImpl.initTransaction(DBTransactionImpl.java:1103)
at oracle.jbo.server.DBTransactionImpl.initTxn(DBTransactionImpl.java:6275)
at oracle.jbo.server.DBTransactionImpl2.connect(DBTransactionImpl2.java:131)
at oracle.jbo.common.ampool.DefaultConnectionStrategy.connect(DefaultConnectionStrategy.java:213)
at oracle.jbo.server.ApplicationPoolMessageHandler.doPoolConnect(ApplicationPoolMessageHandler.java:561)
at oracle.jbo.server.ApplicationPoolMessageHandler.doPoolMessage(ApplicationPoolMessageHandler.java:417)
at oracle.jbo.server.ApplicationModuleImpl.doPoolMessage(ApplicationModuleImpl.java:8470)
at oracle.jbo.common.ampool.ApplicationPoolImpl.sendPoolMessage(ApplicationPoolImpl.java:4389)
at oracle.jbo.common.ampool.ApplicationPoolImpl.prepareApplicationModule(ApplicationPoolImpl.java:2385)
at oracle.jbo.common.ampool.ApplicationPoolImpl.doCheckout(ApplicationPoolImpl.java:2201)
at oracle.jbo.common.ampool.ApplicationPoolImpl.useApplicationModule(ApplicationPoolImpl.java:3085)
at oracle.jbo.common.ampool.SessionCookieImpl.useApplicationModule(SessionCookieImpl.java:460)
at oracle.jbo.common.ampool.SessionCookieImpl.useApplicationModule(SessionCookieImpl.java:431)
at oracle.jbo.common.ampool.SessionCookieImpl.useApplicationModule(SessionCookieImpl.java:426)
at oracle.jbo.client.Configuration.getApplicationModule(Configuration.java:1398)
at oracle.jbo.client.Configuration.createRootApplicationModule(Configuration.java:1366)
at oracle.jbo.client.Configuration.createRootApplicationModule(Configuration.java:1338)
at hod.tasdeeq.servlet.pdfServlet.doGet(pdfServlet.java:37) <---------------------------------------------------Servlet CallSolution:
TasdeeqServiceAMLocal is not defined on the WLS
Need to use the Datasource application module defined on the server
String amDef = "hod.tasdeeq.workspace.service.TasdeeqServiceAM";
String config = "JNDI";<----------------------------
ApplicationModule am = Configuration.createRootApplicationModule(amDef,config);
ViewObject vo = am.findViewObject("CertifiedDocPDFVO");
Jamil -
Hi,
I'm trying to call a native method from a EJBean class,using iPlanet App Server, after deployment, when i run, I'm getting the following error,
"com.netscape.server.eb.UncheckedException: java.lang.Error thrown by impl nextgensecurity.NgtnSecurityBean@1ade762, err = java.lang.UnsatisfiedLinkError: validateinHSM "
But the same thing is working when tried with a simple java class,
can any one help regarding this ASAP,
Thanx in advance
KiranHi Joe,
Thanks a lot for ur reply,
But the LD_LIBRARY PATH is set to the user that runs the App Server, Since it is throwing a UnsatisfiedLinkError, there must be a problem with the link only(i.e calling native method).
The flow of data is as follows
1 A method from ejb calls another java method in an other java class which is in the same jar file,passing the actual arguments.
2 That java method calls the Native methos residing in the same class file
3 The Native mentod calls a c function as usual
My ejb is working fine up to the Native Method call, at this point it is throwing an error
All my java files are in a package, and my .h file contains package name in the prototype of c function
If you get any ideas please mail me ASAP
ThanQ
Kiran -
Calling Oracle Reports from a servlet
Hi
I want use Oracle Reports to build reports
and then call them from a servlet via a URL.
How can i do this?
Thanks
Alexandre BaptistaYou can write a Java Stored Procedure that executes a Java
Runtime object. This allows you to call an OS command. It's
quite straightforward to do and you can find examples on this
forum and on the AskTom site (among other places).
With this Java built you ought (I haven't tried it myself) to be
able to call run_product (or whatever the Reports runtime is
these days) - providing it's on the same server as the
database. I'm not sure whether you can use this java workaround
to call OS commans on remote servers, although in principle I
don't see why not.
Try it and let the forum know how it works.
HTH, APC -
Have a java bea located at \web-inf\classes\mybeans called UserData.java
And would like to call it from my servlet to pass data located at \web-inf\classesHow would I do that?If your using webLogic server, then the below link may help you.
http://edocs.bea.com/workshop/docs81/doc/en/core/index.html -
How to invoke a OSB Proxy Service from a Servlet??
Hi!!
I'm a begginer in OSB, and right now I have a OSB configuration in production mode. So, using the console test it's very easy to test (doh) my configuration. But now, I have to make a stress test and after read a lot of documentation I did'nt found the way to do that. So I'm trying to do it by using a Servlet, a doPost method in especific, but after a lot of time I can't invoke the proxy service.
What is the right way to use a proxy service in production mode??
How can I call it from my servlet??
How can I send an xml (or any other object, file, text...) as a Request??
Help please, thank you...
Edited by: user12116998 on 18-mar-2010 12:40If you have your proxy service published as http/soap, then I recommend you to use SoapUI to test it. It can help you with stress test too.
-
Which package is use for call jni
i call jni from java bean.
so which package is to be used
is there any
java.jni.*; --> ???JNI is used to extend the functionality of the Java Virtual Machine through native code. Packages are used as a way of physically separating Java code in a logical fashion.
As the native code is not part of your Java code, it has no package, in fact any libraries (be it win32 dll's or another breed) are unlikely to be on your classpath at all. They have to be in your PATH (win32) or LD_LIBRARY_PATH for linux/unix. Have a read of the JNI tutorial on here, it is a great way to get you started. -
How to Call SQL Loader from Java ( servlet )?
We need to call SQL Loader command from Java Servlets? Any suggestions how this can be done?
Thanks
RahulProbably not the best way, but you could try using JNI to call a C function which then invokes SQL Loader via system() or exec(). I haven't done this myself though...
-
How to call a specific method in a servlet from another servlet
Hi peeps, this post is kinda linked to my other thread but more direct !!
I need to call a method from another servlet and retrieve info/objects from that method and manipulate them in the originating servlet .... how can I do it ?
Assume the originating servlet is called Control and the servlet/method I want to access is DAO/login.
I can create an object of the DAO class, say newDAO, and access the login method by newDAO.login(username, password). Then how do I get the returned info from the DAO ??
Can I use the RequestDispatcher to INCLUDE the call to the DAO class method "login" ???
Cheers
KevinThanks for the reply.
So if I have a method in my DAO class called login() and I want to call it from my control servlet, what would the syntax be ?
getrequestdispatcher.include(newDAO.login())
where newDAO is an instance of the class DAO, would that be correct ?? I'd simply pass the request object as a parameter in the login method and to retrieve the results of login() the requestdispatcher.include method will return whatever I set as an attribute to the request object, do I have that right ?!!!!
Kevin
Maybe you are looking for
-
How do I send files from iPad to Mac book pro
Hi I am having trouble blue too thing my new IPad Air to my mac book pro?
-
I have a windows Xp computer. and i needed to download the newest itunes to support my ipod touch. but now my computer doesn't let me open itunes. The the data execution prevention pops up and says "to protect your computer, windows has closed this p
-
"Choose a Language" Instead of Opening a Scanned .pdf
Reader 10 cannot 'read' .pdf attached to email. I get a dropdown box asking me to choose a language. This has happened with three different attachments (scans of documenhts) on two emails from different sources. I uninstalled 10, rebooted and then re
-
File sharing trough Leopard Macs and Tiger macs
Is it not possible to share files via "afp://" when one computer is having Leopard and another is having Tiger or am I just doing something wrong?
-
Accessing BPEL Variables in XSLT
Hi All, In a BPEL PM process I need to be able to access a global BPEL process variable in the XSL transformation. When I use any functions in the "Transform" activity I do not see the BPEL variables in scope. Any idea on how can this can be done ? R