JAX-WS + Spring integration example

Here’s a guide to show you how to integrate Spring with JAX-WS, as mention in this link : http://jax-ws-commons.java.net/spring/. Upon finishing this tutorial, you will create a simple HelloWorld web service (JAX-WS), and DI a bean into the web service via Spring. 1. Project Folder See the final project folder structure. 2. Project Dependencies Use …

Read more

Unable to locate Spring NamespaceHandler for XML schema namespace [http://jax-ws.dev.java.net/spring/servlet]

Problem Integrate Spring with JAX-WS, according to this link: http://jax-ws-commons.java.net/spring/ . When start the web application, get this exception : org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://jax-ws.dev.java.net/spring/servlet] Here’s the Spring + JAX-WS configuration file. <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ws="http://jax-ws.dev.java.net/spring/core" xmlns:wss="http://jax-ws.dev.java.net/spring/servlet" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://jax-ws.dev.java.net/spring/core http://jax-ws.dev.java.net/spring/core.xsd http://jax-ws.dev.java.net/spring/servlet http://jax-ws.dev.java.net/spring/servlet.xsd" > …

Read more

JAX-WS + Java Web Application Integration Example

Often times, JAX-WS always be part of your Java web application. Here we show you how to integrate JAX-WS into Java web application easily. 1. Project Folder First, review this project folder structure. 2. Web Service A super simple web service. Code is self-explanatory. File : HelloWorld.java package com.mkyong.ws; import javax.jws.WebMethod; import javax.jws.WebService; @WebService public …

Read more

Metro on WebSphere 7 – com.ibm.xml.xlxp2.jaxb.JAXBContextImpl incompatible exception

Problem Developed a SOAP web service via Metro 2.0.1 (webservices-rt.jar), integrate with Spring via jaxws-spring-1.8.jar and deployed on WebSphere Application Server (WAS) version 7.0.0.13 . See web service below : File : UserWS.java package com.mkyong.user.ws; //import… @WebService() public class UserWS { private UserBo userBo; @WebMethod(exclude = true) public UserBo getUserBo() { return userBo; } @WebMethod(exclude …

Read more

JAX-WS : SOAP handler in server side

SOAP handler is a SOAP message interceptor, which is able to intercept incoming or outgoing SOAP message and manipulate its values. For example, attach a SOAP handler in client side, which will inject client’s computer MAC address into the SOAP header block for every outgoing SOAP message that is send by the client. In server …

Read more

javax.xml.stream.XMLStreamException : ParseError at [row,col]:[x,xx]

Problem Created a JAX-WS handler to inject a mac address into the client side SOAP request header automatically : File : MacAddressInjectHandler.java public class MacAddressInjectHandler implements SOAPHandler<SOAPMessageContext>{ @Override public boolean handleMessage(SOAPMessageContext context) { //…… //get mac address String mac = getMACAddress(); //add a soap header, name as "mac address" QName qname = new QName("http://ws.mkyong.com/", "mac …

Read more

JAX-WS : wsgen tool example

The wsgen tool is used to parse an existing web service implementation class and generates required files (JAX-WS portable artifacts) for web service deployment. This wsgen tool is available in $JDK/bin folder. Use cases 2 common use cases for wsgen tool : Generates JAX-WS portable artifacts (Java files) for web service deployment. Generates WSDL and …

Read more

JAX-WS : wsimport tool example

The wsimport tool is used to parse an existing Web Services Description Language (WSDL) file and generate required files (JAX-WS portable artifacts) for web service client to access the published web services. This wsimport tool is available in the $JDK/bin folder. Use Case An common use case of this wsimport tool. 1. Server – Published …

Read more

Container Authentication with JAX-WS – (Tomcat version)

In this article, we show you how to implement container authentication with JAX-WS, under Tomcat 6.0. In this way, the authentication is declarative rather than programmatic like this – application authentication in JAX-WS. And Tomcat implement the container authentication via security realm. At the end of this article, the deployed web service will authenticate user …

Read more

Application Authentication with JAX-WS

One of the common way to handle authentication in JAX-WS is client provides “username” and “password”, attached it in SOAP request header and send to server, server parse the SOAP document and retrieve the provided “username” and “password” from request header and do validation from database, or whatever method prefer. In this article, we show …

Read more

How to bypass certificate checking in a Java web service client

In Java web service development environment, developer are always generate a test certificate using keytool. While doing client testing, often times, the web service test client will hits following error messages : java.security.cert.CertificateException: No name matching localhost found SunCertPathBuilderException: unable to find valid certification path to requested target Here’s a source code, that i copied …

Read more

SunCertPathBuilderException: unable to find valid certification path to requested target

1. Problem Set up a localhost Tomcat to support SSL and deployed this web service for testing. While connecting to the deployed web service over SSL connection via this URL : https://localhost:8443/HelloWorld/hello?wsdl, it hits Terminal javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target Caused by: sun.security.validator.ValidatorException: PKIX …

Read more

java.security.cert.CertificateException: No name matching localhost found

Problem Configured Tomcat to support SSL and deployed this simple hello world web service. And use following client connect to the deployed web service over SSL connection : package com.mkyong.client; import java.net.URL; import javax.xml.namespace.QName; import javax.xml.ws.Service; import com.mkyong.ws.HelloWorld; public class HelloWorldClient{ public static void main(String[] args) throws Exception { URL url = new URL("https://localhost:8443/HelloWorld/hello?wsdl"); QName …

Read more

JAX-WS attachment with MTOM

A complete JAX-WS SOAP-based example to show how to use Message Transmission Optimization Mechanism (MTOM) and XML-Binary Optimized Packaging (XOP) technique to send a binary attachment (image) from server to client and vice verse. Note There are ton of articles about what’s MTOM and the benefits of using it (see reference sites below), but it’s …

Read more

Wrapper class package.jaxws.methodName is not found. Have you run APT to generate them?

Problem In JAX-WS development, when following service endpoint is deploying, File : HelloWorld.java package com.mkyong.ws; //Service Endpoint Interface @WebService public interface HelloWorld{ @WebMethod String getHelloWorldAsString(); } File : HelloWorldImpl.java //Service Implementation package com.mkyong.ws; @WebService(endpointInterface = "com.mkyong.ws.HelloWorld") public class HelloWorldImpl implements HelloWorld{ @Override public String getHelloWorldAsString() { //… } } It hits following error message immediately? …

Read more

How to trace SOAP message in Eclipse IDE

In SOAP web service, each HTTP request or response encapsulates a SOAP envelope, these messages are easy to trace by using Eclipse IDE, build-in “TCP/IP monitor” tool. The idea is host another server in between the client and server to perform port forward function to intercept the HTTP traffic. 1. Normal SOAP envelope flows In …

Read more

JAX-WS – java.net.BindException: Address already in use: bind

Developing a Java web service development with JAX-WS, and publish an end point… public static void main(String[] args) { Endpoint.publish("http://localhost:8080/ws/hello", new WallStreetImpl()); } 1. Problem It hits the following error message. Exception in thread "main" com.sun.xml.internal.ws.server.ServerRtException: Server Runtime Error: java.net.BindException: Address already in use: bind … Caused by: java.net.BindException: Address already in use: bind at …

Read more