How to use JAXP to validate a xml file against schema.
File NewXMLSchema.xsd is a resource.
File NewXMlSchema.xml is a xml file which we need to validate against schema NewXMlSchema.xsd
package validator;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import javax.xml.XMLConstants;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
public class JAXPValidation {
public JAXPValidation() {
try {
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = factory.newSchema(this.getClass().getResource("NewXMLSchema.xsd"));
Validator validator = schema.newValidator();
validator.setErrorHandler(new ErrorHandler(){
public void error(SAXParseException exception) throws SAXException {
exception.printStackTrace();
throw exception;
}
public void fatalError(SAXParseException exception) throws SAXException {
exception.printStackTrace();
throw exception;
}
public void warning(SAXParseException exception) throws SAXException {
exception.printStackTrace();
throw exception;
}
});
URL url = this.getClass().getResource("NewXMlSchema.xml");
InputStream stream = url.openStream();
StreamSource source = new StreamSource(stream);
validator.validate(source);
System.out.println("validate sucessfully");
} catch (SAXException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
static public void main(String[] args) {
new JAXPValidation();
}
}
Friday, August 24, 2007
How to validate JAXP 1.3
Posted by CABA LAM at 10:17 PM 0 comments
Tuesday, August 21, 2007
How to validate request in jax-ws
JAX-WS has the hole in validate soap request. But we can work around by using SoapHandler and JAXP to validate soap request.
As we can see from the picture from the left, we have 2 chance to validate request:
SOAPHandler and LogicalHandler. We use SOAPHandler if we want to validate soap header and soap body and use logicalhandler to validate soap body.
In method: handleMessage() in class SOAPHanlder, we can easily get the raw soap message by using: SOAPMessageContext and write them to ByteArrayOutputStream. After we got the xml string, we can use JAXP to validate the request. Detail in how to implement the idea will be presented in next post.
Posted by CABA LAM at 8:01 AM 0 comments
Sunday, August 19, 2007
Default Password List for Routers
To know the default password list for router, please refer to this url:
http://www.phenoelit-us.org/dpl/dpl.html
Posted by CABA LAM at 9:13 AM 0 comments
Thursday, August 16, 2007
How to deploy an FTP server with FileZilla
Today, i meet a problem with ftp server. I will share my experience with you about it.
Download FTP Server at:
http://filezilla.sourceforge.net/
Download FTP Client at:
http://filezilla.sourceforge.net
Setup FileZilla server:
1.Run installer.
2.If you are behind the router, remember to open 2 port at router: port 20, 21.
By opening these 2 ports, the users from internet can access to server. If your server is behind the firewall, you have to let firewall also open 2 ports 20,21 .
3. Next, please refer to this document:
http://filezilla.sourceforge.net/documentation/
Hope this post will help you in setup ftp server: FileZilla.
Posted by CABA LAM at 8:56 AM 0 comments