我希望Glassfish服務器中的所有應用程序在進入syslog輸出時都有一個單獨的點。我找到了一個處理Syslog輸出的庫(https://github.com/CloudBees-community/syslog-java-client),並且我做了這個工作。但是,這需要每個應用程序都有自己的執行ILogger的:Syslog EJB Java EE
public interface ILogger extends Serializable {
public void alert(String message);
public void critical(String message);
public void debug(String message);
public void emergency(String message);
public void error(String message);
public void informational(String message);
public void notice(String message);
public void warning(String message);
public void exception(Exception e);
}
所以我想有一個bean返回此ILogger的實現,這樣的事:
public interface ILoggerFacade extends Serializable {
// beanName is the name of the bean requesting a Logger
public ILogger get(String beanName);
public void log(String beanName, int severity, String message);
}
到目前爲止,我的實現產生在例外情況:
javax.ejb.EJBException
at com.sun.ejb.containers.EJBContainerTransactionManager.processSystemException(EJBContainerTransactionManager.java:748)
at com.sun.ejb.containers.EJBContainerTransactionManager.checkExceptionNoTx(EJBContainerTransactionManager.java:638)
at com.sun.ejb.containers.EJBContainerTransactionManager.checkExceptionBeanMgTx(EJBContainerTransactionManager.java:597)
at com.sun.ejb.containers.EJBContainerTransactionManager.postInvokeTx(EJBContainerTransactionManager.java:467)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4475)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2009)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1979)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:212)
at com.sun.ejb.containers.EJBObjectInvocationHandlerDelegate.invoke(EJBObjectInvocationHandlerDelegate.java:79)
at com.sun.proxy.$Proxy528.getWlcById(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.privateInvoke(StubInvocationHandlerImpl.java:239)
at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.invoke(StubInvocationHandlerImpl.java:150)
at com.sun.corba.ee.impl.presentation.rmi.codegen.CodegenStubBase.invoke(CodegenStubBase.java:226)
at xxx.interfaces.domain.__IOrmFacade_Remote_DynamicStub.method1(xxx/interfaces/domain/__IOrmFacade_Remote_DynamicStub.java)
at xxx.interfaces.domain._IOrmFacade_Wrapper.method1(xxx/interfaces/domain/_IOrmFacade_Wrapper.java)
at xxx.test.QcastInterfaces.OrmFacadeTest.getApsByStatus(OrmFacadeTest.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at xxx.test.TestBackend.testMethod(TestBackend.java:95)
at xxx.test.TestBackend.testClass(TestBackend.java:78)
at xxx.test.TestBackend.test(TestBackend.java:62)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:75)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
at xxx.logger.Logger.debug(Logger.java:34)
at xxx.orm.beans.OrmFacadeBean.getWlcById(OrmFacadeBean.java:164)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1081)
at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1153)
at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4695)
at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:630)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:582)
at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:46)
at sun.reflect.GeneratedMethodAccessor340.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:582)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:163)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:140)
at sun.reflect.GeneratedMethodAccessor341.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:369)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:4667)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4655)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:205)
... 53 more
實現至今:
記錄儀
@SuppressWarnings("serial")
public class Logger implements ILogger {
private final ILoggerFacade loggerFacade;
private final String bean;
public Logger(ILoggerFacade loggerFacade, String bean) throws NamingException {
//this.loggerFacade = InitialContext.doLookup("java:global/QcastORM/logger/LoggerBean");
//loggerFacade = null;
this.loggerFacade = loggerFacade;
this.bean = bean;
}
@Override
public void alert(String message) {
loggerFacade.log(bean, Severity.ALERT.numericalCode(), message);
}
@Override
public void critical(String message) {
loggerFacade.log(bean, Severity.ALERT.numericalCode(), message);
}
@Override
public void debug(String message) {
loggerFacade.log(bean, Severity.ALERT.numericalCode(), message);
}
@Override
public void emergency(String message) {
loggerFacade.log(bean, Severity.ALERT.numericalCode(), message);
}
@Override
public void error(String message) {
loggerFacade.log(bean, Severity.ALERT.numericalCode(), message);
}
@Override
public void informational(String message) {
loggerFacade.log(bean, Severity.ALERT.numericalCode(), message);
}
@Override
public void notice(String message) {
loggerFacade.log(bean, Severity.ALERT.numericalCode(), message);
}
@Override
public void warning(String message) {
loggerFacade.log(bean, Severity.ALERT.numericalCode(), message);
}
@Override
public void exception(Exception e) {
// TODO stacktrace uitschrijven
loggerFacade.log(bean, Severity.ALERT.numericalCode(), e.toString());
}
}
LoggerFacade
@SuppressWarnings("serial")
@EJB(name = "samename", beanInterface = ILoggerFacade.class)
@Stateless
@TransactionManagement(TransactionManagementType.BEAN)
@Remote
public class LoggerFacade implements ILoggerFacade {
@Override
public ILogger get(String bean) {
// This is not ideal
try {
return new Logger(this, bean);
} catch (NamingException e) {
e.printStackTrace();
return null;
}
}
@Override
public void log(String bean, int severity, String message) {
// When this works, change syso into syslog
System.out.println(message);
}
}
我已搜查谷歌和SO但到目前爲止,我還沒有發現我很高興與任何解決方案。我的問題是,如果我應該以不同的方式思考這個問題或者說這是如何實現的例子。
在此先感謝!
你能告訴我們你的完整例外和接口的實現嗎? –
我已經添加了他們 –
您調用LoggerFacade的哪種方法? –