org.apache.hadoop.yarn.webapp.WebAppException Java Examples

The following examples show how to use org.apache.hadoop.yarn.webapp.WebAppException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HamletImpl.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * Parse selector into id and classes
 * @param selector in the form of (#id)?(.class)*
 * @return an two element array [id, "space-separated classes"].
 *         Either element could be null.
 * @throws WebAppException when both are null or syntax error.
 */
public static String[] parseSelector(String selector) {
  String[] result = new String[]{null, null};
  Iterable<String> rs = SS.split(selector);
  Iterator<String> it = rs.iterator();
  if (it.hasNext()) {
    String maybeId = it.next();
    if (maybeId.charAt(0) == '#') {
      result[S_ID] = maybeId.substring(1);
      if (it.hasNext()) {
        result[S_CLASS] = SJ.join(Iterables.skip(rs, 1));
      }
    } else {
      result[S_CLASS] = SJ.join(rs);
    }
    return result;
  }
  throw new WebAppException("Error parsing selector: "+ selector);
}
 
Example #2
Source File: HamletImpl.java    From big-c with Apache License 2.0 6 votes vote down vote up
/**
 * Parse selector into id and classes
 * @param selector in the form of (#id)?(.class)*
 * @return an two element array [id, "space-separated classes"].
 *         Either element could be null.
 * @throws WebAppException when both are null or syntax error.
 */
public static String[] parseSelector(String selector) {
  String[] result = new String[]{null, null};
  Iterable<String> rs = SS.split(selector);
  Iterator<String> it = rs.iterator();
  if (it.hasNext()) {
    String maybeId = it.next();
    if (maybeId.charAt(0) == '#') {
      result[S_ID] = maybeId.substring(1);
      if (it.hasNext()) {
        result[S_CLASS] = SJ.join(Iterables.skip(rs, 1));
      }
    } else {
      result[S_CLASS] = SJ.join(rs);
    }
    return result;
  }
  throw new WebAppException("Error parsing selector: "+ selector);
}
 
Example #3
Source File: HtmlPage.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void render() {
  puts(DOCTYPE);
  render(page().html().meta_http("X-UA-Compatible", "IE=8")
      .meta_http("Content-type", MimeType.HTML));
  if (page().nestLevel() != 0) {
    throw new WebAppException("Error rendering page: nestLevel="+
                              page().nestLevel());
  }
}
 
Example #4
Source File: AMWebController.java    From tez with Apache License 2.0 5 votes vote down vote up
void sendErrorResponse(int sc, String msg, Exception e) {
  if (LOG.isDebugEnabled()) {
    LOG.debug(msg, e);
  }

  try {
    response().sendError(sc, msg);
  } catch (IOException e1) {
    throw new WebAppException(e);
  }
}
 
Example #5
Source File: WebAppTests.java    From big-c with Apache License 2.0 5 votes vote down vote up
public static <T> Injector testController(Class<? extends Controller> ctrlr,
    String methodName, Class<T> api, T impl, Module... modules) {
  try {
    Injector injector = createMockInjector(api, impl, modules);
    Method method = ctrlr.getMethod(methodName, (Class<?>[])null);
    method.invoke(injector.getInstance(ctrlr), (Object[])null);
    return injector;
  } catch (Exception e) {
    throw new WebAppException(e);
  }
}
 
Example #6
Source File: HtmlBlock.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void render() {
  int nestLevel = context().nestLevel();
  LOG.debug("Rendering {} @{}", getClass(), nestLevel);
  render(block());
  if (block.nestLevel() != nestLevel) {
    throw new WebAppException("Error rendering block: nestLevel="+
                              block.nestLevel() +" expected "+ nestLevel);
  }
  context().set(nestLevel, block.wasInline());
}
 
Example #7
Source File: HtmlPage.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void render() {
  puts(DOCTYPE);
  render(page().html().meta_http("X-UA-Compatible", "IE=8")
      .meta_http("Content-type", MimeType.HTML));
  if (page().nestLevel() != 0) {
    throw new WebAppException("Error rendering page: nestLevel="+
                              page().nestLevel());
  }
}
 
Example #8
Source File: WebAppTests.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public static <T> Injector testController(Class<? extends Controller> ctrlr,
    String methodName, Class<T> api, T impl, Module... modules) {
  try {
    Injector injector = createMockInjector(api, impl, modules);
    Method method = ctrlr.getMethod(methodName, (Class<?>[])null);
    method.invoke(injector.getInstance(ctrlr), (Object[])null);
    return injector;
  } catch (Exception e) {
    throw new WebAppException(e);
  }
}
 
Example #9
Source File: HtmlBlock.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public void render() {
  int nestLevel = context().nestLevel();
  LOG.debug("Rendering {} @{}", getClass(), nestLevel);
  render(block());
  if (block.nestLevel() != nestLevel) {
    throw new WebAppException("Error rendering block: nestLevel="+
                              block.nestLevel() +" expected "+ nestLevel);
  }
  context().set(nestLevel, block.wasInline());
}
 
Example #10
Source File: WebAppTests.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * Create a mock injector for tests
 * @param <T> type of class/interface
 * @param api the interface class of the object to inject
 * @param impl the implementation object to inject
 * @param modules additional guice modules
 * @return an injector
 */
public static <T> Injector createMockInjector(final Class<T> api,
                                              final T impl,
                                              final Module... modules) {
  return Guice.createInjector(new AbstractModule() {
    final PrintWriter writer = spy(new PrintWriter(System.out));
    final HttpServletRequest request = createRequest();
    final HttpServletResponse response = createResponse();

    @Override
    protected void configure() {
      if (api != null) {
        bind(api).toInstance(impl);
      }
      bindScope(RequestScoped.class, Scopes.SINGLETON);
      if (modules != null) {
        for (Module module : modules) {
          install(module);
        }
      }
    }

    @Provides HttpServletRequest request() {
      return request;
    }

    @Provides HttpServletResponse response() {
      return response;
    }

    @Provides PrintWriter writer() {
      return writer;
    }

    HttpServletRequest createRequest() {
      // the default suffices for now
      return mock(HttpServletRequest.class);
    }

    HttpServletResponse createResponse() {
      try {
        HttpServletResponse res = mock(HttpServletResponse.class);
        when(res.getWriter()).thenReturn(writer);
        return res;
      } catch (Exception e) {
        throw new WebAppException(e);
      }
    }
  });
}
 
Example #11
Source File: TestParseRoute.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Test(expected=WebAppException.class) public void testMissingLeadingSlash() {
  WebApp.parseRoute("foo/bar");
}
 
Example #12
Source File: TestParseSelector.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Test(expected=WebAppException.class) public void testMissingAll() {
  parseSelector("");
}
 
Example #13
Source File: TestHtmlPage.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Test(expected=WebAppException.class) public void testShort() {
  WebAppTests.testPage(ShortView.class);
}
 
Example #14
Source File: TestHtmlBlock.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Test(expected=WebAppException.class) public void testShortPage() {
  WebAppTests.testPage(ShortPage.class);
}
 
Example #15
Source File: HamletGen.java    From big-c with Apache License 2.0 4 votes vote down vote up
static void throwUnhandled(String className, Method method) {
  throw new WebAppException("Unhandled " + className + "#" + method);
}
 
Example #16
Source File: TestHtmlBlock.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Test(expected=WebAppException.class) public void testShortBlock() {
  WebAppTests.testBlock(ShortBlock.class);
}
 
Example #17
Source File: TestHtmlBlock.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Test(expected=WebAppException.class) public void testShortBlock() {
  WebAppTests.testBlock(ShortBlock.class);
}
 
Example #18
Source File: TestHtmlBlock.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Test(expected=WebAppException.class) public void testShortPage() {
  WebAppTests.testPage(ShortPage.class);
}
 
Example #19
Source File: TestHtmlPage.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Test(expected=WebAppException.class) public void testShort() {
  WebAppTests.testPage(ShortView.class);
}
 
Example #20
Source File: TestParseRoute.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Test(expected=WebAppException.class) public void testMissingLeadingSlash() {
  WebApp.parseRoute("foo/bar");
}
 
Example #21
Source File: WebAppTests.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * Create a mock injector for tests
 * @param <T> type of class/interface
 * @param api the interface class of the object to inject
 * @param impl the implementation object to inject
 * @param modules additional guice modules
 * @return an injector
 */
public static <T> Injector createMockInjector(final Class<T> api,
                                              final T impl,
                                              final Module... modules) {
  return Guice.createInjector(new AbstractModule() {
    final PrintWriter writer = spy(new PrintWriter(System.out));
    final HttpServletRequest request = createRequest();
    final HttpServletResponse response = createResponse();

    @Override
    protected void configure() {
      if (api != null) {
        bind(api).toInstance(impl);
      }
      bindScope(RequestScoped.class, Scopes.SINGLETON);
      if (modules != null) {
        for (Module module : modules) {
          install(module);
        }
      }
    }

    @Provides HttpServletRequest request() {
      return request;
    }

    @Provides HttpServletResponse response() {
      return response;
    }

    @Provides PrintWriter writer() {
      return writer;
    }

    HttpServletRequest createRequest() {
      // the default suffices for now
      return mock(HttpServletRequest.class);
    }

    HttpServletResponse createResponse() {
      try {
        HttpServletResponse res = mock(HttpServletResponse.class);
        when(res.getWriter()).thenReturn(writer);
        return res;
      } catch (Exception e) {
        throw new WebAppException(e);
      }
    }
  });
}
 
Example #22
Source File: HamletGen.java    From hadoop with Apache License 2.0 4 votes vote down vote up
static void throwUnhandled(String className, Method method) {
  throw new WebAppException("Unhandled " + className + "#" + method);
}
 
Example #23
Source File: TestParseSelector.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Test(expected=WebAppException.class) public void testMissingAll() {
  parseSelector("");
}