-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
594 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,27 @@ | ||
# Compiled class file | ||
*.class | ||
.gradle | ||
/build/ | ||
!gradle/wrapper/gradle-wrapper.jar | ||
|
||
# Log file | ||
*.log | ||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
|
||
# BlueJ files | ||
*.ctxt | ||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.nar | ||
*.ear | ||
*.zip | ||
*.tar.gz | ||
*.rar | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
### NetBeans ### | ||
nbproject/private/ | ||
build/ | ||
nbbuild/ | ||
dist/ | ||
nbdist/ | ||
.nb-gradle/ | ||
/bin/ | ||
/target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,30 @@ | ||
# Cloud Native Book Demos | ||
|
||
|
||
## 内容简介 | ||
|
||
技术版本如下: | ||
|
||
* Apache Maven 3.5.2 | ||
* Jersey 2.27 | ||
* JUnit 4.12 | ||
* Apache CXF 3.2.4 | ||
* ... | ||
|
||
## Code 源码 | ||
|
||
所有示例源码,移步至<https://github.com/waylau/cloud-native-book-demos/> `samples` 目录下 | ||
|
||
内容如下: | ||
|
||
* ch02\Jersey-rest:基于 Jersey 构建 REST 服务 | ||
* ch02\cxf-rest:基于 Apache CXF 构建 REST 服务 | ||
* ... 强势更新中 | ||
|
||
## Contact 联系作者: | ||
|
||
* Blog: [waylau.com](https://waylau.com) | ||
* Gmail: [waylau521(at)gmail.com](mailto:waylau521@gmail.com) | ||
* Weibo: [waylau521](http://weibo.com/waylau521) | ||
* Twitter: [waylau521](https://twitter.com/waylau521) | ||
* Github : [waylau](https://github.com/waylau) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.waylau.cxf</groupId> | ||
<artifactId>cxf-rest</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>war</packaging> | ||
<name>Simple CXF JAX-RS webapp service using spring configuration</name> | ||
<description>Simple CXF JAX-RS webapp service using spring configuration</description> | ||
<properties> | ||
<jackson.version>1.8.6</jackson.version> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.cxf</groupId> | ||
<artifactId>cxf-rt-frontend-jaxrs</artifactId> | ||
<version>3.2.4</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.cxf</groupId> | ||
<artifactId>cxf-rt-rs-client</artifactId> | ||
<version>3.2.4</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.codehaus.jackson</groupId> | ||
<artifactId>jackson-core-asl</artifactId> | ||
<version>${jackson.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.codehaus.jackson</groupId> | ||
<artifactId>jackson-mapper-asl</artifactId> | ||
<version>${jackson.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.codehaus.jackson</groupId> | ||
<artifactId>jackson-jaxrs</artifactId> | ||
<version>${jackson.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-web</artifactId> | ||
<version>4.3.14.RELEASE</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.12</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.tomcat.maven</groupId> | ||
<artifactId>tomcat7-maven-plugin</artifactId> | ||
<version>2.0</version> | ||
<executions> | ||
<execution> | ||
<id>default-cli</id> | ||
<goals> | ||
<goal>run</goal> | ||
</goals> | ||
<configuration> | ||
<port>13000</port> | ||
<path>/jaxrs-service</path> | ||
<useSeparateTomcatClassLoader>true</useSeparateTomcatClassLoader> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-eclipse-plugin</artifactId> | ||
<configuration> | ||
<projectNameTemplate>[artifactId]-[version]</projectNameTemplate> | ||
<wtpmanifest>true</wtpmanifest> | ||
<wtpapplicationxml>true</wtpapplicationxml> | ||
<wtpversion>2.0</wtpversion> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.eclipse.m2e</groupId> | ||
<artifactId>lifecycle-mapping</artifactId> | ||
<version>1.0.0</version> | ||
<configuration> | ||
<lifecycleMappingMetadata> | ||
<pluginExecutions> | ||
<pluginExecution> | ||
<pluginExecutionFilter> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<versionRange>[2.5,)</versionRange> | ||
<goals> | ||
<goal>compile</goal> | ||
<goal>testCompile</goal> | ||
</goals> | ||
</pluginExecutionFilter> | ||
<action> | ||
<ignore /> | ||
</action> | ||
</pluginExecution> | ||
</pluginExecutions> | ||
</lifecycleMappingMetadata> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>build-helper-maven-plugin</artifactId> | ||
<version>1.5</version> | ||
<!-- <executions> --> | ||
<!-- <execution> --> | ||
<!-- <id>reserve-network-port</id> --> | ||
<!-- <goals> --> | ||
<!-- <goal>reserve-network-port</goal> --> | ||
<!-- </goals> --> | ||
<!-- <phase>process-test-resources</phase> --> | ||
<!-- <configuration> --> | ||
<!-- <portNames> --> | ||
<!-- <portName>test.server.port</portName> --> | ||
<!-- </portNames> --> | ||
<!-- </configuration> --> | ||
<!-- </execution> --> | ||
<!-- </executions> --> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.tomcat.maven</groupId> | ||
<artifactId>tomcat7-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>start-tomcat</id> | ||
<goals> | ||
<goal>run-war</goal> | ||
</goals> | ||
<phase>pre-integration-test</phase> | ||
<configuration> | ||
<port>${test.server.port}</port> | ||
<path>/jaxrs-service</path> | ||
<fork>true</fork> | ||
<useSeparateTomcatClassLoader>true</useSeparateTomcatClassLoader> | ||
</configuration> | ||
</execution> | ||
<execution> | ||
<id>stop-tomcat</id> | ||
<goals> | ||
<goal>shutdown</goal> | ||
</goals> | ||
<phase>post-integration-test</phase> | ||
<configuration> | ||
<path>/jaxrs-service</path> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
<version>2.20</version> | ||
<executions> | ||
<execution> | ||
<id>integration-test</id> | ||
<goals> | ||
<goal>integration-test</goal> | ||
</goals> | ||
<configuration> | ||
<systemPropertyVariables> | ||
<service.url>http://localhost:${test.server.port}/jaxrs-service</service.url> | ||
</systemPropertyVariables> | ||
</configuration> | ||
</execution> | ||
<execution> | ||
<id>verify</id> | ||
<goals> | ||
<goal>verify</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
29 changes: 29 additions & 0 deletions
29
samples/ch02/cxf-rest/src/main/java/com/waylau/cxf/HelloWorld.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.waylau.cxf; | ||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.Response; | ||
|
||
@Path("/hello") | ||
public class HelloWorld { | ||
|
||
@GET | ||
@Path("/echo/{input}") | ||
@Produces("text/plain") | ||
public String ping(@PathParam("input") String input) { | ||
return input; | ||
} | ||
|
||
@POST | ||
@Produces("application/json") | ||
@Consumes("application/json") | ||
@Path("/jsonBean") | ||
public Response modifyJson(JsonBean input) { | ||
input.setVal2(input.getVal1()); | ||
return Response.ok().entity(input).build(); | ||
} | ||
} | ||
|
24 changes: 24 additions & 0 deletions
24
samples/ch02/cxf-rest/src/main/java/com/waylau/cxf/JsonBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.waylau.cxf; | ||
|
||
|
||
public class JsonBean { | ||
private String val1; | ||
private String val2; | ||
|
||
public String getVal1() { | ||
return val1; | ||
} | ||
|
||
public void setVal1(String val1) { | ||
this.val1 = val1; | ||
} | ||
|
||
public String getVal2() { | ||
return val2; | ||
} | ||
|
||
public void setVal2(String val2) { | ||
this.val2 = val2; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Context/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd"> | ||
<import resource="classpath:META-INF/cxf/cxf.xml"/> | ||
<context:property-placeholder/> | ||
<context:annotation-config/> | ||
<!-- <bean class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer"/> --> | ||
<!-- <bean class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"/> --> | ||
<jaxrs:server id="services" address="/"> | ||
<jaxrs:serviceBeans> | ||
<bean class="com.waylau.cxf.HelloWorld"/> | ||
</jaxrs:serviceBeans> | ||
<jaxrs:providers> | ||
<bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/> | ||
</jaxrs:providers> | ||
</jaxrs:server> | ||
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> | ||
<display-name>JAX-RS Simple Service</display-name> | ||
<description>JAX-RS Simple Service</description> | ||
<context-param> | ||
<param-name>contextConfigLocation</param-name> | ||
<param-value>WEB-INF/beans.xml</param-value> | ||
</context-param> | ||
<listener> | ||
<listener-class> | ||
org.springframework.web.context.ContextLoaderListener | ||
</listener-class> | ||
</listener> | ||
<servlet> | ||
<servlet-name>CXFServlet</servlet-name> | ||
<servlet-class> | ||
org.apache.cxf.transport.servlet.CXFServlet | ||
</servlet-class> | ||
<load-on-startup>1</load-on-startup> | ||
</servlet> | ||
<servlet-mapping> | ||
<servlet-name>CXFServlet</servlet-name> | ||
<url-pattern>/*</url-pattern> | ||
</servlet-mapping> | ||
</web-app> |
Oops, something went wrong.