當前位置: 首頁>>代碼示例>>Java>>正文


Java DispatcherServlet.service方法代碼示例

本文整理匯總了Java中org.springframework.web.servlet.DispatcherServlet.service方法的典型用法代碼示例。如果您正苦於以下問題:Java DispatcherServlet.service方法的具體用法?Java DispatcherServlet.service怎麽用?Java DispatcherServlet.service使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.web.servlet.DispatcherServlet的用法示例。


在下文中一共展示了DispatcherServlet.service方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doubles

import org.springframework.web.servlet.DispatcherServlet; //導入方法依賴的package包/類
@Test
@SuppressWarnings("serial")
public void doubles() throws Exception {
	servlet = new DispatcherServlet() {
		@Override
		protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent)
				throws BeansException {
			GenericWebApplicationContext wac = new GenericWebApplicationContext();
			wac.registerBeanDefinition("controller", new RootBeanDefinition(DoubleController.class));
			RootBeanDefinition mappingDef = new RootBeanDefinition(DefaultAnnotationHandlerMapping.class);
			mappingDef.getPropertyValues().add("useDefaultSuffixPattern", false);
			wac.registerBeanDefinition("handlerMapping", mappingDef);
			wac.refresh();
			return wac;
		}
	};
	servlet.init(new MockServletConfig());

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/lat/1.2/long/3.4");
	MockHttpServletResponse response = new MockHttpServletResponse();
	servlet.service(request, response);

	assertEquals("latitude-1.2-longitude-3.4", response.getContentAsString());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:25,代碼來源:UriTemplateServletAnnotationControllerTests.java

示例2: suppressDefaultSuffixPattern

import org.springframework.web.servlet.DispatcherServlet; //導入方法依賴的package包/類
@Test
@SuppressWarnings("serial")
public void suppressDefaultSuffixPattern() throws Exception {
	servlet = new DispatcherServlet() {
		@Override
		protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent)
				throws BeansException {
			GenericWebApplicationContext wac = new GenericWebApplicationContext();
			wac.registerBeanDefinition("controller", new RootBeanDefinition(VariableNamesController.class));
			RootBeanDefinition mappingDef = new RootBeanDefinition(DefaultAnnotationHandlerMapping.class);
			mappingDef.getPropertyValues().add("useDefaultSuffixPattern", false);
			wac.registerBeanDefinition("handlerMapping", mappingDef);
			wac.refresh();
			return wac;
		}
	};
	servlet.init(new MockServletConfig());

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/test/[email protected]");
	MockHttpServletResponse response = new MockHttpServletResponse();
	servlet.service(request, response);
	assertEquals("[email protected]", response.getContentAsString());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:24,代碼來源:UriTemplateServletAnnotationControllerTests.java

示例3: badRequestRequestBody

import org.springframework.web.servlet.DispatcherServlet; //導入方法依賴的package包/類
@Test
public void badRequestRequestBody() throws ServletException, IOException {
	@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() {
		@Override
		protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
			GenericWebApplicationContext wac = new GenericWebApplicationContext();
			wac.registerBeanDefinition("controller", new RootBeanDefinition(RequestResponseBodyController.class));
			RootBeanDefinition adapterDef = new RootBeanDefinition(AnnotationMethodHandlerAdapter.class);
			adapterDef.getPropertyValues().add("messageConverters", new NotReadableMessageConverter());
			wac.registerBeanDefinition("handlerAdapter", adapterDef);
			wac.refresh();
			return wac;
		}
	};
	servlet.init(new MockServletConfig());

	MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/something");
	String requestBody = "Hello World";
	request.setContent(requestBody.getBytes("UTF-8"));
	request.addHeader("Content-Type", "application/pdf");
	MockHttpServletResponse response = new MockHttpServletResponse();
	servlet.service(request, response);
	assertEquals("Invalid response status code", HttpServletResponse.SC_BAD_REQUEST, response.getStatus());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:25,代碼來源:ServletAnnotationControllerTests.java

示例4: proxiedStandardHandleMethod

import org.springframework.web.servlet.DispatcherServlet; //導入方法依賴的package包/類
@Test
@SuppressWarnings("serial")
public void proxiedStandardHandleMethod() throws Exception {
	DispatcherServlet servlet = new DispatcherServlet() {
		@Override
		protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
			GenericWebApplicationContext wac = new GenericWebApplicationContext();
			wac.registerBeanDefinition("controller", new RootBeanDefinition(MyController.class));
			DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
			autoProxyCreator.setBeanFactory(wac.getBeanFactory());
			wac.getBeanFactory().addBeanPostProcessor(autoProxyCreator);
			wac.getBeanFactory().registerSingleton("advisor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor()));
			wac.refresh();
			return wac;
		}
	};
	servlet.init(new MockServletConfig());

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath.do");
	MockHttpServletResponse response = new MockHttpServletResponse();
	servlet.service(request, response);
	assertEquals("test", response.getContentAsString());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:24,代碼來源:ServletAnnotationControllerTests.java

示例5: formController

import org.springframework.web.servlet.DispatcherServlet; //導入方法依賴的package包/類
@Test
public void formController() throws Exception {
	@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() {
		@Override
		protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
			GenericWebApplicationContext wac = new GenericWebApplicationContext();
			wac.registerBeanDefinition("controller", new RootBeanDefinition(MyFormController.class));
			wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.class));
			wac.refresh();
			return wac;
		}
	};
	servlet.init(new MockServletConfig());

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath.do");
	request.addParameter("name", "name1");
	request.addParameter("age", "value2");
	MockHttpServletResponse response = new MockHttpServletResponse();
	servlet.service(request, response);
	assertEquals("myView-name1-typeMismatch-tb1-myValue", response.getContentAsString());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:22,代碼來源:ServletAnnotationControllerTests.java

示例6: commandProvidingFormControllerWithCustomEditor

import org.springframework.web.servlet.DispatcherServlet; //導入方法依賴的package包/類
@Test
public void commandProvidingFormControllerWithCustomEditor() throws Exception {
	@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() {
		@Override
		protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
			GenericWebApplicationContext wac = new GenericWebApplicationContext();
			wac.registerBeanDefinition("controller",
					new RootBeanDefinition(MyCommandProvidingFormController.class));
			wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.class));
			RootBeanDefinition adapterDef = new RootBeanDefinition(AnnotationMethodHandlerAdapter.class);
			adapterDef.getPropertyValues().add("webBindingInitializer", new MyWebBindingInitializer());
			wac.registerBeanDefinition("handlerAdapter", adapterDef);
			wac.refresh();
			return wac;
		}
	};
	servlet.init(new MockServletConfig());

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath.do");
	request.addParameter("defaultName", "myDefaultName");
	request.addParameter("age", "value2");
	request.addParameter("date", "2007-10-02");
	MockHttpServletResponse response = new MockHttpServletResponse();
	servlet.service(request, response);
	assertEquals("myView-String:myDefaultName-typeMismatch-tb1-myOriginalValue", response.getContentAsString());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:27,代碼來源:ServletAnnotationControllerTests.java

示例7: binderInitializingCommandProvidingFormController

import org.springframework.web.servlet.DispatcherServlet; //導入方法依賴的package包/類
@Test
public void binderInitializingCommandProvidingFormController() throws Exception {
	@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() {
		@Override
		protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
			GenericWebApplicationContext wac = new GenericWebApplicationContext();
			wac.registerBeanDefinition("controller",
					new RootBeanDefinition(MyBinderInitializingCommandProvidingFormController.class));
			wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.class));
			wac.refresh();
			return wac;
		}
	};
	servlet.init(new MockServletConfig());

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath.do");
	request.addParameter("defaultName", "myDefaultName");
	request.addParameter("age", "value2");
	request.addParameter("date", "2007-10-02");
	MockHttpServletResponse response = new MockHttpServletResponse();
	servlet.service(request, response);
	assertEquals("myView-String:myDefaultName-typeMismatch-tb1-myOriginalValue", response.getContentAsString());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:24,代碼來源:ServletAnnotationControllerTests.java

示例8: parameterCsvAsIntegerSetWithCustomSeparator

import org.springframework.web.servlet.DispatcherServlet; //導入方法依賴的package包/類
@Test
@SuppressWarnings("serial")
public void parameterCsvAsIntegerSetWithCustomSeparator() throws Exception {
	servlet = new DispatcherServlet() {
		@Override
		protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
			GenericWebApplicationContext wac = new GenericWebApplicationContext();
			wac.registerBeanDefinition("controller", new RootBeanDefinition(CsvController.class));
			RootBeanDefinition csDef = new RootBeanDefinition(FormattingConversionServiceFactoryBean.class);
			RootBeanDefinition wbiDef = new RootBeanDefinition(ConfigurableWebBindingInitializer.class);
			wbiDef.getPropertyValues().add("conversionService", csDef);
			wbiDef.getPropertyValues().add("propertyEditorRegistrars", new RootBeanDefinition(ListEditorRegistrar.class));
			RootBeanDefinition adapterDef = new RootBeanDefinition(AnnotationMethodHandlerAdapter.class);
			adapterDef.getPropertyValues().add("webBindingInitializer", wbiDef);
			wac.registerBeanDefinition("handlerAdapter", adapterDef);
			wac.refresh();
			return wac;
		}
	};
	servlet.init(new MockServletConfig());

	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setRequestURI("/integerSet");
	request.setMethod("POST");
	request.addParameter("content", "1;2");
	MockHttpServletResponse response = new MockHttpServletResponse();
	servlet.service(request, response);
	assertEquals("1-2", response.getContentAsString());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:30,代碼來源:ServletAnnotationControllerTests.java

示例9: controllerClassName

import org.springframework.web.servlet.DispatcherServlet; //導入方法依賴的package包/類
@Test
@SuppressWarnings("serial")
public void controllerClassName() throws Exception {
	servlet = new DispatcherServlet() {
		@Override
		protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent)
				throws BeansException {
			GenericWebApplicationContext wac = new GenericWebApplicationContext();
			wac.registerBeanDefinition("controller", new RootBeanDefinition(ControllerClassNameController.class));
			RootBeanDefinition mapping = new RootBeanDefinition(ControllerClassNameHandlerMapping.class);
			mapping.getPropertyValues().add("excludedPackages", null);
			wac.registerBeanDefinition("handlerMapping", mapping);
			wac.refresh();
			return wac;
		}
	};
	servlet.init(new MockServletConfig());

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/controllerclassname/bar");
	MockHttpServletResponse response = new MockHttpServletResponse();
	servlet.service(request, response);
	assertEquals("plain-bar", response.getContentAsString());

	request = new MockHttpServletRequest("GET", "/controllerclassname/bar.pdf");
	response = new MockHttpServletResponse();
	servlet.service(request, response);
	assertEquals("pdf-bar", response.getContentAsString());

	request = new MockHttpServletRequest("GET", "/controllerclassname/bar.do");
	response = new MockHttpServletResponse();
	servlet.service(request, response);
	assertEquals("plain-bar", response.getContentAsString());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:34,代碼來源:UriTemplateServletAnnotationControllerTests.java

示例10: overlappingMesssageConvertersRequestBody

import org.springframework.web.servlet.DispatcherServlet; //導入方法依賴的package包/類
@Test
public void overlappingMesssageConvertersRequestBody() throws ServletException, IOException {
	@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() {
		@Override
		protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
			GenericWebApplicationContext wac = new GenericWebApplicationContext();
			wac.registerBeanDefinition("controller", new RootBeanDefinition(RequestResponseBodyController.class));
			RootBeanDefinition adapterDef = new RootBeanDefinition(AnnotationMethodHandlerAdapter.class);
			List<HttpMessageConverter> messageConverters = new ArrayList<HttpMessageConverter>();
			messageConverters.add(new StringHttpMessageConverter());
			messageConverters
					.add(new SimpleMessageConverter(new MediaType("application","json"), MediaType.ALL));
			adapterDef.getPropertyValues().add("messageConverters", messageConverters);
			wac.registerBeanDefinition("handlerAdapter", adapterDef);
			wac.refresh();
			return wac;
		}
	};
	servlet.init(new MockServletConfig());

	MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/something");
	request.setContent("Hello World".getBytes("UTF-8"));
	request.addHeader("Content-Type", "text/plain; charset=utf-8");
	request.addHeader("Accept", "application/json, text/javascript, */*");
	MockHttpServletResponse response = new MockHttpServletResponse();
	servlet.service(request, response);
	assertEquals("Invalid response status code", "application/json", response.getHeader("Content-Type"));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:29,代碼來源:ServletAnnotationControllerTests.java

示例11: defaultExpressionParameters

import org.springframework.web.servlet.DispatcherServlet; //導入方法依賴的package包/類
@Test
@SuppressWarnings("serial")
public void defaultExpressionParameters() throws Exception {
	servlet = new DispatcherServlet() {
		@Override
		protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
			GenericWebApplicationContext wac = new GenericWebApplicationContext();
			wac.registerBeanDefinition("controller", new RootBeanDefinition(DefaultExpressionValueParamController.class));
			RootBeanDefinition ppc = new RootBeanDefinition(PropertyPlaceholderConfigurer.class);
			ppc.getPropertyValues().add("properties", "myKey=foo");
			wac.registerBeanDefinition("ppc", ppc);
			wac.refresh();
			return wac;
		}
	};
	servlet.init(new MockServletConfig());

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myApp/myPath.do");
	request.setContextPath("/myApp");
	MockHttpServletResponse response = new MockHttpServletResponse();
	System.setProperty("myHeader", "bar");
	try {
		servlet.service(request, response);
	}
	finally {
		System.clearProperty("myHeader");
	}
	assertEquals("foo-bar-/myApp", response.getContentAsString());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:30,代碼來源:ServletAnnotationControllerTests.java

示例12: typeNestedSetBinding

import org.springframework.web.servlet.DispatcherServlet; //導入方法依賴的package包/類
@Test
@SuppressWarnings("serial")
public void typeNestedSetBinding() throws Exception {
	servlet = new DispatcherServlet() {
		@Override
		protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
			GenericWebApplicationContext wac = new GenericWebApplicationContext();
			wac.registerBeanDefinition("controller", new RootBeanDefinition(NestedSetController.class));
			RootBeanDefinition csDef = new RootBeanDefinition(FormattingConversionServiceFactoryBean.class);
			csDef.getPropertyValues().add("converters", new TestBeanConverter());
			RootBeanDefinition wbiDef = new RootBeanDefinition(ConfigurableWebBindingInitializer.class);
			wbiDef.getPropertyValues().add("conversionService", csDef);
			RootBeanDefinition adapterDef = new RootBeanDefinition(AnnotationMethodHandlerAdapter.class);
			adapterDef.getPropertyValues().add("webBindingInitializer", wbiDef);
			wac.registerBeanDefinition("handlerAdapter", adapterDef);
			wac.refresh();
			return wac;
		}
	};
	servlet.init(new MockServletConfig());

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath.do");
	request.addParameter("testBeanSet", new String[] {"1", "2"});
	MockHttpServletResponse response = new MockHttpServletResponse();
	servlet.service(request, response);
	assertEquals("[1, 2]-org.springframework.tests.sample.beans.TestBean", response.getContentAsString());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:28,代碼來源:ServletAnnotationControllerTests.java

示例13: responseBodyNoAcceptableMediaType

import org.springframework.web.servlet.DispatcherServlet; //導入方法依賴的package包/類
@Test
public void responseBodyNoAcceptableMediaType() throws ServletException, IOException {
	@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() {
		@Override
		protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
			GenericWebApplicationContext wac = new GenericWebApplicationContext();
			wac.registerBeanDefinition("controller", new RootBeanDefinition(RequestResponseBodyController.class));
			RootBeanDefinition converterDef = new RootBeanDefinition(StringHttpMessageConverter.class);
			converterDef.getPropertyValues().add("supportedMediaTypes", new MediaType("text", "plain"));
			RootBeanDefinition adapterDef = new RootBeanDefinition(AnnotationMethodHandlerAdapter.class);
			StringHttpMessageConverter converter = new StringHttpMessageConverter();
			converter.setSupportedMediaTypes(Collections.singletonList(new MediaType("text", "plain")));
			adapterDef.getPropertyValues().add("messageConverters", converter);
			wac.registerBeanDefinition("handlerAdapter", adapterDef);
			wac.refresh();
			return wac;
		}
	};
	servlet.init(new MockServletConfig());

	MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/something");
	String requestBody = "Hello World";
	request.setContent(requestBody.getBytes("UTF-8"));
	request.addHeader("Content-Type", "text/plain; charset=utf-8");
	request.addHeader("Accept", "application/pdf, application/msword");
	MockHttpServletResponse response = new MockHttpServletResponse();
	servlet.service(request, response);
	assertEquals(406, response.getStatus());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:30,代碼來源:ServletAnnotationControllerTests.java

示例14: sessionAttributeExposure

import org.springframework.web.servlet.DispatcherServlet; //導入方法依賴的package包/類
@Test
public void sessionAttributeExposure() throws Exception {
	@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() {
		@Override
		protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
			GenericWebApplicationContext wac = new GenericWebApplicationContext();
			wac.registerBeanDefinition("controller", new RootBeanDefinition(MySessionAttributesController.class));
			wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(ModelExposingViewResolver.class));
			wac.refresh();
			return wac;
		}
	};
	servlet.init(new MockServletConfig());

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPage");
	MockHttpServletResponse response = new MockHttpServletResponse();
	servlet.service(request, response);
	assertEquals("page1", request.getAttribute("viewName"));
	HttpSession session = request.getSession();
	assertTrue(session.getAttribute("object1") != null);
	assertTrue(session.getAttribute("object2") != null);
	assertTrue(((Map) session.getAttribute("model")).containsKey("object1"));
	assertTrue(((Map) session.getAttribute("model")).containsKey("object2"));

	request = new MockHttpServletRequest("POST", "/myPage");
	request.setSession(session);
	response = new MockHttpServletResponse();
	servlet.service(request, response);
	assertEquals("page2", request.getAttribute("viewName"));
	assertTrue(session.getAttribute("object1") != null);
	assertTrue(session.getAttribute("object2") != null);
	assertTrue(((Map) session.getAttribute("model")).containsKey("object1"));
	assertTrue(((Map) session.getAttribute("model")).containsKey("object2"));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:35,代碼來源:ServletAnnotationControllerTests.java

示例15: parameterCsvAsIntegerSet

import org.springframework.web.servlet.DispatcherServlet; //導入方法依賴的package包/類
@Test
@SuppressWarnings("serial")
public void parameterCsvAsIntegerSet() throws Exception {
	servlet = new DispatcherServlet() {
		@Override
		protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
			GenericWebApplicationContext wac = new GenericWebApplicationContext();
			wac.registerBeanDefinition("controller", new RootBeanDefinition(CsvController.class));
			RootBeanDefinition csDef = new RootBeanDefinition(FormattingConversionServiceFactoryBean.class);
			RootBeanDefinition wbiDef = new RootBeanDefinition(ConfigurableWebBindingInitializer.class);
			wbiDef.getPropertyValues().add("conversionService", csDef);
			RootBeanDefinition adapterDef = new RootBeanDefinition(AnnotationMethodHandlerAdapter.class);
			adapterDef.getPropertyValues().add("webBindingInitializer", wbiDef);
			wac.registerBeanDefinition("handlerAdapter", adapterDef);
			wac.refresh();
			return wac;
		}
	};
	servlet.init(new MockServletConfig());

	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setRequestURI("/integerSet");
	request.setMethod("POST");
	request.addParameter("content", "1,2");
	MockHttpServletResponse response = new MockHttpServletResponse();
	servlet.service(request, response);
	assertEquals("1-2", response.getContentAsString());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:29,代碼來源:ServletAnnotationControllerTests.java


注:本文中的org.springframework.web.servlet.DispatcherServlet.service方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。