當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。