Invoke beanshell methods from java
Hello
I'm learning beanshell and using it to write scripts that are ran in JDK 6.
My question is how to invok beanshell methods from java source codes.
My codes is:
import javax.script.*;
public class InvokeFunctions {
public static void main (String[] args)throws ScriptException, NoSuchMethodException
ScriptEngineManager sem = new ScriptEngineManager();
ScriptEngine bshEngine = sem.getEngineByName("beanshell");
String script = "public void sayHello()"+"{print (\"sayHello() is a method in bsh script\");}";
bshEngine.eval(script);
Invocable inbshEngine = (Invocable)bshEngine;
inbshEngine.invokeFunction("sayHello");
I defined a method "sayHello()" using beanshell, but i just can't invoke it in Java.
I got an error msg said:
Exception in thread "main" java.lang.IllegalAccessError: tried to access method bsh.NameSpace.getThis(Lbsh/Interpreter;)Lbsh/This; from class bsh.engine.BshScriptEngine
Any one has any idea about it?
Thanks
Look at the Javadoc documentation of IllegalAccessError. It says:
Thrown if an application attempts to access or modify a field, or to call a method that it does not have access to.
Normally, this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed.
Maybe recompiling all your sources (make sure you delete all existing *.class files) will help?
Similar Messages
-
Problems invoking a method from a web service
Am using netbeans 6.1 and my problem is when i invoke a method from a web service that has a custom class as a return type.
When I debug the client that consumes my web service, It get Stack in this line:
com.webservice.WebServiceInfoBean result = port.getWebServiceInfo(nameSpace, serviceName, portName, wsdlURL);
i don't get any error on the console.
static public void function1() {
try { // Call Web Service Operation
com.webservice.WebServiceMonitorService service = new com.webservice.WebServiceMonitorService();
com.webservice.WebServiceMonitor port = service.getWebServiceMonitorPort();
// TODO initialize WS operation arguments here
java.lang.String nameSpace = "NameSpaceHere";
java.lang.String serviceName = "WebServicePrueba";
java.lang.String portName = "Soap";
java.lang.String wsdlURL = "http://localhost/Prueba/WebServicePrueba.asmx?wsdl";
// TODO process result here
com.webservice.WebServiceInfoBean result = port.getWebServiceInfo(nameSpace, serviceName, portName, wsdlURL); // <--- here it stack
System.out.println("getWebServiceInfo");
Iterator i = result.getMethods().iterator();
while (i.hasNext()) {
MethodBean method = (MethodBean) i.next();
System.out.print("Nombre: " + method.getname());
System.out.print(" Returns: " + method.getreturnType());
Iterator j = method.getparameters().iterator();
while (j.hasNext()) {
ParameterBean parameter = (ParameterBean) j.next();
System.out.print(" ParameterName: " + parameter.getname());
System.out.print(" ParameterType: " + parameter.gettype());
System.out.print("\n");
System.out.print(method.getfirma());
System.out.print("\n");
System.out.print("\n");
} catch (Exception ex) {
ex.printStackTrace();
}Web Service side
* Web service operation
@WebMethod(operationName = "getWebServiceInfo")
public WebServiceInfoBean getWebServiceInfo(@WebParam(name = "nameSpace")
String nameSpace, @WebParam(name = "portName")
String portName, @WebParam(name = "serviceName")
String serviceName, @WebParam(name = "wsdlURL")
String wsdlURL) throws Throwable {
//TODO write your implementation code here:
webservicemonitor instance = new webservicemonitor();
return instance.getWebServiceInfo(nameSpace, serviceName, portName, wsdlURL);
}I have tested my internal code from the web service side and everything works fine. The problem occurs when i invoke it from a client side. probably I did not made the right serialization form my class WebServiceInfoBean? or am missing something. here it is:
* To change this template, choose Tools | Templates
* and open the template in the editor.
package com.beans;
import java.util.ArrayList;
* @author Tequila_Burp
public class WebServiceInfoBean implements java.io.Serializable {
* Holds value of property wsdlURL.
private String wsdlURL;
* Getter for property wsdlURL.
* @return Value of property wsdlURL.
public String getwsdlURL() {
return this.wsdlURL;
* Setter for property wsdlURL.
* @param wsdlURL New value of property wsdlURL.
public void setwsdlURL(String wsdlURL) {
this.wsdlURL = wsdlURL;
* Holds value of property namespace.
private String namespace;
* Getter for property namespace.
* @return Value of property namespace.
public String getnamespace() {
return this.namespace;
* Setter for property namespace.
* @param namespace New value of property namespace.
public void setnamespace(String namespace) {
this.namespace = namespace;
* Holds value of property serviceName.
private String serviceName;
* Getter for property serviceName.
* @return Value of property serviceName.
public String getserviceName() {
return this.serviceName;
* Setter for property serviceName.
* @param serviceName New value of property serviceName.
public void setserviceName(String serviceName) {
this.serviceName = serviceName;
* Holds value of property wsdlURL.
private String portName;
* Getter for property wsdlURL.
* @return Value of property wsdlURL.
public String getportName() {
return this.portName;
* Setter for property wsdlURL.
* @param wsdlURL New value of property wsdlURL.
public void setportName(String portName) {
this.portName = portName;
* Holds value of property methods.
private ArrayList methods = new ArrayList();
* Getter for property methods.
* @return Value of property methods.
public ArrayList getmethods() {
return this.methods;
* Setter for property methods.
* @param methods New value of property methods.
public void setmethods(ArrayList methods) {
this.methods = methods;
public MethodBean getMethod(int i) {
return (MethodBean)methods.get(i);
}by the way, everything has been worked on the same PC.Hi Paul,
This sound familiar, but I cannot at the moment locate a reference to
the issue. I would encourage you to seek the help of our super support
team [1].
Regards,
Bruce
[1]
http://support.bea.com
[email protected]
Paul Merrigan wrote:
>
I'm trying to invoke a secure 8.1 web service from a 6.1 client application and keep getting rejected with the following message:
Security Violation: User: '<anonymous>' has insufficient permission to access EJB:
In the 6.1 client, I've established a WebServiceProxy and set the userName and password to the proper values, but I can't seem to get past the security.
If there something special I need to do on either the 8.1 securing side or on the 6.1 accessing side to make this work?
Any help would be GREATLY appreciated. -
Is it possible to invoke JEB method from thread?
Hello everybody!
I have problem creating EJB from the thread. Here is the part of code below:
public void email() throws Exception {
class MailThread implements Runnable {
public MailThread() {
public void run() {
try {
String jndiName "java:comp/env/ejb/PROG/Mail";
IMailHome mailHome;
IMail mail;
InitialContext context = new InitialContext();
Object objref = context.lookup(jndiName);
mailHome = (IMailHome) PortableRemoteObject.narrow(objref, IMailHome.class);
// Exception here:
// java.rmi.RemoteException: Exception Substitute; nested exception is:
// java.lang.NullPointerException mail = mailHome.create();
// business metods
// mail.method1();
} catch (Exception e) {
System.out.println("Exception:" + e);
MailThread mt = new MailThread();
Thread thread = new Thread(mt);
thread.start();
Exception:
java.rmi.RemoteException: Exception Substitute; nested exception is:
java.lang.NullPointerException
I am not able to create EJB instance from the thread. The same code works well in servlet. Am I doing something wrong?
May be there are some different approaches to implement some operations asynchronously at EJB level do not using JMS and MDB? J2EE specification prohibits to use threads inside EJB so the only way I see is to create different thread on servlet side and invoke EJB methods from it. But it seems that this doesn't work too. Could anyone help me?
Thanks in advance,
Vadim LotarevIf the passcode will not work, the only alternative is to restore the phone as new. You cannot change the passcode from the lock screen.
-
Call Javascript methods from Java methods
Dear All,
I have a requirement where I need to invoke Javascript methods from a Java file located in the same machine. Are there any possible solutions for this?
Regards,
AlokHi,
Thanks for all your replies. Does this work on Java 5 too? Could you please share the complete code snippet which makes it work? I tried working on yours but no success.
Regards,
Alok -
How to Call C++ Method from Java
I need to call C++ method from Java.
I have gone through the JNI tuorial , but was not able to pin point things.
I read that :
You have to write JNI c functions which then call your C++ member functions.You need to write a JNI function which will call new on your C++ class.
Now i have java class :
Java Code JavaClass.java ---->
class JavaClass{
public native void nativeMethod();
static
System.loadLibrary("NativeCppCode");
private void callCppMethod()
//call C++ method
JavaClass jvc = new JavaClass();
jvc.nativeMethod()
}Cpp Code:
NativeCppCode.h---->
class NativeCppCode
public:
getValue();
setValue();
private:
int a;
JNIEXPORT void JNICALL Java_JavaClass_nativeMethod(JNIEnv *env
,jobject obj);NativeCppCode.C---->
NativeCppCode::getValue()
return a;
NativeCppCode::setValue()
a = 1;
JNIEXPORT void JNICALL Java_JavaClass_nativeMethod(JNIEnv *env
,jobject obj)
NativeCppCode* nativeInstabce = new NativeCppCode();
NativeCppCode.setValue();
}Is this the correct way to do it.
Any suggestion would be a great help to metryit wrote:
I need to call C++ method from Java.Not possible.
JNI uses C methods.
Is this the correct way to do it.Same way you would do it in any C/C++ method (not java)
MyClass* p = ....
p->doit();
Common idiom for the pointer in the above is to pass it back and forth to your java code as a java long. You cast it it and from your class pointer. Provide an explicit java method to free it when done. Besides providing the explicit method also implement a finalizer to free it as well (however that is a fail safe and should not be relied upon.) -
How to invoke dos shell from java program
Hi,
I'm not able to invoke dos shell from java.
Can any one help me in this issue.
I'm providing the source code below:
try{
Runtime.getRuntime().exec("cmd.exe")
catch(IOException e) {
System.out.println(e.getStackTrace());
ThanksDoes it throw a different exception?
Or does it just do nothing at all?
It does nothing at all[/b
Is this a standalone Java app?
Or a Java Applet running via a webbrowser? [b]It's a standalone application -
How to invoke BPEL process from JAVA API
Hi Guys
Any idea if you can tell me how to invoke BPEL process from JAVA API ?
What to do in BPEL process manager to achieve that?
Regards
DeepakSee http://download-west.oracle.com/docs/cd/B31017_01/integrate.1013/b28981/invoke.htm#sthref1373 and the JavaDocs http://download-west.oracle.com/docs/cd/B31017_01/integrate.1013/b28986/toc.htm.
-
Invoking Microsoft Word from Java code
I want to invoke Microsoft word from Java code. How can i do this plz ............... Help
do something along these lines.... here is an example with notepad
create a .bat file with the commmand in to run notepad for example
notpad c:\test.txtthis command calls notepad and passes it the argument C:\test.txt which is the file and it's location, that I want to open.
The Java program
import java.util.*;
import java.io.*;
public class Run
public static void main(String args[])
try
//the name of the batch file with your commands in
String command ="runprog.bat";
//get the runtime
Runtime rt = Runtime.getRuntime();
//run the bat file
Process proc = rt.exec(command);
//wait for the program to exit i.e notepad then get the return code
int exitVal = proc.waitFor();
//print out the exit value
System.out.println(2THe Process exit value is: " + exitVal);
catch(Throwable t)
t.printStackTrace();
}have a look at this
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html
and this
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps_p.html -
Are DLL methods called as instance or static methods from Java ?
Hi,
I have only a small question.
When I call a C++ DLL method from Java using JNI, do I instantiate it like an object method or is it called as a static method ?
I am asking you this because I will use servlets (Java 1.2.2) to call a DLL. These servlets may run concurrently in any moment, and I pass some data to this DLL. I want to know if there is any possibility of this data becoming corrupt, because of one concurrent servlet rewriting the data another servlet has passed.
Thanks and regards.The question is not specific enough.
Methods in C/C++ can be qualified with the following forms:
-global (C/C++)
-static member(C++ class method)
-instance member(C++ class method)
Since you didn't provide your code I couldn't possible determine which of the above you are using, but presumably you know.
On the other hand a java native method is either static or non-static depending on how you defined it in the class. Once again without the code there is no way to say and presumably you already know this.
The context of the methods is the same context that a similar servlet method has. But naturally in C/C++ is is easy to circumvent the context - for example by using a global variable.
Data in C/C++ can always become corrupt and in the vast (all?) cases it is because something is wrong in the C/C++ code. Like a pointer that is not initialized, or a pointer used after it is free'd. Or writing past the end of a buffer, or writing before the beginning of a buffer. -
How to call backing bean method from java script
Hi,
I would like to know how to call backing bean method from java script.
I am aware of serverListener and [AjaxAutoSuggest article|http://www.oracle.com/technology/products/jdev/tips/mills/AjaxAutoSuggest/AjaxAutoSuggest.html]
but i am running in to some issues with [AjaxAutoSuggest article|http://www.oracle.com/technology/products/jdev/tips/mills/AjaxAutoSuggest/AjaxAutoSuggest.html]
regarding which i asked for help in other thread with subject ....Question on AjaxAutoSuggest article (Ajax Transactions Using ADF and J...)
The reason why i posted is ( though i realise both are duplicates) .. that threads looks as a specific question to that article hence i would like to ask the quantified problem is asked in this thread.
So could any please letme know how to call backing bean method from java script
Thanks
Murali
Edited by: mchepuri on Oct 24, 2009 6:17 PM
Edited by: mchepuri on Oct 24, 2009 6:20 PMHello,
May know how to submit a button autoamtically on onload of page with clicking a welcome alert box. the submit button has managed button too to show a message on console using SOP.
the problem is.
1. before loading the page a javascript comes on which i clicked ok
2. the page gets loaded and the button is there which gets automatically clicked and the managed bean associated with prints a message on console using SOP.
I m trying to do this through server listener and click listener. the code is(adf jspx page)
<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
<jsp:directive.page contentType="text/html;charset=UTF-8"/>
<f:view>
<af:document id="d1" binding="#{backingBeanScope.backing_check4.d1}">
<af:form id="f1" binding="#{backingBeanScope.backing_check4.f1}">
<af:commandButton text="commandButton 1"
binding="#{backingBeanScope.backing_check4.cb1}"
id="cb1" action="#{beanCheck4.submit1}"/>
<af:clientListener type="click" method="delRow"/>
<af:serverListener type= "jsServerListener"
method="#{backingBeanScope.backing_check4.submit1}"/>
<f:facet name="metaContainer">
<af:resource type ="javascript">
x=confirm("hi");
// if(x){
delRow = function(event){
AdfCustomEvent.queue(event.getSource(), "jsServerListener", {}, false);
return true;
</af:resource>
</f:facet>
</af:form>
</af:document>
</f:view>
<!--oracle-jdev-comment:auto-binding-backing-bean-name:backing_check4-->
</jsp:root>
the backing bean code is -----
public class classCheck4 {
public classCheck4() {
public String submit1() {
System.out.println("hello");
return null;
} -
How to invoke action method from mail contained link
Hello,
my application needs to send mails to users that include links for the user to click on. Something like www.mysite.com/displayData.jsp&id=123. My question is now how I make JSF invoke the respective method in the backed bean to display the data with the id 123 when the user clicks on the link int the mail.
I wonder whether there is some kind of "catch-all action" that checks whether the user is logged in and authorized whenever any JSP page is invoked. I'm a bit tired of first checking the authorization of some user before processing the remaining part od the backed bean's action method.
Thanks for any hints,
Oliver Plohmannmy application needs to send mails to users that
include links for the user to click on. Something
like www.mysite.com/displayData.jsp&id=123. My
question is now how I make JSF invoke the respective
method in the backed bean to display the data with
the id 123 when the user clicks on the link int the
mail.I dont think there is a way to submit to an action on click of a link. Only possible solution is to invoke the method from the constructor of your Backing Bean and populate the bean fields displayed on your page.
I wonder whether there is some kind of "catch-all
action" that checks whether the user is logged in and
authorized whenever any JSP page is invoked. I'm a
bit tired of first checking the authorization of some
user before processing the remaining part od the
backed bean's action method. You can try out a Servlet filter for doing this. -
Can you give me an example of where or why you would invoke a CFC from Java? I have used CF to call Java and then having Java return "data" back to the CFC but not sure I know why I would want my Java to invoke a CFC.
ThanksHi,
how to invoke a exe file from a java program. (
operating system: windows )
is it possible ?Yep.
Navigate yourself around pitfalls related to the Runtime.exec() method -
Invoking dos commands from java
hi all,
I just want to invoke dos prompt from java.I know it can be done using "Runtime.getRuntime()" command.But when i try to create a directory inside another directory,how can i specify the path of the destination directory.i googled as well as tried different things.But i failed to make it up.Please help me solve this problem.
thanks in advance
RegardsHai,
Thanks for your respond.
If I give "cmd" command only, I am getting dos command window, but I didn't get the prompt like
c: or d:
How can I do it?
Expecting more helps
Joseph -
Calling javascript method from java
Hi this is sri,
I have one doubt on Java Applets "how to call the javascript method from java Applet".Can u give me the complete sample code for one program(both java applet file and html file also)because i can easily understand the programming flow.
Thanks ,
Srilekha.It's an extremely important skill to learn how to search the web. Not only will it increase your research and development talents, it will also save you from asking questions that have already been answered numerous times before. By doing a little research before you ask a question, you'll show that you're willing to work and learn without needing to have your hand held the entire time; a quality that is seemingly rare but much appreciated by the volunteers who are willing to help you.
If you've done the research, found nothing useful, and decide to post your question, it's a great idea to tell us that you've already searched (and what methodologies you used to do your research). That way, we don't refer you back to something you've already seen.
To get you started, here's a link...
http://www.google.com/search?q=call+java+from+javascript -
Invoking a method from a java class to a jsp file
Maybe i'm going through a very basic error, but as i've looked for in some forums and nothing found decided to post. So let's go to the problem.
Well, i have a form in a jsp file, it's basicaly html, but as i need some select boxes populated with data from the database i decided to create some methods in java classes. This is the point.
My method receive some attributes, like the table and colums names, the name of the select box and the HttpServletResponse object.
So after making all the database process. The method is supposed to write the result through the out.println(); object
It goes everything all right except that the method seems to be called first than the html code coz' my select boxes comes above the head in the begin of the page and was supposed to come in the middle.
part of the code:
package pacote;
import java.packages.*
public class Class{
public void metodo(HttpServletResponse response, String tableName, String column name, String selectName){
PrintWriter out = response.getWriter();
openConnection();
//After making the query stuff
//caso n�o haja nada na consulta
if(rst == null)
out.println("N�o h� registros.");
else{
out.println( "<select name='" +SelectName + "' id='" +SelectName + "' class=\"input_ob\" >");
out.println( "<option value=''>Escolha: "+objeto+"</option>");
//fill the select body with options; A while that sweap the resultSet and use the out object to write the results
getSelectBody(out,rst, selectValue);
}This method is called this way:
<tr valign="baseline">
<td nowrap align="right">Grupo</td>
<jsp:useBean id="m" scope="page" class="pacote.Class" />
<td>
<%
try{
m.metodo(response, "tabela","grupo","id_grupo);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
%></td>I'd like to know what i'm missing here. why the answer doesn't go in the place It's supposed to go.
any answer will be greatly apreciatedThe issue is caused because you are using the response to get the writer directly.
The JSP has gotten the same writer, but has wrapped it in a JSPWriter class. That class has got a buffer.
So it writes the beginning html to the JSPWriter buffer.
You write your stuff to the response writer - gets sent to the output.
It writes more stuff to the JSPWriter buffer, then flushes that buffer - at which point all the text written into the JSP writer now gets added to the response.
You see how your code is coming out first?
Solution - instead of getting the writer from the response, pass the writer into your method (maybe instead of response if you don't use response for anything else)
public void metodo(Writer jspWriter, String tableName, String column name, String selectName){
PrintWriter out = new PrintWriter(jspWriter);
...That means that you will be writing to the same writer, and the text should come out in sequence.
Cheers,
evnafets
Maybe you are looking for
-
After sync'ing my IPOD, the songs on my IPOD are separated by the album names from which they were downloaded from. Can I get rid of those album names on my IPOD somehow? I'd like to show nothing but the songs as I search thru the artists...... Plea
-
Laptop starts randomly(w​ont boot from first time)
I own HP Pavilion tx1000 for 2 yrs, it was working normal since now. The problem is - laptop starts from second third or more times. When I switch it on, only led indicators start working and hard drive, but no initial boot and screen blank. Then i
-
Photosmart 5510 All In One won't print black
One week ago I copied an A4 page and it worked. Last night, I tried to copy something and I realised that the printer has black ink issues. At first I thought that the printhead is dry so I did a printhead clean without any results. Then I thought th
-
Hello, since I have boucht a new iMac with Maverick, the Mail application doesn't find anything when I search with a key word. My VIP mailbox are empty too. Anyone experiencing the same issue?
-
I'm using Aperture 3.1.2. My Workflow is to arrange the images by file name, group the bracketed images, select them, create an HDR image via NiK HRD Efex Pro and then add the HDR image to the group. The problem is that after I create the HDR image t