示例#1
0
  @Override
  public void unsubscribe(
      InputTransportAdaptorMessageConfiguration inputTransportMessageConfiguration,
      InputTransportAdaptorConfiguration inputTransportAdaptorConfiguration,
      AxisConfiguration axisConfiguration,
      String subscriptionId) {

    try {
      Axis2Util.removeOperation(
          inputTransportMessageConfiguration,
          inputTransportAdaptorConfiguration,
          axisConfiguration,
          subscriptionId);
    } catch (AxisFault axisFault) {
      throw new InputTransportAdaptorEventProcessingException(
          "Can not unsubscribe from the ws broker", axisFault);
    }

    Map<String, String> localSubscriptionIdSubscriptionsMap =
        this.adaptorSubscriptionsMap.get(inputTransportAdaptorConfiguration.getName());
    if (localSubscriptionIdSubscriptionsMap == null) {
      throw new InputTransportAdaptorEventProcessingException(
          "There is no subscription for broker " + inputTransportAdaptorConfiguration.getName());
    }

    String topicName =
        inputTransportMessageConfiguration
            .getInputMessageProperties()
            .get(WSEventTransportAdaptorConstants.TRANSPORT_MESSAGE_TOPIC_NAME);

    String subscriptionID = localSubscriptionIdSubscriptionsMap.remove(subscriptionId);
    if (subscriptionID == null) {
      throw new InputTransportAdaptorEventProcessingException(
          "There is no subscriptions for this topic" + topicName);
    }

    try {
      Map<String, String> properties = inputTransportAdaptorConfiguration.getInputProperties();
      ConfigurationContextService configurationContextService =
          WSEventTransportAdaptorServiceValueHolder.getConfigurationContextService();
      BrokerClient brokerClient =
          new BrokerClient(
              configurationContextService.getClientConfigContext(),
              properties.get(WSEventTransportAdaptorConstants.TRANSPORT_CONF_WSEVENT_URI),
              properties.get(WSEventTransportAdaptorConstants.TRANSPORT_CONF_WSEVENT_USERNAME),
              properties.get(WSEventTransportAdaptorConstants.TRANSPORT_CONF_WSEVENT_PASSWORD));
      brokerClient.unsubscribe(subscriptionID);
    } catch (AuthenticationExceptionException e) {
      throw new InputTransportAdaptorEventProcessingException(
          "Can not authenticate the ws broker, hence not un subscribing from the broker", e);
    } catch (RemoteException e) {
      throw new InputTransportAdaptorEventProcessingException(
          "Can not connect to the server, hence not un subscribing from the broker", e);
    }
  }
示例#2
0
  @Override
  public String subscribe(
      InputTransportAdaptorMessageConfiguration inputTransportMessageConfiguration,
      InputTransportAdaptorListener inputTransportAdaptorListener,
      InputTransportAdaptorConfiguration inputTransportAdaptorConfiguration,
      AxisConfiguration axisConfiguration) {

    inputTransportAdaptorListener.setStatisticsEnabled(
        inputTransportAdaptorConfiguration.isEnableStatistics());
    inputTransportAdaptorListener.setTraceEnabled(
        inputTransportAdaptorConfiguration.isEnableTracing());
    inputTransportAdaptorListener.setTransportAdaptorName(
        inputTransportAdaptorConfiguration.getName());

    String subscriptionId = UUID.randomUUID().toString();
    try {
      AxisService axisService =
          Axis2Util.registerAxis2Service(
              inputTransportMessageConfiguration,
              inputTransportAdaptorListener,
              inputTransportAdaptorConfiguration,
              axisConfiguration,
              subscriptionId);

      String httpEpr = null;
      for (String epr : axisService.getEPRs()) {
        if (epr.startsWith("http")) {
          httpEpr = epr;
          break;
        }
      }

      if (httpEpr != null && !httpEpr.endsWith("/")) {
        httpEpr += "/";
      }

      String topicName =
          inputTransportMessageConfiguration
              .getInputMessageProperties()
              .get(WSEventTransportAdaptorConstants.TRANSPORT_MESSAGE_TOPIC_NAME);
      httpEpr += topicName.replaceAll("/", "");

      Map<String, String> properties = inputTransportAdaptorConfiguration.getInputProperties();
      BrokerClient brokerClient =
          new BrokerClient(
              properties.get(WSEventTransportAdaptorConstants.TRANSPORT_CONF_WSEVENT_URI),
              properties.get(WSEventTransportAdaptorConstants.TRANSPORT_CONF_WSEVENT_USERNAME),
              properties.get(WSEventTransportAdaptorConstants.TRANSPORT_CONF_WSEVENT_PASSWORD));
      brokerClient.subscribe(topicName, httpEpr);

      String subscriptionID = brokerClient.subscribe(topicName, httpEpr);

      // keep the subscription id to unsubscribe
      Map<String, String> localSubscriptionIdSubscriptionsMap =
          this.adaptorSubscriptionsMap.get(inputTransportAdaptorConfiguration.getName());
      if (localSubscriptionIdSubscriptionsMap == null) {
        localSubscriptionIdSubscriptionsMap = new ConcurrentHashMap<String, String>();
        this.adaptorSubscriptionsMap.put(
            inputTransportAdaptorConfiguration.getName(), localSubscriptionIdSubscriptionsMap);
      }

      localSubscriptionIdSubscriptionsMap.put(subscriptionId, subscriptionID);
      return subscriptionId;

    } catch (BrokerClientException e) {
      throw new InputTransportAdaptorEventProcessingException(
          "Can not create the adaptor client", e);
    } catch (AuthenticationExceptionException e) {
      throw new InputTransportAdaptorEventProcessingException(
          "Can not authenticate the adaptor client", e);
    } catch (AxisFault axisFault) {
      throw new InputTransportAdaptorEventProcessingException("Can not subscribe", axisFault);
    }
  }