@Override
  protected void setUp() throws Exception {
    System.setProperty("brokername", "testbroker");
    brokerService = createBroker();
    broker = brokerService.getBroker();

    // started automatically
    // brokerService.start();

    context = new ConnectionContext();
    context.setBroker(broker);
    info = new ConnectionInfo();
    info.setClientId("James");
    info.setUserName("James");
    info.setConnectionId(new ConnectionId("1234"));

    try {
      broker.addConnection(context, info);
    } catch (Throwable e) {
      e.printStackTrace();
      fail(e.getMessage());
    }

    assertNotNull("No broker created!");
  }
  @Override
  protected void setUp() throws Exception {
    receiveBroker = new StubBroker();

    authBroker = new JaasCertificateAuthenticationBroker(receiveBroker, "");

    connectionContext = new ConnectionContext();
    connectionInfo = new ConnectionInfo();

    connectionInfo.setTransportContext(new StubX509Certificate[] {});
  }
  @Override
  public Response processAddConnection(ConnectionInfo info) throws Exception {
    WireFormatInfo wireFormatInfo = wireFormat.getPreferedWireFormatInfo();
    // Older clients should have been defaulting this field to true.. but
    // they were not.
    if (wireFormatInfo != null && wireFormatInfo.getVersion() <= 2) {
      info.setClientMaster(true);
    }

    state = new ConnectionState(info);

    context = new AMQConnectionContext();

    state.reset(info);

    this.faultTolerantConnection = info.isFaultTolerant();
    // Setup the context.
    String clientId = info.getClientId();
    context.setBroker(protocolManager);
    context.setClientId(clientId);
    context.setClientMaster(info.isClientMaster());
    context.setConnection(this);
    context.setConnectionId(info.getConnectionId());
    // for now we pass the manager as the connector and see what happens
    // it should be related to activemq's Acceptor
    context.setConnector(this.acceptorUsed);
    context.setMessageAuthorizationPolicy(getMessageAuthorizationPolicy());
    context.setNetworkConnection(networkConnection);
    context.setFaultTolerant(faultTolerantConnection);
    context.setTransactions(new ConcurrentHashMap<TransactionId, AMQTransaction>());
    context.setUserName(info.getUserName());
    context.setWireFormatInfo(wireFormatInfo);
    context.setReconnect(info.isFailoverReconnect());
    this.manageable = info.isManageable();
    context.setConnectionState(state);
    if (info.getClientIp() == null) {
      info.setClientIp(getRemoteAddress());
    }

    try {
      protocolManager.addConnection(context, info);
    } catch (Exception e) {
      if (e instanceof SecurityException) {
        // close this down - in case the peer of this transport doesn't play
        // nice
        delayedStop(2000, "Failed with SecurityException: " + e.getLocalizedMessage(), e);
      }
      Response resp = new ExceptionResponse(e);
      return resp;
    }
    if (info.isManageable()) {
      // send ConnectionCommand
      ConnectionControl command = this.acceptorUsed.getConnectionControl();
      command.setFaultTolerant(protocolManager.isFaultTolerantConfiguration());
      if (info.isFailoverReconnect()) {
        command.setRebalanceConnection(false);
      }
      dispatchAsync(command);
    }
    return null;
  }
예제 #4
0
 public ConnectionContext(ConnectionInfo info) {
   this();
   setClientId(info.getClientId());
   setUserName(info.getUserName());
   setConnectionId(info.getConnectionId());
 }