예제 #1
0
 @Override
 public void handleUpstream(final ChannelHandlerContext ctx, final ChannelEvent e)
     throws Exception {
   final MappingHttpRequest request = MappingHttpMessage.extractMessage(e);
   final BaseMessage msg = BaseMessage.extractMessage(e);
   if (msg != null) {
     try {
       final Class<? extends ComponentId> compClass = ComponentMessages.lookup(msg);
       ComponentId compId = ComponentIds.lookup(compClass);
       if (compId.isAlwaysLocal() || Topology.isEnabledLocally(compClass)) {
         ctx.sendUpstream(e);
       } else {
         Handlers.sendRedirect(ctx, e, compClass, request);
       }
     } catch (final NoSuchElementException ex) {
       LOG.warn(
           "Failed to find reverse component mapping for message type: " + msg.getClass());
       ctx.sendUpstream(e);
     } catch (final Exception ex) {
       Logs.extreme().error(ex, ex);
       ctx.sendUpstream(e);
     }
   } else {
     ctx.sendUpstream(e);
   }
 }
  public static ServiceConfiguration findService(final String name) {
    checkParam(name, notNullValue());
    Predicate<ServiceConfiguration> nameOrFullName =
        new Predicate<ServiceConfiguration>() {

          @Override
          public boolean apply(ServiceConfiguration input) {
            return name.equals(input.getName()) || name.equals(input.getFullName().toString());
          }
        };
    for (final ComponentId compId : ComponentIds.list()) {
      ServiceConfiguration a;
      try {
        return Iterables.find(Components.lookup(compId).services(), nameOrFullName);
      } catch (NoSuchElementException ex) {
        if (compId.isRegisterable()) {
          try {
            return ServiceConfigurations.lookupByName(compId.getClass(), name);
          } catch (Exception ex1) {
          }
        }
      }
    }
    throw new NoSuchElementException("Failed to lookup service named: " + name);
  }
예제 #3
0
 private static FilteredPipeline findAccepting(final HttpRequest request) {
   final FilteredPipeline candidate = null;
   for (final FilteredPipeline f : pipelines) {
     if (f.checkAccepts(request)) {
       return f;
     }
   }
   if (request.getHeader(HttpHeaders.Names.HOST).contains("amazonaws.com")
       || request.getHeader(HttpHeaders.Names.HOST).contains(subDomain.get())) {
     String hostHeader = request.getHeader(HttpHeaders.Names.HOST);
     LOG.debug("Trying to intercept request for " + hostHeader);
     for (final FilteredPipeline f : pipelines) {
       if (Ats.from(f).has(ComponentPart.class)) {
         Class<? extends ComponentId> compIdClass = Ats.from(f).get(ComponentPart.class).value();
         ComponentId compId = ComponentIds.lookup(compIdClass);
         if (Ats.from(compIdClass).has(PublicService.class)) {
           if (request.getHeaderNames().contains("SOAPAction")
               && f.addHandlers(Channels.pipeline()).get(SoapHandler.class) == null) {
             continue; // Skip pipeline which doesn't handle SOAP for this SOAP request
           } else if (!request.getHeaderNames().contains("SOAPAction")
               && f.addHandlers(Channels.pipeline()).get(SoapHandler.class) != null) {
             continue; // Skip pipeline which handles SOAP for this non-SOAP request
           }
           LOG.debug("Maybe intercepting: " + hostHeader + " using " + f.getClass());
           if (Ats.from(compIdClass).has(AwsServiceName.class)
               && request
                   .getHeader(HttpHeaders.Names.HOST)
                   .matches(
                       "[\\w\\.-_]*" + compId.getAwsServiceName() + "\\.\\w+\\.amazonaws.com")) {
             return f; // Return pipeline which can handle the request for
                       // ${service}.${region}.amazonaws.com
           } else if (request
               .getHeader(HttpHeaders.Names.HOST)
               .matches("[\\w\\.-_]*" + compId.name() + "\\." + subDomain.get())) {
             return f; // Return pipeline which can handle the request for
                       // ${service}.${system.dns.dnsdomain}
           }
         }
       }
     }
   }
   if (candidate == null) {
     for (final FilteredPipeline f : internalPipelines) {
       if (f.checkAccepts(request)) {
         return f;
       }
     }
   }
   return candidate;
 }
예제 #4
0
    @SuppressWarnings({"rawtypes", "unchecked", "synthetic-access"})
    @Override
    public boolean processClass(final Class candidate) throws Exception {
      if (FilteredPipeline.class.isAssignableFrom(candidate)
          && !Modifier.isAbstract(candidate.getModifiers())
          && !Modifier.isInterface(candidate.getModifiers())
          && Ats.from(candidate).has(ComponentPart.class)) {
        try {
          final ComponentId compId =
              Ats.from(candidate).get(ComponentPart.class).value().newInstance();
          final Class<? extends FilteredPipeline> pipelineClass = candidate;
          final FilteredPipeline pipeline = Classes.newInstance(pipelineClass);
          Pipelines.pipelines.add(pipeline);
          return true;
        } catch (final Exception ex) {
          LOG.trace(ex, ex);
          return false;
        }
      } else if (ChannelPipelineFactory.class.isAssignableFrom(candidate)
          && !Modifier.isAbstract(candidate.getModifiers())
          && !Modifier.isInterface(candidate.getModifiers())
          && Ats.from(candidate).has(ComponentPart.class)) {
        try {
          final ComponentId compId =
              Ats.from(candidate).get(ComponentPart.class).value().newInstance();
          final Class<? extends ChannelPipelineFactory> pipelineClass = candidate;
          final ChannelPipelineFactory pipeline = Classes.newInstance(pipelineClass);
          Pipelines.clientPipelines.put(compId.getClass(), pipeline);
          return true;
        } catch (final Exception ex) {
          LOG.trace(ex, ex);
          return false;
        }

      } else {
        return false;
      }
    }
예제 #5
0
 public InternalQueryPipeline(final ComponentId componentId) {
   super(componentId);
   this.servicePath = componentId.getServicePath();
   this.internalServicePath = componentId.getInternalServicePath();
   this.serviceName = componentId.getFullName().toString();
 }