JSP & Native methods -  Is JNI best practice?

I have been doing some research before beginning my next project, which needs JSP to interact with a C API. I have only used JSP for 3-4 months, and that was 2 years ago, so I'm not too fluent with it yet. (My company primarily uses PHP.) So far, the options I have come across are:
1) Executing the C program from a Servlet using CLI and parsing the output.
2) JNI function calls (preferable)
However, while researching this subject, I have come across some discussions/threads (not in this forum) that suggested JNI doesn't work well with JSP. Their reasonings included:
-- If anything goes seriously wrong in the C part of your application, it will very likely crash your J2EE server, downing all other web services and applications it is running.
-- Because of the 'reactivatable' nature of web applications means there is no guarantee that a static initializer will not be executed more than once during one JVM run.
-- Problems involving servlets' multi-threaded nature. (http://www.javaquestions.org/ftopic19816.html) I don't think this will be a problem for me, since this is for an intranet, and I believe there should only be one user at a time.
Are any of those points valid? Is JNI the best way to go?
Thanks for any help you can give,
Matt Calderwood

Valid, sure. But you should be able to overcome most of these through coding:
If anything goes seriously wrong in the C part of your application, it will very likely crash your J2EE server, downing all other web services and applications it is running.
Yeah, so test it first. There's 100 other ways your server can (and probably will) go down. What do you do about those?
Because of the 'reactivatable' nature of web applications means there is no guarantee that a static initializer will not be executed more than once during one JVM run.
And how relevant is this to what you're doing? Not terribly, I bet.
Problems involving servlets' multi-threaded nature. (http://www.javaquestions.org/ftopic19816.html) I don't think this will be a problem for me, since this is for an intranet, and I believe there should only be one user at a time.
Can't you resolve this mostly yourself through good threaded code?
I run a website that connects to some ActiveX controls (namely CXServer, which access Omron PLC controllers) through JNI for purposes of retrieving and displaying line status through webpages. I generated the JNI code dynamically using JacoZoom's product. It has been no more troublesome than any other J2EE application. Everytime there's a problem, I can directly attribute it to my level of retardation, or lack of sleep.

Similar Messages

  • Exception when creating instance of a class with native method by JNI

    I am trying to use JNI - I want to have a Java class Foo have a
    method, that is a native C function.
    I follow the Sun's tutorial
    http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jnie...
    exactly, and everything compiles fine, and I have compiled my C .dll
    as well (on Win XP). So I am ready to run - ...
    Now when I finally try to run the Java application, it throws this
    exception when it tries to create the Foo instance:
    at Foo.<init>(Foo.java:11)
    at
    sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at
    sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct
    orAccessorImpl.java:39)
    at
    sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC
    onstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:
    513)
    at java.lang.Class.newInstance0(Class.java:355)
    at java.lang.Class.newInstance(Class.java:308)
    at sun.applet.AppletPanel.createApplet(AppletPanel.java:786)
    at sun.applet.AppletPanel.runLoader(AppletPanel.java:715)
    at sun.applet.AppletPanel.run(AppletPanel.java:369)
    at java.lang.Thread.run(Thread.java:619)
    Caused by: java.security.AccessControlException: access denied
    (java.lang.Runtim
    ePermission loadLibrary.Foo)
    Why would this be so??? Thank you for your insights

    Mark_Galeck wrote:
    I am trying to use JNI - I want to have a Java class Foo have a
    method, that is a native C function.
    I follow the Sun's tutorial
    http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jnie...
    exactlyNot quite exactly. Yours is an applet, theirs is an application.
    Applets are not allowed many things that applications can do.
    Among them, loading native libraries.

  • Customize OIM jsp forms using xlWebApp.war: Best Practice?

    Based on searching the forum, it appears that inflating the war files, making changes and putting them back again is the way to customize the jsp forms in OIM. Is this a best practice though? What happens when I want to upgrade? Do I lose all my customizations or is there another way to do this?
    Edited by: user4486549 on Jun 5, 2009 5:11 AM

    Hi,
    That is the only way to do it.In case of upgrade every time you will have to merge the changes in new war file and redeploy it. Just take care of one thing that do not modify existing jsp or classes.Create your own jsps and classes.
    Regards

  • Error while compiling javacode with native method using jni

    im trying to call function in dll that is written in vc++ from java application.
    For that i write a native method .the method name is StopDS1.
    my native method is : public native DWORD StopDS1();
    when compiling using javac i'm getting message like this:
    testdss.java:4: cannot found symbol
    symbol:class dword
    location :class testdss
    1error

    DWORD isn't a Java type, therefore you cannot use it as one.

  • Oracle BPM Best Practices

    Hi all,
    Anybody has any information on the Oracle BPM Best Practices?
    Any guide?

    All,
    I was trying to find a developers guide for using Oracle BPM Suite (11g). I found the one in the following link, however this looks like a pretty detailed one...
    http://download.oracle.com/docs/cd/B31017_01/integrate.1013/b28981/toc.htm
    Can you someone help me find any other flavors of the developers guide? I am looking for the following...
    1. Methods of work - Best Practices for design and development of BPM process models.
    2. Naming Conventions for Process Modeling - Best Practices
    3. Coding standards for Process Modeling (J Developer)
    4. Guide with FAQ's for connecting / Publishing Process Models to the MDS Database.
    5. Deployment Standards - best practices....
    6. Infrastructure - Recommendations for Scale out deployment in Linux v/s Windows OS.
    Regards,
    Dinesh Reddy

  • [XI 3.1] BEST PRACTICE method of Oracle connection for RPTs on Linux

    Business Objects XI (3.1) - SP3.
    Running on Red Hat Enterprise Linux OS.
    7,000+ Crystal Reports 2008 *.rpt objects ONLY (No Universe / No WebI).
    All reports connecting to Oracle 10g databases.
    ==================
    In the past, all of this infrastructure was running on Windows Server OS and providing the database access via a Named ODBC connection (eg. "APP_DATA".)
    This made it easy to manage as all the Report Developers had a standard System DSN called "APP_DATA" which was the same as the System DSN name on all of our DEV, TEST/UAT, and PROD servers for Business Objects.
    When we wanted to move/promote a *.rpt file from DEV to PROD we did not have to change any "Database Connection" info as it was all taken care of by pointing the System DSN called "APP_DATA" a a different physical Oracle server at the ODBC level.
    Now, that hardware is moving from Windows OS to Red Hat Linux and we are trying to determine the Best Practices (and Pros/Cons) of using one of the three methods below to access the Oracle database for our *.rpts....
    1.) Oracle Native connection
    2.) ODBC connection
    3.) JDBC connection
    Here's what we have determined so far -
    1a.) Oracle Native connection should be the most efficient method of passing SQL-query to the DB with the fewest issues and best speed [PRO]
    1b.) Oracle Native connection may not be supported on Linux - http://www.forumtopics.com/busobj/viewtopic.php?t=118770&view=previous&sid=9cca754b468fc67888ab2553c0fbe448 [CON]
    1c.) Using Oracle Native would require special-handling on the *.rpts at either the source-file or the CMC level to change them from DEV -> TEST -> PROD connection. This would result in a lot more Developer / Admin overhead than they are currently used to. [CON]
    2a.) A 3rd-Party Linux ODBC option may be available from EasySoft - http://www.easysoft.com/products/data_access/odbc_oracle_driver/index.html - which would allow us to use a similar Developer / Admin overhead to what we are used to. [PRO]
    2b.) Adding a 3rd-Party Vendor into the mix may lead to support issues is we have problems with results or speeds of our queries. [CON]
    3a.) JDBC appears to be the "defacto standard" when running Oracle SQL queries from Linux. [PRO]
    3b.) There may be issues with results or speeds of our queries when using JDBC. [CON]
    3c.) Using JDBC requires the explicit-IP of the Oracle server to be defined for each connection. This would require special-handling on the *.rpts at either the source-file (and NOT the CMC level) to change them from DEV -> TEST -> PROD connection. This would result in a lot more Developer / Admin overhead than they are currently used to. [CON]
    ==================
    We would appreciate some advice from anyone who has been down this road before.
    What were your Best Practices?
    What can you add to the Pros and Cons listed above?
    How do we find the "sweet spot" between quality/performance/speed of reports and easy-overhead for the Admins and Developers?
    As always, thanks in advance for your comments.

    Hi,
    I just saw this article and I would like to add some infos.
    First you can quite easely reproduce the same way of working with the odbc entries by playing with the oracle name resolution on the server. By changing some files (sqlnet, tnsnames.ora,..) you can define a different oracle server for a specific name that will be the same accross all environments.
    Database name will be resolved differently regarding to the environment and therefore will access a different database.
    Second option is the possibility to change the connection in .rpt files by an automated way like the schedule manager. This tool is a additional web application to deploy that can change the connection settings of rpt reports on thousands of reports in a few clicks. you can find it here :
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/80af7965-8bdf-2b10-fa94-bb21833f3db8
    The last option is to do it with a small sdk script, for this purpose, a few lines of codes can change all the reports in a row.
    After some implementations on linux to oracle database I would prefer also the native connection. ODBC and JDBC are deprecated ways to connect to database. You can use DATADIRECT connectors that are quite good but for volumes you will see the difference.

  • Access object attributes using other object JNI native method

    Hi. I'm trying to change an attribute of object O1 from another object O2 without invoking a O1 method and without making the attribute as public or protected.
    The only possibility that comes to my mind for doing so is writting a JNI native method
    public class O1 {
    static public native changeAttribute (Object O2, Object newAttributeValue) ;
    that change the attribute memory reference, but all I've found about accesing attributes in JNI is about accessing the invoker attributes (in this case, O1).
    �Does any one know if it's possible to do so? Thanks.

    I know that is not a good practice but I cannot figure out another way.
    I'll try to explain the whole problem so you see the reason. I'm working with transactions, using objects as the data. An object can be opened for write by several transactions because the granularity for conflicts is not the object, is each of its attributes. As long as two transaction don't write the same attribute, they both can write. For writing, each transactions uses a private copy of the object. At committing, the actual copy of the object must be replaced by the committer one, but as far as the granularity is the object attributes, only each written attribute must be replaced (if not, only the last commit would be visible).
    This attribute replace must be done by the transaction manager as far as the transactional object is provided by the client. So what i was thinking was to use JNI or some trick like that to replace the object attributes transparently to the object.
    I hope the explain is clear, my english is a little asleep :-(.
    How to do it with reflection? I thought that was only for method calling. Anyway, there wouldn't be problems if the attributes are private?
    Thanks for answering.
    EDIT: I've been able to change a public field using reflection, but not the private one
    import java.lang.reflect.*;
    class Caca {
    public static void main(String[] args) {
    Integer r = new Integer(0);
    System.out.println("original: " + r.toString());
    modifyWidth(r, 300);
    System.out.println("modified: " + r.toString());
    static void modifyWidth(Integer r, int newValue ) {
    Field valueField; Class c = r.getClass();
    try {
    valueField = c.getField("value");
    valueField.set(r, newValue);
    } catch (Exception e) { System.out.println(e); }
    Message was edited by:
    dfasdfsdafsadfasdf

  • JSP Best Practices and Oracle Report

    Hello,
    I am writing an application that obtains information from the user using a JSP/HTML form and then submitted to a database, the JSP page is setup using JSP Best Practices in which the SQL statments, database connectivity information, and most of the Java source code in a java bean/java class. I want to use Oracle Reports to call this bean, and generate a JSP page displaying the information the user requested from the database. Would you please offer me guidance for setting this up.
    Thank you,
    Michelle

    JSP Best Practices.
    More JSP Best Practices
    But the most important Best Practice has already been given in this thread: use JSP pages for presentation only.

  • Best practice for dealing with Recordsets, JDBC and JSP?

    I've spent the last three years developing web apps using JSP, Struts and Kodo JDO for persistence. All of the content for the apps was created as Java objects using model classes and saved to an Oracle db. Thus, data retrieved from the db was as instances of the model classes and then put into Struts form beans, etc.
    I changed jobs last month and am now having to use Servlets with JDBC to retrieve records from db tables and returning it into Recordsets. Oh, and I can't use Struts in my JSPs either. I'm beginning to think that I had it easy at my previous job but maybe that's just because I was used to it.
    So here are my problems/questions:
    I have two tables with a one to many relationship that I need to retrieve data from, show in a jsp and be able to update eventually.
    So here's what I am doing:
    a) In a servlet, I use a SQL statement to join the tables and retrieve the results into a Recordset.
    b) I created a class with a bunch of String attributes to copy the Recordset data into, one Recordset row per each instance of the bean and then close the Recordset
    c) I then add the beans to an ArrayList and save the ArrayList into the session.
    d) Then, in the JSP, I retrieve the ArrayList from the session and iterate over each bean instance, printing the data out to the jsp. There are some logic statements to determine when not to print redundant data caused by the one to many join.
    e) I have not written the code to update the data yet but was planning on having separate jsps for updating the (one) table and the (many) table.
    Would most of you do something similar? Would you use one SQL statement to retrieve all of the data for display and use logic to avoid printing the redundant part of the data? Or would you have used separate SQL queries, one for each table? Would you have saved the results into something other than an instance of a bean class that represents one record in the RecordSet? Would you have had a bean class with attributes other than Strings - like had a collection attribute to hold the results from the "many" table? The way that I am doing everything just seems so cumbersome and difficult compared to using Struts and JDO before.
    Your help/opinion will be greatly appreciated!

    Would you use one SQL statement to retrieve all of the data for display Yes.
    and use logic to avoid printing the redundant part of the dataNo.
    I believe in minimising the number of queries. If it is a simple one-many join on a db table, then one query is better than one + n queries.
    However I prefer to store the objects in a bean class with attributes other than strings - ie one object, with a collection attribute to hold the related "many" records.
    Does the fact you are not using Struts mean that you have to use scriptlet code? (shudder)
    Or are you using JSTL, or other custom tags?
    How about tools like Ant? Junit testing?
    The way that I am doing everything just seems so cumbersome and difficult
    compared to using Struts and JDO before.Anything different takes adjusting to. Sounds like you know what you're doing for the most part. I agree, in terms of best practices what you have described so far sounds like a step backwards from what you were previously doing.
    However I wouldn't go complaining about it too loudly, too quickly. If you're new on the block theres nothing like making a pain of yourself, and complaining how backwards the work they have done is to put your new workmates' backs up
    Look on it as a challenge. Maybe discuss it quietly with a team leader, to see if they understand how much easier/better/less error prone such approaches can be?
    Struts, cumbersome as it can be, definitely has the advantage of pushing you to follow good MVC practice.
    Good luck,
    evnafets

  • Does JSP best practice of putting under WEB-INF apply to JSF pages?

    I'm new to JSF and wondering if the "best practice" advice that used to be given of storing your jsp pages under WEB-INF (when using Model2) to keep them from being served up without going through your controller still applies with JSF.
    Since the component lifecycle is so different, I'm wondering if it would still apply? If anyone can explain why it might or might not apply I'd appreciate it!
    Thanks!

    The rule is:
    keep all the pages you don�t user to "browse", under the WEB-INF directory.
    MeTitus

  • JNI Calls to Native Methods No Longer Work: Possible Versioning Issue ?

    Hello, all. Just a quick question... is it possible that invoking a method in a JNI-compliant DLL from Java 6 will fail if the DLL's source was compiled against the JNI header files from Java 4 or 5 ? I have a DLL with methods that used to be called successfully (and now fail outright and don't even seem to be getting inside the native method), but it seems that the only thing that could have changed in the environment is the installed JRE. Even stranger, I don't get the hs_err* files anymore to indicate that the JVM crashed. Does anyone know why this might happen ? Thanks !

    Cthulhu76 wrote:
    Hello, all. Just a quick question... is it possible that invoking a method in a JNI-compliant DLL from Java 6 will fail if the DLL's source was compiled against the JNI header files from Java 4 or 5 ? Solely? No.
    You could of course be doing something in the JNI code in terms of working with Java which no longer works. Just as it is at least possible that java code from one version might not work with another.
    Correct error checking in the JNI code would at least correctly identify this problem however.
    I have a DLL with methods that used to be called successfully (and now fail outright and don't even seem to be getting inside the native method), but it seems that the only thing that could have changed in the environment is the installed JRE.The only thing that you assume changed was the JRE.
    You seem unsure whether the JNI is being called at all, so verifying that first would be a good idea.

  • Best Practice for Updating Infotype HRP1001 via Class / Methods

    I want to update an existing (custom) relationship between two positions.
    For example I want
    Position 1 S  = '50007200'
    Position 2 S =  '50007202'
    Relationship = 'AZCR'
    effective today through 99991231
    Is there a best practice or generally accepted way for doing this using classes/methods rather than RH_INSERT_INFTY ?
    If so, please supply an example.
    Thanks...
    ....Mike

    Hi Scott
    You can use a BAPI to do that.
    Check the following thread:
    BAPI to update characteristics in Material master?
    BR
    Caetano

  • What is the best practice to handle JPA methods in JSF app?

    I am building a JSF-JPA web app(No EJB).
    I have several methods that has JPA QL inside.
    Because I have to put those methods inside JSF beans to inject EntityManagerFactory (am I right about this?).
    And I do want to separate those methods from regular JSF beans which are used by page authors.
    And I may need to use them in different JSF managed beans.
    My question here is that what is the best practice to handle that?
    I. write a or a few separate JSF Beans and inject them into regular Beans?
    II. write a or a few separate JSF Beans and access them into regular Beans using FacesContext?
    III. others?
    Waiting to hear from you opinions.

    You can create named queries on your Entities themselves then just call entityMgr.createNamedQuery("nameOfQuery");
    Normally, we put these named queries in the class of the entity which will be returned. This allows for all information pertaining to a given entity and all ways of accessing that entity (except em.find() and stuff, of course) to be in one place. As long as the entity is defined in your persistence.xml file, any named queries which reside on that entity will be available through the EntityManager.
    As for the EntityManagerFactory, we normally create an application scope bean which holds the factory itself (because this is a heavy-weight object) and then just get all EntityManager instances from that by injecting this bean into whatever needs it. For example, I might have:
    //emfBB is the injected app scope bean which holds the entity manager factory.
    private EmfBB emfBB;
    private void lookupSomeData()
    EntityManager em = this.getEmfBB().getEmf()
    I hope this answered your question?
    ~Zack
    Edited by: zmarr on Nov 6, 2008 1:29 PM

  • JSP best practices...

    I know that in the MVC model for web services/application design that the JSP is the view component and so therefore the idea is to take out all scripting code (except for JavaScript maybe). I was wondering if the best practice for using/writing JSPs is to have a servlet determine what action the user requests and then dynamically generating the JSP based on that action. I believe that this is what the Sun developers are doing with the index.jsp page for the forums section. They use a SessionServlet although for which purposes I am not entirly sure. I downloaded the index.jsp page to see if it had scripting code in it, but it was just a buch of HTML, so am I wrong to assume that it was dynamically generated? Any insight to this mystery would be much appreciated!

    Normally you cant donwload JSP code.
    You downloaded HTML that was generated by JSP

  • Native Toplink to EclipseLink to JPA - Migration Best Practice

    I am currently looking at the future technical stack of our developments, and would appreciate any advise concerning best practice migration paths.
    Our current platform is as follows:
    Oracle 10g AS -> Toplink 10g -> Spring 2.5.x
    We have (approx.) 100 seperate Toplink Mapping Workbench projects (we have one per DDD Aggregate object in effect) and therefore 100 Repositories (or DAOs), some using Toplink code (e.g. Expression Builder, Class Extractors etc) on top of the mappings to support Object to RDB (legacy) mismatch.
    Future platform is:
    Oracle 11g AS -> EclipseLink -> Spring 3.x
    Migration issues are as follows:
    Spring 3.x does not provide any Native Toplink ORM support
    Spring 2.5.x requires Toplink 10g to provide Native Toplink ORM support
    My current plan is as follows:
    1. Migrate Code and Mappings to use EclipseLink (as per Link:[http://wiki.eclipse.org/EclipseLink/Examples/MigratingFromOracleTopLink])
    2. Temporarily re-implement the Spring 2.5.x ->Toplink 10g support code to use EclipseLink (e.g. TopLinkDaoSupport etc) to enable testing of this step.
    3. Refactor all Repositories/DAOs and Support code to use JPA engine (i.e. Entity Manager etc.)
    4. Move to Spring 3.x
    5. Move to 11g (when available!)
    Step 2 is only required to enable testing of the mapping changes, without changing to use the JPA engine.
    Step 3 will only work if my understanding of the following statement is correct (i.e. I can use the JPA engine to run native Toplink mappings and associated code):
    Quote:"Deployment XML files from Oracle TopLink 10.1.3 and above can be read by EclipseLink."
    Speciifc questions are:
    Is my understanding correct regarding the above?
    Is there any other path to achieve the goal of using 11g, EclipseLink (and Spring 3.x)?
    Is this achieveable without refactoring all XML mappings from Native -> JPA?
    Many thanks for any assistance.
    Marc

    It is possible to use the native/MW TopLink/EclipseLink deployment xml files with JPA in EclipseLink, this is correct. You just need to pass a persistence property giving your sessions.xml file location. The native API is also still supported in EclipseLink.
    James : http://www.eclipselink.org

Maybe you are looking for

  • We can use JSR-168 JPS portlet upload file,

    We can use JSR-168 JPS portlet upload file, here is the source for you referrence: upload file can use JSR168 portlet, 1,CustomizablePortlet.java File import java.io.IOException; import java.io.PrintWriter; import java.util.ResourceBundle; import jav

  • How to write driver programming in smartforms

    hi Floks <i>how to write driver programmig and how many types of driver programs available to trigger smartforms what are they . how to call the url in smartforms ? help me  out  .thanking you ,</i> with regards, suresh

  • MAX Reports-Initialization Error, Editing Components missing?

    Using a NI PXI-1042Q and an 4472B Daq card to capture data.  Running LabVIEW 8.2 on a Windows XP system.  The program controls an MID7604 which controls a motor.  Using a program that was written and is now an executable.  To run the program minor fi

  • How to detect baby crying using labview and webcam?

    Hi, I am new to labVIEW. I have a project that it requires me to develope a application to detect various types of  baby crying using labVIEW.The hardware we use will be webcam or kinect xbox 360. The system for my computer is windows 7. I used to tr

  • Photoshop 7.0 for Mac OSX

    I bought Photoshop 7.0 for my Mac OSX and it won't install. The site I bought it from won't return it because the package is open. (duh, I have to open it to install it) but I get a message saying my computer does not support PowerPC. I specifically