How to enable remote management operations in Wildfly - java

Trying to read some values from my standalone.xml in Wildfly, I have got the following error message:
{
"outcome" => "failed",
"failure-description" => "WFLYCTL0379: System boot is in process; execution of remote management operations is not currently available"
}
In JBoss 7.1.1 it works fine, please see my java coding inside Ejb Singleton:
#Startup
#Singleton
#ConcurrencyManagement(ConcurrencyManagementType.BEAN)
public class TestBean {
#PostConstruct
private void init() throws Exception {
final ModelNode request = new ModelNode();
request.get(ClientConstants.OP).set("read-resource");
request.get("recursive").set(true);
request.get(ClientConstants.OP_ADDR).add("subsystem", "security");
final ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getByName("127.0.0.1"),
9029);
final ModelNode response = client.execute(new OperationBuilder(request).build());
}
}
This error comes at the moment when the client.execute() tries to get ModelNode.
I'd appreciate any help!

Don't know what El Lord Code was trying to accomplish, but in my project, for example, we are using the pattern of Startup Singleton to initialize the application. Now, during that thing, we need to do some programatic login - logout to Wildfly and the logout does some credential cache flushing which depends on acccessing the security domain. The problem is that this whole remote management is not accessible during startup and shutdown (it starts after and ends before the application is started / stopped).
I have posted a similar question here: https://developer.jboss.org/message/944842#944842

The Error is stating that Wildfly is still deploying some WAR/application
In this period the management is still not accessible.
Try to start the Wildfly without any applications in deployment folder and then try to read the standalone config for what ever needs.

Related

JavaEE Batch Processing Start Process

I want to go throw javaee batch processing, so I create a simple web application where I want to expose a get method for starting a job.
#GET
#Produces(MediaType.APPLICATION_JSON)
public Response helloWorld() {
Hello hello = new Hello();
hello.setMessage("Hello World");
JobOperator jobOperator = getJobOperator();
Long executionId = jobOperator.start("myJob", new Properties());
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
System.out.println(jobExecution.getBatchStatus());
return Response.ok(hello).build();
The rest service is working fine, I am running it on an intellij idea community edition and I am using maven plugin for running it on a tomcat server.
The problem is that the BatchRuntime.getJobOperator() is always returning null. I tried to use only the javaee-api dependecy, but then the BatchRuntime class is not found. After that I added javax.batch-api dependency and after that the class BatchRuntime was found, but getJobOperator() always return null.
Please tell me how can I run a job in order to get more familiarized with batch processing in javaee. I have looked over tutorials, git repo, but I didn't there is no clear way for how to run a xml job.
Tomcat is not a full Java EE server, and does not include JBatch. You should use an application server that is Java EE compliant, e.g. Glassfish/Payara, TomEE, or Wildfly.

Issues deploying a Java application to Tomcat

I built a simple Java web application. It provides a series of RESTful APIs for the user to carry out certain operations on a Java DB through a web interface. I used NetBeans environment during the development, and Glassfish for testing.
Now that I finished it, I would like to be able to deploy it on another machine using binaries (although as for now I use the same machine until I learn how to do it).
I installed Tomcat 7, and moved the .war file into Tomcat's webapp folder. The application deploys. Thereafter I try to read some data from the databse using a button I created just for this, but get the following error
I am not sure what went wrong, but I have two theories.
1) The web application cannot connect to the database. Yet when I attempted to run the application again, after starting JavaDB from NetBeans, there was no difference.
2) Somehow, the application cannot reach the Node service. I assumed that there will be no need to change the API links while moving the app, but perhaps I was wrong.
Or maybe there is some other issue I did not consider? I will be grateful for any advice about how to properly deploy such an application.
EDIT: The issue was solved by using TomEE.
The error is come from your application server of choice.
TomCat is only a servlet container (means it only support Servlet/JSP).
Any other feature (JAX-RS, CDI etc) require a Java EE certified server e.g. GlassFish, WildFly,Payara, WebLogic, OpenLiberty or TomEE.
TomEE could be your best bet if you want to use TomCat in your production or test environment, it is basically TomCat + Java EE other feature.
EDIT:
TomEE don't have a GUI for JNDI datasource configuration like GlassFish, you need to edit conf/tomee.xml
<Resource id="myDataSource" type="javax.sql.DataSource">
jdbcDriver = org.apache.derby.jdbc.ClientDriver
jdbcUrl = jdbc:derby://localhost:1527/dbname
userName = app
password = app
</Resource>
And in your java code:
#Path("resources")
#Stateless
public class MyResources{
#Resource(name="myDataSource")
DataSource dataSource;
#GET
public Response SomeMethod(){
//Do stuff here
}
}
You can check here for more detail configuration on data source.

Close spring on initialization

So I have a Spring app running on Tomcat. While deploying initialization I sometimes may run into some errors (i.e. that some JDNI value is not found or that the app is not able to connect to some service). So when this happen I throw and exception and catch it in the #Configuration file. In the catch block I try to close the app with a System.exit(-1). But it doesn't seem to be the right way to do it. Cause Intellij is no capable or turning off the server, I even have seen that resources are not released till server is OFF.
I have also tried:
#Autowired
public ApplicationContext application context
#Bean
public IServerDataCache serverDataCache() {
try {
return new ServerDataCache(args);
} catch(InitializationError initializationError) {
log.error("Unable to load configuration for Server Data Cache. Closing application.");
System.exit(1); OR SpringApplication.exit(applicationContext)
}
return null;
}
Both System.exit(1); OR SpringApplication.exit(applicationContext) seem to have the same effect. Any idea of a better way to enforce application finalization.
BTW it is a spring boot application.
Just let your #Bean method throw the exception. It will be caught by the container and it'll then take care of tidying things up.
Although Andy Wilkinson's answer is correct, I'd just like to add that, since you're running your application on Tomcat (and not an embedded Tomcat), the Tomcat server doesn't shutdown when the application fails to start.
This happens by design, since Tomcat is, like all JavaEE containers, meant to run several applications at once.
If you want the whole process to stop when the application fails, you need to switch to using an embedded container.

Java bean server not running properly

I am currently using java beans to create an application with a remote interface, i have very simple methods like printDetail which returns "abcd", just a test method. I have a session bean like this:
#Stateless
public class MySession implements MySessionRemote {
#Override
public void businessMethod() {
System.out.println("aaaababa");
}
when i deploy the server, i get this error:
SEVERE: CORE10012: Application previously deployed is not at its
original location any more
I use Glassfish 3.1
I Found the solution, go to your browser type localhost:4848, select applications in left list, disable any other running apps that was deployed. e.g mine was saying something like
SEVERE: CORE10012: Application previously deployed is not at its original location any more "C:user/ .... / XYZ "
Then you should disable the app XYZ because apparently the server is still running this app even if you have created a new one.

Calling Ilog Jrule Rules Execution server from java client

I am trying to execute a rule in IBM Jrule Rules execution server , using a java client. I am having Websphere community Edition V2.1 server, I am able call and execute the rules using JSF deployed in the samae server.
I want to call and execute the rules using a java client. I didn't find any way to do this,
In EJB. we can call EJB from web as well as from java client , by setting Initial Context envionment property. Is there any way similar to this is there, to call Rule Execution server rules, using java client, web part is already working.
import ilog.rules.res.session.IlrPOJOSessionFactory;
import ilog.rules.res.session.IlrStatelessSession;
import ilog.rules.res.session.IlrSessionFactory;
import ilog.rules.res.session.IlrStatefulSession;
import ilog.rules.res.session.IlrSessionRequest;
import ilog.rules.res.session.IlrJ2SESessionFactory;
import ilog.rules.res.session.IlrSessionResponse;
import ilog.rules.res.model.IlrPath;
import ilog.rules.res.session.extension.IlrExtendedJ2SESessionFactory;
import miniloan.Borrower;
import miniloan.Loan;
public class POJOEx {
public static void main(String... arg) {
// create rule session factory
//IlrSessionFactory sessionFactory = new IlrPOJOSessionFactory();
//IlrExtendedJ2SESessionFactory sessionFactory = new IlrExtendedJ2SESessionFactory();
// j2se factory
IlrSessionFactory sessionFactory = new IlrJ2SESessionFactory();
try {
// use stateless session for invocation
IlrStatelessSession statelessSession = sessionFactory.createStatelessSession();
//input parameter
Borrower borrower = new miniloan.Borrower("Joe", 600,
80000);
// in out parameter
Loan loan = new miniloan.Loan(500000, 240, 0.05);
IlrSessionRequest request = sessionFactory.createRequest();
//rule path
request.setRulesetPath(IlrPath.parsePath("/miniloanruleapp/2.0/miniloanrules/1.0"));
request.setUserDat("miniloanruleapp.MiniloanrulesclientRunnerImpl.executeminiloanrules");
request.setInputParameter("borrower", borrower);
request.setInputParameter("loan", loan);
//executing
IlrSessionResponse response = statelessSession.execute(request);
System.out.println("userdata = " + response.getOutputParameters().get("loan"));
System.out.println("outputString = " + (String) response.getUserData());
System.out.println("executionId = " + response.getExecutionId());
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
I am getting below error.
ilog.rules.res.xu.ruleset.impl.archive.IlrRulesetArchiveInformationNotFoundException: Cannot get the information about the ruleset /miniloanruleapp/2.0/miniloanrules/1.0
can anybody suggest where to specify Rules execution server url, username and password. like we specify InitialContext values in EJB.
Let me clarify what is RES because it seems there is a misunderstanding here, it may be me.
RES is used in Ilog terminology to describe multiple things:
- The web interface that allows you to manage your ruleapp.
- The actual application that you deploy on your WebSphere CE (or else) in order to execute the rules.
- The .jar files that allows you to execute the ruleapp locally.
You, AFAIK, cannot connect RES using a local JAVA application.
What you have coded is calling the rule engine contained in the RES*.jar files in order to execute your ruleapp locally.
There is no way you can use your JAVA application like you are using your EJB application.
You have to use a webservice or else which is feasible if you put the ruleapp name as a parameter of the web service for instance.
You are using miniloan so you probably know the example using the web interface where you can tell which version of the ruleset to use.
It will be the same if you want to programmatically manage your ruleapp deployed on RES (real application on your application server) you will need to use MDB. Nothing else.
It is disapointing, I know because I went through that, but there is no way I know (at least) to do that. This is not the behaviour you have to follow.
To make it work then put your ruleapp in the classpath (or root of your JAVA application in eclipse) and run it... Then you will execute your rules.
RES doesn't provide the same tools than RTS where you can access RTS from any JAVA application in order to manipulate your rule project.
You are 100% correct there is no way to tell the J2SE connection what is the server URL and hence no way to run your rules from the server.
Hope it helps.
You can absolutely call a Rule Execution Server from J2EE code or as in your case via a remote J2SE call and there is documentation provided to do this. But I do want to clarify a few things regarding the first response.
The Rule Execution Server is the runtime for executing rules. It has a persistence layer (file or database) and a management console that is used to manage it and any other connected Rule Execution Server.
It is this management server you connect to when you using the:
server:port/res URL
You do not connect to an actual RES as you can connect many RES to a single management console. The management console has the details about the persistence layer and a way of extracting the ruleset you wish to execute.
To your question. The reason that you are getting an error is that you have not configured which remote rule execution server you wish to pull the ruleset from, which is why you get the error you see.
To configure the remote connection, you use a file called 'ra.xml' and change the settings to point to your remote res/console.
There is a default ra.xml in the '/executionserver/bin' directory (default to ./IBM/ODM87/ODM/executionserver/bin).
The major aspects in that file to consider would be:
To enable management of Java SE XU instances that are running on different JVM or JMX MBean server, you must configure the XU MBean plug-in with the TCPIP protocol:
<config-property>
<config-property-name>plugins</config-property-name>
<config-property-type>java.lang.String</config-property-type>
<config-property-value>{pluginClass=Management,xuName=default,protocol=tcpip,tcpip.port=TCPIP_PORT,tcpip.host=RES_CONSOLE_HOST,tcpip.retryInterval=INTERVAL}
</config-property-value>
</config-property>
where:
RES_CONSOLE_HOST is the host on which the Rule Execution Server console is deployed.
TCPIP_PORT is the TCP/IP port on which the Rule Execution Server console management server is listening.
INTERVAL is the interval of time, in milliseconds, during which the console tries to reconnect to the management server if a connection fails.
As long as the ra.xml is in the classpath of the application you are running the local J2SE engine should make a call to the remote RES console and request the rule app specified in the provide RuleSet path.
For J2EE, this is similar but you actually execute the rule in the remote RES rather than pull the ruleset locally.
If you check the ODM Samples there is both a J2EE and J2SE sample that demonstrates both techniques.
adding below files in the same folder of *.dsar worked for me
creation_date.txt, display_name.txt, properties.txt

Categories

Resources