
de.codecentric.cxf.autodetection.PackageNameReader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cxf-spring-boot-starter Show documentation
Show all versions of cxf-spring-boot-starter Show documentation
Boot starter for SOAP-Webservices with Apache CXF using JAX-WS & JAXB with Annotations only
The newest version!
package de.codecentric.cxf.autodetection;
import de.codecentric.cxf.autodetection.diagnostics.CxfSpringBootMavenPropertiesNotFoundException;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Optional;
import java.util.Properties;
public class PackageNameReader {
protected static final String CXF_SPRING_BOOT_MAVEN_PROPERTIES_FILE_NOT_FOUND = "Could not read packageNames from cxf-spring-boot-maven.properties.";
public static PackageNameReader build() {
return new PackageNameReader();
}
public String readSeiImplementationPackageNameFromCxfSpringBootMavenProperties() throws CxfSpringBootMavenPropertiesNotFoundException {
return readPackageNameFromCxfSpringBootMavenProperties("sei.implementation.package.name");
}
public String readSeiAndWebServiceClientPackageNameFromCxfSpringBootMavenProperties() throws CxfSpringBootMavenPropertiesNotFoundException {
return readPackageNameFromCxfSpringBootMavenProperties("sei.and.webserviceclient.package.name");
}
private String readPackageNameFromCxfSpringBootMavenProperties(String seiImplementationPackageNameKey) throws CxfSpringBootMavenPropertiesNotFoundException {
try {
Properties cxfSpringBootMavenProperties = new Properties();
cxfSpringBootMavenProperties.load(cxfSpringBootMavenPropertiesAsInputStream());
return cxfSpringBootMavenProperties.getProperty(seiImplementationPackageNameKey);
} catch (IOException ioExc) {
throw new CxfSpringBootMavenPropertiesNotFoundException(CXF_SPRING_BOOT_MAVEN_PROPERTIES_FILE_NOT_FOUND, ioExc);
}
}
private InputStream cxfSpringBootMavenPropertiesAsInputStream() throws IOException {
return findInClasspath("classpath*:**/" + "cxf-spring-boot-maven.properties").getInputStream();
}
private Resource findInClasspath(String pattern) throws IOException {
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] resources = resolver.getResources(pattern);
Optional first = Arrays.stream(resources).findFirst();
if(first.isPresent()) {
return first.get();
} else {
throw new FileNotFoundException();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy