Tomek Sztelak skrev:
> Hi
> When do you plan to finish this ? Maybe me could add support for your
> framework to XFire distro.
>
Hi
The project is planed finished mid-may. It would be have been real nice
to get the validation handler into the XFire distro, since it would make
it even easier to make use of my framework and hopefully help making web
services more secure.
The XFire handler itself is quite simple and only about 60-70 lines of
code (see attachment). Don't think that would be to much of a hassle to
include in the XFire distro ;)
I'm currently in the middle of doing a restructuring and clean up of the
code, so perhaps I can contact you when I'm finished?
--
Regards
Henning Jensen
package no.fjas.henning.ws.validator.xfire;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import no.fjas.henning.ws.validator.ConfigParser;
import no.fjas.henning.ws.validator.Constants;
import no.fjas.henning.ws.validator.ServiceConfig;
import no.fjas.henning.ws.validator.ValidatorSupport;
import no.fjas.henning.ws.validator.util.ClassLoaderUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.codehaus.xfire.MessageContext;
import org.codehaus.xfire.exchange.AbstractMessage;
import org.codehaus.xfire.handler.AbstractHandler;
import org.codehaus.xfire.handler.Phase;
import org.codehaus.xfire.util.dom.DOMInHandler;
import org.w3c.dom.Document;
/**
* @author <a href="mailto:henning _at_ fjas.no">Henning Jensen</a>
*
*/
public class XFireValidatorHandler extends AbstractHandler {
protected static Log log = LogFactory.getLog(XFireValidatorHandler.class
.getName());
private Map<String, ServiceConfig> globalServiceConfig = new HashMap<String, ServiceConfig>();
public XFireValidatorHandler() {
super();
loadConfiguration();
}
public XFireValidatorHandler(String configurationFile) {
super();
loadConfiguration(configurationFile);
}
private void loadConfiguration() {
loadConfiguration(Constants.DEFAULT_CONFIGURATION_FILE);
}
@SuppressWarnings("unchecked")
private void loadConfiguration(String configurationFile) {
// Make sure handler is in correct phase and after DOMInHandler
setPhase(Phase.PARSE);
getAfter().add(DOMInHandler.class.getName());
InputStream is = ClassLoaderUtil.getResourceAsStream(configurationFile,
XFireValidatorHandler.class);
if (is != null) {
globalServiceConfig = ConfigParser.parseValidatorConfigs(is,
configurationFile);
} else {
if (log.isWarnEnabled())
log.warn("Validation configuration not loaded, config file not found.");
}
}
public void invoke(MessageContext context) throws Exception {
if (log.isDebugEnabled())
log.debug("ValidatorInHandler has been invoked");
String serviceName = context.getService().getName().getLocalPart();
if (log.isDebugEnabled())
log.debug("service.name: " + serviceName);
ServiceConfig serviceConfig = globalServiceConfig.get(serviceName);
if (serviceConfig != null) {
if (log.isDebugEnabled())
log.debug("Service configuration found for service: "
+ serviceName);
AbstractMessage currentMessage = context.getInMessage();
Document doc = (Document) currentMessage
.getProperty(DOMInHandler.DOM_MESSAGE);
if (doc == null) {
log.warn("Document is null!");
} else {
if (log.isDebugEnabled())
log.debug("Validating document");
ValidatorSupport.validateEnvelope(serviceConfig, doc);
}
} else {
log.warn("No validation configuration exists for service: "
+ serviceName);
}
}
}
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email