sanjaya 2003/07/27 03:03:34
Modified: c/src/engine Axis.cpp
Log:
added routine to display list of deployed webservices as hyperlinks to their
respective wsdls on a GET request
Revision Changes Path
1.5 +81 -40 xml-axis/c/src/engine/Axis.cpp
Index: Axis.cpp
===================================================================
RCS file: /home/cvs/xml-axis/c/src/engine/Axis.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Axis.cpp 23 Jul 2003 13:52:16 -0000 1.4
+++ Axis.cpp 27 Jul 2003 10:03:33 -0000 1.5
@@ -4,87 +4,128 @@
#include <stdlib.h>
#include <malloc.h>
#include "../common/Packet.h"
+#include <string>
+#include <map>
+
+#define res(X); send_response_bytes(X);
unsigned char chEBuf[1024];
-//17.07.2003 the name process is changed to process_request(soapstream * str)
extern "C" int process_request(soapstream *str)
{
- DEBUG1("in axis.cpp");
+DEBUG1("in axis.cpp");
AxisEngine* engine = AxisEngine::GetAxisEngine();
int ret = FAIL;
- //the location of the wsdl hardcoded
- char * wsdlloc = "e:\\Axis\\Calculator.wsdl";
- //char pointer to which the wsdl file will be read
- char * wsdl = NULL;
+ char * wsdlloc = NULL;
+ char * uri = NULL;
+ int pos=0;
+ int slashcount=0;
+ int len = 0;
+
FILE * outfile;
const int bytestoread = 6;
char oneword [bytestoread];
oneword[bytestoread-1] = '\0';
+
+ const WSDDServiceMap * svsmap = NULL;
+ WSDDServiceMap::const_iterator iter;
+ WSDDService * svs = NULL;
+ //the location of the wsdl files hardcoded
+ string svr("./Axis/wsdl/");
+
switch(str->trtype)
{
case APTHTTP:
+ //Handle the POST method
if(str->so.http.ip_method==POST)
{
-
DEBUG1("method is POST");
if (engine)
{
ret = engine->Process(str);
- DEBUG1("ret = engine->Process(str);");
+ DEBUG1("ret = engine->Process(str);");
DEBUG1("are we successful?");
ret = SUCCESS;
}
}
+ //Handler the GET method
if(str->so.http.ip_method==GET)
{
-DEBUG1("method is GET");
- if((outfile = fopen(wsdlloc,"r"))==NULL)
+ //get the uri path
+ //i.e "/abc/xyz/" part of http://somehost/abc/xyz/
+ string sUri = str->so.http.uri_path;
+ string sUriWOAxis = "";
+ string sServiceName;
+ bool bNoSlash = false;
+
+ if (sUri.find("/axis/") != string::npos)
{
- send_response_bytes("no wsdl to be found");
- //handle the error
- //str->so.http.op_soap = "Error in reading
wsdl file";
+ sUriWOAxis = sUri.substr(sUri.find("/axis/") +
6);
}
else
+ {
+ bNoSlash = true;
+ }
+ if (sUriWOAxis.empty())
+ {
+ svsmap =
engine->getWSDDDeployment()->GetWSDDServiceMap();
+ //dep = engine->getWSDDDeployment();
+ //svsmap = depGetWSDDServiceMap();
+ res("<html><body>\
+ <h1 align=\"center\">Welcome to Axis
C++</h1>\
+ <br>\
+ <h2>List of Deployed Web
services<br></h2>\
+ <h3>click on the links to view the
WSDL</h3>\
+ <br>\
+ <table width=\"400\">");
+
+ for
(iter=svsmap->begin();iter!=svsmap->end();iter++)
+ {
+ svs = iter->second;
+ res("<tr><td width=\"200\">");
+ res((char
*)svs->GetServiceName().c_str());
+ res("</td><td width=\"200\"><a
href=\"./");
+ if (bNoSlash)
send_response_bytes("axis/");
+ send_response_bytes((char
*)svs->GetServiceName().c_str());
+ send_response_bytes("?wsdl");
+
send_response_bytes("\">wsdl</a></td>");
+ res("</tr>");
+ }
+ res("</table></body></html>");
+ }
+ else
{
- int charcount = 0;
- int acc = 0;
+ sServiceName = "./Axis/wsdl/" + sUriWOAxis +
".wsdl";
+ //check whether wsdl file is available
+ if((outfile =
fopen(sServiceName.c_str(),"r"))==NULL)
+ {
+ send_response_bytes("<h3>Url not
available</h3>");
+ //handle the error
+ }
+ else
+ {
+ int charcount = 0;
+ int acc = 0;
while((charcount=fread(oneword,1,bytestoread-1, outfile)) != 0)
{
- if(wsdl==NULL)
- {
- acc += charcount;
- wsdl = (char
*)realloc(wsdl,acc);
- wsdl = strcpy(wsdl,oneword);
- }
- else
- {
- wsdl = (char
*)realloc(wsdl,acc+charcount);
- *(wsdl+(acc))='\0';
- acc += charcount;
- wsdl = strncat(wsdl,
oneword,charcount);
- }
- }
- //assign the char pointer that contains the
- //wsdl file to the response
- //str->so.http.op_soap = wsdl;
- send_response_bytes("dummy wsdl");
- ret = SUCCESS;
- fclose(outfile);
- //free (wsdl);
+ *(oneword+charcount) = '\0';
+ send_response_bytes(oneword);
+ }
+ ret = SUCCESS;
+ fclose(outfile);
+ }
}
}
break;
default:
- //str->so.http.op_soap = "Unknown protocol";
+ send_response_bytes("Unknown Protocol");
break;
-
}
-
- //str->op_soap = chEBuf;
+ svsmap = NULL;
+ svs =NULL;
return ret;
}
