Package com.google.dataconnector.protocol.proto.SdcFrame

Examples of com.google.dataconnector.protocol.proto.SdcFrame.FetchRequest


  @Override
  protected void setUp() throws Exception {
  }
 
  public void testGetFromFrameInfo() throws Exception {
    FetchRequest request = FetchRequest.newBuilder()
      .setId("requestId").setStrategy("HttpClient")
      .setResource("http://www.google.com").build();
   
      String sessionId = UUID.randomUUID().toString();

      SdcKeysManager sm = new SdcKeysManager();
      sm.storeSessionKey(sessionId,
          SessionEncryption.JCE_ALGO, SessionEncryption.newKeyBytes());
   
    FrameInfo frameInfo = FrameInfo.newBuilder()
      .setSessionId(sessionId)
      .setPayload(sm.getSessionEncryption().encrypt(request.toByteString())).build();

    FetchRequestHandler handler = new FetchRequestHandler(
        sm,
        EasyMock.createMock(ThreadPoolExecutor.class),
        EasyMock.createMock(Injector.class),
        EasyMock.createMock(ClockUtil.class));

    FetchRequest parsed = sm.getSessionEncryption().getFrom(frameInfo,
        new SessionEncryption.Parse<FetchRequest>() {
      public FetchRequest parse(ByteString s) throws InvalidProtocolBufferException {
        return FetchRequest.parseFrom(s);
      }
    });
    assertEquals(request, parsed);

      FrameInfo frameInfo2 = FrameInfo.newBuilder()
        .setSessionId(UUID.randomUUID().toString())
        .setPayload(sm.getSessionEncryption().encrypt(request.toByteString())).build();

      FetchRequest parsed2 = sm.getSessionEncryption().getFrom(frameInfo2,
          new SessionEncryption.Parse<FetchRequest>() {
        public FetchRequest parse(ByteString s) throws InvalidProtocolBufferException {
          return FetchRequest.parseFrom(s);
        }
      });
View Full Code Here


      assertTrue(frame.hasSessionId());
      assertEquals(reply.toByteString(), sm.getSessionEncryption().decrypt(frame.getPayload()));
    }

  public void testValidateFetchRequest() throws Exception {
    FetchRequest request = FetchRequest.newBuilder()
     .setId("requestId").setStrategy("HttpClient").setResource("badUrl").build();
   
    FetchRequestHandler handler = new FetchRequestHandler(
            EasyMock.createMock(SdcKeysManager.class),
        EasyMock.createMock(ThreadPoolExecutor.class),
View Full Code Here

  /**
   * Tests processing of response.
   * @throws Exception
   */
  public void testProcess() throws Exception {
    FetchRequest ar = FetchRequest.newBuilder()
        .setId("test1").setStrategy("HttpClient").setResource("http://www.google.com")
        .build();
   
    FetchReply.Builder builder = FetchReply.newBuilder();
   
View Full Code Here

  /**
   * This test requires network + availability. Therefore, it can be unreliable.
   * @throws Exception
   */
  public void testProcessSimple() throws Exception {
    FetchRequest ar = FetchRequest.newBuilder()
      .setId("test1").setStrategy("URLConnection").setResource("http://www.google.com")
      .build();
   
    FetchReply.Builder builder = FetchReply.newBuilder();
   
View Full Code Here

    if (!this.sdcKeysManager.hasSessionEncryption()) {
      LOG.warn("Cannot decrypt message for fetch protocol: no session encryption.");
      return;
    }

    FetchRequest request;
    try {
      request = sdcKeysManager.getSessionEncryption().getFrom(frameInfo,
          new SessionEncryption.Parse<FetchRequest>() {
        public FetchRequest parse(ByteString s) throws InvalidProtocolBufferException {
          return FetchRequest.parseFrom(s);
        }
      });
    } catch (InvalidProtocolBufferException e) {
      throw new FramingException(e);
    }

    if (request == null) {
      return;
    }
    // Now we have the request.  Check the request:
    FetchReply.Builder replyBuilder = FetchReply.newBuilder().setId(request.getId());
    try {
      validate(request);
    } catch (IllegalArgumentException e) {
      logExceptionInReply(request, replyBuilder, e);
      sendReply(replyBuilder.setStatus(StatusCode.BAD_REQUEST.value).build());
      LOG.warn(request.getId() + ": Bad request: " + request, e);
      throw new FramingException(e);
    } catch (MalformedURLException e) {
      logExceptionInReply(request, replyBuilder, e);
      sendReply(replyBuilder.setStatus(StatusCode.BAD_REQUEST.value).build());
      LOG.warn("Bad request: " + request, e);
      throw new FramingException(e);
    }

    // Now execute work asynchronously.
    try {
      StrategyType strategyType = StrategyType.match(request.getStrategy());
      Strategy strategy = injector.getInstance(strategyType.strategyClz);
      ResourceFetcher fetcher = new ResourceFetcher(request, strategy);
      threadPoolExecutor.submit(fetcher);
    } catch (Exception e) {
      LOG.warn(request.getId() + ": Agent error: " + request, e);
      throw new FramingException(e);
    }
  }
View Full Code Here

TOP

Related Classes of com.google.dataconnector.protocol.proto.SdcFrame.FetchRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.