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

The following examples show how to use org.apache.hadoop.yarn.webapp.WebAppException. These examples are extracted from open source projects. 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 Project: hadoop   Source File: HamletImpl.java    License: 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 Project: big-c   Source File: HamletImpl.java    License: 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 Project: hadoop   Source File: HtmlPage.java    License: 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 Project: hadoop   Source File: HtmlBlock.java    License: 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 5
Source Project: hadoop   Source File: WebAppTests.java    License: 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 Project: big-c   Source File: HtmlPage.java    License: 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 7
Source Project: big-c   Source File: HtmlBlock.java    License: 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 8
Source Project: big-c   Source File: WebAppTests.java    License: 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 Project: tez   Source File: AMWebController.java    License: 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 10
Source Project: hadoop   Source File: HamletGen.java    License: Apache License 2.0 4 votes vote down vote up
static void throwUnhandled(String className, Method method) {
  throw new WebAppException("Unhandled " + className + "#" + method);
}
 
Example 11
Source Project: hadoop   Source File: TestHtmlBlock.java    License: Apache License 2.0 4 votes vote down vote up
@Test(expected=WebAppException.class) public void testShortBlock() {
  WebAppTests.testBlock(ShortBlock.class);
}
 
Example 12
Source Project: hadoop   Source File: TestHtmlBlock.java    License: Apache License 2.0 4 votes vote down vote up
@Test(expected=WebAppException.class) public void testShortPage() {
  WebAppTests.testPage(ShortPage.class);
}
 
Example 13
Source Project: hadoop   Source File: TestHtmlPage.java    License: Apache License 2.0 4 votes vote down vote up
@Test(expected=WebAppException.class) public void testShort() {
  WebAppTests.testPage(ShortView.class);
}
 
Example 14
Source Project: hadoop   Source File: TestParseRoute.java    License: Apache License 2.0 4 votes vote down vote up
@Test(expected=WebAppException.class) public void testMissingLeadingSlash() {
  WebApp.parseRoute("foo/bar");
}
 
Example 15
Source Project: hadoop   Source File: WebAppTests.java    License: 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 16
Source Project: hadoop   Source File: TestParseSelector.java    License: Apache License 2.0 4 votes vote down vote up
@Test(expected=WebAppException.class) public void testMissingAll() {
  parseSelector("");
}
 
Example 17
Source Project: big-c   Source File: HamletGen.java    License: Apache License 2.0 4 votes vote down vote up
static void throwUnhandled(String className, Method method) {
  throw new WebAppException("Unhandled " + className + "#" + method);
}
 
Example 18
Source Project: big-c   Source File: TestHtmlBlock.java    License: Apache License 2.0 4 votes vote down vote up
@Test(expected=WebAppException.class) public void testShortBlock() {
  WebAppTests.testBlock(ShortBlock.class);
}
 
Example 19
Source Project: big-c   Source File: TestHtmlBlock.java    License: Apache License 2.0 4 votes vote down vote up
@Test(expected=WebAppException.class) public void testShortPage() {
  WebAppTests.testPage(ShortPage.class);
}
 
Example 20
Source Project: big-c   Source File: TestHtmlPage.java    License: Apache License 2.0 4 votes vote down vote up
@Test(expected=WebAppException.class) public void testShort() {
  WebAppTests.testPage(ShortView.class);
}
 
Example 21
Source Project: big-c   Source File: TestParseRoute.java    License: Apache License 2.0 4 votes vote down vote up
@Test(expected=WebAppException.class) public void testMissingLeadingSlash() {
  WebApp.parseRoute("foo/bar");
}
 
Example 22
Source Project: big-c   Source File: WebAppTests.java    License: 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 23
Source Project: big-c   Source File: TestParseSelector.java    License: Apache License 2.0 4 votes vote down vote up
@Test(expected=WebAppException.class) public void testMissingAll() {
  parseSelector("");
}