Exemplo n.º 1
0
  public Object intercept(Invocation invocation) throws Exception {
    Channel channel = null;
    try {
      channel = beanFactory.establish(protocol, Channel.class);
      channel.initialize(host, port, invocation.getPath(), timeout, format);

      channel.getAttributes().putAll(client.getAttributes());
      channel.addAttribute(CHANNEL_INVOCATION_ATTRIBUTE_KEY, invocation);

      Set<Filter<Channel>> _filters = new LinkedHashSet<Filter<Channel>>();
      _filters.add(this);
      new FixedFilterChain<Channel>(_filters).go(channel);

      return invocation.getResult();
    } catch (Exception e) {
      throw e;
    } finally {
      IOToolkit.close(channel);
    }
  }
Exemplo n.º 2
0
 public void filtrate(Channel channel, FilterChain<Channel> chain) throws Exception {
   Invocation request = (Invocation) channel.getAttribute(CHANNEL_INVOCATION_ATTRIBUTE_KEY);
   Collection<Step> steps = processings.get(request.getMethod()).values();
   channel.send(null, request, beanFactory, streamFactory, new ArrayList<Step>(steps));
   State status = channel.getStatus();
   switch (status.getCode()) {
     case HttpURLConnection.HTTP_OK:
       {
         Method method = correspondences.get(request.getMethod());
         Invocation response =
             channel.receive(null, method, beanFactory, streamFactory, new ArrayList<Step>(steps));
         request.setServerHeader(response.getServerHeader());
         request.setResult(response.getResult());
         break;
       }
     default:
       throw new RemoteMethodException(
           channel.getStatus().getCode(),
           channel.getStatus().getMessage(),
           IOToolkit.toString(channel));
   }
 }