1 #include "CreateConfigFile.h"
2 #include "CreateConfigFileResponse.h"
4 #include "GetFileResponse.h"
6 #include "PutFileResponse.h"
7 #include "SimanSalomeServiceStub.h"
9 #include <Environment.h>
13 #include <ServiceClient.h>
14 #include <SimanIO_Link.hxx>
21 using namespace org_splat_ws_server_service_salome;
22 using namespace wso2wsf;
24 SimanIO_Link::SimanIO_Link(const char* theStudyID,
25 const char* theScenarioID, const char* theUserID)
26 : myStudy(theStudyID), myScenario(theScenarioID), myUser(theUserID)
30 bool SimanIO_Link::IsConnected()
36 // unification of the error handling in the RetrieveConf and StoreConf methods
37 #define CONFIGURSION_ERROR(message) {cerr<<message<<endl;}
39 SimanIO_Configuration SimanIO_Link::RetrieveConf()
41 SimanIO_Configuration aResult;
42 // for now use simple initial cfg file for testings purposes only
43 // in the future this file must be downloaded from the SIMAN server somehow
44 //const char* aCFGFile = "/dn20/salome/mpv/siman/text1.conf";
46 char* aSimanHost = getenv("SIMAN_WS_HOST");
47 if (aSimanHost == NULL)
49 CONFIGURSION_ERROR("The SIMAN_WS_HOST variable does not exist. Please set it.\n");
53 string aSimanWSHost(aSimanHost);
54 string anEndpointUri = "http://" + aSimanWSHost + "/Siman-WS/services/SimanSalomeService";
56 Environment::initialize("SimanSalomeService.log",AXIS2_LOG_LEVEL_DEBUG);
57 char* aClientHomeEnv = getenv("WSFCPP_HOME");
59 if (aClientHomeEnv == NULL)
61 CONFIGURSION_ERROR("The WSFCPP_HOME variable does not exist. Please set it.\n");
65 string aClientHome = AXIS2_GETENV("WSFCPP_HOME");
66 SimanSalomeServiceStub* aStub = new SimanSalomeServiceStub(aClientHome, anEndpointUri);
67 ServiceClient *client = aStub->getServiceClient();
69 //Set the ServiceClient options
70 client->engageModule(AXIS2_MODULE_ADDRESSING);
71 Options *options = client->getOptions();
72 axis2_options_t *axis2options = options->getAxis2Options();
73 axis2_options_set_action(axis2options, Environment::getEnv(), "urn:createConfigFile");
76 options->setTimeout(1000000);
77 options->setSoapVersion(AXIOM_SOAP12);
79 //CreateConfigFile operation
80 CreateConfigFile* aCreateConfigFileRequest = new CreateConfigFile();
82 aCreateConfigFileRequest->setArgs0(atoll(myStudy.c_str()));
83 aCreateConfigFileRequest->setArgs1(atoll(myScenario.c_str()));
84 aCreateConfigFileRequest->setArgs2(atoll(myUser.c_str()));
86 //cout<<"StudyId = " << atoll(myStudy.c_str()) << "\n";
87 //cout<<"ScenarioId = " << atoll(myScenario.c_str()) << "\n";
88 //cout<<"UserId = " << atoll(myUser.c_str()) << "\n";
90 CreateConfigFileResponse* aCreateConfigFileResponse = new CreateConfigFileResponse();
91 aCreateConfigFileResponse = aStub->createConfigFile(aCreateConfigFileRequest);
93 string aResponseFilePath = aCreateConfigFileResponse->get_return();
95 //cout << "Response file path = " << aResponseFilePath << "\n";
97 string aResponseFileName = aResponseFilePath.substr(aResponseFilePath.find_last_of("/\\")+1);
99 //Get the created config file to client
102 axis2_options_set_action(axis2options, Environment::getEnv(), "urn:getFile");
104 GetFile* aGetFileRequest = new GetFile();
105 aGetFileRequest->setArgs0(aResponseFilePath);
106 GetFileResponse* aGetFileResponse = new GetFileResponse();
107 aGetFileResponse = aStub->getFile(aGetFileRequest);
109 //Parse the response and get the filename
110 string aTmpDir = "/tmp";
111 string aClientFileDir = aTmpDir + "/SimanSalome/" + myUser + "/download/";
112 string aClientFilePath = aClientFileDir + aResponseFileName;
114 //Cretae the directories
115 system(("mkdir -p " + aClientFileDir).c_str());
117 //Download the siman-salome.conf file
118 ofstream outputStream;
119 outputStream.open(aClientFilePath.c_str(), ofstream::binary);
120 int aBufferSize = axutil_base64_binary_get_decoded_binary_len(aGetFileResponse->get_return(), Environment::getEnv());
121 int* aBufSize = new int[aBufferSize];
122 unsigned char* aCopyBuffer = axutil_base64_binary_get_plain_binary(aGetFileResponse->get_return(), Environment::getEnv(), aBufSize);
123 outputStream.write(reinterpret_cast<const char*>(aCopyBuffer),aBufferSize);
124 outputStream.flush();
125 outputStream.close();
126 delete[] aCopyBuffer;
128 //Parse the downloaded siman-salome.conf file
129 aResult.Parse(aClientFilePath.c_str());
131 //Set the actual file URLs and get these files onto client.
132 SimanIO_Configuration::ActivitiesIterator actIter(aResult);
133 for(; actIter.More(); actIter.Next()) {
134 SimanIO_Activity::DocumentsIterator aDocIter(actIter.Activity());
135 for(; aDocIter.More(); aDocIter.Next()) {
136 /*const*/ SimanIO_Document& aDoc = aDocIter.Document();
137 SimanIO_Document::FilesIterator aFileIter(aDoc);
138 for(; aFileIter.More(); aFileIter.Next()) {
139 string aURL = aFileIter.URL();
140 string aFileName = aURL.substr(aURL.find_last_of("/\\")+1);
142 //cout << "aURL = " << "http://" << aSimanWSHost << "/repository/" << aURL << "\n";
143 string aPathToVault = aResponseFilePath.substr(0, aResponseFilePath.find("download")) + "vault/";
145 //only for test only for WIN
146 //replace(aURL.begin(),aURL.end(),'/','\\');
147 //end only for test only for WIN
149 //cout << "Path to vault" << aPathToVault + aURL << "\n";
152 //aGetFileRequest->setArgs0("http://" + aSimanWSHost + "/repository/" + aURL);
153 aGetFileRequest->setArgs0(aPathToVault + aURL);
154 aGetFileResponse = aStub->getFile(aGetFileRequest);
156 outputStream.open((aClientFileDir + aFileName).c_str(), ofstream::binary);
157 int aBufferSize = axutil_base64_binary_get_decoded_binary_len(aGetFileResponse->get_return(), Environment::getEnv());
158 int* aBufSize = new int[aBufferSize];
159 unsigned char* aCopyBuffer = axutil_base64_binary_get_plain_binary(aGetFileResponse->get_return(), Environment::getEnv(), aBufSize);
160 outputStream.write(reinterpret_cast<const char*>(aCopyBuffer),aBufferSize);
161 outputStream.flush();
162 outputStream.close();
163 delete[] aCopyBuffer;
166 aFileIter.SetURL((aClientFileDir + aFileName).c_str());
167 //cout << "New location of the files " << aClientFileDir + aFileName << "\n";
174 delete aCreateConfigFileRequest;
175 delete aCreateConfigFileResponse;
176 delete aGetFileResponse;
177 delete aGetFileRequest;
183 void SimanIO_Link::StoreConf(/*const*/ SimanIO_Configuration& theConf)
185 char* aSimanHost = getenv("SIMAN_WS_HOST");
186 if (aSimanHost == NULL)
188 CONFIGURSION_ERROR("The SIMAN_WS_HOST variable does not exist. Please set it.\n");
191 string aSimanWSHost(aSimanHost);
192 string anEndpointUri = "http://" + aSimanWSHost + "/Siman-WS/services/SimanSalomeService";
194 Environment::initialize("SimanSalomeService.log",AXIS2_LOG_LEVEL_DEBUG);
195 char* aClientHomeEnv = getenv("WSFCPP_HOME");
197 if (aClientHomeEnv == NULL)
199 CONFIGURSION_ERROR("The WSFCPP_HOME variable does not exist. Please set it.\n");
202 string aClientHome = AXIS2_GETENV("WSFCPP_HOME");
203 SimanSalomeServiceStub* aStub = new SimanSalomeServiceStub(aClientHome, anEndpointUri);
204 ServiceClient *client = aStub->getServiceClient();
206 //Set the ServiceClient options
207 client->engageModule(AXIS2_MODULE_ADDRESSING);
208 Options *options = client->getOptions();
209 axis2_options_t *axis2options = options->getAxis2Options();
210 axis2_options_set_action(axis2options, Environment::getEnv(), "urn:putFile");
213 options->setTimeout(1000000);
214 options->setSoapVersion(AXIOM_SOAP12);
216 //Upload the file onto server
217 PutFile* aPutFileRequest = new PutFile();
218 PutFileResponse* aPutFileResponse = new PutFileResponse();
220 //Prepare salome-siman.conf file
221 string aTmpDir = "/tmp";
222 string aClientFileDir = aTmpDir + "/SimanSalome/" + myUser + "/download/";
223 string aClientFilePath = aClientFileDir + "salome-siman.conf";
224 ofstream aSalomeSimanFile;
225 aSalomeSimanFile.open(aClientFilePath.c_str());
227 //Get the actual file URLs and put these files onto server.
228 SimanIO_Configuration::ActivitiesIterator actIter(theConf);
230 for(; actIter.More(); actIter.Next()) {
231 SimanIO_Activity::DocumentsIterator aDocIter(actIter.Activity());
232 for(; aDocIter.More(); aDocIter.Next()) {
233 /*const*/ SimanIO_Document& aDoc = aDocIter.Document();
234 SimanIO_Document::FilesIterator aFileIter(aDoc);
235 for(; aFileIter.More(); aFileIter.Next()) {
236 string aURL = aFileIter.URL();
237 string aFileName = aURL.substr(aURL.find_last_of("/\\")+1);
238 cout << "aURL = " << aURL << "\n";
239 cout << " aFileName= " << aFileName << "\n";
240 //get size of the input file
241 ifstream inputStream (aURL.c_str(), ifstream::binary);
242 inputStream.seekg(0,ifstream::end);
243 int aSize = inputStream.tellg();
244 inputStream.seekg(0);
248 aCopyBuffer = new char [aSize];
249 inputStream.read(aCopyBuffer,aSize);
250 axutil_base64_binary_t* aRequestDH = axutil_base64_binary_create_with_plain_binary(Environment::getEnv(), reinterpret_cast<unsigned char*>(aCopyBuffer), aSize);
252 delete[] aCopyBuffer;
255 aPutFileRequest->setArgs0(aRequestDH);
256 aPutFileRequest->setArgs1(aFileName);
257 aPutFileRequest->setArgs2(atoll(myUser.c_str()));
259 aPutFileResponse = aStub->putFile(aPutFileRequest);
261 //Write information into salome-siman.conf file
262 ostringstream activityId;
263 ostringstream documentId;
264 activityId << actIter.ActivityId();
265 documentId << aDocIter.DocId();
266 aSalomeSimanFile << myScenario + "," + myUser + "," + activityId.str() + "," + documentId.str() + "," + aPutFileResponse->get_return() + "\n";
272 aSalomeSimanFile.close();
274 //Put the salome-siman.conf file onto server
275 ifstream inputStream (aClientFilePath.c_str(), ifstream::binary);
276 inputStream.seekg(0,ifstream::end);
277 int aSize = inputStream.tellg();
278 inputStream.seekg(0);
281 aCopyBuffer = new char [aSize];
282 inputStream.read(aCopyBuffer,aSize);
283 axutil_base64_binary_t* aRequestDH = axutil_base64_binary_create_with_plain_binary(Environment::getEnv(), reinterpret_cast<unsigned char*>(aCopyBuffer), aSize);
285 delete[] aCopyBuffer;
288 aPutFileRequest->setArgs0(aRequestDH);
289 aPutFileRequest->setArgs1("salome-siman.conf");
290 aPutFileRequest->setArgs2(atoll(myUser.c_str()));
292 aPutFileResponse = aStub->putFile(aPutFileRequest);
295 axis2_options_set_action(axis2options, Environment::getEnv(), "urn:checkIn");
297 CheckIn* aCheckInRequest = new CheckIn();
298 CheckInResponse* aCheckInResponse = new CheckInResponse();
299 aCheckInRequest->setArgs0(aPutFileResponse->get_return());
300 aCheckInRequest->setArgs1(atoll(myUser.c_str()));
301 aCheckInResponse = aStub->checkIn(aCheckInRequest);