2 Replies Latest reply on Jan 15, 2010 1:44 AM by Willem Jiang

    camel snmp problem

    unwired unwired Newbie

      Using Camel 2.1.0

       

      I have a simple route

       

      from("snmp:192.168.1.4:162?protocol=udp&type=TRAP").convertBodyTo(String.class).to("bean:snmpprocessor");

       

      snmpprocessor takes the XML generated and parses it.  This route fails occasionally whenever there are < or > in any of the traps.

       

      I looked up the source and SnmpConverters toString() method needs to escape any XML characters otherwise the output from convertBodyTo(String.class) ends up having XML which cannot be parsed.

       

      The line below  sb.append(b.getVariable().toString());

      needs to be escaped since the variable may contain XML special characters.

       

      @Converter
          public static String toString(PDU pdu) {
           // the output buffer
              StringBuffer sb = new StringBuffer();
              
              // prepare the header
              sb.append(SNMP_TAG_OPEN);
                      
              // now loop all variables of the response
              for (Object o : pdu.getVariableBindings()) {
                  VariableBinding b = (VariableBinding)o;
      
                  sb.append(ENTRY_TAG_OPEN);
                  sb.append(OID_TAG_OPEN);
                  sb.append(b.getOid().toString());
                  sb.append(OID_TAG_CLOSE);
                  sb.append(VALUE_TAG_OPEN);
                  sb.append(b.getVariable().toString());
                  sb.append(VALUE_TAG_CLOSE);
                  sb.append(ENTRY_TAG_CLOSE);
              }
              
              // prepare the footer
              sb.append(SNMP_TAG_CLOSE);
              
              return sb.toString();
          }
      
      

       

      Thanks