Example #1
0
int _tmain(int argc, _TCHAR* argv[])
{
	try
	{
		XMLPlatformUtils::Initialize();
	}
	catch(...)
	{
		return 1;
	}

	XMLCh* Path  = NULL;
	DOMImplementation* impl =  DOMImplementationRegistry::getDOMImplementation(L"Core");
	XERCES_CPP_NAMESPACE::DOMDocument* doc = impl->createDocument( 0, L"directory", 0);
	
	if( argc >= 2)
		Path = argv[1];
	else
		Path = L".\\";
	SaveFileTreeToXML(Path, doc->getDocumentElement() ,doc);

	PrintXMLdoc( doc );

	doc->release();

	XMLPlatformUtils::Terminate();
	return 0;
}
Example #2
0
int main( int aArgC, char *aArgV[] )
{
    std::cout << "**************** starting" << std::endl;

    for( int i = 0; i < 100; ++i )
    {
        XERCES_CPP_NAMESPACE::XMLPlatformUtils::Initialize();
        //XERCES_CPP_NAMESPACE::DOMDocument * doc = createNewDoc();
        XERCES_CPP_NAMESPACE::DOMDocument * doc = createNewDocWithType();
        std::cout << "    - Doing something with the document" << std::endl;
        //delete doc;
        doc->release();
        usleep(100000);
        std::cout << "* Memory (rss): " << getMemorySize() << std::endl;
        XERCES_CPP_NAMESPACE::XMLPlatformUtils::Terminate();
        std::cout << "* Memory (rss): " << getMemorySize() << std::endl;
    }
    
    std::cout << "**************** ending" << std::endl;
    return 0;
}
Example #3
0
int HttpServer::svc(void)
{
	char buf[2048];
	buf[2047] = '\0';	// security
	ACE_Time_Value timeout;
	timeout.sec(5);

	ssize_t size = peer().recv(buf, 2040, &timeout);

	if (size > 5)
	{
		try
		{
			int startUrlOffset = 5;		// get rid of "GET /" from Http request, so skip 5 chars
			char* stopUrl = ACE_OS::strstr(buf+startUrlOffset, " HTTP");	// detect location of post-URL trailing stuff
			if(!stopUrl)
			{
				throw (CStdString("Malformed http request"));							;
			}
			*stopUrl = '\0';									// Remove post-URL trailing stuff
			CStdString url(buf+startUrlOffset);
			int queryOffset = url.Find("?");
			if (queryOffset	 > 0)
			{
				// Strip beginning of URL in case the command is received as an URL "query" of the form:
				// http://hostname/service/command?type=ping
				url = url.Right(url.size() - queryOffset - 1);
			}


			CStdString className = UrlSerializer::FindClass(url);
			ObjectRef objRef = ObjectFactory::GetSingleton()->NewInstance(className);
			if (objRef.get())
			{
				objRef->DeSerializeUrl(url);
				ObjectRef response = objRef->Process();

				if(response.get() == NULL)
				{
					throw (CStdString("Command does not return a response:") + className);
				}
				else
				{
					DOMImplementation* impl =  DOMImplementationRegistry::getDOMImplementation(XStr("Core").unicodeForm());
					XERCES_CPP_NAMESPACE::DOMDocument* myDoc;
					   myDoc = impl->createDocument(
								   0,			 // root element namespace URI.
								   XStr("response").unicodeForm(),	   // root element name
								   0);			 // document type object (DTD).
					response->SerializeDom(myDoc);
					CStdString pingResponse = DomSerializer::DomNodeToString(myDoc);

					CStdString httpOk("HTTP/1.0 200 OK\r\nContent-type: text/xml\r\n\r\n");
					peer().send(httpOk, httpOk.GetLength(), MSG_NOSIGNAL);
					peer().send(pingResponse, pingResponse.GetLength(), MSG_NOSIGNAL);

					myDoc->release();
				}
			}
			else
			{
				throw (CStdString("Command not found:") + className);							;
			}

		}
		catch (CStdString &e)
		{
			CStdString error("HTTP/1.0 404 not found\r\nContent-type: text/html\r\n\r\nError\r\n");
			error = error + e + "\r\n";
			peer().send(error, error.GetLength(), MSG_NOSIGNAL);
		}
		catch(const XMLException& e)
		{
			CStdString error("HTTP/1.0 404 not found\r\nContent-type: text/html\r\n\r\nXML Error\r\n");
			peer().send(error, error.GetLength(), MSG_NOSIGNAL);
		}
	}
	else
	{
		CStdString notFound("HTTP/1.0 404 not found\r\nContent-type: text/html\r\n\r\nNot found\r\n");
		peer().send(notFound, notFound.GetLength(), MSG_NOSIGNAL);
	}
	return 0;
}