Tag: CXF

Developing Spring based CXF WebService in JBoss AS7

Hi,

C O N G R A T U L A T I O N S …Awaited “jboss-as-7.1.0.CR1” is released recently. So here we are going to test a Simple WebService in JBoss AS7.1 CR1. In this sample we will see how to develop a Simple Apache CXF based webService with the help of Spring. Also we will see how to use a Simple Spring WebService Client to reduce the code at the client side and the utilize the beans feature provided by the Spring.

More informations about the CXF Spring Client can be found in the following link:
http://cxf.apache.org/docs/writing-a-service-with-spring.html

Highlights of Article

Point-1). In this example we are going to use “jboss-as-7.1.0.CR1” which can be downloaded from the following link: http://www.jboss.org/jbossas/downloads

Point-2). We will see how to use the cxf-servlet.xml file.

Point-3). How to use the Spring ApplicationContext and ClassPathXmlApplicationContext to initialize the jaxws based beans for Service client.

Point-4). As the client is going to use spring features to access the web service so we will need to make sure that “spring-2.5.6.jar” jar is present in the client classpath. This jar can be downloaded from the following link:
http://repo1.maven.org/maven2/org/springframework/spring/2.5.6/spring-2.5.6.jar

Developing Spring CXF WebService

Step1). Create a Directory somewhere in your filesystem like “/home/userone/CXF_Spring_Demo/” and then create “src” directory inside “/home/userone/CXF_Spring_Demo/”.

Step2). Now we will write the Web Service Endpoint Interface “Spring_CXF_Service_Intf.java” inside “/home/userone/CXF_Spring_Demo/src” as following:

package ws;
import javax.jws.WebService;

@WebService
public interface Spring_CXF_Service_Intf
  {
      public String sayHello(String name);
  }

Step4). Now we will provide the WebService Implementation class “Spring_CXF_Service.java” inside “/home/userone/CXF_Spring_Demo/src” as following:

package ws;
import javax.jws.WebService;

@WebService(endpointInterface = "ws.Spring_CXF_Service_Intf")
public class Spring_CXF_Service implements Spring_CXF_Service_Intf
  {
      public String sayHello(String name)
        {
            System.out.println("[Spring_CXF_Service] sayHello("+name+") invoked.");
            return "Hello World !!! Mr. "+name;
        }
  }

Step4). We will write the “web.xml” inside “/home/userone/CXF_Spring_Demo/src” as following (practically this file is almost empty):

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

</web-app>

Step5). We will write the “cxf-servlet.xml” inside “/home/userone/CXF_Spring_Demo/src” to define “jaxws:endpoint” and it’s implementation class details as following:

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:jaxws="http://cxf.apache.org/jaxws"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                            http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

        <!--
	<import resource="classpath:META-INF/cxf/cxf.xml" />
	<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
        -->

        <!-- In My case i am putting "cxf-servlet.xml" inside WEB-INF directory -->
	<jaxws:endpoint 
	  id="cxfSpringServiceHelloWorld" 
	  implementor="client.SpringCXFService" 
	  address="/Spring_CXF_Service" />
	  
</beans>

NOTE: We need to make sure that this “cxf-servlet.xml” file is present inside the “WEB-INF” diectory of our service.

Developing Spring CXF based Client

Step6). Now we will write the WebService Client “Test_CXF_Client.java” inside “/home/userone/CXF_Spring_Demo/src” using CXF standard code as following :

package client;
import java.util.Date;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Test_CXF_Client
  {
     public static void main(String ar[]) throws Exception
      {
        ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"client-beans.xml"});
        SpringCXFServiceIntf client = (SpringCXFServiceIntf) context.getBean("testClient");
        System.out.println("ntGot Client: "+client);         
        System.out.println("ntclient.sayHello(Middleware Magic): "+client.sayHello("Middleware Magic"));                
      }
  }

Step7). We will create the “client-beans.xml” XML file inside “/home/userone/CXF_Spring_Demo/src” directory as following. (This file name may be anything)

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:jaxws="http://cxf.apache.org/jaxws"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

    <jaxws:client id="testClient"
                  serviceClass="client.SpringCXFServiceIntf"
                  address="http://localhost:8080/Spring_CXF_Service_Demo/Spring_CXF_Service" />
</beans>

NOTE: The file name “client-beans.xml” may be anything but we need to make sure that this file is present in the client classpath.
NOTE: client-beans.xml file should be written only when you have run the wsconsume anttask to generate Client side artifacts for your WebService, Because the classes like “client.SpringCXFServiceIntf” will be generated at client side only after generating the client side artifacts.

Step8). As our weservice client is going to use the spring features to access the web service so we will need to make sure that the following JAR is present in the client classpath and place it inside “/home/userone/CXF_Spring_Demo/src” directory. This file can be downloaded from the following link:
http://repo1.maven.org/maven2/org/springframework/spring/2.5.6/spring-2.5.6.jar

Building, Deploying and Testing

Step9). As everything is done so we will write a ant build script in order to build/deploy/run and test the WebService and Basic Authentication, So create a file “build.xml” inside “/home/userone/CXF_Spring_Demo/” as following:

<project name="JBoss_Service" default="post-deploy">
<property name="jboss.home" value="/home/userone/jboss-as-7.1.0.CR1" />
<property name="jboss.module.dir" value="${jboss.home}/modules" />
<property name="basedir" value="." />
<property name="war.tmp.name" value="Spring_CXF_Service_Demo" />
<property name="war.name" value="Spring_CXF_Service_Demo.war" />
<property name="src.dir" value="src" />
<property name="client.src.dir" value="${basedir}/clientSrc" />
<property name="output.dir" value="build" />
<property name="client.dir" value="${basedir}/clientStuff" />
<property name="client.jar.name" value="Spring_CXF_Client.jar" />
 
   <path id="jboss.classpath">
     <fileset dir="${jboss.module.dir}">
        <include name="**/*.jar"/>
     </fileset>  
   </path>

   <path id="client.classpath">
     <fileset dir="${jboss.module.dir}">
        <include name="**/*.jar"/>
     </fileset>  
     <fileset dir="${src.dir}">
        <include name="**/spring-2.5.6.jar"/>
        <!-- This Jar is needed at client side and can be downloaded from the following link -->
        <!-- http://repo1.maven.org/maven2/org/springframework/spring/2.5.6/spring-2.5.6.jar    -->
     </fileset>  
     <fileset dir="${client.dir}">
        <include name="*.jar"/>
     </fileset>  
   </path>

   <taskdef name="wsprovide" classname="org.jboss.ws.tools.ant.WSProvideTask">
       <classpath refid="jboss.classpath"/>
   </taskdef>

   <taskdef name="wsconsume" classname="org.jboss.ws.tools.ant.WSConsumeTask">
       <classpath refid="jboss.classpath"/>
   </taskdef>

        <target name="init">
           <delete dir="${output.dir}" />
           <mkdir dir="${output.dir}" />
           <mkdir dir="${output.dir}/${war.tmp.name}/META-INF"/>
           <mkdir dir="${output.dir}/${war.tmp.name}/WEB-INF/classes"/>
           <delete dir="${client.dir}" />
           <mkdir dir="${client.dir}"/>
        </target>
	 
    <target name="build" depends="init">
       <javac srcdir="${src.dir}" destdir="${output.dir}/${war.tmp.name}/WEB-INF/classes"  includes="*.java" excludes="Test_CXF_Client.java" classpathref="jboss.classpath"/>
        <copy todir="${output.dir}/${war.tmp.name}/WEB-INF">
	  <fileset dir="${basedir}/src">
	      <include name="web.xml"/>
	      <include name="cxf-servlet.xml"/>
	  </fileset>
	</copy>   
       <wsprovide
        	fork="false"
        	keep="true"
        	destdir="${output.dir}"
        	resourcedestdir="${output.dir}/${war.tmp.name}/WEB-INF/wsdl"
        	sourcedestdir="${output.dir}"
        	genwsdl="true" 
        	verbose="true"
        	sei="ws.Spring_CXF_Service">
            	<classpath>
                	  <pathelement path="${output.dir}/${war.tmp.name}/WEB-INF/classes"/>
            	</classpath>
      </wsprovide>
      <jar jarfile="${output.dir}/${war.name}" basedir="${output.dir}/${war.tmp.name}" compress="true" />  
      <delete dir="${output.dir}/${war.tmp.name}" />
    </target>

        <target name="deploy" depends="build">
            <echo message="*******************  Deploying   *********************" />  
            <echo message="********** ${war.name} to ${jboss.home}/standalone/deployments **********" />  
            <copy todir="${jboss.home}/standalone/deployments/">
                <fileset dir="${output.dir}/">
                  <include name="${war.name}"/> 
                </fileset>
            </copy>
            <echo message="*******************  Deployed Successfully   *********************" />  
        </target>
  
        <target name="post-deploy" depends="deploy">
            <echo message="*******************  NOTE  *********************" />
            <echo message="***** You should be able to access your WSDL using Browser now *****" />
            <echo message="                http://localhost:8080/Spring_CXF_Service_Demo/Spring_CXF_Service?wsdl          " />
        </target>  

        <target name="client">
             <delete dir="${client.dir}" />
             <wsconsume
                      fork="true"
                      keep="true"
                      destdir="${client.dir}"
                      sourcedestdir="${client.dir}"
                      package="client"
                      wsdlLocation="http://localhost:8080/Spring_CXF_Service_Demo/Spring_CXF_Service?wsdl"
                      wsdl="http://localhost:8080/Spring_CXF_Service_Demo/Spring_CXF_Service?wsdl">
            </wsconsume>
            <jar jarfile="${client.dir}/${client.jar.name}" basedir="${client.dir}" compress="true" />  
            <zip destfile="${client.dir}/${client.jar.name}" 
                 update="true"> 
                 <fileset dir="${src.dir}"> 
                       <include name="client-beans.xml" /> 
                 </fileset> 
            </zip> 
       </target>

        <target name="run" depends="client">
            <javac srcdir="${src.dir}" destdir="${client.dir}"  includes="Test_CXF_Client.java" classpathref="client.classpath"/>
            <java classname="client.Test_CXF_Client"  >
	        <classpath>
	            <pathelement location="${client.dir}"/>
	            <path refid="client.classpath"/>
	        </classpath>
                <arg value="http://localhost:8080/Spring_CXF_Service_Demo"/>
            </java>
        </target>  

</project>

NOTE: The only change in the above file you need to do is to change the “jboss.home” directory path in the second line of the above script is to point to your own JBoss AS7 directory home directory.

Step10). Now before running your ANT script to build and deploy the above webapplication you should have the ANT as well as JAVA set in the $PATH variable of the Shell / command prompt as following:

For Unix Based OS:
export PATH=/home/userone/jdk1.6.0_21/bin:/home/userone/org.apache.ant_1.6.5/bin:$PATH

For Windows Based OS:
set PATH=C:/jdk1.6.0_21/bin;C:/org.apache.ant_1.6.5/bin;%PATH%

Step11). Run the command “ant” or “ant post-deploy” which will internally build the WebService and deploy it inside the JBoss AS7 standalone profile.

[userone@localhost CXFTimeoutClientDemo]$ ant
Buildfile: /home/userone/CXF_Spring_Demo/build.xml

init:
   [delete] Deleting directory /home/userone/CXF_Spring_Demo/build
    [mkdir] Created dir: /home/userone/CXF_Spring_Demo/build
    [mkdir] Created dir: /home/userone/CXF_Spring_Demo/build/Spring_CXF_Service_Demo/META-INF
    [mkdir] Created dir: /home/userone/CXF_Spring_Demo/build/Spring_CXF_Service_Demo/WEB-INF/classes
   [delete] Deleting directory /home/userone/CXF_Spring_Demo/clientStuff
    [mkdir] Created dir: /home/userone/CXF_Spring_Demo/clientStuff

build:
    [javac] Compiling 2 source files to /home/userone/CXF_Spring_Demo/build/Spring_CXF_Service_Demo/WEB-INF/classes
     [copy] Copying 2 files to /home/userone/CXF_Spring_Demo/build/Spring_CXF_Service_Demo/WEB-INF
[wsprovide] Generating from endpoint: ws.Spring_CXF_Service
[wsprovide] log4j:WARN No appenders could be found for logger (org.apache.cxf.common.logging.LogUtils).
[wsprovide] log4j:WARN Please initialize the log4j system properly.
[wsprovide] log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
[wsprovide] java2ws -s /home/userone/CXF_Spring_Demo/build -classdir /home/userone/CXF_Spring_Demo/build -d /home/userone/CXF_Spring_Demo/build/Spring_CXF_Service_Demo/WEB-INF/wsdl -verbose -wsdl -cp ::::::: -wrapperbean -createxsdimports ws.Spring_CXF_Service
[wsprovide] java2ws - Apache CXF 2.4.4
[wsprovide] 
      [jar] Building jar: /home/userone/CXF_Spring_Demo/build/Spring_CXF_Service_Demo.war
   [delete] Deleting directory /home/userone/CXF_Spring_Demo/build/Spring_CXF_Service_Demo

deploy:
     [echo] *******************  Deploying   *********************
     [echo] ********** Spring_CXF_Service_Demo.war to /home/userone/jboss-as-7.1.0.CR1/standalone/deployments **********
     [copy] Copying 1 file to /home/userone/jboss-as-7.1.0.CR1/standalone/deployments
     [echo] *******************  Deployed Successfully   *********************

post-deploy:
     [echo] *******************  NOTE  *********************
     [echo] ***** You should be able to access your WSDL using Browser now *****
     [echo]                 http://localhost:8080/Spring_CXF_Service_Demo/Spring_CXF_Service?wsdl          

BUILD SUCCESSFUL
Total time: 5 seconds

Step12). As soon as the service is deployed on JBoss AS7 you will see the following kind of output in the JBoss console :

12:27:16,426 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) Starting deployment of "Spring_CXF_Service_Demo.war"
12:27:16,479 INFO  [org.jboss.wsf.stack.cxf.metadata.MetadataBuilder] (MSC service thread 1-4) Add Service
 id=ws.Spring_CXF_Service
 address=http://localhost:8080/Spring_CXF_Service_Demo/Spring_CXF_Service
 implementor=ws.Spring_CXF_Service
 invoker=org.jboss.wsf.stack.cxf.JBossWSInvoker
 serviceName={http://ws/}Spring_CXF_ServiceService
 portName={http://ws/}Spring_CXF_ServicePort
 wsdlLocation=null
 mtomEnabled=false
12:27:16,479 INFO  [org.jboss.ws.common.management.DefaultEndpointRegistry] (MSC service thread 1-4) register: jboss.ws:context=Spring_CXF_Service_Demo,endpoint=ws.Spring_CXF_Service
12:27:16,491 INFO  [org.apache.cxf.service.factory.ReflectionServiceFactoryBean] (MSC service thread 1-4) Creating Service {http://ws/}Spring_CXF_ServiceService from class ws.Spring_CXF_Service_Intf
12:27:16,533 INFO  [org.apache.cxf.endpoint.ServerImpl] (MSC service thread 1-4) Setting the server's publish address to be http://localhost:8080/Spring_CXF_Service_Demo/Spring_CXF_Service
12:27:16,548 INFO  [org.jboss.wsf.stack.cxf.deployment.WSDLFilePublisher] (MSC service thread 1-4) WSDL published to: file:/home/userone/jboss-as-7.1.0.CR1/standalone/data/wsdl/Spring_CXF_Service_Demo.war/Spring_CXF_ServiceService.wsdl
12:27:16,550 INFO  [org.jboss.as.webservices] (MSC service thread 1-1) JBAS015539: Starting service jboss.ws.port-component-link
12:27:16,555 INFO  [org.jboss.as.webservices] (MSC service thread 1-1) JBAS015539: Starting service jboss.ws.endpoint."Spring_CXF_Service_Demo.war"."ws.Spring_CXF_Service"
12:27:16,571 INFO  [org.jboss.web] (MSC service thread 1-7) registering web context: /Spring_CXF_Service_Demo
12:27:16,594 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 1) JBAS018565: Replaced deployment "Spring_CXF_Service_Demo.war" with deployment "Spring_CXF_Service_Demo.war"

Step13). Now run the command “ant run” in your shell prompt to run the WebService client to access the WebService operation. “ant run” command will automatically build the client side artifacts using the “wsconsume” ant task as well and then it will run the client:

[userone@localhost CXFTimeoutClientDemo]$ ant run
Buildfile: /home/userone/CXF_Spring_Demo/build.xml

client:
   [delete] Deleting directory /home/userone/CXF_Spring_Demo/clientStuff
[wsconsume] Consuming wsdl: http://localhost:8080/Spring_CXF_Service_Demo/Spring_CXF_Service?wsdl
[wsconsume] log4j:WARN No appenders could be found for logger (org.apache.cxf.common.logging.LogUtils).
[wsconsume] log4j:WARN Please initialize the log4j system properly.
[wsconsume] log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
      [jar] Building jar: /home/userone/CXF_Spring_Demo/clientStuff/Spring_CXF_Client.jar
      [zip] Updating zip: /home/userone/CXF_Spring_Demo/clientStuff/Spring_CXF_Client.jar

run:
     [javac] Compiling 1 source file to /home/userone/CXF_Spring_Demo/clientStuff
      log4j:WARN No appenders could be found for logger (org.apache.cxf.common.logging.LogUtils).
      log4j:WARN Please initialize the log4j system properly.
      log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
      
      	Got Client: org.apache.cxf.jaxws.JaxWsClientProxy@6ed3199e
      
      	client.sayHello(Middleware Magic): Hello World !!! Mr. Middleware Magic

BUILD SUCCESSFUL
Total time: 9 seconds

.
.
Thanks
MiddlewareMagic Team


CXF Client side Tuning Parameters and disabling Chunking in JBoss AS7

Hi,

JBoss AS7 provides support for Apache CXF 2.4.4, so in this demonstration we will see how to develop a Simple example of CXF webService. In this Example we see how to apply the different CXF specific settings pragmatically on the CXF Client code like setting “ReceiveTimeout”, “ConnectionTimeout” and enabling or disabling “Chunking”.

There are two ways of putting a body into an HTTP stream:

Standard streaming” way used by most browsers is to specify a Content-Length header in the HTTP headers. This allows the receiver to know how much data is coming and when to stop reading. The problem with this approach is that the length needs to be pre-determined. The data cannot be streamed as generated as the length needs to be calculated upfront. Thus, if chunking is turned off, we need to buffer the data in a byte buffer (or temp file if too large) so that the Content-Length can be calculated.

Chunked Streaming – with this mode, the data is sent to the receiver in chunks. Each chunk is preceded by a hexidecimal chunk size. When a chunk size is 0, the receiver knows all the data has been received. This mode allows better streaming as we just need to buffer a small amount, up to 8K by default, and when the buffer fills, write out the chunk.

In general, Chunked will perform better as the streaming can take place directly. HOWEVER, there are some problems with chunking:

Many proxy servers don’t understand it, especially older proxy servers. Many proxy servers want the Content-Length up front so they can allocate a buffer to store the request before passing it onto the real server.

Some of the older WebServices stacks also have problems with Chunking. Specifically, older versions of .NET.

NOTE: If you are getting strange errors (generally not soap faults, but other HTTP type errors) like following, when trying to interact with a service, try turning off chunking to see if that helps.

Caused by: org.jboss.soa.esb.UnmarshalException: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog
 at [row,col {unknown-source}]: [1,0]
 at org.jboss.internal.soa.esb.addressing.helpers.EPRHelper.fromXMLString(EPRHelper.java:148)
 at org.jboss.internal.soa.esb.services.registry.JAXRRegistryImpl.findEPRs(JAXRRegistryImpl.java:292)
 ... 63 more
 
Caused by: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog
 at [row,col {unknown-source}]: [1,0]
 at com.ctc.wstx.sr.StreamScanner.throwUnexpectedEOF(StreamScanner.java:661)
 at com.ctc.wstx.sr.BasicStreamReader.handleEOF(BasicStreamReader.java:2134)
 at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2040)
 at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1069)
 at org.jboss.internal.soa.esb.util.stax.StreamHelper.skipToStartElement(StreamHelper.java:317)
 at org.jboss.internal.soa.esb.addressing.helpers.EPRHelper.fromXMLString(EPRHelper.java:138)

More informations about the CXF Client Parameters you can refer to the following link:
http://cxf.apache.org/docs/client-http-transport-including-ssl-support.html#ClientHTTPTransport%28includingSSLsupport%29-The%7B%7Bclient%7D%7Delement

In this example we are going to use “jboss-as-7.1.0.Beta1” which can be downloaded from the following link: http://www.jboss.org/jbossas/downloads

Developing Simple WebApp CXFWebService

Step1). Create a Directory somewhere in your filesystem like “/home/userone/CXFTimeoutClientDemo” and then create “src” directory inside “/home/userone/CXFTimeoutClientDemo”.

Step2). Now we will write the EJB3 webservice implementation class with name “Test_CXF_WS.java” inside “/home/userone/CXFTimeoutClientDemo/src” as following:

package ws;
package ws;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.annotation.Resource;
import javax.xml.ws.WebServiceContext;
import java.util.Collection;
import java.util.Date;
@WebService(name = "DemoCXFService", targetNamespace="http://test.org")
public class Test_CXF_WS
{
  @Resource
  WebServiceContext ctx;

  @WebMethod()
  public String getProperty(String propertyName)
  {
        System.out.println("nnt Method Invoked....String getProperty(String propertyName)");
        for(int i=0;i<15;i++)
          {
             System.out.println("nt getProperty(String propertyName)  PROCESSING "+"t"+new Date());
             try{  Thread.sleep(1000);  } 
             catch(InterruptedException e){ e.printStackTrace(); }
          }
        return "RETURNED: "+(Collection) ctx.getMessageContext().values();
  }
}

Step3). We will write the “web.xml” inside “/home/userone/CXFTimeoutClientDemo/src” to define the servlet and servlet-mapping for our WebService as following:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <servlet> 
    <servlet-name>Test_CXF_WS</servlet-name>  
    <servlet-class>ws.Test_CXF_WS</servlet-class>  
  </servlet>  

  <servlet-mapping> 
    <servlet-name>Test_CXF_WS</servlet-name>  
    <url-pattern>/*</url-pattern> 
  </servlet-mapping>  
</web-app>

Step4). Now we will write the WebService Client “Test_CXF_Client.java” inside “/home/userone/CXFTimeoutClientDemo/src” using CXF standard code as following :

package client;
import java.util.Date;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;

public class Test_CXF_Client
  {
     public static void main(String ar[]) throws Exception
      {
        String ENDPOINT_URL=ar[0];

        JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
        factory.getInInterceptors().add(new LoggingInInterceptor());
        factory.getOutInterceptors().add(new LoggingOutInterceptor());

        factory.setServiceClass(DemoCXFService.class);
        factory.setAddress(ENDPOINT_URL);
        DemoCXFService service = (DemoCXFService) factory.create();
 
        Client client = ClientProxy.getClient(service); 
        if (client != null) {
            HTTPConduit conduit = (HTTPConduit) client.getConduit();
            HTTPClientPolicy policy = new HTTPClientPolicy();
             
            /*
                ConnectionTimeout 
                ================== Specifies the amount of time, in milliseconds, that the client will attempt to establish 
                                   a connection before it times out. The default is 30000 (30 seconds).  
                                   0 specifies that the client will continue to attempt to open a connection indefinitely.
             */
            /*
                ReceiveTimeout
                ==================Specifies the amount of time, in milliseconds, that the client will wait for 
                                  a response before it times out. The default is 60000. 
                                  0 specifies that the client will wait indefinitely.
             */
             /*
               Chunking is by default enabled in CXF webservices so we are disabling it.
             */

             policy.setConnectionTimeout(10000);
             policy.setReceiveTimeout(5000);
             policy.setAllowChunking(false);
            conduit.setClient(policy);
        }        

        System.out.println("nt service.getProperty("something") invoked at : "+new Date());                
        System.out.println("nt service.getProperty("something") = "+service.getProperty("something"));        
      }
  }

Step5). AS we are going to deploy the WebService in Exploded format inside the JBoss AS7 container so we will need to create and deploy a File with name “${AppName}.dodeploy” means in our case the filename will be “CXFTimeoutClientDemo.war.dodeploy”. Create this EMPTY file and place it inside “/home/userone/CXFTimeoutClientDemo/src” directory. For archived deployable applications this file is not required.

Step6). As everything is done so we will write a ant build script in order to build/deploy and test the WebService and Basic Authentication, So create a file “build.xml” inside “/home/userone/CXFTimeoutClientDemo” as following:

<project name="JBoss_Service" default="deploy">
<property name="jboss.home" value="/home/userone/jboss-as-7.0.2.Final" />
<property name="jboss.module.dir" value="${jboss.home}/modules" />
<property name="java.home.dir" value="/home/userone/MyJdks/jdk1.6.0_05" />
<property name="basedir" value="." />
<property name="war.name" value="CXFTimeoutClientDemo.war" />
<property name="src.dir" value="src" />
<property name="client.src.dir" value="${basedir}/clientSrc" />
<property name="output.dir" value="build" />
<property name="client.dir" value="${basedir}/clientStuff" />
<property name="client.jar.name" value="DemoCXF_Timeout_Client.jar" />
 
   <path id="jboss.classpath">
     <fileset dir="${jboss.module.dir}">
        <include name="**/*.jar"/>
     </fileset>  
   </path>

   <path id="client.classpath">
     <fileset dir="${jboss.module.dir}">
        <include name="**/*.jar"/>
     </fileset>  
     <fileset dir="${client.dir}">
        <include name="*.jar"/>
     </fileset>  
   </path>

   <taskdef name="wsprovide" classname="org.jboss.ws.tools.ant.WSProvideTask">
       <classpath refid="jboss.classpath"/>
   </taskdef>

   <taskdef name="wsconsume" classname="org.jboss.ws.tools.ant.WSConsumeTask">
       <classpath refid="jboss.classpath"/>
   </taskdef>

        <target name="init">
           <delete dir="${output.dir}" />
           <mkdir dir="${output.dir}" />
           <mkdir dir="${output.dir}/${war.name}"/>
           <mkdir dir="${output.dir}/${war.name}/META-INF"/>
           <mkdir dir="${output.dir}/${war.name}/WEB-INF"/>
           <mkdir dir="${output.dir}/${war.name}/WEB-INF/classes"/>
           <delete dir="${client.dir}" />
           <mkdir dir="${client.dir}"/>
        </target>
	 
    <target name="build" depends="init">
       <javac srcdir="${src.dir}" destdir="${output.dir}/${war.name}/WEB-INF/classes"  includes="*.java" excludes="Test_CXF_Client.java" classpathref="jboss.classpath"/>
        <copy todir="${output.dir}/${war.name}/WEB-INF">
	  <fileset dir="${basedir}/src">
	      <include name="web.xml"/>
	  </fileset>
	</copy>   
       <wsprovide
        	fork="false"
        	keep="true"
        	destdir="${output.dir}"
        	resourcedestdir="${output.dir}/${war.name}/WEB-INF/wsdl"
        	sourcedestdir="${output.dir}"
        	genwsdl="true" 
        	verbose="true"
        	sei="ws.Test_CXF_WS">
            	<classpath>
                	  <pathelement path="${output.dir}/${war.name}/WEB-INF/classes"/>
            	</classpath>
      </wsprovide>
    </target>

        <target name="deploy" depends="build">
            <echo message="*******************  Deploying   *********************" />  
            <echo message="********** ${war.name} to ${jboss.home}/standalone/deployments **********" />  
            <copy todir="${jboss.home}/standalone/deployments/">
                <fileset dir="${output.dir}/">
                  <include name="${war.name}/**"/> 
                </fileset>
            </copy>
            <echo message="The EMPTY '${war.name}.dodeploy' tells JBoss AS7 to deploy the application"/>
            <echo message="This file is needed if we want to deploy an exploded application in JBossAS7"/>
            <copy todir="${jboss.home}/standalone/deployments/">
	        <fileset dir="${basedir}/src">
	          <include name="${war.name}.dodeploy"/>
	        </fileset>
	    </copy>   
            <echo message="*******************  Deployed Successfully   *********************" />  
        </target>
  
        <target name="post-deploy">
            <echo message="*******************  NOTE  *********************" />
            <echo message="***** You should be able to access your WSDL using Browser now *****" />
            <echo message="                http://localhost:8080/CXFTimeoutClientDemo?wsdl          " />
        </target>  

        <target name="client" depends="post-deploy">
             <delete dir="${client.dir}" />
             <wsconsume
                      fork="true"
                      keep="true"
                      destdir="${client.dir}"
                      sourcedestdir="${client.dir}"
                      package="client"
                      wsdlLocation="service.wsdl"
                      wsdl="http://localhost:8080/CXFTimeoutClientDemo?wsdl">
            </wsconsume>
            <jar jarfile="${client.dir}/${client.jar.name}" basedir="${client.dir}" compress="true" />  
       </target>

        <target name="run" depends="client">
            <javac srcdir="${src.dir}" destdir="${client.dir}"  includes="Test_CXF_Client.java" classpathref="client.classpath"/>
            <java classname="client.Test_CXF_Client"  >
	        <classpath>
	            <pathelement location="${client.dir}"/>
	            <path refid="client.classpath"/>
	        </classpath>
                <arg value="http://localhost:8080/CXFTimeoutClientDemo"/>
            </java>
        </target>  

</project>

NOTE: The only change in the above file you need to do is to change the “jboss.home” directory path in the second line of the above script is to point to your own JBoss AS7 directory home directory.

Step7). Now before running your ANT script to build and deploy the above webapplication you should have the ANT as well as JAVA set in the $PATH variable of the Shell / command prompt as following:

For Unix Based OS:
export PATH=/home/userone/jdk1.6.0_21/bin:/home/userone/org.apache.ant_1.6.5/bin:$PATH

For Windows Based OS:
set PATH=C:/jdk1.6.0_21/bin;C:/org.apache.ant_1.6.5/bin;%PATH%

Step8). Run the command “ant” or “ant post-deploy” which will internally build the WebService and deploy it inside the JBoss AS7 standalone profile.

[userone@localhost CXFTimeoutClientDemo]$ ant
Buildfile: build.xml

init:
   [delete] Deleting directory /home/userone/CXFTimeoutClientDemo/build
    [mkdir] Created dir: /home/userone/CXFTimeoutClientDemo/build
    [mkdir] Created dir: /home/userone/CXFTimeoutClientDemo/build/CXFTimeoutClientDemo.war
    [mkdir] Created dir: /home/userone/CXFTimeoutClientDemo/build/CXFTimeoutClientDemo.war/META-INF
    [mkdir] Created dir: /home/userone/CXFTimeoutClientDemo/build/CXFTimeoutClientDemo.war/WEB-INF
    [mkdir] Created dir: /home/userone/CXFTimeoutClientDemo/build/CXFTimeoutClientDemo.war/WEB-INF/classes
   [delete] Deleting directory /home/userone/CXFTimeoutClientDemo/clientStuff
    [mkdir] Created dir: /home/userone/CXFTimeoutClientDemo/clientStuff

build:
    [javac] Compiling 1 source file to /home/userone/CXFTimeoutClientDemo/build/CXFTimeoutClientDemo.war/WEB-INF/classes
     [copy] Copying 1 file to /home/userone/CXFTimeoutClientDemo/build/CXFTimeoutClientDemo.war/WEB-INF
[wsprovide] Generating from endpoint: ws.Test_CXF_WS
[wsprovide] log4j:WARN No appenders could be found for logger (org.apache.cxf.common.logging.LogUtils).
[wsprovide] log4j:WARN Please initialize the log4j system properly.
[wsprovide] log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
[wsprovide] java2ws -s /home/userone/CXFTimeoutClientDemo/build -classdir /home/userone/CXFTimeoutClientDemo/build -d /home/userone/CXFTimeoutClientDemo/build/CXFTimeoutClientDemo.war/WEB-INF/wsdl -verbose -wsdl -cp :::::::: -wrapperbean -createxsdimports ws.Test_CXF_WS
[wsprovide] java2ws - Apache CXF 2.4.4
[wsprovide] 

deploy:
     [echo] *******************  Deploying   *********************
     [echo] ********** CXFTimeoutClientDemo.war to /home/userone/jboss-as-7.1.0.Beta1/standalone/deployments **********
     [copy] Copying 4 files to /home/userone/jboss-as-7.1.0.Beta1/standalone/deployments
     [copy] Copied 6 empty directories to 1 empty directory under /home/userone/jboss-as-7.1.0.Beta1/standalone/deployments
     [echo] The EMPTY 'CXFTimeoutClientDemo.war.dodeploy' tells JBoss AS7 to deploy the application
     [echo] This file is needed if we want to deploy an exploded application in JBossAS7
     [copy] Copying 1 file to /home/userone/jboss-as-7.1.0.Beta1/standalone/deployments
     [echo] *******************  Deployed Successfully   *********************

BUILD SUCCESSFUL
Total time: 4 seconds

Step9). As soon as the service is deployed on JBoss AS7 you will see the following kind of output in the JBoss console :

02:20:41,193 INFO  [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 2) JBAS015003: Found CXFTimeoutClientDemo.war in deployment directory. To trigger deployment create a file called CXFTimeoutClientDemo.war.dodeploy
02:20:41,197 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) Starting deployment of "CXFTimeoutClientDemo.war"
02:20:41,304 INFO  [org.jboss.wsf.stack.cxf.metadata.MetadataBuilder] (MSC service thread 1-5) Add Service
 id=Test_CXF_WS
 address=http://localhost:8080/CXFTimeoutClientDemo
 implementor=ws.Test_CXF_WS
 invoker=org.jboss.wsf.stack.cxf.JBossWSInvoker
 serviceName={http://test.org}Test_CXF_WSService
 portName={http://test.org}DemoCXFServicePort
 wsdlLocation=null
 mtomEnabled=false
02:20:41,304 INFO  [org.jboss.ws.common.management.DefaultEndpointRegistry] (MSC service thread 1-5) register: jboss.ws:context=CXFTimeoutClientDemo,endpoint=Test_CXF_WS
02:20:41,312 INFO  [org.apache.cxf.service.factory.ReflectionServiceFactoryBean] (MSC service thread 1-5) Creating Service {http://test.org}Test_CXF_WSService from class ws.Test_CXF_WS
02:20:41,339 INFO  [org.apache.cxf.endpoint.ServerImpl] (MSC service thread 1-5) Setting the server's publish address to be http://localhost:8080/CXFTimeoutClientDemo
02:20:41,347 INFO  [org.jboss.wsf.stack.cxf.deployment.WSDLFilePublisher] (MSC service thread 1-5) WSDL published to: file:/home/userone/jboss-as-7.1.0.Beta1/standalone/data/wsdl/CXFTimeoutClientDemo.war/Test_CXF_WSService.wsdl
02:20:41,372 INFO  [org.jboss.as.webservices] (MSC service thread 1-5) JBAS015539: Starting service jboss.ws.endpoint."CXFTimeoutClientDemo.war".Test_CXF_WS
02:20:41,383 INFO  [org.jboss.web] (MSC service thread 1-3) registering web context: /CXFTimeoutClientDemo
02:20:41,400 INFO  [org.jboss.as.server.controller] (DeploymentScanner-threads - 1) Deployed "CXFTimeoutClientDemo.war"

Step10). Now run the command “ant run” in your shell prompt to run the WebService client to access the WebService operation. “ant run” command will automatically build the client side artifacts using the “wsconsume” ant task as well and then it will run the client:

[userone@localhost CXFTimeoutClientDemo]$ ant run
Buildfile: build.xml

post-deploy:
 *******************  NOTE  *********************
 ***** You should be able to access your WSDL using Browser now *****
                 http://localhost:8080/CXFTimeoutClientDemo?wsdl          

client:
] Deleting directory /home/userone/CXFTimeoutClientDemo/clientStuff
 Consuming wsdl: http://localhost:8080/CXFTimeoutClientDemo?wsdl
 log4j:WARN No appenders could be found for logger (org.apache.cxf.common.logging.LogUtils).
 log4j:WARN Please initialize the log4j system properly.
 log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
 Building jar: /home/userone/CXFTimeoutClientDemo/clientStuff/DemoCXF_Timeout_Client.jar

run:
 Compiling 1 source file to /home/userone/CXFTimeoutClientDemo/clientStuff
 log4j:WARN No appenders could be found for logger (org.apache.cxf.common.logging.LogUtils).
 log4j:WARN Please initialize the log4j system properly.
 log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
 
 	 service.getProperty("something") invoked at : Sun Nov 27 02:23:49 IST 2011
 javax.xml.ws.WebServiceException: Could not send Message.
 	at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:194)
 	at org.apache.tools.ant.taskdefs.Java.run(Java.java:764)
 	at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:218)
 	at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:132)
 	at org.apache.tools.ant.taskdefs.Java.execute(Java.java:105)
 	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
 	at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 	at java.lang.reflect.Method.invoke(Method.java:597)
 	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
 	at org.apache.tools.ant.Task.perform(Task.java:348)
 	at org.apache.tools.ant.Target.execute(Target.java:357)
 	at org.apache.tools.ant.Target.performTasks(Target.java:385)
 	at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
 	at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
 	at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
 	at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
 	at org.apache.tools.ant.Main.runBuild(Main.java:758)
 	at org.apache.tools.ant.Main.startAnt(Main.java:217)
 	at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
 	at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
 Caused by: javax.xml.ws.WebServiceException: Could not send Message.
 	at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:145)
 	at $Proxy36.getProperty(Unknown Source)
 	at client.Test_CXF_Client.main(Unknown Source)
 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 	at java.lang.reflect.Method.invoke(Method.java:597)
 	at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:217)
 	at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:152)
 	... 20 more
 Caused by: java.net.SocketTimeoutException: SocketTimeoutException invoking http://localhost:8080/CXFTimeoutClientDemo: Read timed out
 	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
 	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
 	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
 	at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.mapException(HTTPConduit.java:1430)
 	at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1415)
 	at org.apache.cxf.io.CacheAndWriteOutputStream.postClose(CacheAndWriteOutputStream.java:47)
 	at org.apache.cxf.io.CachedOutputStream.close(CachedOutputStream.java:194)
 	at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
 	at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:648)
 	at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
 	at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
 	at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:533)
 	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:463)
 	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:366)
 	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:319)
 	at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:88)
 	at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:134)
 	... 28 more
 Caused by: java.net.SocketTimeoutException: Read timed out
 	at java.net.SocketInputStream.socketRead0(Native Method)
 	at java.net.SocketInputStream.read(SocketInputStream.java:129)
 	at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
 	at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
 	at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
 	at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:687)
 	at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:632)
 	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1072)
 	at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:373)
 	at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1541)
 	at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1493)
 	at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1401)
 	... 40 more
 --- Nested Exception ---
 javax.xml.ws.WebServiceException: Could not send Message.
 	at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:145)
 	at $Proxy36.getProperty(Unknown Source)
 	at client.Test_CXF_Client.main(Unknown Source)
 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 	at java.lang.reflect.Method.invoke(Method.java:597)
 	at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:217)
 	at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:152)
 	at org.apache.tools.ant.taskdefs.Java.run(Java.java:764)
 	at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:218)
 	at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:132)
 	at org.apache.tools.ant.taskdefs.Java.execute(Java.java:105)
 	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
 	at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 	at java.lang.reflect.Method.invoke(Method.java:597)
 	at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
 	at org.apache.tools.ant.Task.perform(Task.java:348)
 	at org.apache.tools.ant.Target.execute(Target.java:357)
 	at org.apache.tools.ant.Target.performTasks(Target.java:385)
 	at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
 	at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
 	at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
 	at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
 	at org.apache.tools.ant.Main.runBuild(Main.java:758)
 	at org.apache.tools.ant.Main.startAnt(Main.java:217)
 	at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
 	at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
 Caused by: java.net.SocketTimeoutException: SocketTimeoutException invoking http://localhost:8080/CXFTimeoutClientDemo: Read timed out
 	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
 	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
 	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
 	at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.mapException(HTTPConduit.java:1430)
 	at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1415)
 	at org.apache.cxf.io.CacheAndWriteOutputStream.postClose(CacheAndWriteOutputStream.java:47)
 	at org.apache.cxf.io.CachedOutputStream.close(CachedOutputStream.java:194)
 	at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
 	at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:648)
 	at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
 	at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
 	at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:533)
 	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:463)
 	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:366)
 	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:319)
 	at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:88)
 	at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:134)
 	... 28 more
 Caused by: java.net.SocketTimeoutException: Read timed out
 	at java.net.SocketInputStream.socketRead0(Native Method)
 	at java.net.SocketInputStream.read(SocketInputStream.java:129)
 	at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
 	at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
 	at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
 	at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:687)
 	at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:632)
 	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1072)
 	at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:373)
 	at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1541)
 	at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1493)
 	at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1401)
 	... 40 more
 Java Result: -1

NOTE: You are seeing the above “java.net.SocketTimeoutException: Read timed out” because the client has set “RecieveTimeout” as 5-Seconds where as the Webservice for loop will process the operation in 15 Seconds.

.
.
Thanks
MiddlewareMagic Team


Basic Authentication in WebApp Based CXF WebService JBoss AS7

Hi,

JBoss AS7 provides support for Apache CXF 2.4.4, so in this demonstration we will see how to develop a Simple Non-EJB CXF webService with Basic Authentication enabled. In this Example we will using the jboss-web.xml file to map the security-domain defined inside our “standalone-full.xml” file and we will write the “web.xml” manually to define the Basic Authentication and role mapping.

If you want to see how to avoid writing the deployment descriptors like jboss-web.xml, by using JBoss Specific annotations then you can refer to the following article: http://middlewaremagic.com/jboss/?p=958 (EJB based CXF WebService with Basic Authentication in JBoss AS7)

In this example we are going to use “jboss-as-7.1.0.Beta1” which can be downloaded from the following link: http://www.jboss.org/jbossas/downloads

Configuring “security-domain” inside the “standalone-full.xml” file

Here we will first create a security-domain inside the security subsystem “/home/userone/jboss-as-7.1.0.Beta1/standalone/configuration/standard-full.xml” file as following:

        <subsystem xmlns="urn:jboss:domain:security:1.1">
            <security-domains>
                <security-domain name="other" cache-type="default">
                    <authentication>
                        <login-module code="UsersRoles" flag="required"/>
                    </authentication>
                </security-domain>
                <security-domain name="jboss-web-policy" cache-type="default">
                    <authorization>
                        <policy-module code="Delegating" flag="required"/>
                    </authorization>
                </security-domain>
                <security-domain name="jboss-ejb-policy" cache-type="default">
                    <authorization>
                        <policy-module code="Delegating" flag="required"/>
                    </authorization>
                </security-domain>

                <!--****************************************************************--> 
                <!-- Following Part is added Here for Our CXF Application security -->
                <security-domain name="cxfservice-security-domain" cache-type="default">
                    <authentication>
                        <login-module code="UsersRoles" flag="required">
                            <module-option name="usersProperties" value="cxfservice-users.properties"/>
                            <module-option name="rolesProperties" value="cxfservice-roles.properties"/>
                            <module-option name="unauthenticatedIdentity" value="nobody"/>
                        </login-module>
                    </authentication>
                </security-domain>
            </security-domains>
        </subsystem>

NOTE: the properties files “cxfservice-users.properties” and “cxfservice-roles.properties” we will later add inside our CXFBasedEJB3 Service Jar file.

Developing Simple WebApp CXFWebService

Step1). Create a Directory somewhere in your filesystem like “/home/userone/CXFTimeoutClientDemo” and then create “src” directory inside “/home/userone/CXFTimeoutClientDemo”.

Step2). Create a property file with name “cxfservice-roles.properties” inside “/home/userone/CXFTimeoutClientDemo/src” as following:

userone=TestRole

Step3). Create a property file with name “cxfservice-users.properties” inside “/home/userone/CXFTimeoutClientDemo/src” as following:

userone=passwordone

Step4).Now we will write the EJB3 webservice implementation class with name “Test_CXF_WS.java” inside “/home/userone/CXFTimeoutClientDemo/src” as following:

package ws;
import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService(name = "DemoCXFService", targetNamespace="http://test.org")
public class Test_CXF_WS
{
  @WebMethod()
  public String sayHello(String name)
  {
        System.out.println("nnt Method Invoked sayHello() ...  Hello, "+name);
        return "Hello Mr, "+name;
  }
}

Step5). We will write the “web.xml” inside “/home/userone/CXFTimeoutClientDemo/src” to define the BASIC Authentication and secured resources as following:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <servlet> 
    <servlet-name>Test_CXF_WS</servlet-name>  
    <servlet-class>ws.Test_CXF_WS</servlet-class>  
  </servlet>  

  <servlet-mapping> 
    <servlet-name>Test_CXF_WS</servlet-name>  
    <url-pattern>/*</url-pattern> 
  </servlet-mapping>  

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>MySecureResources</web-resource-name>
            <description>Some Description</description>
            <url-pattern>/*</url-pattern>
            <http-method>GET</http-method>
            <http-method>POST</http-method>
        </web-resource-collection>
        <auth-constraint>
            <role-name>TestRole</role-name>
        </auth-constraint>
    </security-constraint>
    <login-config>
        <auth-method>BASIC</auth-method>
    </login-config>
    <security-role>
        <role-name>TestRole</role-name>
    </security-role>
</web-app>

Step6). We will write the “jboss-web.xml” inside “/home/userone/CXFTimeoutClientDemo/src” to map the security-domain defined in the “standalone-full.xml” file as following:

<jboss-web>
    <security-domain>java:/jaas/cxfservice-security-domain</security-domain>
</jboss-web>

Step7). Now we will write the WebService Client “Test_CXF_Client.java” inside “/home/userone/CXFTimeoutClientDemo/src” using CXF standard code as following :

package client;
import java.util.Date;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import javax.xml.ws.BindingProvider;

public class Test_CXF_Client
  {
     public static void main(String ar[]) throws Exception
      {
        String ENDPOINT_URL=ar[0];
        String BASIC_USER="userone";
        String BASIC_PWD="passwordone";

        JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();

        factory.setServiceClass(DemoCXFService.class);
        factory.setAddress(ENDPOINT_URL);
        DemoCXFService service = (DemoCXFService) factory.create();

        BindingProvider bp = (BindingProvider)service;
        bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, BASIC_USER);
        bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, BASIC_PWD);

        System.out.println("nt service.sayHello("MiddlewareMagic") invoked at : "+new Date());                
        System.out.println("nt service.sayHello("MiddlewareMagic") = "+service.sayHello("MiddlewareMagic"));        
      }
  }

Step8). AS we are going to deploy the WebService in Exploded format inside the JBoss AS7 container so we will need to create and deploy a File with name “${AppName}.dodeploy” means in our case the filename will be “CXF_BasicAuthDemo.war.dodeploy”. Create this EMPTY file and place it inside “/home/userone/CXFTimeoutClientDemo/src” directory.

Step8). As everything is done so we will write a ant build script in order to build/deploy and test the WebService and Basic Authentication, So create a file “build.xml” inside “/home/userone/CXFTimeoutClientDemo” as following:

<project name="JBoss_Service" default="post-deploy">
<property name="jboss.home" value="/home/userone/jboss-as-7.1.0.Beta1" />
<property name="jboss.module.dir" value="${jboss.home}/modules" />
<property name="java.home.dir" value="/home/userone/MyJdks/jdk1.6.0_05" />
<property name="basedir" value="." />
<property name="war.name" value="CXF_BasicAuthDemo.war" />
<property name="src.dir" value="src" />
<property name="client.src.dir" value="${basedir}/clientSrc" />
<property name="output.dir" value="build" />
<property name="client.dir" value="${basedir}/clientStuff" />
<property name="client.jar.name" value="DemoCXF_BasicAuth_Client.jar" />
 
   <path id="jboss.classpath">
     <fileset dir="${jboss.module.dir}">
        <include name="**/*.jar"/>
     </fileset>  
   </path>

   <path id="client.classpath">
     <fileset dir="${jboss.module.dir}">
        <include name="**/*.jar"/>
     </fileset>  
     <fileset dir="${client.dir}">
        <include name="*.jar"/>
     </fileset>  
   </path>

   <taskdef name="wsprovide" classname="org.jboss.ws.tools.ant.WSProvideTask">
       <classpath refid="jboss.classpath"/>
   </taskdef>

   <taskdef name="wsconsume" classname="org.jboss.ws.tools.ant.WSConsumeTask">
       <classpath refid="jboss.classpath"/>
   </taskdef>

        <target name="init">
           <delete dir="${output.dir}" />
           <mkdir dir="${output.dir}" />
           <mkdir dir="${output.dir}/${war.name}"/>
           <mkdir dir="${output.dir}/${war.name}/META-INF"/>
           <mkdir dir="${output.dir}/${war.name}/WEB-INF"/>
           <mkdir dir="${output.dir}/${war.name}/WEB-INF/classes"/>
           <delete dir="${client.dir}" />
           <mkdir dir="${client.dir}"/>
        </target>
	 
    <target name="build" depends="init">
       <javac srcdir="${src.dir}" destdir="${output.dir}/${war.name}/WEB-INF/classes"  includes="*.java" excludes="Test_CXF_Client.java" classpathref="jboss.classpath"/>
        <copy todir="${output.dir}/${war.name}/WEB-INF">
	  <fileset dir="${basedir}/src">
	      <include name="web.xml"/>
	      <include name="jboss-web.xml"/>
	  </fileset>
	</copy>   
       <wsprovide
        	fork="false"
        	keep="true"
        	destdir="${output.dir}"
        	resourcedestdir="${output.dir}/${war.name}/WEB-INF/wsdl"
        	sourcedestdir="${output.dir}"
        	genwsdl="true" 
        	verbose="true"
        	sei="ws.Test_CXF_WS">
            	<classpath>
                	  <pathelement path="${output.dir}/${war.name}/WEB-INF/classes"/>
            	</classpath>
      </wsprovide>
        <copy todir="${output.dir}/${war.name}/WEB-INF/classes">
	  <fileset dir="${basedir}/src">
	      <include name="*.properties"/>
	  </fileset>
	</copy>  
    </target>

        <target name="deploy" depends="build">
            <echo message="*******************  Deploying   *********************" />  
            <echo message="********** ${war.name} to ${jboss.home}/standalone/deployments **********" />  
            <copy todir="${jboss.home}/standalone/deployments/">
                <fileset dir="${output.dir}/">
                  <include name="${war.name}/**"/> 
                </fileset>
            </copy>
            <echo message="The EMPTY '${war.name}.dodeploy' tells JBoss AS7 to deploy the application"/>
            <echo message="This file is needed if we want to deploy an exploded application in JBossAS7"/>
            <copy todir="${jboss.home}/standalone/deployments/">
	        <fileset dir="${basedir}/src">
	          <include name="${war.name}.dodeploy"/>
	        </fileset>
	    </copy>   
            <echo message="*******************  Deployed Successfully   *********************" />  
        </target>
  
        <target name="post-deploy" depends="deploy">
            <echo message="*******************  NOTE  *********************" />
            <echo message="***** You should be able to access your WSDL using Browser now *****" />
            <echo message="http://userone:passwordone@localhost:8080/CXF_BasicAuthDemo/Test_CXF_WSService?wsdl" />
            <echo message="            " />
            <echo message="            " />
            <echo message="RMEMBER *** Syntax: " />
            <echo message="http://BasicUsername:BasicPassword@localhost:8080/CXF_BasicAuthDemo/Test_CXF_WSService?wsdl" />
            <echo message="and then save it in your file system with following name:" />
            <echo message="${src.dir}/META-INF/wsdl/CXFBasicAuthService.wsdl "/>
            <echo message="And then run the ' ant client' To generate client artifacts" />
            <echo message="************************************************" />
        </target>


        <target name="client">
             <delete dir="${client.dir}" />
             <wsconsume
                      fork="true"
                      keep="true"
                      destdir="${client.dir}"
                      sourcedestdir="${client.dir}"
                      package="client"
                      wsdlLocation="service.wsdl"
                      wsdl="${src.dir}/META-INF/wsdl/CXFBasicAuthService.wsdl">
            </wsconsume>
            <jar jarfile="${client.dir}/${client.jar.name}" basedir="${client.dir}" compress="true" />  
       </target>

        <target name="run" depends="client">
            <javac srcdir="${src.dir}" destdir="${client.dir}"  includes="Test_CXF_Client.java" classpathref="client.classpath"/>
            <java classname="client.Test_CXF_Client"  >
	        <classpath>
	            <pathelement location="${client.dir}"/>
	            <path refid="client.classpath"/>
	        </classpath>
                <arg value="http://localhost:8080/CXF_BasicAuthDemo"/>
            </java>
        </target>  

</project>

NOTE: The only change in the above file you need to do is to change the “jboss.home” directory path in the second line of the above script is to point to your own JBoss AS7 directory home directory.

Step9). Now before running your ANT script to build and deploy the above webapplication you should have the ANT as well as JAVA set in the $PATH variable of the Shell / command prompt as following:

For Unix Based OS:
export PATH=/home/userone/jdk1.6.0_21/bin:/home/userone/org.apache.ant_1.6.5/bin:$PATH

For Windows Based OS:
set PATH=C:/jdk1.6.0_21/bin;C:/org.apache.ant_1.6.5/bin;%PATH%

Step10). Run the command “ant” or “ant post-deploy” which will internally build the WebService and deploy it inside the JBoss AS7 standalone profile.

[userone@localhost CXFTimeoutClientDemo]$ ant
Buildfile: build.xml

init:
   [delete] Deleting directory /home/userone/CXFTimeoutClientDemo/build
    [mkdir] Created dir: /home/userone/CXFTimeoutClientDemo/build
    [mkdir] Created dir: /home/userone/CXFTimeoutClientDemo/build/CXF_BasicAuthDemo.war
    [mkdir] Created dir: /home/userone/CXFTimeoutClientDemo/build/CXF_BasicAuthDemo.war/META-INF
    [mkdir] Created dir: /home/userone/CXFTimeoutClientDemo/build/CXF_BasicAuthDemo.war/WEB-INF
    [mkdir] Created dir: /home/userone/CXFTimeoutClientDemo/build/CXF_BasicAuthDemo.war/WEB-INF/classes
   [delete] Deleting directory /home/userone/CXFTimeoutClientDemo/clientStuff
    [mkdir] Created dir: /home/userone/CXFTimeoutClientDemo/clientStuff

build:
    [javac] Compiling 1 source file to /home/userone/CXFTimeoutClientDemo/build/CXF_BasicAuthDemo.war/WEB-INF/classes
     [copy] Copying 2 files to /home/userone/CXFTimeoutClientDemo/build/CXF_BasicAuthDemo.war/WEB-INF
[wsprovide] Generating from endpoint: ws.Test_CXF_WS
[wsprovide] log4j:WARN No appenders could be found for logger (org.apache.cxf.common.logging.LogUtils).
[wsprovide] log4j:WARN Please initialize the log4j system properly.
[wsprovide] log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
[wsprovide] java2ws -s /home/userone/CXFTimeoutClientDemo/build -classdir /home/userone/CXFTimeoutClientDemo/build -d /home/userone/CXFTimeoutClientDemo/build/CXF_BasicAuthDemo.war/WEB-INF/wsdl -verbose -wsdl -cp :::::::: -wrapperbean -createxsdimports ws.Test_CXF_WS
[wsprovide] java2ws - Apache CXF 2.4.4
[wsprovide] 
     [copy] Copying 2 files to /home/userone/CXFTimeoutClientDemo/build/CXF_BasicAuthDemo.war/WEB-INF/classes

deploy:
     [echo] *******************  Deploying   *********************
     [echo] ********** CXF_BasicAuthDemo.war to /home/userone/jboss-as-7.1.0.Beta1/standalone/deployments **********
     [copy] Copying 7 files to /home/userone/jboss-as-7.1.0.Beta1/standalone/deployments
     [echo] The EMPTY 'CXF_BasicAuthDemo.war.dodeploy' tells JBoss AS7 to deploy the application
     [echo] This file is needed if we want to deploy an exploded application in JBossAS7
     [copy] Copying 1 file to /home/userone/jboss-as-7.1.0.Beta1/standalone/deployments
     [echo] *******************  Deployed Successfully   *********************

post-deploy:
     [echo] *******************  NOTE  *********************
     [echo] ***** You should be able to access your WSDL using Browser now *****
     [echo] http://userone:passwordone@localhost:8080/CXF_BasicAuthDemo/Test_CXF_WSService?wsdl
     [echo]             
     [echo]             
     [echo] RMEMBER *** Syntax: 
     [echo] http://BasicUsername:BasicPassword@localhost:8080/CXF_BasicAuthDemo/Test_CXF_WSService?wsdl
     [echo] and then save it in your file system with following name:
     [echo] src/META-INF/wsdl/CXFBasicAuthService.wsdl 
     [echo] And then run the ' ant client' To generate client artifacts
     [echo] ************************************************

BUILD SUCCESSFUL
Total time: 5 seconds

Step11). As soon as the service is deployed on JBoss AS7 you will see the following kind of output in the JBoss console :

1:39:30,022 INFO  [org.jboss.as.webservices] (MSC service thread 1-4) JBAS015540: Stopping service jboss.ws.endpoint."CXF_BasicAuthDemo.war".Test_CXF_WS
01:39:30,028 INFO  [org.jboss.ws.common.management.DefaultEndpointRegistry] (MSC service thread 1-6) remove: jboss.ws:context=CXF_BasicAuthDemo,endpoint=Test_CXF_WS
01:39:30,030 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-8) Stopped deployment CXF_BasicAuthDemo.war in 10ms
01:39:30,032 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-7) Starting deployment of "CXF_BasicAuthDemo.war"
01:39:30,120 INFO  [org.jboss.wsf.stack.cxf.metadata.MetadataBuilder] (MSC service thread 1-2) Add Service
 id=Test_CXF_WS
 address=http://localhost:8080/CXF_BasicAuthDemo
 implementor=ws.Test_CXF_WS
 invoker=org.jboss.wsf.stack.cxf.JBossWSInvoker
 serviceName={http://test.org}Test_CXF_WSService
 portName={http://test.org}DemoCXFServicePort
 wsdlLocation=null
 mtomEnabled=false
01:39:30,120 INFO  [org.jboss.ws.common.management.DefaultEndpointRegistry] (MSC service thread 1-2) register: jboss.ws:context=CXF_BasicAuthDemo,endpoint=Test_CXF_WS
01:39:30,128 INFO  [org.apache.cxf.service.factory.ReflectionServiceFactoryBean] (MSC service thread 1-2) Creating Service {http://test.org}Test_CXF_WSService from class ws.Test_CXF_WS
01:39:30,154 INFO  [org.apache.cxf.endpoint.ServerImpl] (MSC service thread 1-2) Setting the server's publish address to be http://localhost:8080/CXF_BasicAuthDemo
01:39:30,162 INFO  [org.jboss.wsf.stack.cxf.deployment.WSDLFilePublisher] (MSC service thread 1-2) WSDL published to: file:/home/userone/jboss-as-7.1.0.Beta1/standalone/data/wsdl/CXF_BasicAuthDemo.war/Test_CXF_WSService.wsdl
01:39:30,169 INFO  [org.jboss.as.webservices] (MSC service thread 1-2) JBAS015539: Starting service jboss.ws.endpoint."CXF_BasicAuthDemo.war".Test_CXF_WS
01:39:30,178 INFO  [org.jboss.web] (MSC service thread 1-5) registering web context: /CXF_BasicAuthDemo
01:39:30,190 INFO  [org.jboss.as.server.controller] (DeploymentScanner-threads - 2) Replaced deployment "CXF_BasicAuthDemo.war" with deployment "CXF_BasicAuthDemo.war"

Step12). Now run the command “ant run” in your shell prompt to run the WebService client to access the WebService operation using BASIC Authentication credentials. “ant run” command will automatically build the client side artifacts using the “wsconsume” ant task as well and then it will run the client:

[userone@localhost CXFTimeoutClientDemo]$ ant run
Buildfile: build.xml

client:
   [delete] Deleting directory /home/userone/CXFTimeoutClientDemo/clientStuff
[wsconsume] Consuming wsdl: src/META-INF/wsdl/CXFBasicAuthService.wsdl
[wsconsume] log4j:WARN No appenders could be found for logger (org.apache.cxf.common.logging.LogUtils).
[wsconsume] log4j:WARN Please initialize the log4j system properly.
[wsconsume] log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
      [jar] Building jar: /home/userone/CXFTimeoutClientDemo/clientStuff/DemoCXF_BasicAuth_Client.jar

run:
    [javac] Compiling 1 source file to /home/userone/CXFTimeoutClientDemo/clientStuff
      log4j:WARN No appenders could be found for logger (org.apache.cxf.common.logging.LogUtils).
      log4j:WARN Please initialize the log4j system properly.
      log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
      
      	 service.sayHello("MiddlewareMagic") invoked at : Sun Nov 27 01:41:26 IST 2011
      
      	 service.sayHello("MiddlewareMagic") = Hello Mr, MiddlewareMagic

BUILD SUCCESSFUL
Total time: 8 seconds

NOTE: If you will pass a wrong credential to JBoss then you may see following kind of exceptions:

*************************On Server Side ***********************
1:42:05,021 ERROR [org.jboss.security.authentication.JBossCachedAuthenticationManager] (http-localhost-127.0.0.1-8080-6) Login failure: javax.security.auth.login.LoginException: java.lang.NullPointerException
	at org.jboss.security.vault.SecurityVaultUtil.isVaultFormat(SecurityVaultUtil.java:59)
	at org.jboss.security.auth.spi.UsernamePasswordLoginModule.login(UsernamePasswordLoginModule.java:250)
	at org.jboss.security.auth.spi.UsersRolesLoginModule.login(UsersRolesLoginModule.java:155)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:616)
	at javax.security.auth.login.LoginContext.invoke(LoginContext.java:784)
	at javax.security.auth.login.LoginContext.access$000(LoginContext.java:203)
	at javax.security.auth.login.LoginContext$4.run(LoginContext.java:698)
	at javax.security.auth.login.LoginContext$4.run(LoginContext.java:696)
	at java.security.AccessController.doPrivileged(Native Method)
	at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:695)
	at javax.security.auth.login.LoginContext.login(LoginContext.java:594)
	at org.jboss.security.authentication.JBossCachedAuthenticationManager.defaultLogin(JBossCachedAuthenticationManager.java:412)
	at org.jboss.security.authentication.JBossCachedAuthenticationManager.authenticate(JBossCachedAuthenticationManager.java:346)
	at org.jboss.security.authentication.JBossCachedAuthenticationManager.isValid(JBossCachedAuthenticationManager.java:155)
	at org.jboss.as.web.security.JBossWebRealm.authenticate(JBossWebRealm.java:214)

************************* On Client Side ***********************
 javax.xml.ws.WebServiceException: Could not send Message.
 	at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:194)
 	at org.apache.tools.ant.taskdefs.Java.run(Java.java:764)
 	at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:218)
 	at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:132)
 	at org.apache.tools.ant.taskdefs.Java.execute(Java.java:105)
 	at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
     .
     .
     .
 Caused by: javax.xml.ws.WebServiceException: Could not send Message.
 	at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:145)
 	at $Proxy36.sayHello(Unknown Source)
 	at client.Test_CXF_Client.main(Unknown Source)
 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     .
     .
     .
 Caused by: org.apache.cxf.transport.http.HTTPException: HTTP response '401: Unauthorized' when communicating with http://localhost:8080/CXF_BasicAuthDemo
 	at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1554)
 	at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1493)
 	at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1401)
 	at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
 	at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:648)
 	at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
 	at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
 	at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:533)
 	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:463)
 	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:366)
 	at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:319)
 	at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:88)
 	at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:134)
 	... 28 more
 --- Nested Exception ---
 javax.xml.ws.WebServiceException: Could not send Message.
 	at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:145)
 	at $Proxy36.sayHello(Unknown Source)
 	at client.Test_CXF_Client.main(Unknown Source)
 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 	at java.lang.reflect.Method.invoke(Method.java:597)

.
.
Thanks
MiddlewareMagic Team


Copyright © 2010-2012 Middleware Magic. All rights reserved. |