Recent Notes
Displaying keyword search results 1 - 10
Created by Dr. Xi on March 22, 2013 12:18:39
Last update: March 22, 2013 12:18:39
This is a step-by-step guide to create a "contract-first" web service with Apache CXF. It's a lot easier than doing the same thing with Spring-WS. The project uses standard Maven directory layout. Define the data types ( src/main/resources/hello.xsd ):
<xs:schema xmlns:xs="http://www.w3.org/200... Define the service ( src/main/resources/hello.wsdl ): <?xml version='1.1' encoding='UTF-8'?> <wsdl:de... Create pom.xml : <project xmlns="http://maven.apache.org/POM/4.... Generate jaxb bindings: $ mvn generate-sources Code the web service ( src/main/java/com/example/cxfdemo/HelloPortImpl.java ): package com.example.cxfdemo; import javax.j... Declare the CXF servlet in web.xml ( src/main/webapp/WEB-INF/web.xml ): <?xml version="1.0" encoding="UTF-8"?> <web-app... Wire up the web service implementation ( src/main/webapp/WEB-INF/cxf-servlet.xml ): <?xml version="1.0" encoding="UTF-8"?> <beans x... Build the WAR: $ mvn clean package After the webapp is deployed (Tomcat running on port 8080), the web service (WSDL) is available via...
Created by Fang on March 30, 2012 10:07:25
Last update: March 08, 2013 13:41:57
After a user resets a password, I want to force the user to change the password before she gets access to secured content. This is usually done with a servlet filter. But with Spring MVC, you can also use a HandlerInterceptor . According to Spring JavaDoc: HandlerInterceptor is basically similar to a Servlet 2.3 Filter, but in contrast to the latter it just allows custom pre-processing with the option of prohibiting the execution of the handler itself, and custom post-processing. Filters are more powerful, for example they allow for exchanging the request and response objects that are handed down the chain. Note that a filter gets configured in web.xml, a HandlerInterceptor in the application context. As a basic guideline, fine-grained handler-related preprocessing tasks are candidates...
Created by Dr. Xi on March 07, 2013 20:26:23
Last update: March 07, 2013 20:26:23
Create a jax-ws web service with Spring, Apache CXF and Maven.
Create the pom.xml :
<project xmlns="http://maven.apache.org/POM/4.0.0"...
Create the web service interface ( src/main/java/jaxws/JaxwsHello.java ):
package jaxws;
import javax.jws.WebService;...
Implement the web service ( src/main/java/jaxws/JaxwsHelloImpl.java ):
package jaxws;
import javax.jws.WebService;...
Create src/main/webapp/WEB-INF/cxf-servlet.xml :
<?xml version="1.0" encoding="UTF-8"?>
<beans x...
Register the CXF servlet in src/main/webapp/WEB-INF/web.xml :
<?xml version="1.0" encoding="UTF-8"?>
<web-app...
Build:
mvn package
The resulting WAR file can be deployed to any servlet container (for example, Tomcat).
Created by Dr. Xi on March 01, 2013 16:09:00
Last update: March 04, 2013 12:28:23
This is probably the easiest way to create a web service in JAX-WS. There are no external dependencies other than Java EE. Assuming that you build the web service as a webapp (say jaxws-example.war), the pom.xml can be as simple as:
<project xmlns="http://maven.apache.org/POM/4.0.0"... You can implement and deploy the web service in 3 easy steps: Code the service as a POJO (annotate class to expose it as a web service) package jaxws; import javax.jws.WebMethod; ... Declare the POJO as a servlet in WEB-INF/web.xml : <?xml version="1.0" encoding="UTF-8"?> <web-app... Build the webapp, and deploy the resulting war: mvn package The only catch is, this only works for a Java EE 5+ compliant container such as WebLogic or JBoss. It does not work for a simple servlet...
Created by Dr. Xi on October 08, 2012 11:56:29
Last update: October 08, 2012 11:56:29
This example gets the annotation attributes of of a web service client generated by JAX-WS RI.
The generated web service client looks like this:
import javax.xml.ws.Service;
import javax.xml.w...
This is how to get the attributes for annotation @WebServiceClient :
WebServiceClient wsc = MyTestWebService.class.getA...
Note that even though name , targetNamespace and wsdlLocation are attributes, you get them using a method call.
Also, annotations are available at runtime only when they have RetentionPolicy.RUNTIME .
Created by Fang on April 16, 2012 13:32:10
Last update: April 16, 2012 13:32:10
There are two steps to create a custom function for JSP:
Declare the function in the TLD:
<?xml version="1.0" encoding="UTF-8" ?>
<taglib...
Implement the function (must be static):
package com.example;
public class UrlTransl...
To use the function:
<%@ taglib uri="http://www.example.com/jsp/tags" p...
Created by Dr. Xi on March 08, 2012 12:13:57
Last update: March 08, 2012 12:13:57
This example creates an instance of XMLGregorianCalendar and converts it to java.util.Date :
import java.util.Date;
import javax.xml.datatyp...
Created by Fang on February 10, 2012 16:17:13
Last update: February 10, 2012 16:17:13
The annotation @org.hibernate.annotations.Type overrides the default hibernate mapping type used for a column. This can usually be omitted since Hibernate normaly infers the correct type to use.
But @Type is required in ambiguous scenarios such as a java.util.Date attribute, which can map to SQL DATE , TIME or TIMESTAMP . You use the @Type("timestamp") annotation to tell Hibernate that a timestamp converter should be used, which identifies an instance of org.hibernate.type.TimestampType .
@Type can also be used to identify custom type converters, which can be defined with @TypeDef at the class level:
@TypeDefs(
{
@TypeDef(
na...
or with an xml file:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mappi...
Created by Fang on January 28, 2012 13:24:09
Last update: January 28, 2012 13:31:22
This is a simple JSP custom tags library with tag body. Just like the JSF counterpart , it splits a string and repeats the body for each word, i.e., with this markup:
<%@ taglib uri="http://custom.tag.com/demo" prefix...
output:
<html>
<body>
<p>Hello Tigger!</p>
<p>H...
With Maven, this is the directory structure:
./src
./src/main
./src/main/resources
./s...
There are three files to write:
pom.xml :
<project xmlns="http://maven.apache.org/POM/4.0.0"...
src/main/java/tagdemo/IterateTag.java :
package tagdemo;
import java.io.IOException...
src/main/resources/META-INF/demotag.tld :
<?xml version="1.0" encoding="UTF-8"?>
<!DO...
Build with:
mvn clean install
To use it as a dependency in other Maven projects:
<dependency>
<groupId>tag-demo</groupId>
...
Created by Fang on December 06, 2011 19:03:25
Last update: December 07, 2011 08:54:11
Our custom tag, as implemented in the previous note , is broken when a template is used.
Create a template file ( home-template.xhtml ):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Stric...
and a test page that uses it ( home.xhtml ):
<?xml version="1.0" encoding="UTF-8"?>
<ui:comp...
Then request the page with URL: http://localhost:8080/facelet-demo/home.jsf?name=Jack .
You'll find that our hello tag works inside ui:repeat but fails to get the value defined by ui:param ! What's the problem? Our hello tag implementation evaluated the EL with the wrong EL context!
This is the corrected implementation:
package com.example;
import java.io.IOExcep...