Run Java Agent XPage - java

I try to run an Java Agent in XPage. The Agent runs in the beforePageLoad Event to manipulate the current document.
<xp:this.beforePageLoad><![CDATA[#{javascript:
var agent:NotesAgent =database.getAgent("RedirectGroups")
agent.runWithDocumentContext(currentDocument.getDocument())
}]]></xp:this.beforePageLoad>
For testing the agent prints a simple message to the console.
If I run the XPage in Browser I get an error 500 message. I'm using Notes 9.01 on an Domino 9 Server
Will I have to run the agent in an other event of the XPage?

Well, the first thing you have to realize is that a Java agent runs in a totally different context than the XPage. They are running in two separate JVMs. It is therefore also important to understand that you will NOT have access to any of the classes/resources available to your XPage from your agent.
To run Java code that manipulates your document you would use e.g. managed beans and instead of just having the opening/saving phases of a "traditional" Domino web application you will have the 6 phases in the JSF lifecycle to interact with your data source. This is a better pattern for modifying your data in an XPages application.
When you get an error 500 it means that some logic in the server side has failed (e.g. in a managed bean or some SSJS). The best way to see this is by using the XPages LogReader from openntf.org that will show you the contents of the local files from the server with the error messages (and stack trace).
You can find valuable info about how to use Java in XPages via a number of NotesIn9 video sequences.

The agent has to have
Security option "Run as Web user" set
as Target "None"
As the agent might run with this options it's not good practice to call a Java agent in an XPage. Better call/use the Java code direct in your XPage.

Related

Flow execution in Ejb project in java

Hi am working on very very old projects which contain 10 to 15 dependencies am very curious to know any tool or some utility to track flow execution of java class,method,lines,return type,get query executed while operation ..etc
for example:
if am calling soap request from SoapUI its goes into #WebService() and flow goes on..
How do I trace methods calls in Java? i have seen this link not sure how to incorporate and execute in existing project am doing manual job right now by debug with eclipse.kindly help on if way to write code or tool which i can see executions
JPDA. any decent IDE will connect to your container via JDPA protocol and allow you to debug from inside the container. you have to configure the container using some configuration switches (which get passed onto the JVM at startup time). check the documentation for you app server for how it prefers to be configured for JPDA.

How to build a command line interface in java for an existing web based application

I have created a web based application using JSP and Servlets and the application uses an SQL Server DB as its backend.
The architecture is like this:
I have all my business logic in a jar file
I have created my views using JSPs and am using servlets to interact with my business logic jar
The jar connects to the database to persist and hydrate information, which is relayed to the JSP by my servlets.
My web application runs on a remote Tomcat server.
Now, I have been given a new requirement. I have to create a command line interface, where I should be able to specify a list of commands and hit enter (or alternatively, create a set of commands and save it in a .bat file or something, and run it), so that my application performs the necessary actions. Basically, I have to create a command line interface, which can be used along with the GUI i already have (JSPs).
I am totally new to this. Can anyone throw light on where and how I can start?
Any little help is greatly appreciated.
EDIT
This is what my web application does. User can see a list of test scripts (written in Selenium WebDriver). He can choose script(s), choose a host on where to run them from, and click "Run", and the test executes on the said machines.
Now, I want a command line interface, which will eliminate the need for the GUI. Let's say, I simply want the user to be able to type a command like "execute My_Script_1", and the script should be executed.
The test scripts, the selenium drivers, everything reside on the App server.
My command line interface should be able to work on Windows command prompt.
Thank you.
Are you using Spring?
Can you specify, what exactly your CLI should do?
You may do, what Thomas said.
You also may use template engines like Velocity.. To form your output.
Use some kind of JavaCurses-like library to make your output... Look well.
Specifying commands...
Hm.. think about your business logic what exactly you are showing to user.
Remember webapp ui is webapp ui. Console ui is different. And user expects different behaviour
So commands like
show goods category="for kids"
Will be great.
Also don't forget about different help commands
yourJarName.jar --help / -h and etc
If your are want to write application with interactive mode... think about help command there.
You say you have your business logic in a JAR.
Why not starting another project with this JAR as a dependency and build it as an executable jar ?
Then simply use System.in and System.out to interact with the user.
EDIT :
So your application is hosted. Do you have an API like REST or SOAP or any other ?
Then you can build a client reading a string that the user has written, parsing it and calling the right service in your API.
I see two options:
Create a client-side CLI that generates the same data your server
receives. In other words, you don't modify your server code, and you create a
client-side CLI module (with jQuery for example) that parses the command lines and sends
exactly the same thing your actual GUI sends.
Set up a text area in your web app (decorated as a CLI) that reacts
on each Enter key pressed, and sends the line(s) to your server. On
your server, you can create a utility class (say CLIParser.java for
instance), and use Args4j to parse the received command,
validate it and run it.
Have you looked at Primefaces terminal? http://www.primefaces.org/showcase/ui/misc/terminal.xhtml
You data structure looks simple enough. Also you mentioned you designed your application the way the business logic is separated from the front end.
In this case you may consider exposing your business logic as a REST based WebService. It should not be that hard since you have layered structure in your application.
Looks like a few methods:
list scripts - returns a list of available scripts list hosts
returns a list of available hosts run script(scriptName, hostAddress)
runs script scriptName on a host with on address hostAddress possibly returns the results if your application supports this
All three look like a good candidates for GET methods.
You may consider Jersey or Resteasy or another framework.
You can find plenty tutorials for both of them. Take a look for example here.
From your command line application you can make calls to your web service in different ways. Just because I used to work with Jersey JAX-RS implementation most of the time, I found use of Jersey client(the latest stable version) the most convenient. Here you can find a short tutorial how you can do it from your command line application with Jersey client. JBoss also has a client API as a part of their framework(also fully certified JAX-RS implementation). You may even decide not to use any client API and do all the work manually utilizing HttpURLConnection, but I would not recommend. There is no big difference in using client API or do all the work manually with HttpURLConnection for the simple service, but you never know when your application becomes not that simple because of new requirements your client could not think of at the beginning.
Hope that helps

JD Edwards Enterprise One 9.1 Biztalk Adapter

I am trying to connect Biztalk 2013 to JD Edwards Enterprise One 9.1 Standalone Demo (oracle version).
I have configured all the parameters as it is said in this thread http://mikearnett.wordpress.com/2013/03/26/biztalk-jde-enterpriseone-adapter-configuration-tips/
And I have looked through a lot of information on the web, but just can't understand how JD Edwards data sources work, how and where to create them? And the main question is how to fill properties of biztalk adapter correctly, such as 'Bootstrap Data Source Required Properties'?
My current error in error log is:
E-JDE0010: JNI invocation method failed for the method GetModulePrefixes. JDEdwards error message : com.jdedwards.system.connector.dynamic.spec.SpecFailureException: Fail to connect to oneworld source com.jdedwards.system.connector.dynamic.spec.dbservices.BSFNLookupFailureException: Fail to fetch LibraryInfos [OCM_DEFAULT_ENTRY_NOT_FOUND] The OCM does not contain a default entry for environment DEMO910.
Maybe someone knows where to read information about this topic or have an experience in connecting Biztalk to JD Edwards?
Thanks in advance!
Instead of using adapters to integrate with JDE, consider using web services and do everything that you need to do (in JDE) within web service. The reason for this is performance. Lets say that you want to call 3 business functions for a given integration: If you call them directly from BizTalk (or any external application), you will incur the performance penalty of the latency between BizTalk and JDE. Instead, if you wrap these functions in a web service and call the web service from BizTalk, those functions will run within the context of JDE. This is a simplistic example, but you get the general idea.
For JDE web services, you have (at least) two options: Java Based Business Services or .Net Based Web Services, part of LynX Business Integrator (see http://youtube.com/user/aelliuslynx).
Hope this helps.
Make sure that OCM table has an active record for DEMO910 environment for the user or role or *PUBLIC in order to resolve following exception
com.jdedwards.system.connector.dynamic.spec.dbservices.BSFNLookupFailureException: Fail to fetch LibraryInfos [OCM_DEFAULT_ENTRY_NOT_FOUND]

How do I make a custom windows service?

Actually I am having one java program. That returns "Hello World". I converted it to jar file. After that I changed the file type as .exe with the use of iexpress in my windows XP default sw.
I used the sc create command, for creating new service. I created the windows service successfully. But the thing is I am not able to run this. It is throwing the following error.
This error is coming not only for this javaservice.
I tried to run the chrome.exe as windows service, That time also it is throwing the same error.
Is it windows constraints? or Am I making mistake? Expecting the solution.,
Thanks in Advance...
You cannot just assign any arbitrary .exe file as-is to run as a service. There are specific API functions involved that services must use to interact with the Service Control Manager (SCM). That is why you are getting the errors - those .exe files are not using those APIs to interact with the SCM.
If you are not writing code specifically for SCM interaction (Java does not support creating Windows services), then all is not lost. In some situations (Chrome NOT being one of them!), you can use a separate wrapper to host non-service apps and handle the SCM interactions on their behalf:
Service wrapper
For Java apps, there are a few wrapper projects available:
Java Service Wrapper
Yet Another Java Service Wrapper
ow2

Executing a class in remote jvm

I have a small test class that I want to run on a particular jvm that's already up and running (basically it's an web application running on Tomcat) . The reason I want to do this is I want to execute a small test class (with the main method and all) within that jvm so that I get the same environment (loaded and initialized classes) for my test class.
Is it possible to indicate that ,say through a jvm parameter, that it should not initialize a new vm to execute my class but instead go and execute on the remote vm and show me the result here, on my console. So the local jvm acts as a kind of thin proxy ?
I am not aware in case there are some tools that should make this possible .Also heard somewhere that java 6 jvm comes with an option like this , is that true ?
Please help me.
Thanks,
After reading this question and the answers, I decided to roll my own little utility: remoteJunit
It is lightweight and dynamically loads classes from the client to the server JVM. It uses HTTP for communication.
You might want to take a look at btrace. It allows you to run code in an already started JVM provided you don't change the state of the variables inside that JVM. With this kind of tracing, you might be able solve your problem in a different way. Not by running extra code in form of a new class but by adding safe code to and existing class running inside a JVM.
For instance, you might System.out.println the name of the file when there is a call to File.exists.
You might find JMX useful. Register an MBean in the server process. Invoke it with visualvm (or jconsole). (tutorial) Never tried it myself, mind.
RMI would also do the magic.
http://java.sun.com/javase/6/docs/technotes/guides/rmi/index.html
Make your web application start an RMI registry and register your service
beans there.
Then in other JVM you can run a program that queries the RMI registry
started by your web application for the services you want to verify
and you are done.
I assume "small test class" is basically some debugging code you want to run to monitor your real application, which is deployed remotely on a Tomcat. If this is the case, you should connect your Eclipse debugger remotely to the Tomcat instance, so you can set a breakpoint at interesting locations and then use the Display view of Eclipse to run any arbitrary code you might need to perform advanced debugging code. As java supports Hot Code Replacement using the debug mechanism, you can also change existing code on the remote side with new code at runtime.

Categories

Resources