Revision 47116
Added by Claudio Atzori almost 6 years ago
modules/dnet-container-parent/trunk/src/main/java/eu/dnetlib/swagger/configuration/SwaggerDocumentationConfig.java | ||
---|---|---|
1 |
package eu.dnetlib.swagger.configuration; |
|
2 |
|
|
3 |
import eu.dnetlib.common.rmi.DNetRestDocumentation; |
|
4 |
import org.springframework.beans.factory.annotation.Value; |
|
5 |
import org.springframework.context.annotation.Bean; |
|
6 |
import org.springframework.context.annotation.Configuration; |
|
7 |
import springfox.documentation.builders.ApiInfoBuilder; |
|
8 |
import springfox.documentation.builders.RequestHandlerSelectors; |
|
9 |
import springfox.documentation.service.ApiInfo; |
|
10 |
import springfox.documentation.service.Contact; |
|
11 |
import springfox.documentation.spi.DocumentationType; |
|
12 |
import springfox.documentation.spring.web.plugins.Docket; |
|
13 |
import springfox.documentation.swagger2.annotations.EnableSwagger2; |
|
14 |
|
|
15 |
@Configuration |
|
16 |
@EnableSwagger2 |
|
17 |
public class SwaggerDocumentationConfig { |
|
18 |
|
|
19 |
@Value("${api.rest.contact.name}") |
|
20 |
private String contactName; |
|
21 |
|
|
22 |
@Value("${api.rest.contact.url}") |
|
23 |
private String contactUrl; |
|
24 |
|
|
25 |
@Value("${api.rest.contact.email}") |
|
26 |
private String contactEmail; |
|
27 |
|
|
28 |
@Value("${api.rest.title}") |
|
29 |
private String title; |
|
30 |
|
|
31 |
@Value("${api.rest.description}") |
|
32 |
private String description; |
|
33 |
|
|
34 |
@Value("${api.rest.license}") |
|
35 |
private String license; |
|
36 |
@Value("${api.rest.license.url}") |
|
37 |
private String licenseUrl; |
|
38 |
|
|
39 |
@Bean |
|
40 |
public Docket customImplementation(){ |
|
41 |
return new Docket(DocumentationType.SWAGGER_2) |
|
42 |
.select() |
|
43 |
//.apis(RequestHandlerSelectors.any()) |
|
44 |
//.apis(RequestHandlerSelectors.basePackage("eu.dnetlib.**.controller.*")) |
|
45 |
//.apis(RequestHandlerSelectors.withClassAnnotation(RestController.class)) |
|
46 |
.apis(RequestHandlerSelectors.withClassAnnotation(DNetRestDocumentation.class)) |
|
47 |
//.paths(PathSelectors.ant("/ds/**")) |
|
48 |
.build() |
|
49 |
.directModelSubstitute(org.joda.time.LocalDate.class, java.sql.Date.class) |
|
50 |
.directModelSubstitute(org.joda.time.DateTime.class, java.util.Date.class) |
|
51 |
.apiInfo(apiInfo()); |
|
52 |
} |
|
53 |
|
|
54 |
private ApiInfo apiInfo() { |
|
55 |
return new ApiInfoBuilder() |
|
56 |
.title(title) |
|
57 |
.description(description) |
|
58 |
.license(license) |
|
59 |
.licenseUrl(licenseUrl) |
|
60 |
.termsOfServiceUrl("") |
|
61 |
.version("1.0.0") |
|
62 |
.contact(new Contact(contactName, contactUrl, contactEmail)) |
|
63 |
.build(); |
|
64 |
} |
|
65 |
|
|
66 |
} |
|
0 | 67 |
modules/dnet-container-parent/trunk/src/main/java/eu/dnetlib/swagger/configuration/RFC3339DateFormat.java | ||
---|---|---|
1 |
package eu.dnetlib.swagger.configuration; |
|
2 |
|
|
3 |
import java.text.FieldPosition; |
|
4 |
import java.util.Date; |
|
5 |
|
|
6 |
import com.fasterxml.jackson.databind.util.ISO8601DateFormat; |
|
7 |
import com.fasterxml.jackson.databind.util.ISO8601Utils; |
|
8 |
|
|
9 |
public class RFC3339DateFormat extends ISO8601DateFormat { |
|
10 |
|
|
11 |
// Same as ISO8601DateFormat but serializing milliseconds. |
|
12 |
@Override |
|
13 |
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) { |
|
14 |
String value = ISO8601Utils.format(date, true); |
|
15 |
toAppendTo.append(value); |
|
16 |
return toAppendTo; |
|
17 |
} |
|
18 |
|
|
19 |
} |
|
0 | 20 |
modules/dnet-container-parent/trunk/src/main/java/eu/dnetlib/swagger/configuration/ApiOriginFilter.java | ||
---|---|---|
1 |
package eu.dnetlib.swagger.configuration; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
import javax.servlet.http.HttpServletResponse; |
|
5 |
|
|
6 |
public class ApiOriginFilter implements Filter { |
|
7 |
@Override |
|
8 |
public void doFilter(ServletRequest request, ServletResponse response, |
|
9 |
FilterChain chain) throws IOException, ServletException { |
|
10 |
HttpServletResponse res = (HttpServletResponse) response; |
|
11 |
res.addHeader("Access-Control-Allow-Origin", "*"); |
|
12 |
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT"); |
|
13 |
res.addHeader("Access-Control-Allow-Headers", "Content-Type"); |
|
14 |
chain.doFilter(request, response); |
|
15 |
} |
|
16 |
|
|
17 |
@Override |
|
18 |
public void destroy() { |
|
19 |
} |
|
20 |
|
|
21 |
@Override |
|
22 |
public void init(FilterConfig filterConfig) throws ServletException { |
|
23 |
} |
|
24 |
} |
|
0 | 25 |
modules/dnet-container-parent/trunk/src/main/java/eu/dnetlib/swagger/configuration/HomeController.java | ||
---|---|---|
1 |
package eu.dnetlib.swagger.configuration; |
|
2 |
|
|
3 |
import org.springframework.stereotype.Controller; |
|
4 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
5 |
|
|
6 |
/** |
|
7 |
* Home redirection to swagger api documentation |
|
8 |
*/ |
|
9 |
@Controller |
|
10 |
public class HomeController { |
|
11 |
|
|
12 |
@RequestMapping(value = "/docs") |
|
13 |
public String index() { |
|
14 |
return "redirect:swagger-ui.html"; |
|
15 |
} |
|
16 |
} |
|
0 | 17 |
modules/dnet-container-parent/trunk/src/main/java/eu/dnetlib/swagger/configuration/ApiResponseMessage.java | ||
---|---|---|
1 |
package eu.dnetlib.swagger.configuration; |
|
2 |
|
|
3 |
import javax.xml.bind.annotation.XmlTransient; |
|
4 |
|
|
5 |
@javax.xml.bind.annotation.XmlRootElement |
|
6 |
public class ApiResponseMessage { |
|
7 |
public static final int ERROR = 1; |
|
8 |
public static final int WARNING = 2; |
|
9 |
public static final int INFO = 3; |
|
10 |
public static final int OK = 4; |
|
11 |
public static final int TOO_BUSY = 5; |
|
12 |
|
|
13 |
int code; |
|
14 |
String type; |
|
15 |
String message; |
|
16 |
|
|
17 |
public ApiResponseMessage(){} |
|
18 |
|
|
19 |
public ApiResponseMessage(int code, String message){ |
|
20 |
this.code = code; |
|
21 |
switch(code){ |
|
22 |
case ERROR: |
|
23 |
setType("error"); |
|
24 |
break; |
|
25 |
case WARNING: |
|
26 |
setType("warning"); |
|
27 |
break; |
|
28 |
case INFO: |
|
29 |
setType("info"); |
|
30 |
break; |
|
31 |
case OK: |
|
32 |
setType("ok"); |
|
33 |
break; |
|
34 |
case TOO_BUSY: |
|
35 |
setType("too busy"); |
|
36 |
break; |
|
37 |
default: |
|
38 |
setType("unknown"); |
|
39 |
break; |
|
40 |
} |
|
41 |
this.message = message; |
|
42 |
} |
|
43 |
|
|
44 |
@XmlTransient |
|
45 |
public int getCode() { |
|
46 |
return code; |
|
47 |
} |
|
48 |
|
|
49 |
public void setCode(int code) { |
|
50 |
this.code = code; |
|
51 |
} |
|
52 |
|
|
53 |
public String getType() { |
|
54 |
return type; |
|
55 |
} |
|
56 |
|
|
57 |
public void setType(String type) { |
|
58 |
this.type = type; |
|
59 |
} |
|
60 |
|
|
61 |
public String getMessage() { |
|
62 |
return message; |
|
63 |
} |
|
64 |
|
|
65 |
public void setMessage(String message) { |
|
66 |
this.message = message; |
|
67 |
} |
|
68 |
} |
|
0 | 69 |
modules/dnet-container-parent/trunk/src/main/java/eu/dnetlib/EndpointDocController.java | ||
---|---|---|
1 |
package eu.dnetlib; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
import java.util.Map.Entry; |
|
5 |
import java.util.Set; |
|
6 |
|
|
7 |
import com.google.common.collect.Sets; |
|
8 |
import org.apache.commons.logging.Log; |
|
9 |
import org.apache.commons.logging.LogFactory; |
|
10 |
import org.springframework.beans.factory.annotation.Autowired; |
|
11 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
12 |
import org.springframework.web.bind.annotation.RequestMethod; |
|
13 |
import org.springframework.web.bind.annotation.RestController; |
|
14 |
import org.springframework.web.method.HandlerMethod; |
|
15 |
import org.springframework.web.servlet.mvc.method.RequestMappingInfo; |
|
16 |
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; |
|
17 |
|
|
18 |
/** |
|
19 |
* Created by claudio on 30/11/2016. |
|
20 |
*/ |
|
21 |
@RestController |
|
22 |
public class EndpointDocController { |
|
23 |
|
|
24 |
private static final Log log = LogFactory.getLog(EndpointDocController.class); |
|
25 |
|
|
26 |
@Autowired |
|
27 |
private List<RequestMappingHandlerMapping> handlerMappings; |
|
28 |
|
|
29 |
@RequestMapping(value = "/endpointdoc", method = RequestMethod.GET) |
|
30 |
public Set<String> show() { |
|
31 |
|
|
32 |
final Set<String> res = Sets.newHashSet(); |
|
33 |
for(RequestMappingHandlerMapping handler : handlerMappings) { |
|
34 |
|
|
35 |
for(Entry<RequestMappingInfo, HandlerMethod> e : handler.getHandlerMethods().entrySet()) { |
|
36 |
final RequestMappingInfo info = e.getKey(); |
|
37 |
res.add(info.toString()); |
|
38 |
} |
|
39 |
} |
|
40 |
return res; |
|
41 |
} |
|
42 |
|
|
43 |
} |
modules/dnet-container-parent/trunk/dnet45-container-parent.iml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> |
|
3 |
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false"> |
|
4 |
<output url="file://$MODULE_DIR$/target/classes" /> |
|
5 |
<output-test url="file://$MODULE_DIR$/target/test-classes" /> |
|
6 |
<content url="file://$MODULE_DIR$"> |
|
7 |
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> |
|
8 |
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> |
|
9 |
<excludeFolder url="file://$MODULE_DIR$/target" /> |
|
10 |
</content> |
|
11 |
<orderEntry type="inheritedJdk" /> |
|
12 |
<orderEntry type="sourceFolder" forTests="false" /> |
|
13 |
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.6.1" level="project" /> |
|
14 |
<orderEntry type="library" name="Maven: org.springframework:spring-beans:4.2.5.RELEASE" level="project" /> |
|
15 |
<orderEntry type="library" name="Maven: org.springframework:spring-core:4.2.5.RELEASE" level="project" /> |
|
16 |
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" /> |
|
17 |
<orderEntry type="library" name="Maven: org.springframework:spring-web:4.2.5.RELEASE" level="project" /> |
|
18 |
<orderEntry type="library" name="Maven: org.springframework:spring-aop:4.2.5.RELEASE" level="project" /> |
|
19 |
<orderEntry type="library" name="Maven: aopalliance:aopalliance:1.0" level="project" /> |
|
20 |
<orderEntry type="library" name="Maven: org.springframework:spring-context:4.2.5.RELEASE" level="project" /> |
|
21 |
<orderEntry type="library" name="Maven: org.springframework:spring-webmvc:4.2.5.RELEASE" level="project" /> |
|
22 |
<orderEntry type="library" name="Maven: org.springframework:spring-expression:4.2.5.RELEASE" level="project" /> |
|
23 |
<orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-frontend-jaxws:3.1.5" level="project" /> |
|
24 |
<orderEntry type="library" name="Maven: xml-resolver:xml-resolver:1.2" level="project" /> |
|
25 |
<orderEntry type="library" name="Maven: org.ow2.asm:asm:5.0.4" level="project" /> |
|
26 |
<orderEntry type="library" name="Maven: org.apache.cxf:cxf-core:3.1.5" level="project" /> |
|
27 |
<orderEntry type="library" name="Maven: org.codehaus.woodstox:woodstox-core-asl:4.4.1" level="project" /> |
|
28 |
<orderEntry type="library" name="Maven: org.codehaus.woodstox:stax2-api:3.1.4" level="project" /> |
|
29 |
<orderEntry type="library" name="Maven: org.apache.ws.xmlschema:xmlschema-core:2.2.1" level="project" /> |
|
30 |
<orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-bindings-soap:3.1.5" level="project" /> |
|
31 |
<orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-wsdl:3.1.5" level="project" /> |
|
32 |
<orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-databinding-jaxb:3.1.5" level="project" /> |
|
33 |
<orderEntry type="library" name="Maven: com.sun.xml.bind:jaxb-impl:2.2.11" level="project" /> |
|
34 |
<orderEntry type="library" name="Maven: com.sun.xml.bind:jaxb-core:2.2.11" level="project" /> |
|
35 |
<orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-bindings-xml:3.1.5" level="project" /> |
|
36 |
<orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-frontend-simple:3.1.5" level="project" /> |
|
37 |
<orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-ws-addr:3.1.5" level="project" /> |
|
38 |
<orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-transports-http:3.1.5" level="project" /> |
|
39 |
<orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-ws-policy:3.1.5" level="project" /> |
|
40 |
<orderEntry type="library" name="Maven: wsdl4j:wsdl4j:1.6.3" level="project" /> |
|
41 |
<orderEntry type="library" name="Maven: org.apache.neethi:neethi:3.0.3" level="project" /> |
|
42 |
<orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-ws-rm:3.1.5" level="project" /> |
|
43 |
<orderEntry type="library" name="Maven: org.apache.cxf:cxf-rt-management:3.1.5" level="project" /> |
|
44 |
<orderEntry type="library" name="Maven: org.apache.wss4j:wss4j-policy:2.1.4" level="project" /> |
|
45 |
<orderEntry type="library" scope="TEST" name="Maven: org.apache.cxf:cxf-rt-ws-security:3.1.5" level="project" /> |
|
46 |
<orderEntry type="library" scope="TEST" name="Maven: org.apache.cxf:cxf-rt-security-saml:3.1.5" level="project" /> |
|
47 |
<orderEntry type="library" scope="TEST" name="Maven: org.apache.cxf:cxf-rt-security:3.1.5" level="project" /> |
|
48 |
<orderEntry type="library" scope="TEST" name="Maven: org.apache.wss4j:wss4j-ws-security-common:2.1.4" level="project" /> |
|
49 |
<orderEntry type="library" scope="TEST" name="Maven: org.apache.santuario:xmlsec:2.0.5" level="project" /> |
|
50 |
<orderEntry type="library" scope="TEST" name="Maven: commons-codec:commons-codec:1.10" level="project" /> |
|
51 |
<orderEntry type="library" scope="TEST" name="Maven: org.opensaml:opensaml-saml-impl:3.1.1" level="project" /> |
|
52 |
<orderEntry type="library" scope="TEST" name="Maven: org.opensaml:opensaml-profile-api:3.1.1" level="project" /> |
|
53 |
<orderEntry type="library" scope="TEST" name="Maven: org.opensaml:opensaml-core:3.1.1" level="project" /> |
|
54 |
<orderEntry type="library" scope="TEST" name="Maven: org.opensaml:opensaml-saml-api:3.1.1" level="project" /> |
|
55 |
<orderEntry type="library" scope="TEST" name="Maven: org.opensaml:opensaml-xmlsec-api:3.1.1" level="project" /> |
|
56 |
<orderEntry type="library" scope="TEST" name="Maven: org.opensaml:opensaml-soap-api:3.1.1" level="project" /> |
|
57 |
<orderEntry type="library" scope="TEST" name="Maven: org.opensaml:opensaml-security-impl:3.1.1" level="project" /> |
|
58 |
<orderEntry type="library" scope="TEST" name="Maven: org.opensaml:opensaml-security-api:3.1.1" level="project" /> |
|
59 |
<orderEntry type="library" scope="TEST" name="Maven: org.cryptacular:cryptacular:1.0" level="project" /> |
|
60 |
<orderEntry type="library" scope="TEST" name="Maven: org.opensaml:opensaml-xmlsec-impl:3.1.1" level="project" /> |
|
61 |
<orderEntry type="library" scope="TEST" name="Maven: net.shibboleth.utilities:java-support:7.1.1" level="project" /> |
|
62 |
<orderEntry type="library" scope="TEST" name="Maven: com.google.guava:guava:18.0" level="project" /> |
|
63 |
<orderEntry type="library" scope="TEST" name="Maven: joda-time:joda-time:2.7" level="project" /> |
|
64 |
<orderEntry type="library" scope="TEST" name="Maven: org.opensaml:opensaml-xacml-impl:3.1.1" level="project" /> |
|
65 |
<orderEntry type="library" scope="TEST" name="Maven: org.opensaml:opensaml-xacml-api:3.1.1" level="project" /> |
|
66 |
<orderEntry type="library" scope="TEST" name="Maven: org.opensaml:opensaml-xacml-saml-impl:3.1.1" level="project" /> |
|
67 |
<orderEntry type="library" scope="TEST" name="Maven: org.opensaml:opensaml-xacml-saml-api:3.1.1" level="project" /> |
|
68 |
<orderEntry type="library" scope="TEST" name="Maven: org.jasypt:jasypt:1.9.2" level="project" /> |
|
69 |
<orderEntry type="library" scope="TEST" name="Maven: org.apache.geronimo.specs:geronimo-javamail_1.4_spec:1.7.1" level="project" /> |
|
70 |
<orderEntry type="library" scope="TEST" name="Maven: org.apache.wss4j:wss4j-ws-security-dom:2.1.4" level="project" /> |
|
71 |
<orderEntry type="library" scope="TEST" name="Maven: org.apache.wss4j:wss4j-ws-security-stax:2.1.4" level="project" /> |
|
72 |
<orderEntry type="library" scope="TEST" name="Maven: org.apache.wss4j:wss4j-bindings:2.1.4" level="project" /> |
|
73 |
<orderEntry type="library" scope="TEST" name="Maven: org.apache.wss4j:wss4j-ws-security-policy-stax:2.1.4" level="project" /> |
|
74 |
<orderEntry type="library" name="Maven: eu.dnetlib:cnr-config:1.0.2-SNAPSHOT" level="project" /> |
|
75 |
<orderEntry type="library" name="Maven: eu.dnetlib:dnet-runtime:1.0.1-SNAPSHOT" level="project" /> |
|
76 |
<orderEntry type="library" name="Maven: commons-lang:commons-lang:2.6" level="project" /> |
|
77 |
<orderEntry type="library" name="Maven: eu.dnetlib:cnr-log4j-management:1.0.1-SNAPSHOT" level="project" /> |
|
78 |
<orderEntry type="library" name="Maven: log4j:log4j:1.2.17" level="project" /> |
|
79 |
</component> |
|
80 |
</module> |
modules/dnet-container-parent/trunk/pom.xml | ||
---|---|---|
78 | 78 |
<groupId>org.bouncycastle</groupId> |
79 | 79 |
<artifactId>bcprov-jdk15on</artifactId> |
80 | 80 |
</exclusion> |
81 |
<exclusion>
|
|
82 |
<groupId>net.sf.ehcache</groupId>
|
|
83 |
<artifactId>ehcache</artifactId>
|
|
84 |
</exclusion>
|
|
81 |
<exclusion> |
|
82 |
<groupId>net.sf.ehcache</groupId> |
|
83 |
<artifactId>ehcache</artifactId> |
|
84 |
</exclusion> |
|
85 | 85 |
</exclusions> |
86 | 86 |
</dependency> |
87 |
|
|
88 |
<!-- SWAGGER --> |
|
87 | 89 |
<dependency> |
90 |
<groupId>com.fasterxml.jackson.datatype</groupId> |
|
91 |
<artifactId>jackson-datatype-joda</artifactId> |
|
92 |
<version>${jackson.version}</version> |
|
93 |
</dependency> |
|
94 |
<dependency> |
|
95 |
<groupId>joda-time</groupId> |
|
96 |
<artifactId>joda-time</artifactId> |
|
97 |
<version>2.8.2</version> |
|
98 |
</dependency> |
|
99 |
|
|
100 |
<dependency> |
|
101 |
<groupId>io.springfox</groupId> |
|
102 |
<artifactId>springfox-swagger2</artifactId> |
|
103 |
<version>${springfox-version}</version> |
|
104 |
</dependency> |
|
105 |
<dependency> |
|
106 |
<groupId>io.springfox</groupId> |
|
107 |
<artifactId>springfox-swagger-ui</artifactId> |
|
108 |
<version>${springfox-version}</version> |
|
109 |
</dependency> |
|
110 |
|
|
111 |
<dependency> |
|
88 | 112 |
<groupId>eu.dnetlib</groupId> |
89 | 113 |
<artifactId>cnr-config</artifactId> |
90 | 114 |
<version>[1.0.0,2.0.0)</version> |
... | ... | |
100 | 124 |
<version>[1.0.0,2.0.0)</version> |
101 | 125 |
</dependency> |
102 | 126 |
</dependencies> |
127 |
|
|
128 |
<properties> |
|
129 |
<springfox-version>2.5.0</springfox-version> |
|
130 |
</properties> |
|
131 |
|
|
103 | 132 |
</project> |
104 | 133 |
|
105 | 134 |
|
Also available in: Unified diff
included common swagger stuff