I'm trying to create an ejb timer and successful to do so but however unable to deploy it successfully. I'm using ejb timer first time so I might not be doing it right. so kindly if someone guides me in the right direction. Thank you
followed the tutorial from
http://www.adam-bien.com/roller/abien/entry/simplest_possible_ejb_3_16
import javax.ejb.Schedule;
import javax.ejb.Stateless;
import javax.ejb.Timer;
#Stateless
public class ScheduleRoutine {
/**
* Default constructor.
*/
public ScheduleRoutine() {
// TODO Auto-generated constructor stub
}
#Schedule(second="*/1", minute="*",hour="*", persistent=false)
public void scheduledTimeout(final Timer t) {
System.out.println("#Schedule called at: " + new java.util.Date());
}
}
This is the code I'm using I think there's no problem with it. I'm using JBoss AS 7.1.1 with eclipse and all I'm doing is 'run on server' it runs but it's unable to display the output as it is supposed to.
EDIT :(Solution)
It didn't work when i tried to run it from eclipse but then i tried exporting the jar manually then it was deployed successfully.
I had the same problem with jboss 7.1. To solve the problem I added a stub method to my ejb and annotated it with #Timeout
#Timeout
public void stub(){
// NOOP
}
Also changed #Stateless to #Singleton and #Startup so your code would look like the following:
import javax.ejb.Schedule;
import javax.ejb.Startup;
import javax.ejb.Timer;
import javax.ejb.Timeout;
#Singleton
#Startup
public class ScheduleRoutine {
/**
* Default constructor.
*/
public ScheduleRoutine() {
// TODO Auto-generated constructor stub
}
#Timeout
public void stub() {
// NOOP
}
#Schedule(second="*/1", minute="*",hour="*", persistent=false)
public void scheduledTimeout(final Timer t) {
System.out.println("#Schedule called at: " + new java.util.Date());
}
}
Related
I'm looking for a way to remove stacktraces of fails assertions when using the framework Citrus.
This is done in testNg like this:
public class NoStackTraceListener implements ITestListener {
...
#Override
public void onTestFailure(ITestResult iTestResult) {
Throwable th = iTestResult.getThrowable();
if (Objects.nonNull(th)) {
System.out.println(th.getMessage());
iTestResult.setThrowable(null);
}
}
...
}
#Listeners({ NoStackTraceListener.class })
class A {...}
But I can't find any example of usgin the class 'TestListener' or others in order to override the supplied implementation of 'LoggingReporter'
Please do anyone has already overrided a Listener using framework citrus and could give the snippet to do so ?
Thanks
You need to add the custom reporter as bean to the Spring application context:
#Bean
public NoStackTraceReporter noStackTraceReporter() {
return new NoStackTraceReporter();
}
You can also overwrite the default logging reporter by choosing the bean name loggingReporter
#Bean
public NoStackTraceReporter loggingReporter() {
return new NoStackTraceReporter();
}
The NoStackTraceReporter implementation is then able to overwrite the specific event handler for failed tests:
public class NoStackTraceReporter extends LoggingReporter {
...
#Override
public void onTestFailure(TestCase test, Throwable cause) {
// do something customized
}
...
}
Also you may overwrite the generateTestResults() method in the reporter interface in order to customize logging results.
You can also follow the sample http://www.citrusframework.org/samples/reporting/ that demonstrates how to add customized reporters in Citrus.
I'm trying to implement a batch upload job in my app running on Wildfly 10. I want to create a Quartz job that will download some files and load them in the database. However when my job runs the entitymanager is always null. How can I get my entity manger injected in this case? I wrote the following code that simplifies my situation as much as possible. Can anyone tell me where I've gone wrong?
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
#Stateless
public class DownloadService implements Job {
#PersistenceContext
private EntityManager entityManager;
#Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
if (entityManager == null) {
System.out.println("############## entityManager is null ####");
} else
System.out.println("************** WORKING ***************");
}
}
Have you scanned this class using <context:component-scan base-package="your.package"/>.
Is there a way to detect when a war file is successfully loaded by Wildfly and cause some code to execute?
You have a few options.
If you're leveraging CDI, you can add an observer method for #Observes #Initialized(ApplicationScoped.class) Object o
If you're leveraging EJBs, you can have a #javax.ejb.Singleton #javax.ejb.Startup with a #PostConstruct method that does initialization. Here are two example implementations.
// using a CDI object
#ApplicationScoped
public class SomeStartupBean {
public void initOnStartup(#Observes #Initialized(ApplicationScoped.class) Object obj) {
// do your start up logic here
}
}
or
// using an EJB
#Singleton
#Startup
public class SomeStartupSingleton {
#PostConstruct
public void initOnStartup() {
// do your start up logic here
}
}
You could use an #Startup EJB. That would execute when the application has successfully been deployed.
Im quite new to all this stuff. I try to launch a webservice via GlassFish. When i try to build this project i get an error.
ant -f /home/philipp/NetBeansProjects/sks3 -DforceRedeploy=false -Ddirectory.deployment.supported=true -Dnb.wait.for.caches=true run
init:
deps-module-jar:
deps-ear-jar:
deps-jar:
check-rest-config-props:
generate-rest-config:
library-inclusion-in-archive:
library-inclusion-in-manifest:
compile:
compile-jsps:
In-place deployment at /home/philipp/NetBeansProjects/sks3/build/web
Initializing...
deploy?DEFAULT=/home/philipp/NetBeansProjects/sks3/build/web&name=sks3&contextroot=/sks3&force=true failed on GlassFish Server 3.1.2
Error occurred during deployment: Exception while deploying the app [sks3] : Invalid TYPE-level #EJB with name() = [] and beanInterface = [class java.lang.Object] in class Webservice.MeasurementResources. Each TYPE-level #EJB must specify both name() and beanInterface().at org.glassfish.apf.AnnotationInfo#3b63118a. Please see server.log for more details.
/home/philipp/NetBeansProjects/sks3/nbproject/build-impl.xml:1028: The module has not been deployed.
See the server log for details.
BUILD FAILED (total time: 6 seconds)
I dont have a clue what is going wrong but according to the message it has to be in the file MeasurementResurces.java ...
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Webservice;
import Exception.DALException;
import dal.MeasurementDao;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.Path;
import repo.Measurement;
/**
*
* #author philipp
*/
//#Stateless
//#inject
#EJB
//#LocalBean
#Named
#Path("Measurement")
public class MeasurementResources {
#Inject
MeasurementDao mDao;
public void add(Measurement arg) throws DALException{
mDao.save(arg);
}
/* public void getAll(Measurement arg) throws DALException{
mDao.getAll();
}
*/
}
Someone has at least a hint whats the problem?
You are using a Type-Level EJB without declaring name and beanInterface.
/**
*
* #author philipp
*/
//#Stateless
//#inject
#EJB(name="MyEjb", beanInterface=RemoteEjb.class)
//#LocalBean
#Named
#Path("Measurement")
public class MeasurementResources {
#Inject
MeasurementDao mDao;
public void add(Measurement arg) throws DALException{
mDao.save(arg);
}
}
#Remote
public interface RemoteEjb {
public void doSomething();
}
#Stateless
public class MyEjb implements RemoteEjb {
...
}
name is the name of the EJB you trying to inject. beanInterface is the Local or Remote interface. It's not a real injection. It is a way to use annotation as a replacement of deployment descriptor ejb-ref element. You should use a JNDI lookup in order to inject the ejb.
I don't know what are you trying to do but the common way to inject an ejb is the following:
#Named
#Path("Measurement")
public class MeasurementResources {
#EJB
private MyEjb myejb;
#Inject
MeasurementDao mDao;
public void add(Measurement arg) throws DALException{
mDao.save(arg);
}
...
}
I'm running Selenium tests from within Eclipse, but I can't load a custom Firefox profile.
Most sources suggest I need to launch the Selenium Server like this:
java -jar selenium-server.jar -firefoxProfileTemplate </path/to/template/>
But when launching my test from within Eclipse it doesn't use that - the tests will run if the Selenium Server isn't running.
This thread suggests that I can set the profile in the DefaultSelenium constructor:
Selenium RC - disabling browser cookie
But the code generated for me by Selenium IDE (Firefox plugin) doesn't use that constructor:
package com.example.tests;
import com.thoughtworks.selenium.*;
import java.util.regex.Pattern;
public class Example extends SeleneseTestCase {
public void setUp() throws Exception {
setUp("http://www.example.com/", "*firefox");
}
public void testExample() throws Exception {
selenium.open("/");
selenium.click("//body");
}
}
Where should I set the DefaultSelenium configuration options? Or is there some other method I can use to load my custom Firefox template?
Thanks!
Stu
I made a SeleniumTestCase that starts/stops the server before/after each test class and starts/stops the Selenium instance before/after each test:
public class SeleniumTestCase {
protected static Selenium selenium;
protected static AppNavUtils appNavUtils;
#BeforeClass
public static void setUpBeforeClass() throws Exception {
SeleniumServerControl.getInstance().startSeleniumServer();
}
#AfterClass
public static void tearDownAfterClass() throws Exception {
SeleniumServerControl.getInstance().stopSeleniumServer();
}
#Before
public void setUp() throws Exception {
// Replace "*chrome" with "*firefox" for Selenium > 1.0
selenium = new DefaultSelenium("localhost", 5444, "*chrome", "http://localhost:8080/");
selenium.start();
appNavUtils = new AppNavUtils(selenium);
}
#After
public void tearDown() throws Exception {
selenium.stop();
}
}
The SeleniumServerControl starts and stops the server:
public class SeleniumServerControl {
private static final SeleniumServerControl instance = new SeleniumServerControl();
public static SeleniumServerControl getInstance()
{
return instance;
}
private SeleniumServer server = null;
protected SeleniumServerControl(){}
public void startSeleniumServer() {
if (server == null) {
RemoteControlConfiguration rcc = new RemoteControlConfiguration();
rcc.setPort(5444);
//rcc.setFirefoxProfileTemplate(newFirefoxProfileTemplate)
server = new SeleniumServer(rcc);
}
server.start();
}
public void stopSeleniumServer()
{
if (server != null) {
server.stop();
server = null;
}
}
}
the version of code you have above assumes that you are running your tests against localhost on port 4444 thats why it is has 2 parameters in the setup.
To set up eclipse to run it you will need to update the run configuration. That is under
Run > Run Configurations
Have a look for the item that has selenium in it and add the config above so that when it runs it will pick it up and run.
I personally just fire up the server when I start working by running a batch file and kill it at the end of the day.