Re: [xfire-user] How can I make validation for my payload?

2007-04-23 Thread Henning Jensen
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.noHenning Jensen/a
 *
 */
public class XFireValidatorHandler extends AbstractHandler {

	protected static Log log = LogFactory.getLog(XFireValidatorHandler.class
			.getName());

	private MapString, ServiceConfig globalServiceConfig = new HashMapString, 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

Re: [xfire-user] How can I make validation for my payload?

2007-04-23 Thread Tomek Sztelak

Sure, let me know when you finish.

On 4/23/07, Henning Jensen [EMAIL PROTECTED] wrote:

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

-
To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email





--
-
When one of our products stops working, we'll blame another vendor
within 24 hours.

-
To unsubscribe from this list please visit:

   http://xircles.codehaus.org/manage_email



Re: [xfire-user] How can I make validation for my payload?

2007-04-20 Thread Tomek Sztelak

Hi
When do you plan to finish this ? Maybe me could add support for your
framework to XFire distro.

On 4/20/07, Henning Jensen [EMAIL PROTECTED] wrote:

Makni Hamdi wrote:
 Hello,



 I'm using Xfire1.2.4, aegis, Spring 2 with java 1.4, and I want to make
 validation for my payload.

 How can I do it? What framework should I use?

Hi!

I'm working on a framework that does exactly what you are asking for.
With the framework you can define validation rules in a xml file and
just add a handler to your service definitions.

This work is part of a master thesis and you can find the project on:

http://henning.fjas.no/ws-validator

Not to much documentation yet, but a simple example and a download link
is provided. The project uses Maven 2 and you can build it with mvn
package to get jar files to put in your own project.

--
Henning Jensen

-
To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email





--
-
When one of our products stops working, we'll blame another vendor
within 24 hours.

-
To unsubscribe from this list please visit:

   http://xircles.codehaus.org/manage_email



RE: [xfire-user] How can I make validation for my payload?

2007-04-20 Thread Makni Hamdi
 = faultStringOrReason;
}

/**
 * Returns the SOAP fault reason locale used when validation errors 
occur on
 * the request.
 * 
 * @return faultStringOrReasonLocale
 */
public Locale getFaultStringOrReasonLocale() {
return faultStringOrReasonLocale;
}

/**
 * Sets the SOAP fault reason locale used when validation errors occur 
on
 * the request. It is only added when the underlying message is a
 * codeSoapMessage/code. Defaults to English.
 * 
 * @param faultStringOrReasonLocale
 *faultStringOrReasonLocale
 * @see java.util.Locale#ENGLISH
 */
public void setFaultStringOrReasonLocale(Locale 
faultStringOrReasonLocale) {
this.faultStringOrReasonLocale = faultStringOrReasonLocale;
}

protected boolean handleRequestValidationErrors(
MessageContext messageContext, SAXParseException[] 
errors)
throws TransformerException, XFireFault {
for (int i = 0; i  errors.length; i++) {
log.warn(XML validation error on request: 
+ errors[i].getMessage());
}


throw new XFireFault(Error Validation payload. 
+errors[0].getMessage(), errors[0], XFireFault.SENDER);

}

/**
 * Returns the payload source of the given message.
 * 
 * @throws XMLStreamException
 * zz
 */
protected Source getValidationRequestSource(MessageContext request)
throws XMLStreamException {

InMessage message = request.getInMessage();

XMLStreamReader streamReader = message.getXMLStreamReader();
log.debug(streamReader  + streamReader);

StaxBuilder builder = new StaxBuilder();
log.debug(builder  + builder);

doc = builder.build(streamReader);

log.debug(doc  + doc);
log.debug(documentRoot:  + doc.getRootElement());
log.debug(First children of documentRoot: 
+ ((Element) 
doc.getRootElement().getChildren().get(0))
.getName());
Element body = (Element) 
doc.getRootElement().getChildren().get(1);
log.debug(Second children of documentRoot:  + body.getName());

Element payload = (Element) body.getChildren().get(0);

return new JDOMSource(payload);
}

/**
 * Returns the payload source of the given message.
 */
protected Source getValidationResponseSource(MessageContext response) {

OutMessage message = response.getOutMessage();

return null;
}

/**
 * [EMAIL PROTECTED]
 */
public void invoke(MessageContext messageContext) throws Exception {
log.debug(Begin validation);
afterPropertiesSet();
if (handleRequest(messageContext))
log.debug(Validation of requested payload finished by 
SUCESS);
else
log.debug(Validation of requested payload finished by 
FAULT);
messageContext.getInMessage().setXMLStreamReader(
new JDOMStreamReader(doc));

}

}

And a config file like:
bean ...  

property name=inHandlers
list
ref local=maqValidationHandler/
/list
/property
/bean

bean id=maqValidationHandler
class=com.xxx.mobile.ws.validation.PayloadValidator
property name=schema value=maq.xsd /
property name=validateRequest value=true /
property name=validateResponse value=false /
property name=addValidationErrorDetail value=true /
/bean
I'll do some modifications, there are some undesired code till now.

-Message d'origine-
De : Tomek Sztelak [mailto:[EMAIL PROTECTED] 
Envoyé : vendredi 20 avril 2007 15:45
À : user@xfire.codehaus.org
Objet : Re: [xfire-user] How can I make validation for my payload?

Hi
When do you plan to finish this ? Maybe me could add support for your
framework to XFire distro.

On 4/20/07, Henning Jensen [EMAIL PROTECTED] wrote:
 Makni Hamdi wrote:
  Hello,
 
 
 
  I'm using Xfire1.2.4, aegis, Spring 2 with java 1.4, and I want to make
  validation for my payload.
 
  How can I do it? What framework should I use?

 Hi!

 I'm working on a framework that does exactly what you are asking for.
 With the framework you can define validation rules in a xml file and
 just

[xfire-user] How can I make validation for my payload?

2007-04-17 Thread Makni Hamdi
Hello,

 

I'm using Xfire1.2.4, aegis, Spring 2 with java 1.4, and I want to make
validation for my payload.

How can I do it? What framework should I use?

Does aegis can validate the request?

 

Thks,