Revision 48147
Added by Claudio Atzori almost 7 years ago
webapps/dnet-container-openaireplus/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 |
webapps/dnet-container-openaireplus/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 |
webapps/dnet-container-openaireplus/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.*; |
|
5 |
import javax.servlet.http.HttpServletResponse; |
|
6 |
|
|
7 |
public class ApiOriginFilter implements Filter { |
|
8 |
@Override |
|
9 |
public void doFilter(ServletRequest request, ServletResponse response, |
|
10 |
FilterChain chain) throws IOException, ServletException { |
|
11 |
HttpServletResponse res = (HttpServletResponse) response; |
|
12 |
res.addHeader("Access-Control-Allow-Origin", "*"); |
|
13 |
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT"); |
|
14 |
res.addHeader("Access-Control-Allow-Headers", "Content-Type"); |
|
15 |
chain.doFilter(request, response); |
|
16 |
} |
|
17 |
|
|
18 |
@Override |
|
19 |
public void destroy() { |
|
20 |
} |
|
21 |
|
|
22 |
@Override |
|
23 |
public void init(FilterConfig filterConfig) throws ServletException { |
|
24 |
} |
|
25 |
} |
|
0 | 26 |
webapps/dnet-container-openaireplus/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 |
webapps/dnet-container-openaireplus/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 |
webapps/dnet-container-openaireplus/trunk/src/main/java/eu/dnetlib/EndpointDocController.java | ||
---|---|---|
1 |
package eu.dnetlib; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
import java.util.Set; |
|
5 |
import java.util.stream.Collectors; |
|
6 |
import java.util.stream.Stream; |
|
7 |
|
|
8 |
import org.springframework.beans.factory.annotation.Autowired; |
|
9 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
10 |
import org.springframework.web.bind.annotation.RequestMethod; |
|
11 |
import org.springframework.web.bind.annotation.RestController; |
|
12 |
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; |
|
13 |
|
|
14 |
/** |
|
15 |
* Created by claudio on 30/11/2016. |
|
16 |
*/ |
|
17 |
@RestController |
|
18 |
public class EndpointDocController { |
|
19 |
|
|
20 |
@Autowired |
|
21 |
private List<RequestMappingHandlerMapping> handlerMappings; |
|
22 |
|
|
23 |
@RequestMapping(value = "/endpointdoc", method = RequestMethod.GET) |
|
24 |
public Set<String> show() { |
|
25 |
return handlerMappings.stream() |
|
26 |
.map(r -> r.getHandlerMethods().entrySet().stream() |
|
27 |
.map(k -> k.getKey()) |
|
28 |
.map(i -> i.toString())) |
|
29 |
.reduce(Stream::concat) |
|
30 |
.orElseGet(Stream::empty) |
|
31 |
.collect(Collectors.toSet()); |
|
32 |
} |
|
33 |
|
|
34 |
} |
webapps/dnet-container-openaireplus/trunk/src/main/resources/eu/dnetlib/applicationContext-ehcache.xml | ||
---|---|---|
19 | 19 |
<!-- <ref bean="resultSetCacheManager" /> --> |
20 | 20 |
<!-- <ref bean="repoUICacheManager" /> --> |
21 | 21 |
<ref bean="issnCacheManager" /> |
22 |
<ref bean="datasourceCacheManager" /> |
|
22 | 23 |
</array> |
23 | 24 |
</property> |
24 | 25 |
<property name="fallbackToNoOpCache" value="true" /> |
webapps/dnet-container-openaireplus/trunk/src/main/resources/log4j.properties | ||
---|---|---|
32 | 32 |
log4j.logger.org.apache.cxf.interceptor=FATAL |
33 | 33 |
log4j.logger.org.apache.cxf.ws.addressing.ContextUtils=FATAL |
34 | 34 |
log4j.logger.eu.dnetlib.enabling.tools.AbstractBaseService=INFO |
35 |
log4j.logger.eu.dnetlib.enabling.inspector=DEBUG |
|
36 | 35 |
log4j.logger.eu.dnetlib.xml.database.LoggingTrigger=WARN |
37 | 36 |
log4j.logger.eu.dnetlib.enabling.tools.registration.ServiceRegistrator=INFO |
38 | 37 |
log4j.logger.eu.dnetlib.enabling.inspector=FATAL |
webapps/dnet-container-openaireplus/trunk/src/main/webapp/WEB-INF/dispatcher-servlet.xml | ||
---|---|---|
22 | 22 |
|
23 | 23 |
<mvc:resources mapping="/resources/**" location="classpath:/eu/dnetlib/web/resources/" /> |
24 | 24 |
|
25 |
<mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/" /> |
|
26 |
<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/" /> |
|
27 |
|
|
25 | 28 |
</beans> |
Also available in: Unified diff
added swagger support