00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "wsdlparser/WsdlInvoker.h"
00023 using namespace std;
00024 using namespace WsdlPull;
00025
00026 void
00027 usage(void)
00028 {
00029 std::cout<<"Usage wsdl [options] wsdl-uri [operation name] [method parameters]"<<std::endl;
00030 std::cout<<"Options: "<<std::endl;
00031 std::cout<<" -h Display this message"<<std::endl;
00032 std::cout<<" -x host[:port] Use HTTP proxy on given port"<<std::endl;
00033 std::cout<<" -U user[:password] Specify Proxy authentication"<<std::endl;
00034 std::cout<<" -v Verbose mode,SOAP request and response are logged"<<std::endl;
00035 std::cout<<" -d display WSDL operation's documentation"<<std::endl;
00036 std::cout<<" -l list all the WSDL operations "<<std::endl;
00037 std::cout<<" -o Allow setting occurrence constraint (default is 1)"<<std::endl;
00038 std::cout<<" -s Suppress printing type/element names in the output"<<std::endl;
00039 std::cout<<" -t requesttimeout in seconds"<<std::endl;
00040 std::cout<<" -e set SOAP headers in input"<<std::endl;
00041 std::cout<<"With no arguments,wsdl starts in the interactive mode accepting"<<std::endl;
00042 std::cout<<"operation name and parameters from the standard input"<<std::endl;
00043 }
00044
00045 int
00046 main (int argc, char *argv[])
00047 {
00048 WsdlInvoker invoker;
00049 bool brkloop =false;
00050 bool showDoc = false;
00051 bool verbose = false;
00052 bool occurs = false;
00053 bool listops = false;
00054 bool accept_password =false;
00055 bool accept_headers = false;
00056 long timeout = 0;
00057
00058 int i =1;
00059 for (;i<argc && !brkloop;){
00060 switch(argv[i][0]){
00061 case '-':
00062 {
00063 std::string opt(argv[i]+1);
00064 if (opt=="v"){
00065 invoker.setVerbose(true);
00066 verbose = true;
00067 showDoc = true;
00068 i++;
00069 }
00070 else if (opt == "s"){
00071
00072 invoker.printTypeNames(false);
00073 i++;
00074 }
00075 else if (opt == "d"){
00076
00077 showDoc = true;
00078 i++;
00079 }
00080 else if (opt == "e"){
00081
00082 accept_headers = true;
00083 i++;
00084 }
00085 else if (opt == "l"){
00086
00087 listops=true;
00088 i++;
00089 }
00090 else if (opt == "x"){
00091 opt = argv[i+1];
00092 size_t pos=opt.find(':');
00093 XmlUtils::setProxyHost (opt);
00094 if(pos==std::string::npos){
00095
00096 XmlUtils::setProxyHost (XmlUtils::getProxyHost () + ":80");
00097 }
00098 XmlUtils::setProxy (true);
00099 i+=2;
00100 }
00101 else if (opt == "U"){
00102 opt = argv[i+1];
00103 size_t pos=opt.find(':');
00104 XmlUtils::setProxyUser (opt.substr(0,pos));
00105 if(pos!=std::string::npos)
00106 XmlUtils::setProxyPass (opt.substr(pos+1));
00107 else
00108 accept_password = true;
00109 i+=2;
00110 XmlUtils::setProxy (true);
00111 }
00112 else if (opt =="h"){
00113 usage();
00114 exit(0);
00115 }
00116 else if(opt == "o"){
00117
00118 occurs = true;
00119 i++;
00120 }
00121 else if(opt == "t"){
00122 opt = argv[i+1];
00123 timeout=atoi(opt.c_str());
00124 i+=2;
00125 }
00126 else{
00127 std::cerr<<"Unknown option "<<argv[i]<<std::endl;
00128 usage();
00129 exit(2);
00130 }
00131 break;
00132 }
00133 default:
00134 brkloop = true;
00135
00136 break;
00137 }
00138 }
00139
00140 if (XmlUtils::getProxy () && accept_password){
00141
00142 XmlUtils::setProxyPass (XmlUtils::acceptSecretKey("Proxy Password"));
00143 std::cout<<endl;
00144 }
00145
00146 if (i < argc){
00147 if(!invoker.setWSDLUri(argv[i])) {
00148
00149 std::cerr<<"Error processing "<<argv[i]<<std::endl;
00150 std::cerr<<invoker.errors()<<std::endl;
00151 return 1;
00152 }
00153 i++;
00154 }
00155 else{
00156
00157 usage();
00158 exit (2);
00159 }
00160
00161 if (verbose)
00162 std::cout<<invoker.errors()<<std::endl;
00163
00164 if (i<argc && !listops){
00165
00166 if(!invoker.setOperation(argv[i])){
00167
00168 std::cerr<<"Unkown operation name "<<argv[i]<<std::endl;
00169 return 2;
00170 }
00171 i++;
00172 }
00173 else{
00174
00175 std::vector<std::string> ops;
00176 unsigned int choice = 0;
00177 if (invoker.getOperations(ops)){
00178
00179 for (size_t s = 0;s<ops.size();s++){
00180
00181 std::cout<<s+1<<"."<<ops[s];
00182
00183 if (showDoc) {
00184
00185 std::string doc = invoker.getOpDocumentaion(ops[s]);
00186 if (!doc.empty())
00187 std::cout<<"("<<doc<<")";
00188 }
00189 std::cout<<endl;
00190 }
00191 if (listops == true){
00192
00193 return 0;
00194 }
00195 while (choice==0){
00196
00197 cout<<"Choose one of the above operations [1-"<<ops.size()<<"] :";
00198 std::cin>>choice;
00199 if (choice>0 && choice<=ops.size())
00200 break;
00201 else
00202 choice=0;
00203 }
00204 }
00205 if (!invoker.setOperation(ops[choice-1])){
00206
00207 std::cerr<<"Couldn't invoke operation "<<std::endl;
00208 return 1;
00209 }
00210 }
00211 if(!accept_headers && invoker.nInputHeaders()>0){
00212
00213 std::cout<<"Warning:This operation has some SOAP headers in its inputs!(use -e)"<<std::endl;
00214 }
00215
00216 if (invoker.status()){
00217
00218 int id =0,minimum,maximum,n;
00219 Schema::Type t;
00220 std::string param;
00221 std::string val;
00222 std::vector<std::string> values;
00223 std::vector<std::string> parents;
00224
00225 do{
00226
00227 if (accept_headers && invoker.nInputHeaders()>0){
00228
00229 id = invoker.getNextHeaderInput(param,t,minimum,maximum,parents);
00230 if (id == -1){
00231 accept_headers=false;
00232 continue;
00233 }
00234 }
00235 else{
00236
00237 id = invoker.getNextInput(param,t,minimum,maximum,parents);
00238 }
00239 if (id == -1)
00240 break;
00241 n = minimum;
00242 if (occurs && minimum < maximum) {
00243 values.clear();
00244 cout<<param<<"["<<minimum<<","<<maximum<<"] Enter number of occurrences:";
00245 cin>>n;
00246
00247 if (n<minimum || n>maximum){
00248
00249 std::cerr<<"Didnt match occurrence constraints"<<std::endl;
00250 return 2;
00251 }
00252 while(n--) {
00253
00254 if (i <argc) {
00255 val = argv[i++];
00256 }
00257 else {
00258 cout<<param<<": ";
00259 cin>>val;
00260 }
00261 values.push_back(val);
00262 }
00263 if (!invoker.setInputValue(id,values)){
00264
00265 std::cerr<<"Incorrect input values "<<std::endl;
00266 return 2;
00267 }
00268 }
00269 else{
00270
00271 if (i <argc) {
00272
00273 val = argv[i++];
00274 }
00275 else{
00276 size_t j = 0;
00277 for (j=0;j<parents.size()-1;j++){
00278
00279 cout<<parents[j]<<".";
00280 }
00281 cout<<parents[j]<<": ";
00282 cin>>val;
00283 }
00284 if (!invoker.setInputValue(id,val)){
00285
00286 std::cerr<<"Incorrect input value "<<val<<std::endl;
00287 return 2;
00288 }
00289 }
00290 }while(1);
00291
00292 if (invoker.invoke(timeout)){
00293
00294 TypeContainer* tc = 0;
00295 std::string name;
00296 while(invoker.getNextHeaderOutput(name,tc)) {
00297
00298 tc->print(cout);
00299 }
00300
00301 while (invoker.getNextOutput(name,tc)){
00302
00303 tc->print(cout);
00304 }
00305 return 0;
00306 }
00307 else{
00308 cerr<<invoker.errors()<<endl;
00309 }
00310 }
00311 return 1;
00312 }
00313
00314