JAX-WS Tutorial
JAX-WS tutorial with full example, including JAX-WS annotation, deployment, authentication and integration with Spring and web application.
JAX-WS tutorial with full example, including JAX-WS annotation, deployment, authentication and integration with Spring and web application.
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 …
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" > …
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 …
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 …
Problem Integrate Spring + JAX-WS, see web service below : package com.mkyong.user.ws; //imports… @WebService() public class PGUserWS { //DI via Spring private UserBo userBo; public UserBo getUserBo() { return userBo; } public void setUserBo(UserBo userBo) { this.userBo = userBo; } @WebMethod(operationName = "addUser") public boolean addUser(@WebParam(name = "userId") String userId, @WebParam(name = "User") User user) …
Problem 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" > <wss:binding url="/ws/OrderWs"> <wss:service> <ws:service bean="#orderWs"/> </wss:service> </wss:binding> <!– this bean implements web service methods –> <bean id="#orderWs" class="com.mkyong.order.ws.OrderWS"> <property name="orderBo" ref="OrderBo" /> </bean> </beans> During server start up, it hits following …
Problem Developing jax-ws with Spring, using jdk1.6 + jaxws-spring-1.8.jar + Spring-2.5.6.jar. See following Spring XML 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" > <wss:binding url="/ws"> <wss:service> <ws:service bean="#UserWs"/> </wss:service> </wss:binding> <!– this bean implements web service methods –> <bean id="UserWs" class="com.mkyong.user.ws.UserWS"> <property name="UserBo" ref="com.mkyong.user.bo.UserBo" /> …
Problem Integrating jax-ws with Spring, using xbean-spring-2.8.jar + Spring-2.5.6.jar. While server is starting up, it hits java.lang.ClassNotFoundException: org.springframework.beans.factory.support.ReaderContext Solution The “org.springframework.beans.factory.support.ReaderContext” is no longer exist in Spring-2.5.x, it’s only exist in the old Spring version < 2.5.x. The solution is upgrade your xbean-spring to latest version , for example, v3.7. You can get xbean-spring.jar from ...
This is the part 3 of JAX-WS SOAP handler. A testing result for part 1 : SOAP handler in server side and part 2 : SOAP handler in client side. See following use cases 1. Valid MAC Address From top to bottom showing a client with valid computer’s MAC address sending a request to published …
This is part 2 of JAX-WS SOAP handler. In previous article – JAX-WS : SOAP handler in server side, you created a web service and attach a handler to retrieve the client MAC address in header block, for every incoming SOAP message. SOAP handler in client side In this article, you will develop a web …
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 …
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 …
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 …
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 …
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 …
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 …
In this article, we show you how to deploy a JAX-WS web service on Tomcat with TLS / SSL or https secure connection enabled. Actually, the answer is quite simple, just deploys it as a normal web service and configured SSL connection on your Tomcat server properly 🙂 Note This article is just a combination …
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 …
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 …
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 …
Here’s a guide to show you how to deploy JAX-WS web services on Tomcat servlet container. See following summary steps of a web service deployment. Create a web service (of course). Create a sun-jaxws.xml, defines web service implementation class. Create a standard web.xml, defines WSServletContextListener, WSServlet and structure of a web project. Build tool to …
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 …
In this tutorial, we show you how to use JAX-WS to create a SOAP-based web service (document style) endpoint. Compare with RPC style, it need some extra efforts to get it works. Directory structure of this example JAX-WS Web Service End Point Here are the steps to create a document style web service in JAX-WS. …
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? …
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 …
Problem Deploying a JAX-WS web service on Tomcat, hits following error message : java.lang.ClassNotFoundException: org.glassfish.external.amx.AMXGlassfish Solution The JAX-WS dependency library “management-api.jar” is missing. Go here http://jax-ws.java.net/. Download JAX-WS RI distribution. Unzip it and copy “management-api.jar” to Tomcat library folder “{$TOMCAT}/lib“. Restart Tomcat.
Problem Deploying a JAX-WS web service on Tomcat, hits following error message : java.lang.ClassNotFoundException: org.glassfish.gmbal.ManagedObjectManager Solution The JAX-WS dependency library “gmbal-api-only.jar” is missing. Go here http://jax-ws.java.net/. Download JAX-WS RI distribution. Unzip it and copy “gmbal-api-only.jar” to Tomcat library folder “{$TOMCAT}/lib“. Restart Tomcat.
Problem Deploying a JAX-WS web service on Tomcat, hits following error message : java.lang.ClassNotFoundException: org.jvnet.staxex.XMLStreamReaderEx Solution The JAX-WS dependency library “stax-ex.jar” is missing. Go here http://jax-ws.java.net/. Download JAX-WS RI distribution. Unzip it and copy “stax-ex.jar” to Tomcat library folder “{$TOMCAT}/lib“. Restart Tomcat.
Problem Deploying a JAX-WS web service on Tomcat, hits following error message : java.lang.ClassNotFoundException: javax.xml.ws.soap.AddressingFeature$Responses Solution The JAX-WS dependency library “jaxws-api.jar” is missing. Go here http://jax-ws.java.net/. Download JAX-WS RI distribution. Unzip it and copy “jaxws-api.jar” to Tomcat library folder “{$TOMCAT}/lib“. Restart Tomcat.
Problem Deploying a JAX-WS web service on Tomcat, hits following error message : java.lang.ClassNotFoundException: com/sun/xml/ws/policy/PolicyException Solution The JAX-WS dependency library “policy.jar” is missing. Go here http://jax-ws.java.net/. Download JAX-WS RI distribution. Unzip it and copy “policy.jar” to Tomcat library folder “{$TOMCAT}/lib“. Restart Tomcat.
Problem Deploying a JAX-WS web service on Tomcat, hits following error message : java.lang.ClassNotFoundException: com/sun/xml/bind/v2/model/annotation/AnnotationReader Solution The JAX-WS dependency library “jaxb-impl.jar” is missing. Go here http://jax-ws.java.net/. Download JAX-WS RI distribution. Unzip it and copy “jaxb-impl.jar” to Tomcat library folder “{$TOMCAT}/lib“. Restart Tomcat.
Problem Deploying a JAX-WS web service on Tomcat, hits following error message : java.lang.ClassNotFoundException: com.sun.xml.ws.transport.http.servlet.WSServletContextListener Solution The JAX-WS dependency library “jaxws-rt.jar” is missing. Go here http://jax-ws.java.net/. Download JAX-WS RI distribution. Unzip it and copy “jaxws-rt.jar” to Tomcat library folder “{$TOMCAT}/lib“. Restart Tomcat. Reference WSServletContextListener JavaDoc
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 …
Problem Deploying a JAX-WS web service on Tomcat, hits following error message : java.lang.ClassNotFoundException: com/sun/xml/stream/buffer/XMLStreamBuffer Solution The JAX-WS dependency library “streambuffer.jar” is missing. Go here http://jax-ws.java.net/. Download JAX-WS RI distribution. Unzip it and copy “streambuffer.jar” to Tomcat library folder “{$TOMCAT}/lib“. Restart Tomcat.
JAX-WS is bundled with JDK 1.6, which makes Java web service development easier to develop. This tutorial shows you how to do the following tasks: Create a SOAP-based RPC style web service endpoint by using JAX-WS. Create a Java web service client manually. Create a Java web service client via wsimport tool. Create a Ruby …