Salome HOME
Copyrights update 2015.
[tools/simanio.git] / src / TestCreateConfigFile.cpp
1 // Copyright (C) 2013-2015  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "CreateConfigFile.h"
21 #include "CreateConfigFileResponse.h"
22 #include "GetFile.h"
23 #include "GetFileResponse.h"
24 #include "PutFile.h"
25 #include "PutFileResponse.h"
26 #include "SimanSalomeServiceStub.h"
27 #include <Environment.h>
28 #include <ServiceClient.h>
29 #include <iostream>
30 #include <fstream>
31
32 #include <axiom.h>
33 #include <axis2_util.h>
34 #include <axiom_soap.h>
35 #include <axis2_client.h>
36 #include <axutil_uuid_gen.h>
37
38 using namespace org_splat_ws_server_service_salome;
39 using namespace wso2wsf;
40
41 int main(int argc, char *argv[])
42 {
43         std::string endpointUri = "http://172.22.2.10:8080/Siman-WS/services/SimanSalomeService";
44         
45         char * ttest = getenv("SIMAN_WS_HOS");
46         if (ttest == NULL)
47           std::cout<<"expected\n";
48         else
49           std::cout<<"unexpected\n";
50         
51         std::string aSimanWSHost(getenv("SIMAN_WS_HOST"));
52         std::string endpointUriTT = "http://" + aSimanWSHost + "/Siman-WS/services/SimanSalomeService";
53         
54         std::cout<<"enpoint uri" << endpointUriTT << "\n";
55
56         Environment::initialize("SimanSalomeService.log",AXIS2_LOG_LEVEL_DEBUG);
57
58         //std::string clientHome = AXIS2_GETENV("SALOME_HOME");
59         std::string clientHome = AXIS2_GETENV("WSFCPP_HOME");
60         //std::string clientHome = "/dn24/SIMAN/siman_mandriva_2010";
61         SimanSalomeServiceStub* aStub = new SimanSalomeServiceStub(clientHome, endpointUri);
62         //SimanSalomeServiceStub* aStub = new SimanSalomeServiceStub(clientHome);
63         ServiceClient *client = aStub->getServiceClient();
64         
65         //Set options
66         client->engageModule(AXIS2_MODULE_ADDRESSING);
67         Options *options = client->getOptions();
68         axis2_options_t *axis2options = options->getAxis2Options();
69         axis2_options_set_action(axis2options, Environment::getEnv(), "urn:createConfigFile");
70         
71         //MTOM options
72         //axis2_options_set_enable_mtom(axis2options, Environment::getEnv(), AXIS2_TRUE);
73         options->setTimeout(1000000);
74         options->setSoapVersion(AXIOM_SOAP12);
75
76         CreateConfigFile* aRequest = new CreateConfigFile();
77
78         long long studyId = 1000;
79         long long scenarioId = 1001;
80         long long userId = 8;
81         std::string newUserId = "8";
82
83         aRequest->setArgs0(studyId);
84         aRequest->setArgs1(scenarioId);
85         aRequest->setArgs2(atoll(newUserId.c_str()));
86
87         CreateConfigFileResponse* aResponse = new CreateConfigFileResponse();
88
89         aResponse = aStub->createConfigFile(aRequest);
90
91         std::cout<< "Response:: "<<aResponse->get_return()<<std::endl;
92         
93         //Parse the response and get the filename
94         std::string aResponseFilePath = aResponse->get_return();
95         std::string aResponseFileName = aResponseFilePath.substr(aResponseFilePath.find_last_of("/\\")+1);
96         std::cout << aResponseFileName << "\n";
97         
98         //Set options
99         axis2_options_set_action(axis2options, Environment::getEnv(), "urn:getFile");
100         //GetFile request
101         GetFile* aGetFileRequest = new GetFile();
102         aGetFileRequest->setArgs0(aResponse->get_return());
103         
104         GetFileResponse* aGetFileResponse = new GetFileResponse();
105         aGetFileResponse = aStub->getFile(aGetFileRequest);
106         std::ofstream outputStream;
107         std::string aClientFilePath = "/dn24/SIMAN/siman_temp/download/" + aResponseFileName;
108         
109         outputStream.open(aClientFilePath.c_str(), std::ofstream::binary);
110         
111         int aBufferSize = axutil_base64_binary_get_decoded_binary_len(aGetFileResponse->get_return(), Environment::getEnv());
112         
113         std::cout<<aBufferSize<<"\n";
114         int* aBufSize = new int[aBufferSize];
115         unsigned char* aCopyBuffer = axutil_base64_binary_get_plain_binary(aGetFileResponse->get_return(), Environment::getEnv(), aBufSize);
116         //char* aCopyBuf = aCopyBuf;
117         
118         //outputStream << aGetFileResponse->get_return();
119         outputStream.write(reinterpret_cast<const char*>(aCopyBuffer),aBufferSize);
120         
121         outputStream.flush();
122         outputStream.close();
123         
124         //Second test
125         /*std::string aSourceLoc = "W:\\testvideo\\Darvin.avi";
126         aGetFileRequest->setArgs0(aSourceLoc);
127         aGetFileResponse = aStub->getFile(aGetFileRequest);
128         
129         outputStream.open("/dn24/SIMAN/siman_temp/download/Darvin.avi", std::ofstream::binary);
130         aBufferSize = axutil_base64_binary_get_decoded_binary_len(aGetFileResponse->get_return(), Environment::getEnv());
131         std::cout<<aBufferSize<<"\n";
132         
133         aBufSize = new int[aBufferSize];
134         aCopyBuffer = axutil_base64_binary_get_plain_binary(aGetFileResponse->get_return(), Environment::getEnv(), aBufSize);
135         
136         outputStream.write(reinterpret_cast<const char*>(aCopyBuffer),aBufferSize);
137         
138         outputStream.flush();
139         outputStream.close();
140         */
141         //End second test
142         std::cout << "See file on path" << aClientFilePath << "\n";
143         
144         //Upload test
145         axis2_options_set_action(axis2options, Environment::getEnv(), "urn:putFile");
146         
147         PutFile* aPutFileRequest = new PutFile();
148         //char* aSourceFile = "/dn24/SIMAN/siman_temp/download/Mesh_1.med";
149         
150         //get size of the input file
151         std::ifstream infile ("/dn24/SIMAN/siman_temp/download/Mesh_1.med",std::ifstream::binary);
152         infile.seekg(0,std::ifstream::end);
153         int aSize = infile.tellg();
154         std::cout << "Size of the input file is: " << aSize << "\n";
155         infile.seekg(0);
156         
157         char * inBuffer;
158         inBuffer = new char [aSize];
159         infile.read(inBuffer,aSize);
160         
161         axutil_base64_binary_t* aRequestDH = axutil_base64_binary_create_with_plain_binary(Environment::getEnv(), reinterpret_cast<unsigned char*>(inBuffer), aSize);
162         
163         infile.close();
164         
165         
166         
167         aPutFileRequest->setArgs0(aRequestDH);
168         aPutFileRequest->setArgs1("Mesh_1.med");
169         aPutFileRequest->setArgs2(userId);
170         
171         std::cout << "test" <<"\n";
172         
173         PutFileResponse* aPutFileResponse = new PutFileResponse();
174         aPutFileResponse = aStub->putFile(aPutFileRequest);
175         
176         std::cout<< "Response:: "<<aPutFileResponse->get_return()<<std::endl;
177         
178         delete aResponse;
179         delete aRequest;
180         delete aGetFileResponse;
181         delete aGetFileRequest;
182         delete aPutFileResponse;
183         delete aPutFileRequest;
184         delete aStub;
185 }