Hi,

Thanks for your help. Effectively I forget to engage sandesha2 in the server.

Now I have an other problem in the method request-reply(I join the implementation in attachment):

I send the "CreateSequence", the three messages, and the "TerminateSequence". In TCPMon, the "CreateSequence" and "TerminateSequence" are accepted and the three messages are OK, but the "State" is nerver "Done".

In the client implementation, the expression (!callback3.isComplete()) never takes the value at true. The client seems to not receive the server response. Have you an idea?

Thanks,

Regards

Elodie



Deepal jayasinghe wrote:

Hi Mancinelli;
did you engage sandesha into server side  ?

Mancinelli Elodie wrote:

Hi all,

Tools use: Axis2 1.0, Sandesha2 1.0 and apache-tomcat-5.5.15
I wish to create a client-server which suports the specifications of
WSRM. The service has two functions in "One way" and in
"Response-request". For the moment, I only test the OneWay method. I
generate the server implementation with the wsdl. I Implement the
client and server. Finally, the service has deployed correctly.

When I launch the client, an error appears, it seems to take the
origine on the TomCat server(any information are present on TomCat logs):

HTTP/1.1 500 Erreur Interne de Servlet
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=B3A702F3FF667549CF4BB267BFC32420; Path=/axis2
Content-Type: text/xml;charset=UTF-8
Transfer-Encoding: chunked
Date: Mon, 26 Jun 2006 09:03:14 GMT
Connection: close

2be
<?xml version='1.0' encoding='UTF-8'?>
 <soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/";
xmlns:wsa="http://www.w3.org/2005/08/addressing";>
    <soapenv:Header>
       <wsa:To>http://www.w3.org/2005/08/addressing/anonymous</wsa:To>
       <wsa:ReplyTo>
<wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address>
       </wsa:ReplyTo>
<wsa:MessageID>urn:uuid:4D11878674B6191F4E11513125946953</wsa:MessageID> <wsa:Action>http://www.w3.org/2005/08/addressing/fault</wsa:Action>
       <wsa:RelatesTo
wsa:RelationshipType="http://www.w3.org/2005/08/addressing/reply";>urn:uuid:D7D33AC8C77F2659F411513125923103</wsa:RelatesTo>

    </soapenv:Header>
    <soapenv:Body>
       <soapenv:Fault>
          <faultcode>soapenv:Client</faultcode>b3
          <faultstring>Operation Not found EPR is
http://129.183.149.72:8080/axis2/services/PrestoSvc and WSA Action = http://schemas.xmlsoap.org/ws/2005/02/rm/CreateSequence</faultstring>7ec
          <detail>
             <Exception>org.apache.axis2.AxisFault: Operation Not
found EPR is http://129.183.149.72:8080/axis2/services/PrestoSvc and
WSA Action = http://schemas.xmlsoap.org/ws/2005/02/rm/CreateSequence at org.apache.axis2.engine.DispatchPhase.checkPostConditions(DispatchPhase.java:46) at org.apache.axis2.engine.Phase.invoke(Phase.java:396) at
org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:473)    at
org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:445)    at
org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:284) at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:136) at javax.servlet.http.HttpServlet.service(HttpServlet.java:709) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)    at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869) at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:667) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527) at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684) at java.lang.Thread.run(Thread.java:595)</Exception>
          </detail>32
       </soapenv:Fault>
    </soapenv:Body>
 </soapenv:Envelope>0

The soap message request and the address
"http://129.183.149.72:8080/axis2/services/PrestoSvc"; are good.

POST /axis2/services/PrestoSvc HTTP/1.1
User-Agent: Axis2
SOAPAction: http://schemas.xmlsoap.org/ws/2005/02/rm/CreateSequence
Host: 127.0.0.1:8070
Transfer-Encoding: chunked
Content-Type: text/xml; charset=UTF-8

2f9
<?xml version='1.0' encoding='UTF-8'?>
 <soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/";
xmlns:wsa="http://www.w3.org/2005/08/addressing";>
    <soapenv:Header>
<wsa:To>http://129.183.149.72:8080/axis2/services/PrestoSvc</wsa:To>
       <wsa:ReplyTo>
<wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address>
       </wsa:ReplyTo>
<wsa:MessageID>urn:uuid:D7D33AC8C77F2659F411513125923103</wsa:MessageID> <wsa:Action>http://schemas.xmlsoap.org/ws/2005/02/rm/CreateSequence</wsa:Action>

    </soapenv:Header>
    <soapenv:Body>
       <wsrm:CreateSequence
xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm";>
          <wsrm:AcksTo>
<wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address>
          </wsrm:AcksTo>
       </wsrm:CreateSequence>
    </soapenv:Body>
 </soapenv:Envelope>0

I join the client and server implementations, and the axis2.xml file.
Perhaps the problem becomes to the configuration. I don't understand
why Tomcat return this error.
Can someone have an idea?

Thanks for you time.

Regards
Elodie

------------------------------------------------------------------------

/**
* PrestoSvcSkeleton.java This file was auto-generated from WSDL by the Apache
* Axis2 version: 1.0 May 04, 2006 (09:21:04 IST)
*/
package fr.gouv.finances.dgme.presto;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import fr.gouv.finances.dgme.presto.SubmitResponseDocument.SubmitResponse;
import 
fr.gouv.finances.dgme.presto.SubmitResponseDocument.SubmitResponse.Factory;


/**
* PrestoSvcSkeleton java skeleton for the axisService
*/
public class PrestoSvcSkeleton {

        static String 
fileXMLName="/home/mancinee/workspace/testPresto/test_data_out.xml";
        static String nameNewFile="soapmessout.xml";


  /**
   * Auto generated method signature
   *
   * @param param0
   */
  public fr.gouv.finances.dgme.presto.SubmitResponseDocument submit (
      fr.gouv.finances.dgme.presto.SubmitDocument param0) {
      System.out.println("submit METHOD CALL");
      System.out.println("new trace");
      SubmitResponseDocument response=null;
                try {
                        response = 
SubmitResponseDocument.Factory.parse(createSoapBodyMessage(fileXMLName));
                        System.out.println("response" + response.toString());
                        deleteFile(nameNewFile);


                } catch (Exception e) {
                        System.out.println("Erreur: parser fichier xml");
                        e.printStackTrace();
                }

      System.out.println("c est terminé");
      return response;
  }

  /**
   * Auto generated method signature
   *
   * @param param2
   */
  public void submitOneWay(
      fr.gouv.finances.dgme.presto.SubmitOneWayDocument param2) {
      System.out.println("submit One Way METHOD CALL");

  }


//  Version fichier texte
  public static File createSoapBodyMessage (String nameFile){
      PrintWriter newFile = null;
      try
      {
        //Ajout de l'entete
        newFile =  new PrintWriter(new BufferedWriter(new 
FileWriter(nameNewFile)));
        newFile.println("<m:submitResponse 
xmlns:m='http://dgme.finances.gouv.fr/presto'>");
          //Ajout du contenu du body
          BufferedReader br = new BufferedReader(
                  new InputStreamReader(
                        new FileInputStream(nameFile),"UTF-8"));
            String ligne;
            while((ligne = br.readLine())!=null){
                  newFile.println(ligne);
            }
//            Ajout de la fermeture des balises
            newFile.println("</m:submitResponse>");
            newFile.close();
      }
      catch (FileNotFoundException e)
      {
        System.out.println("Le fichier test_data_out.xml n'a pas été trouvé");
        e.printStackTrace();
      } catch (IOException e) {
        System.out.println("Erreur de lecture-ecriture dans un fichier");
                        e.printStackTrace();
                }
      File xmlFile = new File(nameNewFile);
      return xmlFile;
  }


  public static void deleteFile(String nameFile){
         File file = new File(nameFile);
      Boolean resultat = file.delete();
      System.out.println("The delete of file " + nameFile + " is " + resultat);
  }

}


------------------------------------------------------------------------

<axisconfig name="AxisJava2.0">
  <!-- ================================================= -->
  <!-- Parameters -->
  <!-- ================================================= -->
  <parameter name="hotdeployment" locked="false">true</parameter>
  <parameter name="hotupdate" locked="false">false</parameter>
  <parameter name="enableMTOM" locked="false">false</parameter>
  <!--During a fault, stacktrace can be sent with the fault message. The following 
flag will control -->
  <!--that behaviour.-->
  <parameter name="sendStacktraceDetailsWithFaults" 
locked="false">true</parameter>
  <!--If there aren't any information available to find out the fault reason, we 
set the message of the expcetion-->
  <!--as the faultreason/Reason. But when a fault is thrown from a service or some 
where, it will be -->
  <!--wrapped by different levels. Due to this the initial exception message can 
be lost. If this flag-->
  <!--is set then, Axis2 tries to get the first exception and set its message as 
the faultreason/Reason.-->
  <parameter name="DrillDownToRootCauseForFaultReason" 
locked="false">false</parameter>
  <parameter name="userName" locked="false">admin</parameter>
  <parameter name="password" locked="false">axis2</parameter>
  <!-- If you have a frontend host which exposes this webservice using a different 
public URL  -->
  <!-- use this parameter to override autodetected url -->
  <!--<parameter name="httpFrontendHostUrl" 
locked="false">https://someotherhost/context</parameter>-->
  <!--    The way of adding listener to the system-->
  <!--    <listener class="org.apache.axis2.ObserverIMPL">-->
  <!--        <parameter name="RSS_URL" 
locked="false">http://127.0.0.1/rss</parameter>-->
  <!--    </listener>-->
  <!-- ================================================= -->
  <!-- Message Receivers -->
  <!-- ================================================= -->
  <!--This is the Deafult Message Receiver for the system , if you want to have 
MessageReceivers for -->
  <!--all the other MEP implement it and add the correct entry to here , so that 
you can refer from-->
  <!--any operation -->
  <!--Note : You can ovride this for particular service by adding the same element 
with your requirement-->
  <messageReceivers>
      <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only";
                       
class="org.apache.axis2.receivers.RawXMLINOnlyMessageReceiver"/>
      <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out";
                       
class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
  </messageReceivers>
  <!-- ================================================= -->
  <!-- Transport Ins -->
  <!-- ================================================= -->
  <transportReceiver name="http"
                     class="org.apache.axis2.transport.http.SimpleHTTPServer">
      <parameter name="port" locked="false">6060</parameter>
      <!--If you want to give your own host address for EPR generation-->
      <!--uncommet following paramter , and set as you required.-->
      <!--<parameter name="hostname" 
locked="false">http://myApp.com/ws</parameter>-->
  </transportReceiver>
  <!--Uncomment if you want to have SMTP transport support-->
  <!--<transportReceiver name="mail" 
class="org.apache.axis2.transport.mail.SimpleMailListener">-->
  <!--<parameter name="transport.mail.pop3.host" 
locked="false">127.0.0.1</parameter>-->
  <!--<parameter name="transport.mail.pop3.user" 
locked="false">axis2</parameter>-->
  <!--<parameter name="transport.mail.pop3.password" 
locked="false">axis2</parameter>-->
  <!--<parameter name="transport.mail.pop3.port" 
locked="false">110</parameter>-->
  <!--<parameter name="transport.mail.replyToAddress" locked="false">[EMAIL 
PROTECTED]</parameter>-->
  <!--</transportReceiver>-->
  <transportReceiver name="tcp"
                     class="org.apache.axis2.transport.tcp.TCPServer">
      <parameter name="port" locked="false">6060</parameter>
      <!--If you want to give your own host address for EPR generation-->
      <!--uncommet following paramter , and set as you required.-->
      <!--<parameter name="hostname" 
locked="false">tcp://myApp.com/ws</parameter>-->
  </transportReceiver>
  <!--Uncomment this if you want JMS transport support-->
  <!--<transportReceiver name="jms" 
class="org.apache.axis2.transport.jms.SimpleJMSListener">-->
  <!--<parameter name="transport.jms.Destination" 
locked="false">dynamicQueues/FOO</parameter>-->
  <!--<parameter name="java.naming.factory.initial" locked="false">-->
  <!--org.activemq.jndi.ActiveMQInitialContextFactory</parameter>-->
  <!--<parameter name="java.naming.provider.url" 
locked="false">tcp://localhost:61616</parameter>-->
  <!--</transportReceiver>-->
  <!-- ================================================= -->
  <!-- Transport Outs -->
  <!-- ================================================= -->
  <transportSender name="tcp"
                   class="org.apache.axis2.transport.tcp.TCPTransportSender"/>
  <transportSender name="local"
                   
class="org.apache.axis2.transport.local.LocalTransportSender"/>
  <transportSender name="jms"
                   class="org.apache.axis2.transport.jms.JMSSender"/>
  <transportSender name="http"
                   
class="org.apache.axis2.transport.http.CommonsHTTPTransportSender">
      <parameter name="PROTOCOL" locked="false">HTTP/1.0</parameter>
      <parameter name="Transfer-Encoding" locked="false">chunked</parameter>
  </transportSender>
  <transportSender name="https"
                   
class="org.apache.axis2.transport.http.CommonsHTTPTransportSender">
      <parameter name="PROTOCOL" locked="false">HTTP/1.0</parameter>
      <parameter name="Transfer-Encoding" locked="false">chunked</parameter>
  </transportSender>
  <!-- Uncomment this one with the appropriate papameters to enable the SMTP 
transport Receiver
 <transportSender name="mailto" 
class="org.apache.axis2.transport.mail.MailTransportSender">
     <parameter name="transport.mail.smtp.host" 
locked="false">127.0.0.1</parameter>
     <parameter name="transport.mail.smtp.user" locked="false">axis2</parameter>
     <parameter name="transport.mail.smtp.password" 
locked="false">axis2</parameter>
     <parameter name="transport.mail.smtp.port" locked="false">25</parameter>
 </transportSender>
 -->
  <!-- ================================================= -->
  <!-- Global Modules  -->
  <!-- ================================================= -->
  <!-- Comment this to disable Addressing -->
  <module ref="addressing"/>
  <!--Configuring module , providing parameters for modules whether they refer or 
not-->
  <!--<moduleConfig name="addressing">-->
  <!--<parameter name="addressingPara" locked="false">N/A</parameter>-->
  <!--</moduleConfig>-->
  <!-- ================================================= -->
  <!-- Phases  -->
  <!-- ================================================= -->
  <!-- OTHER PARTS OF THE CONFIGURATOIN-->
  <phaseOrder type="inflow">
       <phase name="Transport">
          <!-- TRANSPORT PHASE HANDLERS-->
            <handler name="RequestURIBasedDispatcher"
                   class="org.apache.axis2.engine.RequestURIBasedDispatcher">
              <order phase="Dispatch"/>
          </handler>
          <handler name="SOAPActionBasedDispatcher"
                   class="org.apache.axis2.engine.SOAPActionBasedDispatcher">
              <order phase="Dispatch"/>
          </handler>
      </phase>
      <phase name="Security"/>
      <phase name="PreDispatch"/>
      <phase name="Dispatch" class="org.apache.axis2.engine.DispatchPhase">
          <!-- DISPATCH PHASE HANDLERS-->
            <handler name="AddressingBasedDispatcher"
                   class="org.apache.axis2.engine.AddressingBasedDispatcher">
              <order phase="Dispatch"/>
          </handler>
          <handler name="SOAPMessageBodyBasedDispatcher"
                   
class="org.apache.axis2.engine.SOAPMessageBodyBasedDispatcher">
              <order phase="Dispatch"/>
          </handler>
          <handler name="InstanceDispatcher"
                   class="org.apache.axis2.engine.InstanceDispatcher">
              <order phase="PostDispatch"/>
          </handler>
      </phase>
      <phase name="OperationInPhase"/>
      <phase name="RMPhase"/>
  </phaseOrder>
  <phaseOrder type="outflow">
      <phase name="RMPhase"/>
      <phase name="OperationOutPhase"/>
      <phase name="PolicyDetermination"/>
      <phase name="MessageOut"/>
  </phaseOrder>
  <phaseOrder type="INfaultflow">
      <phase name="PreDispatch"/>
      <phase name="Dispatch" class="org.apache.axis2.engine.DispatchPhase">
          <!-- DISPATCH PHASE HANDLERS-->
            <handler name="RequestURIBasedDispatcher"
                   class="org.apache.axis2.engine.RequestURIBasedDispatcher">
              <order phase="Dispatch"/>
          </handler>
          <handler name="SOAPActionBasedDispatcher"
                   class="org.apache.axis2.engine.SOAPActionBasedDispatcher">
              <order phase="Dispatch"/>
          </handler>
          <handler name="AddressingBasedDispatcher"
                   class="org.apache.axis2.engine.AddressingBasedDispatcher">
              <order phase="Dispatch"/>
          </handler>
          <handler name="SOAPMessageBodyBasedDispatcher"
                   
class="org.apache.axis2.engine.SOAPMessageBodyBasedDispatcher">
              <order phase="Dispatch"/>
          </handler>
          <handler name="InstanceDispatcher"
                   class="org.apache.axis2.engine.InstanceDispatcher">
              <order phase="PostDispatch"/>
          </handler>
      </phase>
      <phase name="OperationInFaultPhase"/>
      <phase name="RMPhase"/>
  </phaseOrder>
  <phaseOrder type="Outfaultflow">
      <!--      user can add his own phases to this area  -->
      <phase name="RMPhase"/>
      <phase name="OperationOutFaultPhase"/>
      <phase name="PolicyDetermination"/>
      <phase name="MessageOut"/>
  </phaseOrder>
</axisconfig>

------------------------------------------------------------------------

package fr.gouv.finances.dgme.presto;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLOutputFactory;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.soap.SOAPBody;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.client.async.AsyncResult;
import org.apache.axis2.client.async.Callback;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.context.MessageContextConstants;
import org.apache.sandesha2.client.SandeshaClientConstants;


public class PrestoWSRMtest extends junit.framework.TestCase {

        static String fileXMLName="test_data_in.xml";
        private static EndpointReference targetEPR = new 
EndpointReference("http://129.183.149.72:8080/axis2/services/PrestoSvc";);
        private static String targetEPRTcpmon = 
"http://localhost:8070/axis2/services/PrestoSvc";;
        static String namespace="http://dgme.finances.gouv.fr/presto";;
        private static String CLIENT_REPO_PATH = 
"/home/mancinee/workspace/testPresto/test/fr/gouv/finances/dgme/presto/Client_Repo";
        private static String axis2_xml = CLIENT_REPO_PATH + File.separator 
+"client_axis2.xml";

         public static void testSubmitOneWayWSRM() {
                 try{
                         String nameMethod="submitOneWay";
                        ConfigurationContext configContext = 
ConfigurationContextFactory.createConfigurationContextFromFileSystem(CLIENT_REPO_PATH,axis2_xml);
                        ServiceClient sender = new ServiceClient 
(configContext,null);
                        Options options=initOptions(nameMethod);
                        sender.setOptions(options);

                        System.out.println("Envoi");

                        sender.fireAndForget(getOMBlock("ping1",nameMethod));
                        sender.fireAndForget(getOMBlock("ping2",nameMethod));

                        options.setProperty(SandeshaClientConstants.LAST_MESSAGE, 
"true");
                        sender.fireAndForget(getOMBlock("ping3",nameMethod));

                        Thread.sleep(10000);
                 System.out.println("NO RETURN FOR WEBSERVICE");
                 } catch (Exception e) {
                 assertTrue("false", false);
             }
        }


         private static OMElement getOMBlock(String sequenceKey,String 
nameMethod) {

                 OMFactory fac = OMAbstractFactory.getOMFactory();
                OMNamespace omNs = fac.createOMNamespace(namespace, "m");
                OMElement payload = fac.createOMElement(nameMethod, omNs);
                OMElement bodymess = fac.createOMElement("bodymessage", omNs);

                // Définition du contenu du body message
                String bodymessvalue=createSoapMessageString(fileXMLName, 
nameMethod);
                payload.addChild(fac.createOMText(bodymess, bodymessvalue));

                // Ajout d un numero de sequence
                OMElement sequenceElem = fac.createOMElement("Sequence",omNs);
                sequenceElem.setText(sequenceKey);
                payload.addChild(sequenceElem);

                System.out.println("callAXIOM, doc sent : "+payload);

                return payload;

            }

            static class TestCallback extends Callback {

                String name = null;
                public TestCallback (String name) {
                    this.name = name;
                }

                public void onComplete(AsyncResult result) {
                    SOAPBody body = result.getResponseEnvelope().getBody();

                    OMElement echoStringResponseElem = body.getFirstChildWithName(new 
QName (namespace,"submit"));
                    OMElement echoStringReturnElem = 
echoStringResponseElem.getFirstChildWithName(new QName (namespace,"Sequence"));

                    String resultStr = echoStringReturnElem.getText();
                    System.out.println("Callback '" + name +  "' got result:" + 
resultStr);

                    try {
                        // Affichage du contenu du fichier xml
                        StringWriter writer = new StringWriter();
                                        
echoStringResponseElem.serialize(XMLOutputFactory.newInstance().createXMLStreamWriter(writer));
                                        writer.flush();
                                        System.out.println(writer.toString());
                    } catch (Exception e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                }
                }

                public void onError (Exception e) {
                    System.out.println("Error reported for test call back");
                    e.printStackTrace();
                }
            }


         public static Options initOptions(String nameMethod){

        Options options = new Options();
                options.setTo(targetEPR);
                options.setAction(nameMethod);
                options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
                options.setUseSeparateListener(false);
                //Ajout pour le WSRM
                
options.setProperty(MessageContextConstants.TRANSPORT_URL,targetEPRTcpmon);

           return options;
   }



   public static String createSoapMessageString (String nameFile, String 
valueMarker){

       String out="\n";
       BufferedReader br;
                                try {
                                        br = new BufferedReader(
                                                new InputStreamReader(
                                                      new 
FileInputStream(nameFile),"UTF-8"));

                          String ligne;
                          while((ligne = br.readLine())!=null){
                                  out +=ligne + "\n";
                          }

                                } catch (UnsupportedEncodingException e) {
                                        System.out.println("Erreur d'encodage du 
fichier");
                                        e.printStackTrace();
                                } catch (FileNotFoundException e) {
                                        System.out.println("Erreur: le fichier n'a 
pas été trouvé");
                                        e.printStackTrace();
                                } catch (IOException e) {
                                        System.out.println("Erreur de lecture dans 
le fichier");
                                        e.printStackTrace();
                                }
       return out;
   }

}



------------------------------------------------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




package fr.gouv.finances.dgme.presto;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLOutputFactory;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.soap.SOAPBody;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.client.async.AsyncResult;
import org.apache.axis2.client.async.Callback;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.context.MessageContextConstants;
import org.apache.sandesha2.client.SandeshaClientConstants;


public class PrestoWSRMtest extends junit.framework.TestCase {

	static String fileXMLName="test_data_in.xml";
//	private static EndpointReference targetEPR = new EndpointReference("http://129.183.149.72:8080/axis2/services/PrestoSvc";);
	private static EndpointReference targetEPR = new EndpointReference("http://localhost:8080/axis2/services/PrestoSvc";);
	private static String targetEPRTcpmon = "http://localhost:8070/axis2/services/PrestoSvc";;
	static String namespace="http://dgme.finances.gouv.fr/presto";;
	private static String CLIENT_REPO_PATH = "/home/mancinee/workspace/testPresto/test/fr/gouv/finances/dgme/presto/Client_Repo";
	private static String axis2_xml = CLIENT_REPO_PATH + File.separator +"client_axis2.xml";
	/**
     * Appelle du service submitRequestReponse avec un attachement
     * Test
     */
	 public static void testSubmitRequestResponseWSRM(){
		 try {
			String nameMethod="submit";
	        ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(CLIENT_REPO_PATH,axis2_xml);
	        ServiceClient sender = new ServiceClient (configContext,null);
	        Options options=initOptions(nameMethod);
	       	sender.setOptions(options);

	       	System.out.println("Envoi");
	        Callback callback1 = new TestCallback ("Callback 1");
	        sender.sendReceiveNonBlocking (getOMBlock("sequence1",nameMethod),callback1);


	        Callback callback2 = new TestCallback ("Callback 2");
	        sender.sendReceiveNonBlocking(getOMBlock("sequence2",nameMethod),callback2);

	        options.setProperty(SandeshaClientConstants.LAST_MESSAGE, "true");
	        Callback callback3 = new TestCallback ("Callback 3");
	        sender.sendReceiveNonBlocking(getOMBlock("sequence3",nameMethod),callback3);

	        while (!callback1.isComplete()) {
	        	System.out.println("boucle");
	            Thread.sleep(1000);
	        }
	        System.out.println("Fin du programme");
	        Thread.sleep(4000);

		 } catch (Exception e) {
	            assertTrue("false", false);
	     }
     }

	 public static void testSubmitOneWayWSRM() {
		 try{
			 String nameMethod="submitOneWay";
		        ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(CLIENT_REPO_PATH,axis2_xml);
		        ServiceClient sender = new ServiceClient (configContext,null);
		        Options options=initOptions(nameMethod);
		       	sender.setOptions(options);

		       	System.out.println("Envoi");

		       	sender.fireAndForget(getOMBlock("ping1",nameMethod));
		       	sender.fireAndForget(getOMBlock("ping2",nameMethod));

		       	options.setProperty(SandeshaClientConstants.LAST_MESSAGE, "true");
		        sender.fireAndForget(getOMBlock("ping3",nameMethod));

		        Thread.sleep(10000);
	         System.out.println("NO RETURN FOR WEBSERVICE");
	         sender.finalizeInvoke();
		 } catch (Exception e) {
	         assertTrue("false", false);
	     }
	}


	 private static OMElement getOMBlock(String sequenceKey,String nameMethod) {

		 OMFactory fac = OMAbstractFactory.getOMFactory();
	       	OMNamespace omNs = fac.createOMNamespace(namespace, "m");
	       	OMElement payload = fac.createOMElement(nameMethod, omNs);
	       	OMElement bodymess = fac.createOMElement("bodymessage", omNs);

	       	// Définition du contenu du body message
	       	String bodymessvalue=createSoapMessageString(fileXMLName, nameMethod);
	       	payload.addChild(fac.createOMText(bodymess, bodymessvalue));

	       	// Ajout d un numero de sequence
	       	OMElement sequenceElem = fac.createOMElement("Sequence",omNs);
	       	sequenceElem.setText(sequenceKey);
	       	payload.addChild(sequenceElem);

	       	System.out.println("callAXIOM, doc sent : "+payload);

	        return payload;

	    }

	    static class TestCallback extends Callback {

	        String name = null;
	        public TestCallback (String name) {
	            this.name = name;
	        }

	        public void onComplete(AsyncResult result) {
	            SOAPBody body = result.getResponseEnvelope().getBody();

	            OMElement echoStringResponseElem = body.getFirstChildWithName(new QName (namespace,"submit"));
	            OMElement echoStringReturnElem = echoStringResponseElem.getFirstChildWithName(new QName (namespace,"Sequence"));

	            String resultStr = echoStringReturnElem.getText();
	            System.out.println("Callback '" + name +  "' got result:" + resultStr);

//	            try {
//	            	// Affichage du contenu du fichier xml
//	            	StringWriter writer = new StringWriter();
//					echoStringResponseElem.serialize(XMLOutputFactory.newInstance().createXMLStreamWriter(writer));
//					writer.flush();
//					System.out.println(writer.toString());
//	            } catch (Exception e) {
//					// TODO Auto-generated catch block
//					e.printStackTrace();
//				}
	        }

	        public void onError (Exception e) {
	            System.out.println("Error reported for test call back");
	            e.printStackTrace();
	        }
	    }


	 public static Options initOptions(String nameMethod){

     	Options options = new Options();
	       	options.setTo(targetEPR);
//	       	options.setAction(nameMethod);
	       	options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
	       	options.setUseSeparateListener(true);
	       	//Ajout pour le WSRM
	       	options.setProperty(MessageContextConstants.TRANSPORT_URL,targetEPRTcpmon);

	   return options;
     }



     public static String createSoapMessageString (String nameFile, String valueMarker){

         String out="\n";
         BufferedReader br;
				try {
					br = new BufferedReader(
					        new InputStreamReader(
					              new FileInputStream(nameFile),"UTF-8"));

	                  String ligne;
	                  while((ligne = br.readLine())!=null){
	                	  out +=ligne + "\n";
	                  }

				} catch (UnsupportedEncodingException e) {
					System.out.println("Erreur d'encodage du fichier");
					e.printStackTrace();
				} catch (FileNotFoundException e) {
					System.out.println("Erreur: le fichier n'a pas été trouvé");
					e.printStackTrace();
				} catch (IOException e) {
					System.out.println("Erreur de lecture dans le fichier");
					e.printStackTrace();
				}
         return out;
     }

}

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to