io.virtualan.autoconfig.VirtualServiceConfig Maven / Gradle / Ivy
/*
* Copyright 2018 Virtualan Contributors (https://virtualan.io)
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package io.virtualan.autoconfig;
import org.springframework.beans.factory.config.ServiceLocatorFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import io.virtualan.VirtualServiceInfoFactory;
import io.virtualan.controller.VirtualServiceController;
/**
* This is base class to load the service virtaulized service(Virtualan).
*
* @author Elan Thangamani
*
**/
@Configuration
@EnableAspectJAutoProxy
@ComponentScan(basePackages = {"io.virtualan"})
public class VirtualServiceConfig {
@Bean
protected VirtualServiceController virtualServiceController() {
return new VirtualServiceController();
}
@Bean
public ServiceLocatorFactoryBean myFactoryServiceLocatorFactoryBean() {
ServiceLocatorFactoryBean bean = new ServiceLocatorFactoryBean();
bean.setServiceLocatorInterface(VirtualServiceInfoFactory.class);
return bean;
}
/* @Bean
public Docket customImplementation(ServletContext servletContext,
@Value("${openapi.openAPIPetstore.base-path:/api}") String basePath) {
return new Docket(DocumentationType.SWAGGER_2).select()
.apis(RequestHandlerSelectors.basePackage("com.virtualan.api")).build()
.pathProvider(new BasePathAwareRelativePathProvider(servletContext, basePath))
.directModelSubstitute(java.time.LocalDate.class, java.sql.Date.class)
.directModelSubstitute(java.time.OffsetDateTime.class, java.util.Date.class).apiInfo(apiInfo());
}
class BasePathAwareRelativePathProvider extends RelativePathProvider {
private String basePath;
public BasePathAwareRelativePathProvider(ServletContext servletContext, String basePath) {
super(servletContext);
this.basePath = basePath;
}
@Override
protected String applicationPath() {
return Paths.removeAdjacentForwardSlashes(
UriComponentsBuilder.fromPath(super.applicationPath()).path(basePath).build().toString());
}
@Override
public String getOperationPath(String operationPath) {
UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromPath("/");
return Paths.removeAdjacentForwardSlashes(
uriComponentsBuilder.path(operationPath.replaceFirst("^" + basePath, "")).build().toString());
}
}
* @Bean public Docket customImplementation(ServletContext servletContext) {
* Docket docket = new Docket(DocumentationType.SWAGGER_2);
* ApiSelectorBuilder selector = docket.select(); for (Map.Entry virtualServices :
* virtualServiceController().getVirtualServiceInfo()
* .findVirtualServices().entrySet()) {
* println(virtualServices.getValue().getPackage().getName());
* selector.apis(RequestHandlerSelectors.basePackage(virtualServices.
* getValue().getPackage().getName())); }
* selector.build().directModelSubstitute(java.time.LocalDate.class,
* java.sql.Date.class)
* .directModelSubstitute(java.time.OffsetDateTime.class,
* java.util.Date.class).apiInfo(apiInfo()); return docket; }
ApiInfo apiInfo() {
return new ApiInfoBuilder().title("Virtualan").description("Virtualan the service virtualaization service")
.license("Apache-2.0").licenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html")
.termsOfServiceUrl("").version("1.0.0").contact(new Contact("Elan", "", "[email protected]"))
.build(); }*/
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy