Notes by Fang
Displaying keyword search results 1 - 10
Created by Fang on July 25, 2012 12:52:40
Last update: September 14, 2012 13:37:57
Summarized from official JAX-WS documentation : Sending and Receiving SOAP Headers To send a SOAP header:
HelloService helloService = new HelloService(); ... To receive a SOAP header: List<Header> inboundHeaders = bp.getInboundHeaders... Message logging On the client side, set system property: com.sun.xml.ws.transport.http.client.HttpTransport... On the server side, set system property: com.sun.xml.ws.transport.http.HttpAdapter.dump=tru... Propagation of Server-side Stacktrace Propagation of Stack trace is on by default. The whole stacktrace (including nested exceptions) is propagated in the SOAP Fault and the complete exception stacktrace is visible to the client as cause of SOAPFaultException . To turn off stack trace propagation, set this system property on the server: com.sun.xml.ws.fault.SOAPFaultBuilder.disableCaptu... Update: At least on the client side, the property name has been changed to: com.sun.xml.internal.ws.transport.http.client.Http... The messages are dumped to stdout . For...
Created by Fang on March 30, 2012 12:15:49
Last update: March 30, 2012 12:15:49
1. mvc:default-servlet-handler Configures a handler for serving static resources by forwarding to the Servlet container's default Servlet. Use of this handler allows using a "/" mapping with the DispatcherServlet while still utilizing the Servlet container to serve static resources. HandlerMapping: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping Handler: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping Attribute Description default-servlet-name The name of the default Servlet to forward to for static resource requests. The handler will try to auto-detect the container's default Servlet at startup time using a list of known names. If the default Servlet cannot be detected because of using an unknown container or because it has been manually configured, the servlet name must be set explicitly. 2. mvc:view-controller Defines a simple Controller that selects a view to render the response. HandlerMapping: org.springframework.web.servlet.handler.SimpleUrlHandlerMapping Handler: org.springframework.web.servlet.mvc.ParameterizableViewController Attribute Description...
Created by Fang on March 05, 2012 20:49:40
Last update: March 06, 2012 12:28:47
This is an easy to follow step-by-step tutorial to get started with Java JSR303 bean validation. It is solely focused on bean validation without dependency on any other Java technology. I hope that by following these steps you'll gain hands-on experience as well as some insights on how Java bean validation works.
Getting started with Java JSR 303 bean validation: the Maven project
Java JSR 303 bean validation: a simple example
JSR 303 cascade validation through inheritance
JSR 303 cascade validation through composition
JSR 303 validation with validation groups
JSR 303 bean validation *.List annotations
Created by Fang on March 05, 2012 20:32:37
Last update: March 05, 2012 20:32:37
In this simple example, I create a simple validating bean and create a JUnit test to test the validation.
The bean ( src/main/java/com/example/Person.java ):
package com.example;
import javax.validatio...
The test ( src/test/java/com/example/TestPerson.java ):
package com.example;
import java.util.Set;
...
Run the test:
mvn clean test
You'll notice that one test passed and the other failed.
The tests require that a person must have a name and the name cannot be empty, so @NotNull is not the right rule to use here. To make sure that the name is not empty, we need to use @Pattern . But since a null String matches any pattern, @NotNull is also needed:
package com.example;
import javax.validatio...
Created by Fang on February 27, 2012 12:19:19
Last update: February 27, 2012 12:19:19
Mapping Java objects to Jackson JSON is pretty simple. But if you name a JSON field wrong, you'll get the "Unrecognized field ... (Class ...), not marked as ignorable" error. The rule for mapping a Java bean attribute name to a JSON field name is: lower all leading capital letters until the first lower case letter .
For example, this Java class:
package com.example;
public class Person {
...
maps to this JSON string:
{
"firstName": "Jane",
"lastName": "...
Test code:
package com.example;
import java.net.URL;
...
Created by Fang on February 16, 2012 12:27:55
Last update: February 16, 2012 12:34:58
Here are some ways to run a main method using Maven:
Use the exec plugin:
mvn exec:java -Dexec.mainClass="com.example.App"
or, with arguments:
mvn exec:java -Dexec.mainClass="com.example.App" -...
Attach it to a build phase with the build element:
<build>
<plugins>
<plugin>
...
If you want to run main from Maven, it's probably just some test code. You are better off just to write a test case, or call the main method from a test class:
package com.example;
import junit.framework...
Created by Fang on February 15, 2012 21:03:57
Last update: February 15, 2012 21:03:57
Error:
java.lang.NoClassDefFoundError: org/slf4j/impl/Sta...
Soluton: add Maven dependency for one of slf4j-nop , slf4j-simple , slf4j-log4j12 , slf4j-jdk14 . For example:
<dependency>
<groupId>org.slf4j</groupId>
...
or
<dependency>
<groupId>org.slf4j</groupId>
...
Created by Fang on January 10, 2010 00:19:30
Last update: January 31, 2012 16:28:42
Maven is a powerful yet complex tool. When I started learning Maven, the first obstacle was, of course, its complexity. The second, was the lack of documentation that can get me off the ground quickly. This tutorial is an attempt to create a pragmatic guide that aims to get you familiar with Maven in the quickest way possible. The main theme is to get you on some hands on experience to start out and lead you through the creation of a simple Java EE project as quickly as possible. Instead of trying to give you a good read, I try to get you on the journey right away. The topics are roughly ordered by the logical sequence but you can jump around in any way...
Created by Fang on January 31, 2012 15:40:34
Last update: January 31, 2012 15:41:28
This is a simple Hello World application with Spring 3 MVC. Like the default Apache HTTPd welcome page, it displays " It works! " when successfully deployed. The sole purpose is to show the minimum elements needed to setup Spring 3 MVC.
I use Maven since it's so much easier than downloading the dependencies manually.
Directory layout:
./src
./src/main
./src/main/webapp
./src/...
pom.xml :
<?xml version="1.0" encoding="UTF-8"?>
<project...
WEB-INF/web.xml :
<?xml version="1.0" encoding="UTF-8"?>
<web-app...
WEB-INF/applicationContext.xml (empty, but needed):
<?xml version="1.0" encoding="UTF-8"?>
<beans x...
WEB-INF/spring-servlet.xml :
<?xml version="1.0" encoding="UTF-8"?>
<beans x...
WEB-INF/jsp/home.jsp :
<!DOCTYPE html>
<html>
<head>
<title>H...
Build with:
mvn clean package
The resulting webapp is target/springmvc.war .
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>
...