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

    camel snmp problem

    unwired

      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

        • 1. Re: camel snmp problem
          njiang

          I think we can covert the b.getVariable().toString() to XML safe string, so you will not get into trouble of "<", ">" any more.

          I just created a Fuse JIRA for it , please feel free to submit your patch

          • 2. Re: camel snmp problem
            njiang

            I just committed a quick fix for this issue, please check latest Apache Camel 2.2-NAPSHOT or Fuse EIP 2.x-SNAPSHOT for verifying.