本文整理汇总了Java中javax.servlet.http.HttpServlet.service方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServlet.service方法的具体用法?Java HttpServlet.service怎么用?Java HttpServlet.service使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.servlet.http.HttpServlet
的用法示例。
在下文中一共展示了HttpServlet.service方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: service
import javax.servlet.http.HttpServlet; //导入方法依赖的package包/类
/**
* Bridge for Felix DispatcherServlet, delegate all the calls to underlying DispatcherServlet.
*
* @see class header for detailed description.
*/
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) {
HttpServlet dispatcherServlet = ServiceTrackers.INSTANCE.getDispatcherServlet();
try {
if (dispatcherServlet == null) {
LOGGER.error(UNAVAILABLE_MSG, req.getRequestURI());
ResponseUtil.sendError(resp, SC_SERVICE_UNAVAILABLE);
} else {
dispatcherServlet.service(req, resp);
// Check if [javax.servlet.error.exception] set by [Felix Dispatcher]
if (RequestUtil.hasException(req)) {
LOGGER.error("Exception set by Felix Dispatcher!!", RequestUtil.getAttribute(req, ERROR_EXCEPTION));
}
}
} catch (Exception ex) { // NOSONAR
LOGGER.error("Exception while handling request: [{}]", req.getRequestURI(), ex);
ResponseUtil.sendError(resp, SC_INTERNAL_SERVER_ERROR);
}
}
示例2: doMethod
import javax.servlet.http.HttpServlet; //导入方法依赖的package包/类
private HttpServletResponse doMethod(String method, HttpServlet servlet) throws Exception {
when(request.getMethod()).thenReturn(method);
servlet.service(request, response);
writer.flush();
return response;
}
示例3: dispatch
import javax.servlet.http.HttpServlet; //导入方法依赖的package包/类
@SuppressWarnings("nls")
public FilterResult dispatch(HttpServletRequest httpRequest, HttpServletResponse httpResponse)
throws ServletException, IOException
{
String servletPath = httpRequest.getServletPath();
MultiMatcher mappings = ensureMappings();
ResolvedServlet resolved = mappings.matchPath(servletPath);
if( resolved != null )
{
Extension ext = resolved.getExtension();
HttpServlet servlet;
synchronized( ext )
{
servlet = servletTracker.getBeanByExtension(ext);
if( !initedServlets.contains(ext) )
{
initedServlets.add(ext);
Collection<Parameter> initParams = ext.getParameters("init-param");
servlet.init(new DummyServletConfig(context, initParams, servlet.getClass().getName()));
}
}
HttpServletRequest wrappedRequest = RemappedRequest.wrap(httpRequest, httpRequest.getContextPath(),
resolved.getServletPath(), resolved.getPathInfo());
try
{
servlet.service(wrappedRequest, httpResponse);
httpResponse.flushBuffer();
}
catch( SocketException se )
{
// What are you going to do?
}
return new FilterResult(wrappedRequest);
}
return null;
}
示例4: testAsyn
import javax.servlet.http.HttpServlet; //导入方法依赖的package包/类
@Test
public void testAsyn() throws ServletException, IOException {
HttpServlet servlet = new AnnotatedServlet_for_testAsyn();
EvoServletState.initServlet(servlet);
boolean supported = EvoServletState.getRequest().isAsyncSupported();
Assert.assertTrue(supported);
servlet.service(EvoServletState.getRequest(), EvoServletState.getResponse());
String body = EvoServletState.getResponse().getBody();
Assert.assertEquals("foo", body);
}
示例5: handleRequest
import javax.servlet.http.HttpServlet; //导入方法依赖的package包/类
@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpServlet dispatcher = this.tracker.getDispatcher();
if (dispatcher != null) {
dispatcher.service(request, response);
} else {
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
}
}
示例6: testServlet
import javax.servlet.http.HttpServlet; //导入方法依赖的package包/类
@Test
public void testServlet() throws Exception {
HttpServlet servlet = new AbstractAuthHttpServlet() {
@Override
protected SSOService getSsoService() {
return null;
}
};
HttpServletRequest req = Mockito.mock(HttpServletRequest.class);
HttpServletResponse res = Mockito.mock(HttpServletResponse.class);
Mockito.when(req.getMethod()).thenReturn("HEAD");
servlet.service(req, res);
Mockito.verify(res, Mockito.times(1)).sendError(Mockito.eq(HttpServletResponse.SC_METHOD_NOT_ALLOWED));
Mockito.when(req.getMethod()).thenReturn("OPTIONS");
Mockito.reset(res);
servlet.service(req, res);
Mockito.verify(res, Mockito.times(1)).sendError(Mockito.eq(HttpServletResponse.SC_METHOD_NOT_ALLOWED));
Mockito.when(req.getMethod()).thenReturn("PUT");
Mockito.reset(res);
servlet.service(req, res);
Mockito.verify(res, Mockito.times(1)).sendError(Mockito.eq(HttpServletResponse.SC_METHOD_NOT_ALLOWED));
Mockito.when(req.getMethod()).thenReturn("POST");
Mockito.reset(res);
servlet.service(req, res);
Mockito.verify(res, Mockito.times(1)).sendError(Mockito.eq(HttpServletResponse.SC_METHOD_NOT_ALLOWED));
Mockito.when(req.getMethod()).thenReturn("DELETE");
Mockito.reset(res);
servlet.service(req, res);
Mockito.verify(res, Mockito.times(1)).sendError(Mockito.eq(HttpServletResponse.SC_METHOD_NOT_ALLOWED));
Mockito.when(req.getMethod()).thenReturn("TRACE");
Mockito.reset(res);
Mockito.when(req.getHeader(Mockito.eq(SSOConstants.X_REST_CALL))).thenReturn("rest-call");
servlet.service(req, res);
Mockito.verify(res, Mockito.times(1)).sendError(Mockito.eq(HttpServletResponse.SC_METHOD_NOT_ALLOWED));
}