# HelloWorldAsyncControl.jcx Sample

This topic inludes the source code for the HelloWorldAsyncControl.jcx Sample.

## Sample Location

This sample is located in the following directory in your WebLogic Workshop installation:

BEA_HOME/weblogic81/samples/workshop/SamplesApp/WebServices/async/

## Sample Source Code

`001 package async; 002 003 /** 004 * <p> A web service that uses a TimerControl to delay sending a response back to the client.</p> <p>The timer simulates waiting for a slow back end service to complete work for us. We use a callback to asynchronously notify the client when the simulated operation is complete.</p> 005 * @jc:location http-url="HelloWorldAsync.jws" jms-url="HelloWorldAsync.jws" 006 * @jc:wsdl file="#HelloWorldAsyncWsdl" 007 * @editor-info:link autogen-style="java" source="HelloWorldAsync.jws" autogen="true" 008 */ 009 public interface HelloWorldAsyncControl extends com.bea.control.ControlExtension, com.bea.control.ServiceControl 010 { 011 public static class StartHeader 012 implements java.io.Serializable 013 { 014 public java.lang.String conversationID; 015 public java.lang.String callbackLocation; 016 } 017 018 public static class ContinueHeader 019 implements java.io.Serializable 020 { 021 public java.lang.String conversationID; 022 } 023 024 public static class CallbackHeader 025 implements java.io.Serializable 026 { 027 public java.lang.String conversationID; 028 } 029 030 031 public interface Callback extends com.bea.control.ServiceControl.Callback 032 { 033 /** 034 * <p>HelloResult is the message we will send back to the client some time after the client initiates the operation.</p> <p>We mark the callback as finishing the conversation because once we invoke the callback the interaction between client and this service is complete. If we didn't use the @common:conversation tag here to finish the conversation, we would have to call finishConversation() on this service's context object.</p> 035 * @jc:conversation phase="finish" 036 */ 037 public void onHelloResult (java.lang.String hello); 038 039 } 040 041 /** 042 * <p>The client starts the interaction by calling HelloAsync.</p> <p>The client sends this, and some time later our service replies by calling callback.onHelloResult.</p> <p>Because we need to remember which client called us, this is a "conversation start" method. This means the system will automatically track which clients have called us, and where to send the result for each. This is known as <i>correlation</i>.</p> 043 * @jc:conversation phase="start" 044 */ 045 public void HelloAsync (); 046 047 static final long serialVersionUID = 1L; 048 } 049 050 /** @common:define name="HelloWorldAsyncWsdl" value:: 051 <?xml version="1.0" encoding="utf-8"?> 052 <definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:conv="http://www.openuri.org/2002/04/soap/conversation/" xmlns:cw="http://www.openuri.org/2002/04/wsdl/conversation/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:jms="http://www.openuri.org/2002/04/wsdl/jms/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:s0="http://workshop.bea.com/HelloWorldAsync" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" targetNamespace="http://workshop.bea.com/HelloWorldAsync"> 053 <types> 054 <s:schema elementFormDefault="qualified" targetNamespace="http://workshop.bea.com/HelloWorldAsync" xmlns:s="http://www.w3.org/2001/XMLSchema"> 055 <s:element name="onHelloResultResponse"> 056 <s:complexType> 057 <s:sequence/> 058 </s:complexType> 059 </s:element> 060 <s:element name="onHelloResult"> 061 <s:complexType> 062 <s:sequence> 063 <s:element name="hello" type="s:string" minOccurs="0"/> 064 </s:sequence> 065 </s:complexType> 066 </s:element> 067 <s:element name="HelloAsync"> 068 <s:complexType> 069 <s:sequence/> 070 </s:complexType> 071 </s:element> 072 <s:element name="HelloAsyncResponse"> 073 <s:complexType> 074 <s:sequence/> 075 </s:complexType> 076 </s:element> 077 </s:schema> 078 079 <s:schema elementFormDefault="qualified" targetNamespace="http://www.openuri.org/2002/04/soap/conversation/"> 080 <s:element name="StartHeader" type="conv:StartHeader"/> 081 <s:element name="ContinueHeader" type="conv:ContinueHeader"/> 082 <s:element name="CallbackHeader" type="conv:CallbackHeader"/> 083 <s:complexType name="StartHeader"> 084 <s:sequence> 085 <s:element minOccurs="0" maxOccurs="1" name="conversationID" type="s:string"/> 086 <s:element minOccurs="0" maxOccurs="1" name="callbackLocation" type="s:string"/> 087 </s:sequence> 088 </s:complexType> 089 <s:complexType name="ContinueHeader"> 090 <s:sequence> 091 <s:element minOccurs="1" maxOccurs="1" name="conversationID" type="s:string"/> 092 </s:sequence> 093 </s:complexType> 094 <s:complexType name="CallbackHeader"> 095 <s:sequence> 096 <s:element minOccurs="1" maxOccurs="1" name="conversationID" type="s:string"/> 097 </s:sequence> 098 </s:complexType> 099 </s:schema> 100 </types> 101 <message name="onHelloResultSoapIn"> 102 <part name="parameters" element="s0:onHelloResultResponse"/> 103 </message> 104 <message name="onHelloResultSoapOut"> 105 <part name="parameters" element="s0:onHelloResult"/> 106 </message> 107 <message name="HelloAsyncSoapIn"> 108 <part name="parameters" element="s0:HelloAsync"/> 109 </message> 110 <message name="HelloAsyncSoapOut"> 111 <part name="parameters" element="s0:HelloAsyncResponse"/> 112 </message> 113 <message name="onHelloResultHttpGetIn"/> 114 <message name="onHelloResultHttpGetOut"> 115 <part name="hello" type="s:string"/> 116 </message> 117 <message name="HelloAsyncHttpGetIn"/> 118 <message name="HelloAsyncHttpGetOut"/> 119 <message name="onHelloResultHttpPostIn"/> 120 <message name="onHelloResultHttpPostOut"> 121 <part name="hello" type="s:string"/> 122 </message> 123 <message name="HelloAsyncHttpPostIn"/> 124 <message name="HelloAsyncHttpPostOut"/> 125 <message name="StartHeader_literal"> 126 <part name="StartHeader" element="conv:StartHeader"/> 127 </message> 128 <message name="CallbackHeader_literal"> 129 <part name="CallbackHeader" element="conv:CallbackHeader"/> 130 </message> 131 <portType name="HelloWorldAsyncSoap"> 132 <operation name="onHelloResult"> 133 <documentation>&lt;p&gt;HelloResult is the message we will send back to the client some time after the client initiates the operation.&lt;/p&gt; &lt;p&gt;We mark the callback as finishing the conversation because once we invoke the callback the interaction between client and this service is complete. If we didn't use the @common:conversation tag here to finish the conversation, we would have to call finishConversation() on this service's context object.&lt;/p&gt;</documentation> 134 <output message="s0:onHelloResultSoapOut"/> 135 <input message="s0:onHelloResultSoapIn"/> 136 </operation> 137 <operation name="HelloAsync"> 138 <documentation>&lt;p&gt;The client starts the interaction by calling HelloAsync.&lt;/p&gt; &lt;p&gt;The client sends this, and some time later our service replies by calling callback.onHelloResult.&lt;/p&gt; &lt;p&gt;Because we need to remember which client called us, this is a "conversation start" method. This means the system will automatically track which clients have called us, and where to send the result for each. This is known as &lt;i&gt;correlation&lt;/i&gt;.&lt;/p&gt;</documentation> 139 <input message="s0:HelloAsyncSoapIn"/> 140 <output message="s0:HelloAsyncSoapOut"/> 141 </operation> 142 </portType> 143 <portType name="HelloWorldAsyncHttpGet"> 144 <operation name="onHelloResult"> 145 <documentation>&lt;p&gt;HelloResult is the message we will send back to the client some time after the client initiates the operation.&lt;/p&gt; &lt;p&gt;We mark the callback as finishing the conversation because once we invoke the callback the interaction between client and this service is complete. If we didn't use the @common:conversation tag here to finish the conversation, we would have to call finishConversation() on this service's context object.&lt;/p&gt;</documentation> 146 <output message="s0:onHelloResultHttpGetOut"/> 147 <input message="s0:onHelloResultHttpGetIn"/> 148 </operation> 149 <operation name="HelloAsync"> 150 <documentation>&lt;p&gt;The client starts the interaction by calling HelloAsync.&lt;/p&gt; &lt;p&gt;The client sends this, and some time later our service replies by calling callback.onHelloResult.&lt;/p&gt; &lt;p&gt;Because we need to remember which client called us, this is a "conversation start" method. This means the system will automatically track which clients have called us, and where to send the result for each. This is known as &lt;i&gt;correlation&lt;/i&gt;.&lt;/p&gt;</documentation> 151 <input message="s0:HelloAsyncHttpGetIn"/> 152 <output message="s0:HelloAsyncHttpGetOut"/> 153 </operation> 154 </portType> 155 <portType name="HelloWorldAsyncHttpPost"> 156 <operation name="onHelloResult"> 157 <documentation>&lt;p&gt;HelloResult is the message we will send back to the client some time after the client initiates the operation.&lt;/p&gt; &lt;p&gt;We mark the callback as finishing the conversation because once we invoke the callback the interaction between client and this service is complete. If we didn't use the @common:conversation tag here to finish the conversation, we would have to call finishConversation() on this service's context object.&lt;/p&gt;</documentation> 158 <output message="s0:onHelloResultHttpPostOut"/> 159 <input message="s0:onHelloResultHttpPostIn"/> 160 </operation> 161 <operation name="HelloAsync"> 162 <documentation>&lt;p&gt;The client starts the interaction by calling HelloAsync.&lt;/p&gt; &lt;p&gt;The client sends this, and some time later our service replies by calling callback.onHelloResult.&lt;/p&gt; &lt;p&gt;Because we need to remember which client called us, this is a "conversation start" method. This means the system will automatically track which clients have called us, and where to send the result for each. This is known as &lt;i&gt;correlation&lt;/i&gt;.&lt;/p&gt;</documentation> 163 <input message="s0:HelloAsyncHttpPostIn"/> 164 <output message="s0:HelloAsyncHttpPostOut"/> 165 </operation> 166 </portType> 167 <binding name="HelloWorldAsyncSoap" type="s0:HelloWorldAsyncSoap"> 168 <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/> 169 <operation name="onHelloResult"> 170 <soap:operation soapAction="http://workshop.bea.com/HelloWorldAsync/onHelloResult" style="document"/> 171 <cw:transition phase="finish"/> 172 <input> 173 <soap:body use="literal"/> 174 </input> 175 <output> 176 <soap:body use="literal"/> 177 <soap:header wsdl:required="true" message="s0:CallbackHeader_literal" part="CallbackHeader" use="literal" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"/> 178 </output> 179 </operation> 180 <operation name="HelloAsync"> 181 <soap:operation soapAction="http://workshop.bea.com/HelloWorldAsync/HelloAsync" style="document"/> 182 <cw:transition phase="start"/> 183 <input> 184 <soap:body use="literal"/> 185 <soap:header wsdl:required="true" message="s0:StartHeader_literal" part="StartHeader" use="literal" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"/> 186 </input> 187 <output> 188 <soap:body use="literal"/> 189 </output> 190 </operation> 191 </binding> 192 <binding name="HelloWorldAsyncHttpGet" type="s0:HelloWorldAsyncHttpGet"> 193 <http:binding verb="GET"/> 194 <operation name="onHelloResult"> 195 <http:operation location="/onHelloResult"/> 196 <cw:transition phase="finish"/> 197 <input> 198 <mime:mimeXml part="Body"/> 199 </input> 200 <output> 201 <http:urlEncoded/> 202 </output> 203 </operation> 204 <operation name="HelloAsync"> 205 <http:operation location="/HelloAsync"/> 206 <cw:transition phase="start"/> 207 <input> 208 <http:urlEncoded/> 209 </input> 210 <output/> 211 </operation> 212 </binding> 213 <binding name="HelloWorldAsyncHttpPost" type="s0:HelloWorldAsyncHttpPost"> 214 <http:binding verb="POST"/> 215 <operation name="onHelloResult"> 216 <http:operation location="/onHelloResult"/> 217 <cw:transition phase="finish"/> 218 <input> 219 <mime:mimeXml part="Body"/> 220 </input> 221 <output> 222 <mime:content type="application/x-www-form-urlencoded"/> 223 </output> 224 </operation> 225 <operation name="HelloAsync"> 226 <http:operation location="/HelloAsync"/> 227 <cw:transition phase="start"/> 228 <input> 229 <mime:content type="application/x-www-form-urlencoded"/> 230 </input> 231 <output/> 232 </operation> 233 </binding> 234 <service name="HelloWorldAsync"> 235 <documentation>&lt;p&gt; A web service that uses a TimerControl to delay sending a response back to the client.&lt;/p&gt; &lt;p&gt;The timer simulates waiting for a slow back end service to complete work for us. We use a callback to asynchronously notify the client when the simulated operation is complete.&lt;/p&gt;</documentation> 236 <port name="HelloWorldAsyncSoap" binding="s0:HelloWorldAsyncSoap"> 237 <soap:address location="http://localhost:7001/async/HelloWorldAsync.jws"/> 238 </port> 239 <port name="HelloWorldAsyncHttpGet" binding="s0:HelloWorldAsyncHttpGet"> 240 <http:address location="http://localhost:7001/async/HelloWorldAsync.jws"/> 241 </port> 242 <port name="HelloWorldAsyncHttpPost" binding="s0:HelloWorldAsyncHttpPost"> 243 <http:address location="http://localhost:7001/async/HelloWorldAsync.jws"/> 244 </port> 245 </service> 246 </definitions> 247 * :: 248 */`