giovedì 15 gennaio 2015
Wildfly 8 - Query My MBean from bash console using twiddle
[root@CloudServer1 ~]# JBOSS_HOME=/opt/wildfly-8.1.0.Final/ /opt/twiddle-standalone/bin/twiddle.sh -v -s service:jmx:http-remoting-jmx://127.0.0.1:9990 get com.azienda:Name=Statistics,Type=com.azienda.progetto.jmx.Statistics
11:43:11,851 INFO [Twiddle] replacing JMX service url (service:jmx:rmi:///jndi/rmi://localhost:1090/jmxrmi) with service:jmx:http-remoting-jmx://127.0.0.1:9990
11:43:11,942 INFO [xnio] XNIO version 3.2.2.Final
11:43:12,076 INFO [nio] XNIO NIO Implementation Version 3.2.2.Final
11:43:12,207 INFO [remoting] JBoss Remoting version 4.0.3.Final
CountDevice=24
CountDeviceOnline=15
CountApp={iOS=27, WindowsPhone=1, Android=16}
[root@CloudServer1 ~]#
lunedì 19 maggio 2014
martedì 4 febbraio 2014
mercoledì 9 ottobre 2013
Empty e4 RCP Application with livemodel ready
This is the content of Application.e4xml file that represents an empty e4 application with the livemodel tool ready to show when pressed "ALT+F9":
<application:application elementid="backoffice-rcp.bundle.application" xmi:id="_KQrIEDEaEeOrvaIJ_du62A" xmi:version="2.0" xmlns:application="http://www.eclipse.org/ui/2010/UIModel/application" xmlns:basic="http://www.eclipse.org/ui/2010/UIModel/application/ui/basic" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<children elementid="backoffice-rcp.bundle.trimmedwindow.0" xmi:id="_PM_UQDEeEeOm9_xoDmNMiQ" xsi:type="basic:TrimmedWindow">
<handlers command="_spDM0DEiEeOm9_xoDmNMiQ" contributionuri="bundleclass://org.eclipse.e4.tools.emf.liveeditor/org.eclipse.e4.tools.emf.liveeditor.OpenLiveDialogHandler" elementid="e4.tooling.livemodel.handler" xmi:id="_j2GJcDEiEeOm9_xoDmNMiQ">
<bindingtables bindingcontext="_thbUYDEkEeOm9_xoDmNMiQ" contributoruri="platform:/plugin/org.eclipse.platform" elementid="backoffice-rcp.bundle.bindingtable.0" xmi:id="_QHHA4DEjEeOm9_xoDmNMiQ">
<bindings command="_spDM0DEiEeOm9_xoDmNMiQ" elementid="e4.tooling.livemodel.binding" keysequence="ALT+F9" xmi:id="_Q4ezcDEjEeOm9_xoDmNMiQ">
</bindings></bindingtables>
<rootcontext description="Either a dialog or a window is open" elementid="backoffice-rcp.bundle.bindingcontext.0" name="In Dialogs and Windows" xmi:id="_thbUYDEkEeOm9_xoDmNMiQ">
<commands commandname="Show running app model" description="Show the running application model" elementid="e4.tooling.livemodel" xmi:id="_spDM0DEiEeOm9_xoDmNMiQ">
<addons contributionuri="bundleclass://org.eclipse.e4.core.commands/org.eclipse.e4.core.commands.CommandServiceAddon" elementid="org.eclipse.e4.core.commands.service" xmi:id="_KQrIETEaEeOrvaIJ_du62A">
<addons contributionuri="bundleclass://org.eclipse.e4.ui.services/org.eclipse.e4.ui.services.ContextServiceAddon" elementid="org.eclipse.e4.ui.contexts.service" xmi:id="_KQrIEjEaEeOrvaIJ_du62A">
<addons contributionuri="bundleclass://org.eclipse.e4.ui.bindings/org.eclipse.e4.ui.bindings.BindingServiceAddon" elementid="org.eclipse.e4.ui.bindings.service" xmi:id="_KQrIEzEaEeOrvaIJ_du62A">
<addons contributionuri="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.CommandProcessingAddon" elementid="org.eclipse.e4.ui.workbench.commands.model" xmi:id="_KQrIFDEaEeOrvaIJ_du62A">
<addons contributionuri="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.ContextProcessingAddon" elementid="org.eclipse.e4.ui.workbench.contexts.model" xmi:id="_KQrIFTEaEeOrvaIJ_du62A">
<addons contributionuri="bundleclass://org.eclipse.e4.ui.workbench.swt/org.eclipse.e4.ui.workbench.swt.util.BindingProcessingAddon" elementid="org.eclipse.e4.ui.workbench.bindings.model" xmi:id="_KQrIFjEaEeOrvaIJ_du62A">
<addons contributionuri="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.HandlerProcessingAddon" elementid="org.eclipse.e4.ui.workbench.handler.model" xmi:id="_KQrIFzEaEeOrvaIJ_du62A">
</addons></addons></addons></addons></addons></addons></addons></commands></rootcontext></handlers></children></application:application>
domenica 6 ottobre 2013
lunedì 20 maggio 2013
Error mounting ext3 partition: no journal found
After some power failures, I can't mount my HDD ext3 partition.
The kernel says:
The solution was to recreate the journal of ext33 partition (from http://www.watters.ws/mediawiki/index.php/Repair_ext3_journal_errors):
The kernel says:
EXT4-fs (sde1): mounting ext3 file system using the ext4 subsystem
EXT4-fs error (device sde1): ext4_iget:3889: inode #8: comm mount: bad extra_isize (33280 != 256)
EXT4-fs (sde1): no journal found
The solution was to recreate the journal of ext33 partition (from http://www.watters.ws/mediawiki/index.php/Repair_ext3_journal_errors):
tune2fs -O ^has_journal /dev/sdXY
e2fsck -f /dev/sdXY
tune2fs -j /dev/sdXY
domenica 17 febbraio 2013
IpadCharge on Fedora 18
If you installed with you ipad_charge and it dowsn't work, try to update che /etc/udev/95-ipad_charge.rules with the last one from https://github.com/mkorenkov/ipad_charge.
domenica 11 novembre 2012
Redeploy war in Tomcat 7 using curl and bash
curl -T - -u user:password 'http://servername:8000/manager/text/deploy?update=true&path=/webapp' < webapp.war
martedì 17 luglio 2012
Hardware reverse engineering - GSM Modem Da Sistemi MT0124
I bought this printed circuit board in an electronics fair. It contains a well documented GSM module by Telit and a handful of components for its powering and RS232 serial level converter (from CMOS level 2.8Volt to RS232 7.5Volt):
Even if the GSM module is well documented and even if the salesman assured me that I'd find the electric schema of circuit board on the Internet, I not found it, and I had to spend 10 hours to make the reverse engineering of pin out.
This are the pin functions:
1. +Vcc (it works from 6 to 12 Volt)
2. bypass to RJ45 connector
3. Serial DCD (out from pcb)
4. Serial DTR (in)
5. Serial CTS (out)
6. Serial RTS (in)
7. Serial RX (out)
8. Serial TX (in)
9. Reset
10. ON/OFF (pull up, 1 sec to GND to switch on/off the GSM module)
11. bypass to RJ45 connector
12. GND
Even if the GSM module is well documented and even if the salesman assured me that I'd find the electric schema of circuit board on the Internet, I not found it, and I had to spend 10 hours to make the reverse engineering of pin out.
This are the pin functions:
1. +Vcc (it works from 6 to 12 Volt)
2. bypass to RJ45 connector
3. Serial DCD (out from pcb)
4. Serial DTR (in)
5. Serial CTS (out)
6. Serial RTS (in)
7. Serial RX (out)
8. Serial TX (in)
9. Reset
10. ON/OFF (pull up, 1 sec to GND to switch on/off the GSM module)
11. bypass to RJ45 connector
12. GND
giovedì 7 giugno 2012
Get the Realm (or LoginService) instance from a ServletConxtext in Tomcat 7 and Jetty 7.5
Container-Managed Authentication is not always the best choose for implement security in web application. A typical example is when an home page have to be personalized if the current user is logged or not. With Container Managed Security, if a page isn't protected by a security-constraint, also if the current user is logged, the request.getUserPrinipal() is null.
See http://stackoverflow.com/questions/7795012/request-getuserprincipal-got-null.
A way to skip over the problem is to implement Application-Managed Authentication in web application. This means that web-app developer have to implements authentication/authorization.
But not everything is lost! We can reuse the Realm configured within application server to authenticate/authorize application's users.
There are two snippet of code that retrieve the Realm authenticator from ServletContext.
Get Tomcat 7 Realm from ServletContext:
The realm variable is an instance of org.apache.catalina.Realm, and you can call on this the authenticate method to authenticate and get roles of users:
This is the counter part for Jetty 7.5. Be ware that normally Jetty don't allow to reach the container classes from web application class loader, we need to disable this option, see http://docs.codehaus.org/display/JETTY/Classloading.
I use Jetty with maven, this is may configuration:
See http://stackoverflow.com/questions/7795012/request-getuserprincipal-got-null.
A way to skip over the problem is to implement Application-Managed Authentication in web application. This means that web-app developer have to implements authentication/authorization.
But not everything is lost! We can reuse the Realm configured within application server to authenticate/authorize application's users.
There are two snippet of code that retrieve the Realm authenticator from ServletContext.
Get Tomcat 7 Realm from ServletContext:
ApplicationContextFacade acf = (ApplicationContextFacade) servletContext;
Field privateField = ApplicationContextFacade.class.getDeclaredField("context");
privateField.setAccessible(true);
ApplicationContext appContext = (ApplicationContext) privateField.get(acf);
Field privateField2 = ApplicationContext.class.getDeclaredField("context");
privateField2.setAccessible(true);
StandardContext stdContext = (StandardContext) privateField2.get(appContext);
realm = stdContext.getRealm();
The realm variable is an instance of org.apache.catalina.Realm, and you can call on this the authenticate method to authenticate and get roles of users:
Principal principal = realm.authenticate(user, password);
if (principal == null)
return null;
GenericPrincipal genericPrincipal = (GenericPrincipal) principal;
return new DemoPrincipal(principal, genericPrincipal.getRoles());
This is the counter part for Jetty 7.5. Be ware that normally Jetty don't allow to reach the container classes from web application class loader, we need to disable this option, see http://docs.codehaus.org/display/JETTY/Classloading.
WebAppContext.Context context = ((org.eclipse.jetty.webapp.WebAppContext.Context) servletContext);
ContextHandler contextHandler = context.getContextHandler();
ConstraintSecurityHandler securityHandler = contextHandler
.getChildHandlerByClass(org.eclipse.jetty.security.ConstraintSecurityHandler.class);
loginService = securityHandler.getLoginService();
UserIdentity login = loginService.login(user, password);
if (login == null)
return null;
Principal principal = login.getUserPrincipal();
Field privateField = DefaultUserIdentity.class.getDeclaredField("_roles");
privateField.setAccessible(true);
String[] roles = (String[]) privateField.get(login);
return new DemoPrincipal(principal, roles);
I use Jetty with maven, this is may configuration:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
<configuration>
<loginServices>
<loginService implementation="org.eclipse.jetty.security.HashLoginService">
<name>MyRealm</name>
<config>${basedir}/src/main/resources/jetty-realm.properties</config>
</loginService>
</loginServices>
<scanIntervalSeconds>1000</scanIntervalSeconds>
<webAppConfig>
<serverClasses>
<serverClass implementation="java.lang.String">
-org.eclipse.jetty.
</serverClass>
</serverClasses>
</webAppConfig>
</configuration>
</plugin>
martedì 5 giugno 2012
Tell your browser to ask for save password in web AJAX login
Store password in browser is a useful functionality, the browser intercept the POST action of form and under a few condition (browser dependent) ask to store password.
Unfortunately, this mechanism don't works well when you implement a RIA (Rich Internet Application) and use AJAX call for authenticate users because your submit through XHR and not by html form submit.
I use a simple trick to show password store request from browser. After the AJAX login request complete, if the user is successful authenticate, submit the login form to a url that return a HTTP 204 status (204 NO CONTENT). The browser ask to save password but the user does not navigate anywhere else.
This is an example:
try now!
Enjoy with AJAX!
Unfortunately, this mechanism don't works well when you implement a RIA (Rich Internet Application) and use AJAX call for authenticate users because your submit through XHR and not by html form submit.
I use a simple trick to show password store request from browser. After the AJAX login request complete, if the user is successful authenticate, submit the login form to a url that return a HTTP 204 status (204 NO CONTENT). The browser ask to save password but the user does not navigate anywhere else.
This is an example:
<form method="post" action="http://demo.utilities-online.info/backend/none">
Username: <input id="username" type="text" name="username"><br/>
Password: <input id="password" type="password" name="password"><br/>
<input type="button" value="login" onclick="sendRequest();">
</form>
try now!
Enjoy with AJAX!
giovedì 8 marzo 2012
BIRT segmentation fault on linux
I'm running BIRT in my box and experienced, several times, code dump of JVM with segmentation fault.
A problem go away when I added some options of JVM:
-Xss256k -XX:MaxPermSize=384m
Software version:
Fedora 16
JVM 1.7.0_03
Tomcat 17.0.25
BIRT 3.7.1
A problem go away when I added some options of JVM:
-Xss256k -XX:MaxPermSize=384m
Software version:
Fedora 16
JVM 1.7.0_03
Tomcat 17.0.25
BIRT 3.7.1
domenica 4 marzo 2012
Non concurrent HTTP requests on Cluster with Infinispan
On Server-Client Architecture there are two type of call, one that only retrieve information from server (Read-Only) and one that can also change server's status (R/W).
Tipically, the first one can run in concurrency, also with the same parameters, without problem (also maybe a performance increase by cache system).
The second one changes the internal server's status, create file, update database and so on. And, when several calls with same parametres reach the server simoultaneusly, problems often can occur.
When the client is a browser this problem can be mitigated with javascript, disabling button once clicked for example, but cannot be eliminated. Worse if your client isn't a browser.
There is my solution, adopted on a cluster of four machine using JBoss Infinispan.
In my webapp I use Jersey + Guice to serve request, this is a simple class that manage POST request:
@POST
@Path("mpay")
@Produces(MEDIATYPE_WEBPAGEUTF8)
public Object landMPay(@QueryParam("TransactionID") String transactionId, @QueryParam("ResultCode") String resultcode) {
logger.debug("Get user from token, {}.", transactionId);
.
.
.
Now I want only one concurrent call with same TransactionId parameter. I created two annotation, one for Method (@UniqueCallOnCluster) and ane for Parameter (@KeyParameter).
I use first annotation as:
@POST
@Path("mpay")
@UniqueCallOnCluster
@Produces(MEDIATYPE_WEBPAGEUTF8)
public Object landMPay(@QueryParam("TransactionID") String transactionId, @QueryParam("ResultCode") String resultcode) {
logger.debug("Get user from token, {}.", transactionId);
.
.
.
to permit only one concurrent call with all same parameters. But I want to permit only one concurrent call with same TransactionId parameter, ignoring ResultCode values:
@POST
@Path("mpay")
@UniqueCallOnCluster
@Produces(MEDIATYPE_WEBPAGEUTF8)
public Object landMPay(@KeyParameter @QueryParam("TransactionID") String transactionId, @QueryParam("ResultCode") String resultcode) {
logger.debug("Get user from token, {}.", transactionId);
.
.
.
The interceptor that manage this annotations use Infinispan to tell other server that him is starting to serve this call with this parameter/s:
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;
import javax.transaction.TransactionManager;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import com.google.common.base.Joiner;
import com.google.inject.Inject;
public class UniqueCallOnClusterInterceptor implements MethodInterceptor {
@Inject
private Constants constants;
@Inject
private KeyCallOnClusterService keyCallOnClusterService;
public Object invoke(MethodInvocation invocation) throws Throwable {
String classname = invocation.getMethod().getDeclaringClass().getSimpleName();
String methodName = invocation.getMethod().getName();
String key = classname + "_" + methodName + "_" + extractParameterValue(invocation);
TransactionManager tm = keyCallOnClusterService.getTransactionManager();
try {
if (tm != null) {
tm.begin();
boolean success = keyCallOnClusterService.lock(key);
if (!success) {
return Response.status(Status.CONFLICT).entity("Another call with same parameter is in progress.").build();
}
}
String runningServer = (String) keyCallOnClusterService.get(key);
if (runningServer != null) {
return Response.status(Status.CONFLICT).entity("Another call with same parameter is in progress.").build();
}
keyCallOnClusterService.put(key, constants.getHostname());
} finally {
if (tm != null)
tm.commit();
}
try {
return invocation.proceed();
} finally {
keyCallOnClusterService.remove(key);
}
}
public String extractParameterValue(MethodInvocation invocation) {
List<String> list = new ArrayList<String>();
Annotation[][] parameterAnnotations = invocation.getMethod().getParameterAnnotations();
for (int i = 0; i < parameterAnnotations.length; i++) {
Annotation[] annotations = parameterAnnotations[i];
for (int j = 0; j < annotations.length; j++) {
Annotation annotation = annotations[j];
if (annotation instanceof KeyParameter) {
list.add(String.valueOf(invocation.getArguments()[i]));
break;
}
}
}
if (list.size() == 0)
return Joiner.on(", ").useForNull("null").join(invocation.getArguments());
return Joiner.on(", ").useForNull("null").join(list);
}
}
The KeyCallOnClusterService class is a facility for the Infinispan's Cache Object.
Here the configuration of Infinispan:
<?xml version="1.0" encoding="UTF-8"?>
<infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:infinispan:config:5.1 http://www.infinispan.org/schemas/infinispan-config-5.1.xsd"
xmlns="urn:infinispan:config:5.1">
<global>
<globalJmxStatistics enabled="true"
allowDuplicateDomains="true"></globalJmxStatistics>
<transport clusterName="cluster"
distributedSyncTimeout="3000">
<properties>
<property name="configurationFile" value="infinispan-udp.cfg.xml" />
</properties>
</transport>
<shutdown hookBehavior="DONT_REGISTER" />
</global>
<namedCache name="current-call-cache">
<jmxStatistics enabled="true" />
<transaction transactionMode="TRANSACTIONAL" lockingMode="PESSIMISTIC"
transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup"></transaction>
<locking isolationLevel="REPEATABLE_READ" useLockStriping="false" />
<eviction strategy="LRU" maxEntries="600" />
<!-- Due minuti -->
<expiration lifespan="120000" />
<storeAsBinary enabled="true" />
<clustering mode="replication">
<stateTransfer timeout="5000" fetchInMemoryState="true" />
<sync replTimeout="5000" />
</clustering>
</namedCache>
</infinispan>
The result is that when arrive concurrent request with same TransactionId, the first is served regularly, the other get a HTTP 409 Conflict.
You can use ab and wireshark to test this configuration.
Tools:
Jersey 1.6 + Guice 2.0
Google Guava 11.0.1
JBoss Infinispan 5.1.1
Good clustering at all!
lunedì 6 febbraio 2012
Port Knocking via web, Web Knocking!
Port knocking is an ingenious practice used when you want open firewall port through a predefined sequence of SYN packets to closed port. However listen to SYN packages to close port can be a weight process, specially if your system already expose a web server.
What I made is to translate the concept behind port knocking to web, instead of knocking a sequence of pre-shared port number, I send an HTTP POST with a MD5 hash of a pre-shared password plus a timestamp. A flow diagram can make my idea more clearly.
First, I have created a script to make the POST request, open-firewall.sh:
This file contains the per-shared password (MyKey in this case) and a wget to system.
Notice that I call the bash script with sudo because the user that run the PHP is apache, that doesn't have rigth to change firewall configuration (iptables).
Insert into sudoers the row:
to give the rigth to apache to run the script below as root. The content of openfirewall-300min.sh is:
This file check the key of request and if it is valid, open firewall to that ip for 5 hours. The log of this operation are put in /var/log/knock.log, create this file and change the owner to apache:
This is it, folks!
What I made is to translate the concept behind port knocking to web, instead of knocking a sequence of pre-shared port number, I send an HTTP POST with a MD5 hash of a pre-shared password plus a timestamp. A flow diagram can make my idea more clearly.
#!/bin/sh
KEY=`echo SharedKey$(date +%Y%m%d%H%M) | md5sum | awk '{print $1}'`
wget --post-data="key=$KEY" http://SERVER/webknocking.php --delete-after
This file contains the per-shared password (MyKey in this case) and a wget to system.
On server side, I have a file named webknocking.php that catch the key and request's source IP and pass them to a script for verify and open firewall:
<?php
$key = $_POST['key'];
$ip = $_SERVER['REMOTE_ADDR'];
$cmd = 'sudo /var/dev.zonablog.net/openfirewall-300min.sh '.$key.' '.$ip.' >> /var/log/knock.log &';
shell_exec($cmd);
?>
Request forwarded.
Notice that I call the bash script with sudo because the user that run the PHP is apache, that doesn't have rigth to change firewall configuration (iptables).
Insert into sudoers the row:
apache ALL= NOPASSWD: /var/dev.zonablog.net/openfirewall-300min.sh
to give the rigth to apache to run the script below as root. The content of openfirewall-300min.sh is:
#!/bin/bash
echo " "
echo $(date) "Verifico Ip "$2", Key "$1
KEY=`echo SharedKey$(date +%Y%m%d%H%M) | md5sum | awk '{print $1}'`
KEY_1m=`echo SharedKey$(date --date='1 minute ago' +%Y%m%d%H%M) | md5sum | awk '{print $1}'`
if [ $1 != $KEY -a $1 != $KEY_1m ]
then
echo $(date) "Respingo Ip "$2", Key "$1
exit 1
fi
# open firewall
echo $(date) "Ok, apro per 5 ore"
/sbin/iptables -I INPUT -j ACCEPT -i eth0 -p tcp -s $2
sleep 180000
# deny incoming packets
echo $(date) "Chiudo a Ip "$2", Key "$1
/sbin/iptables -D INPUT -j ACCEPT -i eth0 -p tcp -s $2
This file check the key of request and if it is valid, open firewall to that ip for 5 hours. The log of this operation are put in /var/log/knock.log, create this file and change the owner to apache:
# touch /var/log/knock.log
# chown apache.apache /var/log/knock.log
This is it, folks!
domenica 2 ottobre 2011
xfce4-cpugraph-plugin on Fedora 15
This plugin isn't in Fedora repositories. You can download it from source, compile and install it. I spent 1 hours to find the correct parameters to pass to configure script...
[root@precision2 ~]# ./configure --libexecdir=/usr/libexec/ --prefix=/usr/
[root@precision2 ~]# make
[root@precision2 ~]# make install
giovedì 23 giugno 2011
JGroups and slf4j
JGroups offers a mechanism to extend its logger implemented two interface, CustomLogFactory and Log. Here are the two implementations for use slf4j.
JGroupsCustomLoggerFactory:
JGroupsCustomLog.java:
Just befor initialize JGroups, call:
JGroupsCustomLoggerFactory:
import org.jgroups.logging.CustomLogFactory;
import org.jgroups.logging.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class JGroupsCustomLoggerFactory implements CustomLogFactory {
@Override
@SuppressWarnings("rawtypes")
public Log getLog(Class clazz) {
Logger logger = LoggerFactory.getLogger(LogUtils.formatClassName(clazz));
return new JGroupsCustomLog(logger);
}
@Override
public Log getLog(String category) {
Logger logger = LoggerFactory.getLogger(category);
return new JGroupsCustomLog(logger);
}
}
JGroupsCustomLog.java:
import org.jgroups.logging.Log;
import org.slf4j.Logger;
import org.slf4j.Marker;
public class JGroupsCustomLog implements Log {
private Logger logger;
public JGroupsCustomLog(Logger logger) {
this.logger = logger;
}
@Override
public boolean isFatalEnabled() {
return false;
}
@Override
public boolean isErrorEnabled() {
return logger.isErrorEnabled();
}
@Override
public boolean isWarnEnabled() {
return logger.isErrorEnabled();
}
@Override
public boolean isInfoEnabled() {
return logger.isInfoEnabled();
}
@Override
public boolean isDebugEnabled() {
return logger.isDebugEnabled();
}
@Override
public boolean isTraceEnabled() {
return logger.isTraceEnabled();
}
public String getName() {
return logger.getName();
}
public void trace(String msg) {
logger.trace(msg);
}
public void trace(String format, Object arg) {
logger.trace(format, arg);
}
public void trace(String format, Object arg1, Object arg2) {
logger.trace(format, arg1, arg2);
}
public void trace(String format, Object[] argArray) {
logger.trace(format, argArray);
}
public void trace(String msg, Throwable t) {
logger.trace(msg, t);
}
public boolean isTraceEnabled(Marker marker) {
return logger.isTraceEnabled(marker);
}
public void trace(Marker marker, String msg) {
logger.trace(marker, msg);
}
public void trace(Marker marker, String format, Object arg) {
logger.trace(marker, format, arg);
}
public void trace(Marker marker, String format, Object arg1, Object arg2) {
logger.trace(marker, format, arg1, arg2);
}
public void trace(Marker marker, String format, Object[] argArray) {
logger.trace(marker, format, argArray);
}
public void trace(Marker marker, String msg, Throwable t) {
logger.trace(marker, msg, t);
}
public void debug(String msg) {
logger.debug(msg);
}
public void debug(String format, Object arg) {
logger.debug(format, arg);
}
public void debug(String format, Object arg1, Object arg2) {
logger.debug(format, arg1, arg2);
}
public void debug(String format, Object[] argArray) {
logger.debug(format, argArray);
}
public void debug(String msg, Throwable t) {
logger.debug(msg, t);
}
public boolean isDebugEnabled(Marker marker) {
return logger.isDebugEnabled(marker);
}
public void debug(Marker marker, String msg) {
logger.debug(marker, msg);
}
public void debug(Marker marker, String format, Object arg) {
logger.debug(marker, format, arg);
}
public void debug(Marker marker, String format, Object arg1, Object arg2) {
logger.debug(marker, format, arg1, arg2);
}
public void debug(Marker marker, String format, Object[] argArray) {
logger.debug(marker, format, argArray);
}
public void debug(Marker marker, String msg, Throwable t) {
logger.debug(marker, msg, t);
}
public void info(String msg) {
logger.info(msg);
}
public void info(String format, Object arg) {
logger.info(format, arg);
}
public void info(String format, Object arg1, Object arg2) {
logger.info(format, arg1, arg2);
}
public void info(String format, Object[] argArray) {
logger.info(format, argArray);
}
public void info(String msg, Throwable t) {
logger.info(msg, t);
}
public boolean isInfoEnabled(Marker marker) {
return logger.isInfoEnabled(marker);
}
public void info(Marker marker, String msg) {
logger.info(marker, msg);
}
public void info(Marker marker, String format, Object arg) {
logger.info(marker, format, arg);
}
public void info(Marker marker, String format, Object arg1, Object arg2) {
logger.info(marker, format, arg1, arg2);
}
public void info(Marker marker, String format, Object[] argArray) {
logger.info(marker, format, argArray);
}
public void info(Marker marker, String msg, Throwable t) {
logger.info(marker, msg, t);
}
public void warn(String msg) {
logger.warn(msg);
}
public void warn(String format, Object arg) {
logger.warn(format, arg);
}
public void warn(String format, Object[] argArray) {
logger.warn(format, argArray);
}
public void warn(String format, Object arg1, Object arg2) {
logger.warn(format, arg1, arg2);
}
public void warn(String msg, Throwable t) {
logger.warn(msg, t);
}
public boolean isWarnEnabled(Marker marker) {
return logger.isWarnEnabled(marker);
}
public void warn(Marker marker, String msg) {
logger.warn(marker, msg);
}
public void warn(Marker marker, String format, Object arg) {
logger.warn(marker, format, arg);
}
public void warn(Marker marker, String format, Object arg1, Object arg2) {
logger.warn(marker, format, arg1, arg2);
}
public void warn(Marker marker, String format, Object[] argArray) {
logger.warn(marker, format, argArray);
}
public void warn(Marker marker, String msg, Throwable t) {
logger.warn(marker, msg, t);
}
public void error(String msg) {
logger.error(msg);
}
public void error(String format, Object arg) {
logger.error(format, arg);
}
public void error(String format, Object arg1, Object arg2) {
logger.error(format, arg1, arg2);
}
public void error(String format, Object[] argArray) {
logger.error(format, argArray);
}
public void error(String msg, Throwable t) {
logger.error(msg, t);
}
public boolean isErrorEnabled(Marker marker) {
return logger.isErrorEnabled(marker);
}
public void error(Marker marker, String msg) {
logger.error(marker, msg);
}
public void error(Marker marker, String format, Object arg) {
logger.error(marker, format, arg);
}
public void error(Marker marker, String format, Object arg1, Object arg2) {
logger.error(marker, format, arg1, arg2);
}
public void error(Marker marker, String format, Object[] argArray) {
logger.error(marker, format, argArray);
}
public void error(Marker marker, String msg, Throwable t) {
logger.error(marker, msg, t);
}
@Override
public void fatal(String msg) {
logger.error(msg);
}
@Override
public void fatal(String msg, Throwable throwable) {
logger.error(msg, throwable);
}
@Override
public void trace(Object msg) {
logger.trace(msg.toString());
}
@Override
public void trace(Object msg, Throwable throwable) {
logger.trace(msg.toString(), throwable);
}
@Override
public void setLevel(String level) {
}
@Override
public String getLevel() {
return "INFO";
}
}
Just befor initialize JGroups, call:
try {
System.setProperty(Global.CUSTOM_LOG_FACTORY, "package.JGroupsCustomLoggerFactory");
jChannel = new JChannel();
jChannel.connect("channel-ver-3.0");
martedì 10 maggio 2011
Hibernate with Guice and a little of AOP to manage transaction.
What do you think abount @Transactional annotation? I used it with spring framework on service class to manage transaction into and intra service call.
It's a very elegant and easy way to manage transactions.
I've started working on a new project and I decided to use Guice as Dependency Injection framework, IMHO more lite and easy than Spring, and Hibernate
but I would like to continue to use the @Transactional annotation on my service class.
I didn't found anything good to use and I decided to use a little of AOP to recreate this functionality.
Let's started with order, I would like that:
1) When I call a method on a service class, the operations in this method belong to a single transaction.
2) If the caller of the method 1) has a transaction, the thansanction must is the parent (caller) transaction.
In practice the "Required" attribute of EBJ's Transactional parameter, see Required Attribute
This is the first case:
And this the second one:
I'm going to use AOP and Guice to set a Method Interceptor that check is the called method has a transaction, and in case of not, create a new one and link it to thread with ThreadLocal class. I create also an annotation that identify che class and method subject and not subject to this check:
A) The Transactional Annotation:
The NoTransactional annotation, that mark the non-transactional method on a class marked as transactional:
The implementation of this interceptor:
I'm using Jersey with Guice, and I use the @Transactional annotation also on webresources. Es:
Note that to let Guice istantiate the webresource, in addition to configuration needed by jersey-guice module, the @Inject must present on constructor's class.
It's a very elegant and easy way to manage transactions.
I've started working on a new project and I decided to use Guice as Dependency Injection framework, IMHO more lite and easy than Spring, and Hibernate
but I would like to continue to use the @Transactional annotation on my service class.
I didn't found anything good to use and I decided to use a little of AOP to recreate this functionality.
Let's started with order, I would like that:
1) When I call a method on a service class, the operations in this method belong to a single transaction.
2) If the caller of the method 1) has a transaction, the thansanction must is the parent (caller) transaction.
In practice the "Required" attribute of EBJ's Transactional parameter, see Required Attribute
This is the first case:
And this the second one:
I'm going to use AOP and Guice to set a Method Interceptor that check is the called method has a transaction, and in case of not, create a new one and link it to thread with ThreadLocal class. I create also an annotation that identify che class and method subject and not subject to this check:
A) The Transactional Annotation:
|
The NoTransactional annotation, that mark the non-transactional method on a class marked as transactional:
|
The implementation of this interceptor:
|
I'm using Jersey with Guice, and I use the @Transactional annotation also on webresources. Es:
|
Note that to let Guice istantiate the webresource, in addition to configuration needed by jersey-guice module, the @Inject must present on constructor's class.
giovedì 28 aprile 2011
Jersey, @RolesAllowed annotation and 403 Forbidden
I spent last three hours to understand why I always get 403 Forbidden from a secured JAX-RS resource with @RolesAllowed...
After checking the params of Jersey Servlet:
I proceeded to debug the filter under the hood, RolesAllowedResourceFilterFactory, and I noticed that UserPrincipal was null!
What I'd forgotten was to secured the resources with security-constraint:
In role-name you've to insert all the roles that you're going to use in @RolesAllowed.
Good night!
After checking the params of Jersey Servlet:
<init-param>
<param-name>com.sun.jersey.spi.container.ResourceFilters</param-name>
<param-value>com.sun.jersey.api.container.filter.RolesAllowedResourceFilterFactory</param-value>
</init-param>
I proceeded to debug the filter under the hood, RolesAllowedResourceFilterFactory, and I noticed that UserPrincipal was null!
What I'd forgotten was to secured the resources with security-constraint:
<security-constraint>
<web-resource-collection>
<web-resource-name>Protected Area</web-resource-name>
<url-pattern>/resources/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
<role-name>user</role-name>
</auth-constraint>
</security-constraint>
In role-name you've to insert all the roles that you're going to use in @RolesAllowed.
Good night!
Iscriviti a:
Post (Atom)



