Пример #1
0
//////////////////////////////////////////////////////////////////////////////
// TODO: Move all this knowledge about CIM and specific trailers into HTTPClient
void HTTPChunkedIStream::checkForError() const
{
    String errorStr;
    errorStr = getTrailer("CIMError");
    if (!errorStr.empty())
    {
        OW_THROW(CIMErrorException, errorStr.c_str());
    }
    errorStr = getTrailer("CIMStatusCode");
    if (errorStr.empty())
    {
        // try the old OW 2.0.x pre-standard way
        errorStr = getTrailer("CIMErrorCode");
    }
    if (!errorStr.empty())
    {
        String descr;
        descr = getTrailer("CIMStatusDescription");
        if (descr.empty())
        {
            // try the old OW 2.0.x pre-standard way
            descr = getTrailer("CIMErrorDescription");
        }
        if (!descr.empty())
        {
            OW_THROWCIMMSG(CIMException::ErrNoType(errorStr.toInt32()),
                           descr.c_str());
        }
        else
        {
            OW_THROWCIM(CIMException::ErrNoType(errorStr.toInt32()));
        }
    }
}
Пример #2
0
std::string& Message::toXML( std::string& str ) const
{
  std::stringstream stream;
  stream << "<message>"                         << std::endl
         << std::setw(2) << " " << "<header>"   << std::endl
         << toXMLFields(getHeader(), 4)
         << std::setw(2) << " " << "</header>"  << std::endl
         << std::setw(2) << " " << "<body>"     << std::endl
         << toXMLFields(*this, 4)
         << std::setw(2) << " " << "</body>"    << std::endl
         << std::setw(2) << " " << "<trailer>"  << std::endl
         << toXMLFields(getTrailer(), 4)
         << std::setw(2) << " " << "</trailer>" << std::endl
         << "</message>";

  return str = stream.str();
}
Пример #3
0
void Message::setString( int direction, const std::string& string,
                         const ValidationRules *validationRules,
                         const DataDictionary* pSessionDataDictionary,
                         const DataDictionary* pApplicationDataDictionary )
throw( Exception )
{
  clear();

  std::string::size_type pos = 0;
  int count = 0;
  std::string msg;

  /*
  static int const headerOrder[] =
  {
    FIELD::BeginString,
    FIELD::BodyLength,
    FIELD::MsgType
  };
  */

  field_type type = header;

  while ( pos < string.size() )
  {
    FieldBase field = extractField( string, pos, pSessionDataDictionary, pApplicationDataDictionary );
    if ( count < 3 &&
         headerOrder[ count++ ] != field.getTag() && 
         !ValidationRules::shouldTolerateOutOfOrderTag(validationRules, OUTGOING_DIRECTION, safeMsgType(), field.getTag() ) 
 )
    {
      //throw InvalidMessage("Header fields out of order.");
      throw TagOutOfOrder( field.getTag() );
    }

    if ( isHeaderField( field, pSessionDataDictionary ) )
    {
      if ( type != header )
      {
        if(m_tag == 0) m_tag = field.getTag();
        m_validStructure = false;
      }

      if ( field.getTag() == FIELD::MsgType )
        msg = field.getString();

      m_header.setField( field, false );

      if ( pSessionDataDictionary )
        setGroup( "_header_", field, string, pos, getHeader(), *pSessionDataDictionary );
    }
    else if ( isTrailerField( field, pSessionDataDictionary ) )
    {
      type = trailer;
      m_trailer.setField( field, false );

      if ( pSessionDataDictionary )
        setGroup( "_trailer_", field, string, pos, getTrailer(), *pSessionDataDictionary );
    }
    else
    {
      if ( type == trailer )
      {
        if(m_tag == 0) m_tag = field.getTag();
        m_validStructure = false;
      }

      type = body;
      setField( field, false );

      if ( pApplicationDataDictionary )
      {
        setGroup( msg, field, string, pos, *this, *pApplicationDataDictionary );
      }
    }
  }

  validate( validationRules );
}