当前位置: 首页>>代码示例>>Java>>正文


Java HttpServlet.service方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:AdeptJ,项目名称:adeptj-runtime,代码行数:25,代码来源:BridgeServlet.java

示例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;
}
 
开发者ID:dstl,项目名称:baleen,代码行数:7,代码来源:ServletCaller.java

示例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;
}
 
开发者ID:equella,项目名称:Equella,代码行数:39,代码来源:ServletDispatcher.java

示例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);
}
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:14,代码来源:HttpServletTest.java

示例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);
    }
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:10,代码来源:OsgiHttpServiceProxyRequestHandler.java

示例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));
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:43,代码来源:TestAbstractAuthHttpServlet.java


注:本文中的javax.servlet.http.HttpServlet.service方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。