public Object intercept(Invocation invocation) throws Exception {
   try {
     logger.info("{} starting", invocation.getPath());
     return invocation.invoke();
   } catch (Exception e) {
     logger.error("{} exception thrown", invocation.getPath(), e);
     throw e;
   } finally {
     logger.info("{} completed", invocation.getPath());
   }
 }
  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);
    }
  }
 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(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(method, beanFactory, streamFactory, new ArrayList<Step>(steps));
         request.setServerHeader(response.getServerHeader());
         request.setProperties(response.getProperties());
         request.setResult(response.getResult());
         break;
       }
     default:
       throw new RemoteMethodException(
           channel.getStatus().getCode(),
           channel.getStatus().getMessage(),
           IOToolkit.toString(channel));
   }
 }
 public Object intercept(Invocation invocation) throws Exception {
   try {
     Session session = sessionFactory.openSession();
     session.setFlushMode(FlushMode.MANUAL);
     SessionHolder sessionHolder = new SessionHolder(session);
     TransactionSynchronizationManager.bindResource(sessionFactory, sessionHolder);
     return invocation.invoke();
   } catch (Exception e) {
     throw e;
   } finally {
     SessionHolder sessionHolder =
         (SessionHolder) TransactionSynchronizationManager.unbindResource(sessionFactory);
     sessionHolder.getSession().close();
   }
 }
  public Object invoke(Object proxy, Method method, Object[] arguments) throws Throwable {
    if (!Pigeons.isOpenableMethod(method)) {
      // 如果是 Object 的方法 那么可以直接调用不会通过网络进行远程调用
      if (method.getDeclaringClass() == Object.class) {
        return method.invoke(this, arguments);
      }
      throw new NonopenMethodException(interfase, method, arguments);
    }
    try {
      String x = Pigeons.getOpenPath(implementation);
      String y = Pigeons.getOpenPath(interfase);
      String z = Pigeons.getOpenPath(method);

      String path = Pigeons.getOpenPath(x + y + z);

      Header header = new Header();
      header.setContentType(format);
      header.setCharset(client.getCharset());
      header.setConnection("closed");
      header.setHost(host + (port == 80 ? "" : ":" + port));
      header.setPragma("no-cache");
      header.setCacheControl("no-cache");
      header.setUserAgent(
          Version.getCurrent().getName()
              + "/"
              + Version.getCurrent().getCode()
              + "["
              + System.getProperty("user.language")
              + "]"
              + "("
              + System.getProperty("os.name")
              + " "
              + System.getProperty("os.version")
              + ")");

      Invocation invocation = new Invocation();
      invocation.setClientHeader(header);
      invocation.setHost(host);
      invocation.setPort(port);
      invocation.setPath(path);
      invocation.setInterfase(interfase);
      invocation.setMethod(method);
      invocation.setImplementation(this);
      invocation.setArguments(arguments);
      invocation.setInterceptors(interceptors.iterator());

      return invocation.invoke();
    } catch (Throwable e) {
      throw e instanceof IOException ? (IOException) e : new IOException(e);
    }
  }