Salome HOME
First preliminary version
[tools/simanio.git] / src / TestCreateConfigFile.cpp
1 #include "CreateConfigFile.h"
2 #include "CreateConfigFileResponse.h"
3 #include "GetFile.h"
4 #include "GetFileResponse.h"
5 #include "PutFile.h"
6 #include "PutFileResponse.h"
7 #include "SimanSalomeServiceStub.h"
8 #include <Environment.h>
9 #include <iostream>
10 #include <fstream>
11 #include <ServiceClient.h>
12
13 #include <axiom.h>
14 #include <axis2_util.h>
15 #include <axiom_soap.h>
16 #include <axis2_client.h>
17 #include <axutil_uuid_gen.h>
18
19
20 using namespace std;
21 using namespace org_splat_ws_server_service_salome;
22 using namespace wso2wsf;
23
24 int main(int argc, char *argv[])
25 {
26         std::string endpointUri = "http://172.22.2.10:8080/Siman-WS/services/SimanSalomeService";
27         
28         char * ttest = getenv("SIMAN_WS_HOS");
29         if (ttest == NULL)
30             cout<<"expected\n";
31         else
32             cout<<"unexpected\n";
33         
34         string aSimanWSHost(getenv("SIMAN_WS_HOST"));
35         string endpointUriTT = "http://" + aSimanWSHost + "/Siman-WS/services/SimanSalomeService";
36         
37         cout<<"enpoint uri" << endpointUriTT << "\n";
38
39         Environment::initialize("SimanSalomeService.log",AXIS2_LOG_LEVEL_DEBUG);
40
41         //std::string clientHome = AXIS2_GETENV("SALOME_HOME");
42         std::string clientHome = AXIS2_GETENV("WSFCPP_HOME");
43         //std::string clientHome = "/dn24/SIMAN/siman_mandriva_2010";
44         SimanSalomeServiceStub* aStub = new SimanSalomeServiceStub(clientHome, endpointUri);
45         //SimanSalomeServiceStub* aStub = new SimanSalomeServiceStub(clientHome);
46         ServiceClient *client = aStub->getServiceClient();
47         
48         //Set options
49         client->engageModule(AXIS2_MODULE_ADDRESSING);
50         Options *options = client->getOptions();
51         axis2_options_t *axis2options = options->getAxis2Options();
52         axis2_options_set_action(axis2options, Environment::getEnv(), "urn:createConfigFile");
53         
54         //MTOM options
55         //axis2_options_set_enable_mtom(axis2options, Environment::getEnv(), AXIS2_TRUE);
56         options->setTimeout(1000000);
57         options->setSoapVersion(AXIOM_SOAP12);
58
59         CreateConfigFile* aRequest = new CreateConfigFile();
60
61         long long studyId = 1000;
62         long long scenarioId = 1001;
63         long long userId = 8;
64         string newUserId = "8";
65
66         aRequest->setArgs0(studyId);
67         aRequest->setArgs1(scenarioId);
68         aRequest->setArgs2(atoll(newUserId.c_str()));
69
70         CreateConfigFileResponse* aResponse = new CreateConfigFileResponse();
71
72         aResponse = aStub->createConfigFile(aRequest);
73
74         cout<< "Response:: "<<aResponse->get_return()<<endl;
75         
76         //Parse the response and get the filename
77         std::string aResponseFilePath = aResponse->get_return();
78         std::string aResponseFileName = aResponseFilePath.substr(aResponseFilePath.find_last_of("/\\")+1);
79         cout << aResponseFileName << "\n";
80         
81         //Set options
82         axis2_options_set_action(axis2options, Environment::getEnv(), "urn:getFile");
83         //GetFile request
84         GetFile* aGetFileRequest = new GetFile();
85         aGetFileRequest->setArgs0(aResponse->get_return());
86         
87         GetFileResponse* aGetFileResponse = new GetFileResponse();
88         aGetFileResponse = aStub->getFile(aGetFileRequest);
89         std::ofstream outputStream;
90         std::string aClientFilePath = "/dn24/SIMAN/siman_temp/download/" + aResponseFileName;
91         
92         outputStream.open(aClientFilePath.c_str(), ofstream::binary);
93         
94         int aBufferSize = axutil_base64_binary_get_decoded_binary_len(aGetFileResponse->get_return(), Environment::getEnv());
95         
96         cout<<aBufferSize<<"\n";
97         int* aBufSize = new int[aBufferSize];
98         unsigned char* aCopyBuffer = axutil_base64_binary_get_plain_binary(aGetFileResponse->get_return(), Environment::getEnv(), aBufSize);
99         //char* aCopyBuf = aCopyBuf;
100         
101         //outputStream << aGetFileResponse->get_return();
102         outputStream.write(reinterpret_cast<const char*>(aCopyBuffer),aBufferSize);
103         
104         outputStream.flush();
105         outputStream.close();
106         
107         //Second test
108         /*string aSourceLoc = "W:\\testvideo\\Darvin.avi";
109         aGetFileRequest->setArgs0(aSourceLoc);
110         aGetFileResponse = aStub->getFile(aGetFileRequest);
111         
112         outputStream.open("/dn24/SIMAN/siman_temp/download/Darvin.avi", ofstream::binary);
113         aBufferSize = axutil_base64_binary_get_decoded_binary_len(aGetFileResponse->get_return(), Environment::getEnv());
114         cout<<aBufferSize<<"\n";
115         
116         aBufSize = new int[aBufferSize];
117         aCopyBuffer = axutil_base64_binary_get_plain_binary(aGetFileResponse->get_return(), Environment::getEnv(), aBufSize);
118         
119         outputStream.write(reinterpret_cast<const char*>(aCopyBuffer),aBufferSize);
120         
121         outputStream.flush();
122         outputStream.close();
123         */
124         //End second test
125         cout << "See file on path" << aClientFilePath << "\n";
126         
127         //Upload test
128         axis2_options_set_action(axis2options, Environment::getEnv(), "urn:putFile");
129         
130         PutFile* aPutFileRequest = new PutFile();
131         //char* aSourceFile = "/dn24/SIMAN/siman_temp/download/Mesh_1.med";
132         
133         //get size of the input file
134         ifstream infile ("/dn24/SIMAN/siman_temp/download/Mesh_1.med",ifstream::binary);
135         infile.seekg(0,ifstream::end);
136         int aSize = infile.tellg();
137         cout << "Size of the input file is: " << aSize << "\n";
138         infile.seekg(0);
139         
140         char * inBuffer;
141         inBuffer = new char [aSize];
142         infile.read(inBuffer,aSize);
143         
144         axutil_base64_binary_t* aRequestDH = axutil_base64_binary_create_with_plain_binary(Environment::getEnv(), reinterpret_cast<unsigned char*>(inBuffer), aSize);
145         
146         infile.close();
147         
148         
149         
150         aPutFileRequest->setArgs0(aRequestDH);
151         aPutFileRequest->setArgs1("Mesh_1.med");
152         aPutFileRequest->setArgs2(userId);
153         
154         cout << "test" <<"\n";
155         
156         PutFileResponse* aPutFileResponse = new PutFileResponse();
157         aPutFileResponse = aStub->putFile(aPutFileRequest);
158         
159         cout<< "Response:: "<<aPutFileResponse->get_return()<<endl;
160         
161         delete aResponse;
162         delete aRequest;
163         delete aGetFileResponse;
164         delete aGetFileRequest;
165         delete aPutFileResponse;
166         delete aPutFileRequest;
167         delete aStub;
168 }