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

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.