1 // Copyright (C) 2013-2014 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "CreateConfigFile.h"
21 #include "CreateConfigFileResponse.h"
23 #include "GetFileResponse.h"
25 #include "PutFileResponse.h"
26 #include "SimanSalomeServiceStub.h"
27 #include <Environment.h>
28 #include <ServiceClient.h>
33 #include <axis2_util.h>
34 #include <axiom_soap.h>
35 #include <axis2_client.h>
36 #include <axutil_uuid_gen.h>
38 using namespace org_splat_ws_server_service_salome;
39 using namespace wso2wsf;
41 int main(int argc, char *argv[])
43 std::string endpointUri = "http://172.22.2.10:8080/Siman-WS/services/SimanSalomeService";
45 char * ttest = getenv("SIMAN_WS_HOS");
47 std::cout<<"expected\n";
49 std::cout<<"unexpected\n";
51 std::string aSimanWSHost(getenv("SIMAN_WS_HOST"));
52 std::string endpointUriTT = "http://" + aSimanWSHost + "/Siman-WS/services/SimanSalomeService";
54 std::cout<<"enpoint uri" << endpointUriTT << "\n";
56 Environment::initialize("SimanSalomeService.log",AXIS2_LOG_LEVEL_DEBUG);
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();
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");
72 //axis2_options_set_enable_mtom(axis2options, Environment::getEnv(), AXIS2_TRUE);
73 options->setTimeout(1000000);
74 options->setSoapVersion(AXIOM_SOAP12);
76 CreateConfigFile* aRequest = new CreateConfigFile();
78 long long studyId = 1000;
79 long long scenarioId = 1001;
81 std::string newUserId = "8";
83 aRequest->setArgs0(studyId);
84 aRequest->setArgs1(scenarioId);
85 aRequest->setArgs2(atoll(newUserId.c_str()));
87 CreateConfigFileResponse* aResponse = new CreateConfigFileResponse();
89 aResponse = aStub->createConfigFile(aRequest);
91 std::cout<< "Response:: "<<aResponse->get_return()<<std::endl;
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";
99 axis2_options_set_action(axis2options, Environment::getEnv(), "urn:getFile");
101 GetFile* aGetFileRequest = new GetFile();
102 aGetFileRequest->setArgs0(aResponse->get_return());
104 GetFileResponse* aGetFileResponse = new GetFileResponse();
105 aGetFileResponse = aStub->getFile(aGetFileRequest);
106 std::ofstream outputStream;
107 std::string aClientFilePath = "/dn24/SIMAN/siman_temp/download/" + aResponseFileName;
109 outputStream.open(aClientFilePath.c_str(), std::ofstream::binary);
111 int aBufferSize = axutil_base64_binary_get_decoded_binary_len(aGetFileResponse->get_return(), Environment::getEnv());
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;
118 //outputStream << aGetFileResponse->get_return();
119 outputStream.write(reinterpret_cast<const char*>(aCopyBuffer),aBufferSize);
121 outputStream.flush();
122 outputStream.close();
125 /*std::string aSourceLoc = "W:\\testvideo\\Darvin.avi";
126 aGetFileRequest->setArgs0(aSourceLoc);
127 aGetFileResponse = aStub->getFile(aGetFileRequest);
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";
133 aBufSize = new int[aBufferSize];
134 aCopyBuffer = axutil_base64_binary_get_plain_binary(aGetFileResponse->get_return(), Environment::getEnv(), aBufSize);
136 outputStream.write(reinterpret_cast<const char*>(aCopyBuffer),aBufferSize);
138 outputStream.flush();
139 outputStream.close();
142 std::cout << "See file on path" << aClientFilePath << "\n";
145 axis2_options_set_action(axis2options, Environment::getEnv(), "urn:putFile");
147 PutFile* aPutFileRequest = new PutFile();
148 //char* aSourceFile = "/dn24/SIMAN/siman_temp/download/Mesh_1.med";
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";
158 inBuffer = new char [aSize];
159 infile.read(inBuffer,aSize);
161 axutil_base64_binary_t* aRequestDH = axutil_base64_binary_create_with_plain_binary(Environment::getEnv(), reinterpret_cast<unsigned char*>(inBuffer), aSize);
167 aPutFileRequest->setArgs0(aRequestDH);
168 aPutFileRequest->setArgs1("Mesh_1.med");
169 aPutFileRequest->setArgs2(userId);
171 std::cout << "test" <<"\n";
173 PutFileResponse* aPutFileResponse = new PutFileResponse();
174 aPutFileResponse = aStub->putFile(aPutFileRequest);
176 std::cout<< "Response:: "<<aPutFileResponse->get_return()<<std::endl;
180 delete aGetFileResponse;
181 delete aGetFileRequest;
182 delete aPutFileResponse;
183 delete aPutFileRequest;