Recent Notes
Displaying keyword search results 1 - 12
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 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 Fang on January 04, 2013 09:02:44
Last update: January 04, 2013 09:02:44
This snippet sets system properties from Maven surefire test plugin. This is useful when you want to set logging (for example, log4j) properties based on Maven project properties.
Example that sets system property testlog.dir :
<plugins>
<plugin>
<groupId>org.apach...
Example log4j.xml that uses system property testlog.dir :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYP...
Created by Fang on November 08, 2011 20:55:00
Last update: November 21, 2011 18:19:44
In the simple taglib example , I used a tag handler class to implement a taglib. This is an example to implement a taglib with a UI component. The purpose is to use a custom tag to split a string and print each part in a separate paragraph, i.e., print
<p>john</p> <p>steve</p> <p>mike</p> with custom tag <my:foreach> : <my:foreach var="who" value="john steve mike"> ... These are the files: pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0"... src/main/java/com/example/UIForeash.java : package com.example; import java.io.IOExcep... src/main/resources/META-INF/faces-config.xml : <?xml version="1.0" encoding="UTF-8"?> <faces-c... src/main/resources/META-INF/foreach.taglib.xml : <?xml version="1.0" encoding="UTF-8"?> <facelet... How to use: Put the JAR file generated by the above project in the WEB-INF/lib folder of the web app. If the web app is a Maven project, just add the taglib project as a dependency:...
Created by Fang on November 10, 2011 09:26:12
Last update: November 10, 2011 09:26:12
Syntax highlighted XML schema for JSF 2.0 Application Configuration Resource File ( faces-config.xml ). Almost 3000 lines!
<?xml version="1.0" encoding="UTF-8"?>
<xsd:sch...
Created by Fang on November 03, 2011 19:47:38
Last update: November 08, 2011 20:24:47
This is a step-by-step example to create a really simple facelet taglib (in JSF 2 with Maven). Create a simple Maven project with:
mvn archetype:create -DgroupId=com.example -Dartif... Three files are created as a result: pom.xml src/main/java/com/example/App.java src/test/java/com/example/AppTest.java This project should be able to build with: mvn package Add facelet API dependencies to pom.xml : <project xmlns="http://maven.apache.org/POM/4.... The compiler plugin section is optional. Remove src/main/java/com/example/App.java , create a new Java class as the facelet Tag Handler ( HelloTagHandler.java ): package com.example; import java.io.IOExcep... This tag handler simply prints a "Hello" message. Create facelet tag declaration file src/main/resources/META-INF/hello.taglib.xml : <?xml version="1.0" encoding="UTF-8"?> <facelet... Build the JAR with mvn clean package Optionally, install it to the local repository: mvn install To use the taglib, simply drop the...
Created by Fang on October 28, 2011 13:49:40
Last update: October 30, 2011 19:23:25
This is a simple example to demonstrate the templating power of JSF facelets. If you've used struts tiles before, you'll recognize the simplicity of templating with facelets. I've stripped out everything else except the pages themselves, just to put our focus on facelets. This is a Maven based project, and you need Tomcat (or any servlet container) to run the resulting webapp. To begin with this is the list of files:
./pom.xml ./src/main/webapp/home.xhtml ./src... I left faces-config.xml in there for completeness sake, it may not be needed. The Maven POM ( pom.xml ): <?xml version="1.0" encoding="UTF-8"?> <project... Web app configuration ( WEB-INF/web.xml ): <?xml version="1.0" encoding="UTF-8"?> <web-app... Empty WEB-INF/faces-config.xml : <?xml version="1.0" encoding="UTF-8"?> <!-- Thi... index.jsp is simply a redirect to home.jsf : <% response.sendRedirect("home.jsf"); %>...
Created by freyo on May 13, 2011 15:45:29
Last update: September 20, 2011 08:08:12
This is an Android app that dumps any binarized xml file as plain text - to the sdcard on the device or emulator.
build.xml :
<?xml version="1.0" encoding="UTF-8"?>
<project...
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<man...
res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<Lin...
res/values/strings.xml :
<?xml version="1.0" encoding="utf-8"?>
<res...
src/com/android/xmltool/DumpXml.java
package com.android.xmltool;
import java.ut...
Screenshot
Pre-built APK can be downloaded from: http://code.google.com/p/android-binxml-dump/
Created by nogeek on September 29, 2010 19:22:15
Last update: September 29, 2010 19:22:15
Assuming you are using the default server.
Edit the file server/default/conf/login-config.xml
Copy & paste the section:
<application-policy name="web-console">
...
Change the copy to:
<application-policy name="myapp">
<auth...
Create users properties file
Copy server/default/conf/props/jmx-console-users.properties to server/default/conf/props/myapp-users.properties . Change contents to:
# users.properties file for use with the Users...
Create roles properties file
Copy server/default/conf/props/jmx-console-roles.properties to server/default/conf/props/myapp-roles.properties . Change contents to:
# roles.properties file for use with the Users...
Edit web.xml in the application myapp . Add security constraints:
<security-constraint>
<web-resource-col...
Add file WEB-INF/jboss-web.xml with the following contents:
<?xml version='1.0' encoding='UTF-8' ?>
...
where myapp corresponds to the name attribute for application-policy in step 1.
Created by Dr. Xi on August 03, 2010 16:29:35
Last update: August 03, 2010 16:36:50
This utility converts unicode escape strings in a file to UTF-8 encoded. Suppose you received a properties file with contents like:
# @(#)codepoint_zh_CN.properties 1.4 05/09/27
#...
You can use this utility to convert it to UTF-8 and view or edit.
import java.io.*;
/**
* Reads file with...
This utility is equivalent to:
native2ascii -reverse -encoding utf-8
using the standard Java native2ascii utility.
Created by Fang on September 07, 2009 16:39:37
Last update: September 07, 2009 18:43:04
It's easiest to use the archetype plugin to start a new Maven project. I'll use struts 1 as example since it's not in the built-in archetypes for archetype:generate . Generate a simple webapp with archetype:generate :
C:\work\maven>mvn archetype:generate -DarchetypeAr... It generates a directory structure like this: struts1app struts1app/pom.xml struts1app/src... with a simple POM: <project xmlns="http://maven.apache.org/POM/4.0.0"... Create settings.xml in $HOME/.m2 , add Java.net repository for Java EE dependencies: <?xml version="1.0" encoding="UTF-8"?> <setting... Add Java EE and Struts dependencies in pom.xml . Note that the Java EE dependency has scope provided , meaning that the web app container provides the jars, therefore we don't need to bundle them with our war fie. <project xmlns="http://maven.apache.org/POM/4.0.0"... Create a directory named java under main , create the Struts form and...
Created by Dr. Xi on April 30, 2009 23:26:13
Last update: May 01, 2009 17:08:49
ApplicationResources.properties contains these keys:
test.key.1 = Test Key One
test.key.2 = Test Key...
Struts (struts-el):
<%@ page contentType="text/html;charset=UTF-8" lan...
JSTL
<%@ page contentType="text/html;charset=UTF-8" lan...
However, the values for one and two must be passed in from pageScope , requestScope , sessionScope , etc. Values defined by struts bean:define are not interpreted.
Important:
JSTL tags work with servlet spec 2.4 only. So your web.xml must start with this:
<?xml version = '1.0' encoding = 'windows-1252'?> ...
Not this:
<?xml version = '1.0' encoding = 'windows-1252'?>
...
However, the latter does work with struts-el tags.