前提:jenkins是装在CentOS6.7中,同时,我的这台linux上面安装有docker
项目主要是jersey 1.x 版本的maven项目,重点在与我在项目中放置了tomcat,以及使用maven对tomcat进行解压,并将项目打包的文件放置到项目中,那么项目信息就不多写了,把maven配置信息重点写出来吧:
<build>
<finalName>testjersey</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>copy-package</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<unzip dest="target/apache/">
<fileset dir="${basedir}">
<include name="apache-tomcat-7.0.68.zip" />
<servlet> <servlet-name>Rest_Servlet</servlet-name> <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> <init-param> <param-name>com.sun.jersey.config.property.packages</param-name> <param-value>cn.firewarm.testRestShiro.rest</param-value> </init-param> <init-param> <param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name> <param-value>cn.firewarm.testRestShiro.filter.TestFilter</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> |
public class TestFilter implements ContainerRequestFilter { public ContainerRequest filter(ContainerRequest request) { if(判断条件){ return request; }else{ Response response = Response.ok("error").status(401).type(MediaType.APPLICATION_JSON).build(); throw new WebApplicationException(response); // Throw new UnAuthor |
public void normalTest()throws Exception, IOException{CloseableHttpClient httpclient = HttpClients.createDefault();JAXBContext context = JAXBContext.newInstance("org.xwiki.rest.model.jaxb");Unmarshaller unmarshaller = context.createUnmarshaller();HttpUriRequest httpPost = RequestBuilder.get().setUri(new URI("http://172.16.200.220:8082/xwiki/rest/wikis/xwiki/spaces/Main/pages/WebHome")).setHeader("Accept", "application/xml").build();CloseableHttpResponse response = httpclient.execute(httpPost);System.out.println(response.getEntity());HttpEntity responseEntity=response.getEntity();Page page = (Page) unmarshaller.unmarshal(responseEntity.getContent());System.out.println(new Gson().toJson(page));}
public void testLogin() throws Exception{CloseableHttpClient httpclient =