You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by ndeckard <nd...@gmail.com> on 2008/09/15 22:53:50 UTC
Jaxws aegis async - unable to poll with response.isDone()
Hi all,
I’m trying to call my web service asynchronously and have based it on the
jaxws_async example, but my client is unable to poll it with the
response.isDone() call because it is blocking before getting to that call.
The only differences I see between my webservice and the jaxws_async example
are:
- I chose the Java first route instead of WSDL first
- My web service uses the aegis databinding instead of JAXB
- My client is constructed from JaxWsProxyFactoryBean (so I can set the
databinding)
- I’m not returning a String
Can someone tell me why it is blocking?
public class TaskPerformerClient {
public static final QName SERVICE_NAME = new QName(
"http://www.async.aegis.jaxws.com", "TaskPerformerService");
public static void main(String[] args) throws InterruptedException,
ExecutionException {
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.getInInterceptors().add(new LoggingInInterceptor());
factory.getOutInterceptors().add(new LoggingOutInterceptor());
factory.setServiceClass(TaskPerformer.class);
factory.setAddress("http://localhost:7003/sample/taskPerformerService");
factory.getServiceFactory().setDataBinding(new AegisDatabinding());
factory.setWsdlLocation("src/main/resources/TaskPerformerService.wsdl");
factory.getServiceFactory().setServiceName(SERVICE_NAME);
TaskPerformer client = (TaskPerformer) factory.create();
// callback method
AsyncTaskHandler testAsyncHandler = new AsyncTaskHandler();
System.out.println("Invoking performTaskAsync using callback object...");
Future<?> response = client.performTaskAsync(testAsyncHandler);
for (int i = 1; !response.isDone(); i++) {
// PROBLEM: the program never gets here
Thread.sleep(1000);
System.out.println(i);
}
System.out.println();
System.out.println("Operation took " + testAsyncHandler.getTotalTime()
+ " milliseconds to complete.");
System.out.println();
// polling method
System.out.println("BEFORE Invoking performTaskAsync...");
// PROBLEM: blocks here
Response<AsyncTaskStatus> resp = client.performTaskAsync();
System.out.println("AFTER Invoking performTaskAsync...");
for (int i = 1; !resp.isDone(); i++) {
// PROBLEM: the program never gets here
Thread.sleep(1000);
System.out.println(i);
}
AsyncTaskStatus reply = resp.get();
System.out.println("Operation took "
+ (reply.getEndTime().getTime() - reply.getStartTime()
.getTime()) + " milliseconds to complete.");
System.exit(0);
}
}
@WebService
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT)
@Features(features = "org.apache.cxf.feature.LoggingFeature")
public interface TaskPerformer {
public AsyncTaskStatus performTask();
public Future<?> performTaskAsync(AsyncHandler<AsyncTaskStatus>
asyncHandler);
public AsyncResponse<AsyncTaskStatus> performTaskAsync();
}
@WebService(targetNamespace = "http://www.async.aegis.jaxws.com", portName =
"TaskPerformerPort", serviceName = "TaskPerformerService", endpointInterface
= "com.jaxws.aegis.async.TaskPerformer")
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT)
@Features(features = "org.apache.cxf.feature.LoggingFeature")
public class TaskPerformerImpl implements TaskPerformer {
public AsyncTaskStatus performTask() {
AsyncTaskStatus asynchJobStatus = new AsyncTaskStatusImpl();
asynchJobStatus.setStartTime(new Date());
// Simulated processing delay
try {
Thread.sleep(12000);
} catch (InterruptedException e) {
e.printStackTrace();
}
asynchJobStatus.setEndTime(new Date());
return asynchJobStatus;
}
public Future<?> performTaskAsync(AsyncHandler<AsyncTaskStatus>
asyncHandler) {
// following jaxws_async example: this should exist, but return null
return null;
}
public AsyncResponse<AsyncTaskStatus> performTaskAsync() {
// following jaxws_async example: this should exist, but return null
return null;
}
}
public interface AsyncTaskStatus {
public abstract Date getStartTime();
public abstract void setStartTime(Date startTime);
public abstract Date getEndTime();
public abstract void setEndTime(Date endTime);
}
public class AsyncTaskStatusImpl implements AsyncTaskStatus {
private Date startTime;
private Date endTime;
public Date getStartTime() {
return this.startTime;
}
public void setStartTime(Date startTime) {
this.startTime = startTime;
}
public Date getEndTime() {
return this.endTime;
}
public void setEndTime(Date endTime) {
this.endTime = endTime;
}
}
public class AsyncTaskHandler implements AsyncHandler<AsyncTaskStatus> {
private AsyncTaskStatus reply;
public void handleResponse(Response<AsyncTaskStatus> response) {
try {
reply = response.get();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public long getTotalTime() {
return reply.getEndTime().getTime() - reply.getStartTime().getTime();
}
}
<bindings
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
wsdlLocation="TaskPerformerService.wsdl"
xmlns="http://java.sun.com/xml/ns/jaxws">
<bindings node="wsdl:definitions">
<enableAsyncMapping>true</enableAsyncMapping>
</bindings>
</bindings>
<bean id="aegisBean"
class="org.apache.cxf.aegis.databinding.AegisDatabinding"
scope="prototype"/>
<bean id="jaxws-and-aegis-service-factory"
class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean"
scope="prototype">
<property name="dataBinding" ref="aegisBean"/>
<property name="serviceConfigurations">
<list>
<bean
class="org.apache.cxf.jaxws.support.JaxWsServiceConfiguration"/>
<bean
class="org.apache.cxf.aegis.databinding.XFireCompatibilityServiceConfiguration"/>
<bean
class="org.apache.cxf.service.factory.DefaultServiceConfiguration"/>
</list>
</property>
</bean>
<bean id="taskPerformerImpl"
class="com.jaxws.aegis.async.TaskPerformerImpl"/>
<jaxws:endpoint id="taskPerformerServiceEndpoint"
implementor="#taskPerformerImpl" address="/taskPerformerService"
wsdlLocation="TaskPerformerService.wsdl">
<jaxws:serviceFactory>
<ref bean="jaxws-and-aegis-service-factory" />
</jaxws:serviceFactory>
<jaxws:features>
<bean class="org.apache.cxf.feature.LoggingFeature" />
</jaxws:features>
</jaxws:endpoint>
--
View this message in context: http://www.nabble.com/Jaxws-aegis-async---unable-to-poll-with-response.isDone%28%29-tp19500924p19500924.html
Sent from the cxf-user mailing list archive at Nabble.com.