Problems with Asynchronous calls between AXIS Java client and GSOAP C++ server

Reply

Join Date: Dec 2008
Posts: 2
Reputation: rajeesh_11 is an unknown quantity at this point 
Solved Threads: 0
rajeesh_11 rajeesh_11 is offline Offline
Newbie Poster

Problems with Asynchronous calls between AXIS Java client and GSOAP C++ server

 
0
  #1
Dec 29th, 2008
Hi,

I trying to run a Axis JAVA client with a GSOAP C++ server. Here in the below given code I am trying to make an asynchronous call from the JAVA client using "sendReceiveNonBlocking" API. On the GSOAP server side I am using the "soap_send_..." for the asynchronous behaviour.

I have a callback pointer on the JAVA client "MyAxisCallback" which will wait for asynchronous reponse from the GSOAP server. But this approach is not working. The client sends a string to server which is received successfully by the server. After that the callback pointer then keeps on waiting for a response from the server. The client calls the "ns2__hello" function on the server and the server has to send a response using the "soap_send_ns2__hello" function to the JAVA callback pointer. But the callback pointer doesn’t receive anything, it just keeps on waiting till the server times out.

The same GSOAP C++ server works fine with a GSOAP C++ client for asynchronous calls.

What could be the problem here ?? Any inputs will be appreciated…

Thanks and Regards,
Rajeesh


The Server code
  1. // This is the main project file for VC++ application project
  2. // generated using an Application Wizard.
  3.  
  4. #include <soapH.h>
  5. #include < math.h > // for sqrt()
  6. #include "ns2.nsmap"
  7. #include <stdafx.h>
  8. //#include <AsynchOp.h>
  9. //#include <unistd.h>
  10.  
  11. #define BACKLOG (100) // Max. request backlog
  12. #using <mscorlib.dll>
  13. #include <soapProxy.h>
  14. #include "cmythread.h"
  15. #include "cmythread1.h"
  16. using namespace System;
  17.  
  18. int _tmain()
  19. {
  20.  
  21.  
  22.  
  23. struct soap soap;
  24. int m, s; // master and slave sockets
  25.  
  26. soap_init2(&soap, SOAP_IO_KEEPALIVE, SOAP_IO_KEEPALIVE);
  27. soap.send_timeout = 6000; // 60 seconds
  28. soap.recv_timeout = 6000; // 60 seconds
  29. soap.accept_timeout = 3600; // server stops after 1 hour of inactivity
  30. soap.max_keep_alive = 1000; // max keep-alive sequence
  31. void *process_request(void*);
  32. struct soap *tsoap;
  33. //pthread tid;
  34. //soap_init(&soap);
  35. //m = soap_bind(&soap, "http://10.143.73.103/", 80, 100);
  36. m = soap_bind(&soap, NULL,80, 100);
  37. if (m < 0)
  38. {std::cout<<"already inside "<<std::endl;
  39. soap_print_fault(&soap, stderr);}
  40. else
  41. {
  42. fprintf(stderr, "Socket connection successful: master socket = %d\n", m);
  43. CMyThread thread;
  44. // CMyThread1 thread1;
  45.  
  46.  
  47. for (int i = 1; ; i++)
  48. {
  49. s = soap_accept(&soap);
  50. if (!soap_valid_socket(s))
  51. {
  52. if (soap.errnum)
  53. {
  54. soap_print_fault(&soap, stderr);
  55. exit(1);
  56. }
  57. fprintf(stderr, "server timed out\n");
  58. break;
  59. }
  60. fprintf(stderr, "Thread %d accepts socket %d connection from IP %d.%d.%d.%d\n",i, s, (soap.ip>>24)&0xFF, (soap.ip>>16)&0xFF, (soap.ip>>8)&0xFF, soap.ip&0xFF);
  61. /*tsoap = soap_copy(&soap);
  62. if (!tsoap)
  63. break;*/
  64.  
  65. thread.soap1= soap_copy(&soap);
  66. if (!thread.soap1)
  67. break;
  68. std::cout<< " Entering create thread "<< std::endl;
  69. bool ab=thread.CreateThread ();
  70. if(!ab)
  71. {
  72. std::cout<<"ok"<<std::endl;
  73. }
  74. //Sleep (20);
  75. // pthread create(&tid, NULL, (void*(*)(void*))process request, (void*)tsoap);
  76. }
  77. }
  78. std::cout<<"will release callback"<<std::endl;
  79. soap_done(&soap);
  80. return 0;
  81.  
  82. }
  83.  
  84. unsigned long CMyThread1::Process (void* parameter)
  85. {
  86. return 0;
  87. }
  88. unsigned long CMyThread::Process (void* parameter)
  89. {
  90.  
  91. //a mechanism for terminating thread should be implemented
  92. //not allowing the method to be run from the main thread
  93. if (::GetCurrentThreadId () == this->hMainThreadId)
  94. { std::cout<<"Error main thraed"<<std::endl;
  95. return 0;
  96. }
  97. else {
  98.  
  99. std::cout<<"start soap_serve((struct soap*)soap1)"<<std::endl;
  100. //::MessageBoxW (0, _T("I'm running in a different thread!"), _T("CMyThread"), MB_OK);
  101. soap_serve((struct soap*)soap1);
  102.  
  103. std::cout<<"end soap_serve((struct soap*)soap1)"<<std::endl;
  104. soap_destroy((struct soap*)soap1); // dealloc C++ data
  105. soap_end((struct soap*)soap1); // dealloc data and clean up
  106. return 0;
  107.  
  108. }
  109.  
  110. }
  111.  
  112. int ns2__add(struct soap *soap, int a)
  113. {
  114.  
  115. std::cout<<"inside add"<<std::endl;
  116. std::cout<<"a is"<<a<<std::endl;
  117. a = a+8;
  118. soap_send_ns2__add(soap,NULL, NULL,a);
  119.  
  120. std::cout<<"after send"<<std::endl;
  121. return SOAP_OK;
  122. }
  123.  
  124. int ns2__hello(struct soap *soap, char *s)
  125. {
  126. std::cout<<"inside hello -- "<<s<<std::endl;
  127. s = "Hello World!";
  128. if (soap_send_ns2__hello(soap,NULL, NULL,s))
  129. {
  130. std::cout<<"error -- "<<std::endl;
  131. return soap->error;
  132. }
  133. return SOAP_OK;
  134. }


The Client Code
  1. package impl;
  2.  
  3. import java.util.HashMap;
  4.  
  5. import javax.xml.stream.XMLStreamException;
  6.  
  7. import org.apache.axiom.om.OMAbstractFactory;
  8. import org.apache.axiom.om.OMElement;
  9. import org.apache.axiom.om.OMFactory;
  10. import org.apache.axiom.om.OMNamespace;
  11. import org.apache.axiom.om.impl.llom.util.AXIOMUtil;
  12. import org.apache.axis2.AxisFault;
  13. import org.apache.axis2.addressing.EndpointReference;
  14. import org.apache.axis2.client.Options;
  15. import org.apache.axis2.client.ServiceClient;
  16. import org.apache.axis2.client.async.AsyncResult;
  17. import org.apache.axis2.client.async.AxisCallback;
  18. import org.apache.axis2.client.async.Callback;
  19. import org.apache.axis2.context.MessageContext;
  20. import org.apache.xmlbeans.impl.soap.SOAPEnvelope;
  21. import org.tempuri.ns2_xsd.service_wsdl.ServiceStub;
  22.  
  23.  
  24. public class Sync
  25. {
  26. // private static String toEPR = "http://10.143.73.103:80";
  27. private static EndpointReference targetEPR = new EndpointReference("http://10.143.73.103:80");
  28.  
  29. /*static AxisCallback axisCallback = new AxisCallback()
  30.   {
  31. public void onMessage(MessageContext arg0) {
  32. // TODO Auto-generated method stub
  33. System.out.println("got message");
  34. synchronized(this){
  35. this.notify();
  36. }
  37. }
  38.  
  39. public void onFault(MessageContext arg0) {
  40. // TODO Auto-generated method stub
  41. System.out.println("Got fault");
  42. synchronized(this){
  43. this.notify();
  44. }
  45. }
  46.  
  47. public void onError(Exception arg0) {
  48. // TODO Auto-generated method stub
  49. System.out.println("on error" + arg0);
  50. synchronized(this){
  51. this.notify();
  52. }
  53. }
  54.  
  55. public void onComplete() {
  56. // TODO Auto-generated method stub
  57. System.out.println("complete");
  58. synchronized(this){
  59. this.notify();
  60. }
  61. }
  62.  
  63. };*/
  64.  
  65. public static void main(String[] args)
  66. {
  67.  
  68. // First create the payload of the message.
  69. System.out.println("in main");
  70. //OMElement payload = getPayload(); // add your payload here
  71. OMElement payload =createPayLoad();
  72.  
  73. // Create an instance of service client.
  74. ServiceClient serviceClient;
  75.  
  76. try {
  77. serviceClient = new ServiceClient();
  78.  
  79. //ServiceStub s ;
  80.  
  81. // Create an options object to pass parameters to service client.
  82. Options options = new Options();
  83.  
  84. // Set the location of the Web service.
  85. options.setTo(targetEPR);
  86. options.setAction("ns2:hello");
  87.  
  88. serviceClient.setOptions(options);
  89.  
  90. // Create a callback object.
  91. //MyCallback callback = new MyCallback();
  92. MyAxisCallback axisCallback = new MyAxisCallback();
  93. /*try {
  94. Thread.sleep(5000);
  95. } catch (InterruptedException e) {
  96. // TODO Auto-generated catch block
  97. e.printStackTrace();
  98. }*/
  99. // Do an async invocation.
  100. //serviceClient.sendReceiveNonBlocking(payload, callback);
  101. serviceClient.sendReceiveNonBlocking(payload,axisCallback);
  102.  
  103. /*try {
  104. Thread.sleep(5000);
  105. } catch (InterruptedException e) {
  106. // TODO Auto-generated catch block
  107. e.printStackTrace();
  108. }*/
  109.  
  110. while (!axisCallback.isComplete())
  111. {
  112. Thread.sleep(1000);
  113. System.out.println("Not yet completed!!");
  114. }
  115. MessageContext mCont = serviceClient.getLastOperationContext().getMessageContext("Out");
  116. System.out.println(mCont.getEnvelope().getFirstElement().getText());
  117.  
  118. System.out.println("Callback completed!!");
  119. /*while (!callback.isComplete()) {
  120.  
  121. Thread.sleep(1000);
  122.  
  123. System.out.println("axisCallback.isComplete()" + callback.isComplete());
  124.  
  125. }*/
  126.  
  127. //System.out.println("axisCallback.isComplete()" + callback.toString());
  128.  
  129. System.out.println("after non blocking call");
  130. } catch (AxisFault e) {
  131. // TODO Auto-generated catch block
  132. e.printStackTrace();
  133. } catch (Exception e) {
  134. // TODO Auto-generated catch block
  135. e.printStackTrace();
  136. }
  137.  
  138. // Continue doing other work without waiting until the response comes.
  139.  
  140. }
  141.  
  142. public static OMElement getPayload(){
  143. int a = 2;
  144.  
  145. OMFactory fac = OMAbstractFactory.getOMFactory();
  146. OMNamespace omNs = fac.createOMNamespace(
  147. "http://tempuri.org/ns2.xsd", "ns2");
  148. OMElement method = fac.createOMElement("hello", omNs);
  149. OMElement value = fac.createOMElement("value", omNs);
  150. //value.setText("Hello , my first service utilization");
  151. method.addChild(value);
  152. //value.setText(Integer.toString(a));
  153. value.setText("hello India");
  154. System.out.println("value is"+ value);
  155. System.out.println("method is"+ method);
  156. return method;
  157. //return payload;
  158. //return
  159. }
  160. public static OMElement createPayLoad() {
  161.  
  162. OMFactory fac = OMAbstractFactory.getOMFactory();
  163. OMNamespace omNs = fac.createOMNamespace(
  164. "http://tempuri.org/ns2.xsd", "ns2");
  165. OMElement method = fac.createOMElement("hello", omNs);
  166. OMElement value = fac.createOMElement("value", omNs);
  167. method.addChild(value);
  168. value.setText("hello India");
  169. return method;
  170. }
  171. }
  172.  
  173. class MyCallback extends Callback {
  174.  
  175. public void onComplete(AsyncResult result) {
  176. // Get the response SOAP envelope from the result.
  177. //SOAPEnvelope envelope = result.getResponseEnvelope();
  178.  
  179. // Process SOAP envelope.
  180. System.out.println("Inside OnComplete");
  181. }
  182.  
  183. public void onError(Exception e) {
  184. // Write here what you want to do in case of an error.
  185. System.out.println("Inside OnError");
  186. }
  187. }
  188.  
  189. class MyAxisCallback implements AxisCallback {
  190.  
  191. private boolean bComplete;
  192. public void onMessage(MessageContext arg0) {
  193. // TODO Auto-generated method stub
  194. String happy = arg0.getEnvelope().getFirstElement().getText();
  195. System.out.println("Inside onMessage" + happy);
  196. }
  197.  
  198. public void onFault(MessageContext arg0) {
  199. // TODO Auto-generated method stub
  200. String nothappy = arg0.getEnvelope().getFirstElement().getText();
  201. System.out.println("Inside onFault" + nothappy);
  202. }
  203.  
  204. public void onError(Exception arg0) {
  205. // TODO Auto-generated method stub
  206. System.out.println("Inside onError");
  207. bComplete = true;
  208. arg0.printStackTrace();
  209. }
  210.  
  211. public void onComplete() {
  212. // TODO Auto-generated method stub
  213. bComplete = true;
  214. System.out.println("Inside onComplete");
  215. }
  216.  
  217. public boolean isComplete() {
  218. return bComplete;
  219. }
  220. }
Last edited by ~s.o.s~; Dec 29th, 2008 at 10:32 am. Reason: Added code tags, learn to use them.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 2
Reputation: rajeesh_11 is an unknown quantity at this point 
Solved Threads: 0
rajeesh_11 rajeesh_11 is offline Offline
Newbie Poster

Re: Problems with Asynchronous calls between AXIS Java client and GSOAP C++ server

 
0
  #2
Dec 31st, 2008
I am still stuck up with this problem. A simple "sendReceive" call from the Axis Client is also hanging. I have attached the java client file with this reply....if someone knows something about this problem please reply soon...as I said before this GSOAP server is working fine with a GSOAP client....and the Axis Java client can send the payload(data) to GSOAP server using "sendReceive" or "sendReceiveNonBlocking" but the receiving of the data for the client is not happening.....the "sendRecieve" call hangs and the callback pointer for "sendReceiveNonBlocking" doesnt receive anything...
Attached Files
File Type: java Asynch.java (5.0 KB, 1 views)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC