Displaying keyword search results 1 - 10
Created by Dr. Xi on December 03, 2013 09:14:45 Last update: December 03, 2013 09:14:45
To test the effects of proxy settings http.proxyHost and http.proxyPort , I set these values to a non-existing proxy server:
java -Dhttp.proxyHost=example.com -Dhttp.proxyPort...To my surprise, the Google is retrieved successfully! Is Java ignoring these settings? It turns out that Java tries to fetch the URL directly after the proxy connection fails. If a working proxy is found at proxyHost:proxyPort , then the request is routed through the proxy, otherwise a direct connection is tried. The settings are documented here: http://docs.oracle.com/javase/6/docs/technotes/guides/net/proxies.html . For HTTPS use these properties: htttps.proxyHost htttps.proxyPort
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-sourcesCode 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 packageAfter the webapp is deployed (Tomcat running on port 8080), the web service (WSDL) is available via...
Created by Dr. Xi on March 21, 2013 20:29:14 Last update: March 22, 2013 08:58:08
Spring-WS documentation says you can use a Jaxb object as parameter or return type, provided that it is annotated with javax.xml.bind.annotation.XmlRootElement , or is an instance of javax.xml.bind.JAXBElement . But that's a lot easier said than done! For example, if sayHelloResponse is defined as:
<xs:element name="sayHelloResponse" type="tns:sayH...then the JAXB generated class is not annotated with XmlRootElement , therefore, unusable for Spring-WS. You have to define the type as:
<xs:element name="sayHelloResponse"> <xs:compl...in order to generate a type annotated with XmlRootElement . But that is not always possible. Alternatively, you can use the Maven plugin maven-jaxb2-plugin with the jaxb2-basics-annotate plugin (yes, plugin inside plugin) to inject the XmlRootElement annotation into the generated JAXB class. This is the pom:
<project xmlns="http://maven.apache.org/POM/4.0.0"...and the binding file:
<?xml version="1.0" encoding="UTF-8" standalone="y......
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 packageThe 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 packageThe 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 Fang on January 04, 2013 08:00:37 Last update: January 04, 2013 08:00:37
This is a Maven POM that prints out some built-in project properties:
$ mvn validate [INFO] Scanning for projects.....
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 Fang on February 24, 2012 14:38:06 Last update: April 06, 2012 13:19:29
Step 1: create a Json factory:
package com.my.service.dev; import java.io....Step 2: use it:
ObjectMapper mapper = new ObjectMapper(new AllowCo...
Created by Fang on March 30, 2012 15:04:04 Last update: March 30, 2012 15:04:04
Spring MVC 3.1 can send either JSON or HTML response on the same URL, depending on the type of response requested. With this mechanism, a page can be sent when directly requested from a link, but a JSON response can be sent in response to an AJAX request. This is the controller code:
package com.example; import java.util.Map; ...In the above example, JSON response will be sent when the HTTP request contains header "Accept: application/json". HTML response will be sent then the header is "Accept: */*", or "Accept: text/html", or anything else. You can add a limitation that the HTML response does not produce "application/json". But then the question is which response will be sent when the HTTP header is "Accept: */*"? Both methods will...
Created by Dr. Xi on March 13, 2012 08:46:57 Last update: March 13, 2012 08:46:57
This trick sets HTML base to the root context path of the current webapp: The short version:
<!DOCTYPE html> <%@ taglib uri="http://java.sun...The long version:
<!DOCTYPE html> <%@ taglib uri="http://java.sun...