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

Tomcat : java.io.IOException: Keystore was tampered with, or password was incorrect

Problem Configured Tomcat’s SSL, while starting Tomcat server, it hits following exception : 14 Disember 2010 4:18:31 PM org.apache.tomcat.util.net.jsse.JSSESocketFactory getStore SEVERE: Failed to load keystore type JKS with path c:\keystore due to Keystore was tampered with, or password was incorrect java.io.IOException: Keystore was tampered with, or password was incorrect at sun.security.provider.JavaKeyStore.engineLoad(JavaKeyStore.java:771) at sun.security.provider.JavaKeyStore$JKS.engineLoad(JavaKeyStore.java:38) at java.security.KeyStore.load(KeyStore.java:1185) …

Read more

How to configure Tomcat to support SSL or https

A guide to show you how to configure Tomcat 6.0 to support SSL or https connection. 1. Generate Keystore First, uses “keytool” command to create a self-signed certificate. During the keystore creation process, you need to assign a password and fill in the certificate’s detail. $Tomcat\bin>keytool -genkey -alias mkyong -keyalg RSA -keystore c:\mkyongkeystore Enter keystore …

Read more

JSF 2.0 Tutorial

JSF 2.0 tutorial with full example, including JSF’s navigation, form tags, facelets tags, composite components, converter, validator, integrate with other frameworks like Spring, Hibernate and etc

JSF 2.0 + JDBC integration example

Here’s a guide to show you how to integrate JSF 2.0 with database via JDBC. In this example, we are using MySQL database and Tomcat web container. Directory structure of this example 1. Table Structure Create a “customer” table and insert five dummy records. Later, display it via JSF h:dataTable. SQL commands DROP TABLE IF …

Read more

javax.naming.NameNotFoundException: Name jdbc is not bound in this Context

Problem JSF 2.0 web application, a managed bean uses @Resource to inject the “jdbc/mkyongdb” datasource into a ds property. @ManagedBean(name="customer") @SessionScoped public class CustomerBean implements Serializable{ //resource injection @Resource(name="jdbc/mkyongdb") private DataSource ds; When deployed to Tomcat 6, it hits following error messages for the MySQL datasource configuration. com.sun.faces.mgbean.ManagedBeanCreationException: An error occurred performing resource injection on …

Read more

How to configure MySQL DataSource in Tomcat 6

Here’s a guide to show you how to configure MySQL datasource in Tomcat 6. 1. Get MySQL JDBC Driver Get JDBC driver here – http://www.mysql.com/products/connector/ , for example, mysql-connector-java-5.1.9.jar, and copy it to $TOMCAT\lib folder. 2. Create META-INF/context.xml Add a file META-INF/context.xml into the root of your web application folder, which defines database connection detail …

Read more

JSF 2 + Spring 3 integration example

In this tutorial, we will show you how to integrate JSF 2.0 with Spring 3 using : JSF XML faces-config.xml Spring annotations JSR-330 standard injection Tools and technologies used : JSF 2.1.13 Spring 3.1.2.RELEASE Maven 3 Eclipse 4.2 Tomcat 6 or 7 1. Directory Structure A standard Maven project for demonstration. 2. Project Dependencies Declares …

Read more

Java HttpsURLConnection example

Here’s a simple Java HTTPS client to demonstrate the use of HttpsURLConnection class to send a HTTP GET request yo get the https URL content and certificate detail. P.S You may interest at this example – automate login a website with HttpsURLConnection. HttpsClient.java package com.mkyong.client; import java.net.MalformedURLException; import java.net.URL; import java.security.cert.Certificate; import java.io.*; import javax.net.ssl.HttpsURLConnection; …

Read more

Ant Template file to build a Java Project

Here’s a Apache Ant template file , best use to start a project from scratch. File : build.xml <project name="ProjectName" default="dist" basedir="."> <description> Project Description </description> <!– set global properties for this build –> <property name="projectName" value="ProjectName"/> <property name="src" location="src"/> <property name="build" location="build"/> <property name="dist" location="dist"/> <property name="webcontent" location="WebContent"/> <target name="init"> <!– Create the time …

Read more

Deploy JAX-WS web services on Tomcat

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 …

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

java.lang.ClassNotFoundException : org.glassfish.external.amx.AMXGlassfish

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.

java.lang.ClassNotFoundException : org.glassfish.gmbal.ManagedObjectManager

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.

java.lang.ClassNotFoundException : org.jvnet.staxex.XMLStreamReaderEx

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.

java.lang.ClassNotFoundException : javax.xml.ws.soap.AddressingFeature$Responses

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.

java.lang.ClassNotFoundException : com/sun/xml/ws/policy/PolicyException

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.

java.lang.ClassNotFoundException : com/sun/xml/bind/v2/model/annotation/AnnotationReader

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.

java.lang.ClassNotFoundException: com.sun.xml.ws.transport.http.servlet.WSServletContextListener

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

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

Composite Components in JSF 2.0

Since JSF 2.0, it’s very easy to create a reusable component, known as composite components. In this tutorial, we show you how to create a simple composite components (stored as “register.xhtml“), which is an user registration form, includes name and email text fields (h:inputText) and a submit button (h:commandButton). In addition, we also show you …

Read more

java.lang.ClassNotFoundException : com/sun/xml/stream/buffer/XMLStreamBuffer

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.

Multiple Components Validator in JSF 2.0

In JSF, there is no official way to validate multiple components or fields. To solve it, you need to create a custom validator. In this tutorial, we will show you two unofficial ways to create a validator to validate multiple components – password and confirm password. Two ways : 1. Register PostValidateEvent, puts validation inside. …

Read more

JSF 2 PreRenderViewEvent example

In JSF 2.0, you can attach a javax.faces.event.PreRenderViewEvent system event to perform custom task before a view root (JSF page) is display. Let see a complete PreRenderViewEvent example below : 1. Managed Bean Create a normal bean, contains a method signature “public void method-name(ComponentSystemEvent event)“, later you will ask listener to call this method. In …

Read more

JSF 2 PostConstructApplicationEvent and PreDestroyApplicationEvent example

Since JSF 2.0, you can register javax.faces.event.PostConstructApplicationEvent and javax.faces.event.PreDestroyApplicationEvent system event to manipulate the JSF application life cycle. 1. PostConstructApplicationEvent – Perform a custom post-configuration after application has started. 2. PreDestroyApplicationEvent – Perform a custom cleanup task before application is about to be shut down. Note In JSF, you can’t depends on the standard ServletContextListeners …

Read more

4 ways to pass parameter from JSF page to backing bean

As i know,there are 4 ways to pass a parameter value from JSF page to backing bean : Method expression (JSF 2.0) f:param f:attribute f:setPropertyActionListener Let see example one by one : 1. Method expression Since JSF 2.0, you are allow to pass parameter value in the method expression like this #{bean.method(param)}. JSF page… <h:commandButton …

Read more

JSF 2 setPropertyActionListener example

In JSF, “f:setPropertyActionListener” tag is allow you to set a value directly into the property of your backing bean. For example, <h:commandButton action="#{user.outcome}" value="Submit"> <f:setPropertyActionListener target="#{user.username}" value="mkyong" /> </h:commandButton> In above JSF code snippets, if the button is clicked, it will set the “mkyong” value to the “username” property via setUsername() method. @ManagedBean(name="user") @SessionScoped public …

Read more

JSF 2 attribute example

In JSF, “f:attribute” tag allow you to pass a attribute value to a component, or a parameter to a component via action listener. For example, 1. Assign a attribute value to a component. <h:commandButton"> <f:attribute name="value" value="Click Me" /> </h:commandButton> //is equal to <h:commandButton value="Click Me" /> 2. Assign parameter to a component and get …

Read more

JSF 2 param example

In JSF, “f:param” tag allow you to pass a parameter to a component, but it’s behavior is different depends on which type of component it’s attached. For example, 1. f:param + h:outputFormat If attach a “f:param” tag to “h:outputFormat“, the parameter is specifies the placeholder. <h:outputFormat value="Hello,{0}. You are from {1}."> <f:param value="JSF User" /> …

Read more

JSF 2 actionListener example

In JSF, “Action Events” are fired by clicking on a button or link component, e.g h:commandButton or h:commandLink. actions vs action listeners Do not confuse these two tags, actions is used to perform business logic and navigation task; While action listeners are used to perform UI interface logic or action invoke observation. Common use case …

Read more

JSF 2 message and messages example

In JSF, you can output message via following two messages tags : h:message – Output a single message for a specific component. h:messages – Output all messages in current page. See following JSF 2.0 example to show the use of both “h:message” and “h:messages” tags to display the validation error message. JSF page… <?xml version="1.0" …

Read more

JSF 2 internationalization example

In JSF application, you can change your application locale programmatically like this : //this example change locale to france FacesContext.getCurrentInstance().getViewRoot().setLocale(new Locale(‘fr’); It makes JSF support for internationalization or multiple languages easily. Complete JSF internationalization example In this tutorial, we show you a JSF 2.0 web application, which display a welcome page, retrieve a welcome message …

Read more

Access a managed bean from event listener – JSF

Problem How can a JSF event listener class access another managed bean? See scenario below : JSF page… <h:selectOneMenu value="#{country.localeCode}" onchange="submit()"> <f:valueChangeListener type="com.mkyong.CountryValueListener" /> <f:selectItems value="#{country.countryInMap}" /> </h:selectOneMenu> country managed bean… package com.mkyong; import java.io.Serializable; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; @ManagedBean(name="country") @SessionScoped public class CountryBean implements Serializable{ private String localeCode; public void setLocaleCode(String localeCode) { this.localeCode …

Read more

JSF 2 valueChangeListener example

When user make changes in input components, such as h:inputText or h:selectOneMenu, the JSF “value change event” will be fired. Two ways to implement it : 1. Method binding – In input component, specified a bean’s method directly in the “valueChangeListener” attribute. JSF… <h:selectOneMenu value="#{bean.value}" onchange="submit()" valueChangeListener="#{bean.valueChangeMethod}"> <f:selectItems value="#{bean.values}" /> </h:selectOneMenu> Java… The method which …

Read more

Custom validator in JSF 2.0

In this article, we will show you how to create a custom validator in JSF 2.0 Steps Create a validator class by implements javax.faces.validator.Validator interface. Override validate() method. Assign an unique validator ID via @FacesValidator annotation. Reference custom validator class to JSF component via f:validator tag. A detail guide to create a custom validator name …

Read more