Overview
Features
Download
Documentation
Community
Add-Ons & Services

Server side exception Poco::Util::AbstractionConfiguration

A general discussion forum.

Server side exception Poco::Util::AbstractionConfiguration

Postby ma740988 » 27 Jun 2012, 19:40

Consider client side source snippet:

Code: Select all
std::string xml =
  "<test>"
     "<abc id="\xxx\" num=\"1\">"
     "  <stuff>30</stuff>"
     "</abc>
 "</test>;

int main ( int arg, char* argv[] ){
  try {
   //this is just to check if xml is well formed.. apparently the abstraction class will throw exception if it objects
   //start
    std::istringstream iss ( xml ) ;
    Poco::Util::AbstractionConfiguration  *ptr = new  ( std::nothrow ) Poco::Util::AbstractionConfiguration ( iss ) ;
    if ( !ptr )  return EXIT_FAILURE ;
   //end

   Poco::HTTPRequest request( "POST", "/event");
   request.setContentType ( "text/xml");
   //request.setContentType ( "text/xml; char=\"utf-8\"" );  //makes no difference it seems
   request.setContentLength( xml.length() );
   Poco::HTTPClientSession s( "127.0.0.1", 8801 ) ;
   s.sendRequest(request) << xml;

  //check response

  } catch ( Poco::Exception& exec ) {

  }
  return EXIT_SUCCESS ;
}




Server side snippet

Code: Select all
  std::istream& istr = req.stream ;  //where req is Poco::Net::HTTPServerRequest& req
  std::stringstream oss;
  oss << istr.rdbuf();
  std::string request = oss.str();
 
  std::istringstream iss ( xml ) ;
  Poco::Util::AbstractionConfiguration  *ptr = new  ( std::nothrow ) Poco::Util::AbstractionConfiguration ( iss ) ;
  if ( !ptr )  return ;



Invocation of new AbstractionConfiguration invokes an exception on server side. This tells me that something is amiss about the client side transfer. I know the XML is 'loosely speaking' well formed because if it wasn't I would not be able to create an Abstraction object on the client side.

Clearly, i receive the contents on the server side since I'm able to do std::cout << request<< std::endl; What's unclear to me though is why the abstraction class rejects the XML. Ideas? Thanks
ma740988
 
Posts: 2
Joined: 28 Apr 2012, 04:05

Re: Server side exception Poco::Util::AbstractionConfigurati

Postby WittrockJ » 28 Jun 2012, 02:31

Are you sure the xml is well formed? Looks like your xml string has some quoting problems.
Code: Select all
std::string xml =
  "<test>"
     "<abc id="\xxx\" num=\"1\">"
     "  <stuff>30</stuff>"
     "</abc>
"</test>;


Shouldn't this be something like:
Code: Select all
std::string xml =
  "<test>"
     "<abc id=\"xxx\" num=\"1\">"
     "  <stuff>30</stuff>"
     "</abc>"
"</test>";
WittrockJ
 
Posts: 5
Joined: 07 May 2009, 16:15

Re: Server side exception Poco::Util::AbstractionConfigurati

Postby ma740988 » 28 Jun 2012, 03:12

You're correct. I had a typo when I typed my message. It (XML) is well-formed in the code. I have a check on the client side "see source' snippet, so if it wasn't I'd get an exception.
ma740988
 
Posts: 2
Joined: 28 Apr 2012, 04:05

Re: Server side exception Poco::Util::AbstractionConfigurati

Postby rmoffer » 03 Jul 2012, 04:07

Shouldn't you be reading oss not iss ?


We have a lot of code patters that do

Code: Select all

    std::stringstream requestBody;

    // copy the request to local storage
    //
    Poco::StreamCopier::copyStream( req.stream(), requestBody );
   
    // build a config object out of it
    Poco::SharedPtr<XMLConfiguration> cfg = new XMLConfiguration();

     cfg->load( requestBody );




Although note that the XMLConfiguration is our local subclass of the standard Poco::Util::XMLConfiguration - something to do with public vs private data members...
rmoffer
 
Posts: 48
Joined: 09 Feb 2009, 19:20
Location: San Francisco bay area.

Re: Server side exception Poco::Util::AbstractionConfigurati

Postby alex » 03 Jul 2012, 14:48

ma740988 wrote:Clearly, i receive the contents on the server side since I'm able to do std::cout << request<< std::endl; What's unclear to me though is why the abstraction class rejects the XML. Ideas? Thanks


First of all, I suggest you do your homework before posting. Posting code that not only doesn't compile, but is using nonexistent classes is rude.

Aside from your xml snippet being broken, what is Poco::Util::AbstractionConfiguration? There is no such class in Poco::Util. If you meant Poco::Util::AbstractConfiguration, that class is (as it's name implies) abstract, which means it can not be instantiated.

Community will be glad to help you, but you have to do your part. Please do your homework before posting and sending people on a wild goose chase.
alex
 
Posts: 1121
Joined: 11 Jul 2006, 16:27
Location: United_States


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron