Beispiel #1
0
 public void receiveSaslMechanisms(final SaslMechanisms saslMechanisms) {
   if (Arrays.asList(saslMechanisms.getSaslServerMechanisms()).contains(Symbol.valueOf("PLAIN"))) {
     SaslInit init = new SaslInit();
     init.setMechanism(Symbol.valueOf("PLAIN"));
     init.setHostname(_remoteHostname);
     byte[] usernameBytes = _user.getName().getBytes(Charset.forName("UTF-8"));
     byte[] passwordBytes = _password.getBytes(Charset.forName("UTF-8"));
     byte[] initResponse = new byte[usernameBytes.length + passwordBytes.length + 2];
     System.arraycopy(usernameBytes, 0, initResponse, 1, usernameBytes.length);
     System.arraycopy(
         passwordBytes, 0, initResponse, usernameBytes.length + 2, passwordBytes.length);
     init.setInitialResponse(new Binary(initResponse));
     _saslFrameOutput.send(new SASLFrame(init), null);
   }
 }
Beispiel #2
0
  public void initiateSASL() {
    SaslMechanisms mechanisms = new SaslMechanisms();
    final Enumeration<SaslServerFactory> saslServerFactories = Sasl.getSaslServerFactories();

    SaslServerFactory f;
    ArrayList<Symbol> mechanismsList = new ArrayList<Symbol>();
    while (saslServerFactories.hasMoreElements()) {
      f = saslServerFactories.nextElement();
      final String[] mechanismNames = f.getMechanismNames(null);
      for (String name : mechanismNames) {
        mechanismsList.add(Symbol.valueOf(name));
      }
    }
    mechanisms.setSaslServerMechanisms(mechanismsList.toArray(new Symbol[mechanismsList.size()]));
    _saslFrameOutput.send(new SASLFrame(mechanisms), null);
  }
    @Override
    protected Message originalReceive(long waitTimeInMilliseconds) {
      curOffset++;
      if (isFault || curOffset == receiveFaultOffset) {
        isFault = true;
        throw new RuntimeException("Simulate fault in originalReceive()");
      }

      List<Section> sections = new ArrayList<Section>();
      Map<Object, Object> annotations = new HashMap<Object, Object>();
      annotations.put(Symbol.valueOf(Constants.OffsetKey), "" + curOffset);
      sections.add(new MessageAnnotations(annotations));
      sections.add(new Data(new Binary(("message").getBytes())));

      try {
        Thread.sleep(receiveDelay);
      } catch (InterruptedException e) {
      }

      if (isReceiveNull) {
        return null;
      }
      return new Message(sections);
    }
public class ReceivedConstructor extends DescribedTypeConstructor<Received> {
  private static final Object[] DESCRIPTORS = {
    Symbol.valueOf("amqp:received:list"), UnsignedLong.valueOf(0x0000000000000023L),
  };

  private static final ReceivedConstructor INSTANCE = new ReceivedConstructor();

  public static void register(DescribedTypeConstructorRegistry registry) {
    for (Object descriptor : DESCRIPTORS) {
      registry.register(descriptor, INSTANCE);
    }
  }

  public Received construct(Object underlying) {
    if (underlying instanceof List) {
      List list = (List) underlying;
      Received obj = new Received();
      int position = 0;
      final int size = list.size();

      if (position < size) {
        Object val = list.get(position);
        position++;

        if (val != null) {

          try {
            obj.setSectionNumber((UnsignedInteger) val);
          } catch (ClassCastException e) {

            // TODO Error
          }
        }

      } else {
        return obj;
      }

      if (position < size) {
        Object val = list.get(position);
        position++;

        if (val != null) {

          try {
            obj.setSectionOffset((UnsignedLong) val);
          } catch (ClassCastException e) {

            // TODO Error
          }
        }

      } else {
        return obj;
      }

      return obj;
    } else {
      // TODO - error
      return null;
    }
  }
}
Beispiel #5
0
public class TxnCapability
    implements org.apache.qpid.amqp_1_0.type.TxnCapability, RestrictedType<Symbol> {

  private final Symbol _val;

  public static final TxnCapability LOCAL_TXN =
      new TxnCapability(Symbol.valueOf("amqp:local-transactions"));

  public static final TxnCapability DISTRIBUTED_TXN =
      new TxnCapability(Symbol.valueOf("amqp:distributed-transactions"));

  public static final TxnCapability PROMOTABLE_TXN =
      new TxnCapability(Symbol.valueOf("amqp:promotable-transactions"));

  public static final TxnCapability MULTI_TXNS_PER_SSN =
      new TxnCapability(Symbol.valueOf("amqp:multi-txns-per-ssn"));

  public static final TxnCapability MULTI_SSNS_PER_TXN =
      new TxnCapability(Symbol.valueOf("amqp:multi-ssns-per-txn"));

  private TxnCapability(Symbol val) {
    _val = val;
  }

  public Symbol getValue() {
    return _val;
  }

  public String toString() {

    if (this == LOCAL_TXN) {
      return "local-txn";
    }

    if (this == DISTRIBUTED_TXN) {
      return "distributed-txn";
    }

    if (this == PROMOTABLE_TXN) {
      return "promotable-txn";
    }

    if (this == MULTI_TXNS_PER_SSN) {
      return "multi-txns-per-ssn";
    }

    if (this == MULTI_SSNS_PER_TXN) {
      return "multi-ssns-per-txn";
    } else {
      return String.valueOf(_val);
    }
  }

  public static TxnCapability valueOf(Object obj) {
    Symbol val = (Symbol) obj;

    if (LOCAL_TXN._val.equals(val)) {
      return LOCAL_TXN;
    }

    if (DISTRIBUTED_TXN._val.equals(val)) {
      return DISTRIBUTED_TXN;
    }

    if (PROMOTABLE_TXN._val.equals(val)) {
      return PROMOTABLE_TXN;
    }

    if (MULTI_TXNS_PER_SSN._val.equals(val)) {
      return MULTI_TXNS_PER_SSN;
    }

    if (MULTI_SSNS_PER_TXN._val.equals(val)) {
      return MULTI_SSNS_PER_TXN;
    }

    // TODO ERROR
    return null;
  }
}
Beispiel #6
0
public class OpenConstructor extends DescribedTypeConstructor<Open> {
  private static final Object[] DESCRIPTORS = {
    Symbol.valueOf("amqp:open:list"), UnsignedLong.valueOf(0x0000000000000010L),
  };

  private static final OpenConstructor INSTANCE = new OpenConstructor();

  public static void register(DescribedTypeConstructorRegistry registry) {
    for (Object descriptor : DESCRIPTORS) {
      registry.register(descriptor, INSTANCE);
    }
  }

  public Open construct(Object underlying) {
    if (underlying instanceof List) {
      List list = (List) underlying;
      Open obj = new Open();
      int position = 0;
      final int size = list.size();

      if (position < size) {
        Object val = list.get(position);
        position++;

        if (val != null) {

          try {
            obj.setContainerId((String) val);
          } catch (ClassCastException e) {

            // TODO Error
          }
        }

      } else {
        return obj;
      }

      if (position < size) {
        Object val = list.get(position);
        position++;

        if (val != null) {

          try {
            obj.setHostname((String) val);
          } catch (ClassCastException e) {

            // TODO Error
          }
        }

      } else {
        return obj;
      }

      if (position < size) {
        Object val = list.get(position);
        position++;

        if (val != null) {

          try {
            obj.setMaxFrameSize((UnsignedInteger) val);
          } catch (ClassCastException e) {

            // TODO Error
          }
        }

      } else {
        return obj;
      }

      if (position < size) {
        Object val = list.get(position);
        position++;

        if (val != null) {

          try {
            obj.setChannelMax((UnsignedShort) val);
          } catch (ClassCastException e) {

            // TODO Error
          }
        }

      } else {
        return obj;
      }

      if (position < size) {
        Object val = list.get(position);
        position++;

        if (val != null) {

          try {
            obj.setIdleTimeOut((UnsignedInteger) val);
          } catch (ClassCastException e) {

            // TODO Error
          }
        }

      } else {
        return obj;
      }

      if (position < size) {
        Object val = list.get(position);
        position++;

        if (val != null) {

          if (val instanceof Symbol[]) {
            obj.setOutgoingLocales((Symbol[]) val);
          } else {
            try {
              obj.setOutgoingLocales(new Symbol[] {(Symbol) val});
            } catch (ClassCastException e) {
              // TODO Error
            }
          }
        }

      } else {
        return obj;
      }

      if (position < size) {
        Object val = list.get(position);
        position++;

        if (val != null) {

          if (val instanceof Symbol[]) {
            obj.setIncomingLocales((Symbol[]) val);
          } else {
            try {
              obj.setIncomingLocales(new Symbol[] {(Symbol) val});
            } catch (ClassCastException e) {
              // TODO Error
            }
          }
        }

      } else {
        return obj;
      }

      if (position < size) {
        Object val = list.get(position);
        position++;

        if (val != null) {

          if (val instanceof Symbol[]) {
            obj.setOfferedCapabilities((Symbol[]) val);
          } else {
            try {
              obj.setOfferedCapabilities(new Symbol[] {(Symbol) val});
            } catch (ClassCastException e) {
              // TODO Error
            }
          }
        }

      } else {
        return obj;
      }

      if (position < size) {
        Object val = list.get(position);
        position++;

        if (val != null) {

          if (val instanceof Symbol[]) {
            obj.setDesiredCapabilities((Symbol[]) val);
          } else {
            try {
              obj.setDesiredCapabilities(new Symbol[] {(Symbol) val});
            } catch (ClassCastException e) {
              // TODO Error
            }
          }
        }

      } else {
        return obj;
      }

      if (position < size) {
        Object val = list.get(position);
        position++;

        if (val != null) {

          try {
            obj.setProperties((Map) val);
          } catch (ClassCastException e) {

            // TODO Error
          }
        }

      } else {
        return obj;
      }

      return obj;
    } else {
      // TODO - error
      return null;
    }
  }
}
Beispiel #7
0
public class SourceConstructor extends DescribedTypeConstructor<Source> {
  private static final Object[] DESCRIPTORS = {
    Symbol.valueOf("amqp:source:list"), UnsignedLong.valueOf(0x0000000000000028L),
  };

  private static final SourceConstructor INSTANCE = new SourceConstructor();

  public static void register(DescribedTypeConstructorRegistry registry) {
    for (Object descriptor : DESCRIPTORS) {
      registry.register(descriptor, INSTANCE);
    }
  }

  public Source construct(Object underlying) {
    if (underlying instanceof List) {
      List list = (List) underlying;
      Source obj = new Source();
      int position = 0;
      final int size = list.size();

      if (position < size) {
        Object val = list.get(position);
        position++;

        if (val != null) {

          try {
            obj.setAddress((String) val);
          } catch (ClassCastException e) {

            // TODO Error
          }
        }

      } else {
        return obj;
      }

      if (position < size) {
        Object val = list.get(position);
        position++;

        if (val != null) {

          try {
            obj.setDurable(TerminusDurability.valueOf(val));
          } catch (ClassCastException e) {

            // TODO Error
          }
        }

      } else {
        return obj;
      }

      if (position < size) {
        Object val = list.get(position);
        position++;

        if (val != null) {

          try {
            obj.setExpiryPolicy(TerminusExpiryPolicy.valueOf(val));
          } catch (ClassCastException e) {

            // TODO Error
          }
        }

      } else {
        return obj;
      }

      if (position < size) {
        Object val = list.get(position);
        position++;

        if (val != null) {

          try {
            obj.setTimeout((UnsignedInteger) val);
          } catch (ClassCastException e) {

            // TODO Error
          }
        }

      } else {
        return obj;
      }

      if (position < size) {
        Object val = list.get(position);
        position++;

        if (val != null) {

          try {
            obj.setDynamic((Boolean) val);
          } catch (ClassCastException e) {

            // TODO Error
          }
        }

      } else {
        return obj;
      }

      if (position < size) {
        Object val = list.get(position);
        position++;

        if (val != null) {

          try {
            obj.setDynamicNodeProperties((Map) val);
          } catch (ClassCastException e) {

            // TODO Error
          }
        }

      } else {
        return obj;
      }

      if (position < size) {
        Object val = list.get(position);
        position++;

        if (val != null) {

          try {
            obj.setDistributionMode((DistributionMode) val);
          } catch (ClassCastException e) {

            // TODO Error
          }
        }

      } else {
        return obj;
      }

      if (position < size) {
        Object val = list.get(position);
        position++;

        if (val != null) {

          try {
            obj.setFilter((Map) val);
          } catch (ClassCastException e) {

            // TODO Error
          }
        }

      } else {
        return obj;
      }

      if (position < size) {
        Object val = list.get(position);
        position++;

        if (val != null) {

          try {
            obj.setDefaultOutcome((Outcome) val);
          } catch (ClassCastException e) {

            // TODO Error
          }
        }

      } else {
        return obj;
      }

      if (position < size) {
        Object val = list.get(position);
        position++;

        if (val != null) {

          if (val instanceof Symbol[]) {
            obj.setOutcomes((Symbol[]) val);
          } else {
            try {
              obj.setOutcomes(new Symbol[] {(Symbol) val});
            } catch (ClassCastException e) {
              // TODO Error
            }
          }
        }

      } else {
        return obj;
      }

      if (position < size) {
        Object val = list.get(position);
        position++;

        if (val != null) {

          if (val instanceof Symbol[]) {
            obj.setCapabilities((Symbol[]) val);
          } else {
            try {
              obj.setCapabilities(new Symbol[] {(Symbol) val});
            } catch (ClassCastException e) {
              // TODO Error
            }
          }
        }

      } else {
        return obj;
      }

      return obj;
    } else {
      // TODO - error
      return null;
    }
  }
}