-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#6 Implemented Failure Analyzer for Situations, where a Service Endpo…
…int Interface (SEI) could´nt be found. Also refactored the WebServiceAutoDetector module architecture that now separates the Scanning and the working with the specific WebService-Classes. That also results in the possiblility to use Mocks instead of preimplemented WebServiceAutoDetector Testable class, which never felt right.
- Loading branch information
1 parent
199a317
commit 4f03fa3
Showing
13 changed files
with
254 additions
and
197 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
69 changes: 69 additions & 0 deletions
69
src/main/java/de/codecentric/cxf/autodetection/WebServiceScanner.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,69 @@ | ||
package de.codecentric.cxf.autodetection; | ||
|
||
import de.codecentric.cxf.common.BootStarterCxfException; | ||
import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner; | ||
import io.github.lukehutch.fastclasspathscanner.scanner.ScanResult; | ||
|
||
import java.util.List; | ||
|
||
public class WebServiceScanner { | ||
|
||
protected static final String NO_CLASS_FOUND = "No class found"; | ||
|
||
protected <T> Class scanForClassWhichImplementsAndPickFirst(Class<T> interfaceName) throws BootStarterCxfException { | ||
List<String> namesOfClassesImplementing = initScannerAndScan().getNamesOfClassesImplementing(interfaceName); | ||
if (namesOfClassesImplementing.isEmpty()) { | ||
throw new BootStarterCxfException(WebServiceAutoDetector.NO_CLASS_FOUND); | ||
} | ||
return classForName(namesOfClassesImplementing.get(0)); | ||
} | ||
|
||
protected <T> Class scanForClassWithAnnotationAndPickTheFirstOneFound(Class<T> annotationName) throws BootStarterCxfException { | ||
return classForName(scanForClassNamesWithAnnotation(annotationName).get(0)); | ||
} | ||
|
||
protected <T> List<String> scanForClassNamesWithAnnotation(Class<T> annotationName) throws BootStarterCxfException { | ||
List<String> namesOfClassesWithAnnotation = initScannerAndScan().getNamesOfClassesWithAnnotation(annotationName); | ||
|
||
if(namesOfClassesWithAnnotation.isEmpty()) { | ||
throw new BootStarterCxfException(NO_CLASS_FOUND); | ||
} | ||
return namesOfClassesWithAnnotation; | ||
} | ||
|
||
protected <T> Class scanForClassWithAnnotationAndIsAnInterface(Class<T> annotationName) throws BootStarterCxfException { | ||
List<String> namesOfClassesWithAnnotation = scanForClassNamesWithAnnotation(annotationName); | ||
|
||
if(namesOfClassesWithAnnotation.size() > 1) { | ||
return justPickTheClassThatIsAnInterface(namesOfClassesWithAnnotation); | ||
} else { | ||
return classForName(namesOfClassesWithAnnotation.get(0)); | ||
} | ||
} | ||
|
||
protected Class justPickTheClassThatIsAnInterface(List<String> namesOfClassesWithAnnotation) throws BootStarterCxfException { | ||
for (String className : namesOfClassesWithAnnotation) { | ||
if (isInterface(className)) { | ||
return classForName(className); | ||
} | ||
} | ||
throw new BootStarterCxfException(NO_CLASS_FOUND); | ||
} | ||
|
||
protected boolean isInterface(String className) throws BootStarterCxfException { | ||
return classForName(className).isInterface(); | ||
} | ||
|
||
private ScanResult initScannerAndScan() { | ||
return new FastClasspathScanner().scan(); | ||
} | ||
|
||
|
||
protected Class<?> classForName(String className) throws BootStarterCxfException { | ||
try { | ||
return Class.forName(className); | ||
} catch (ClassNotFoundException exception) { | ||
throw new BootStarterCxfException(NO_CLASS_FOUND, exception); | ||
} | ||
} | ||
} |
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
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
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
20 changes: 20 additions & 0 deletions
20
src/main/java/de/codecentric/cxf/diagnostics/SeiMissingFailureAnalyzer.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,20 @@ | ||
package de.codecentric.cxf.diagnostics; | ||
|
||
import org.springframework.boot.diagnostics.AbstractFailureAnalyzer; | ||
import org.springframework.boot.diagnostics.FailureAnalysis; | ||
|
||
/** | ||
* FailureAnalyzer to show custom Failure Message, if the Service Endpoint Interface (SEI) is missing | ||
* (which is mandatory for autodetection and instantiation of the CXF endpoint(s)) | ||
* | ||
* @author jonashackt | ||
*/ | ||
public class SeiMissingFailureAnalyzer extends AbstractFailureAnalyzer<SeiNotFoundException>{ | ||
|
||
@Override | ||
protected FailureAnalysis analyze(Throwable rootFailure, SeiNotFoundException cause) { | ||
return new FailureAnalysis(SeiNotFoundException.MESSAGE, | ||
"Use the cxf-spring-boot-starter-maven-plugin (https://github.com/codecentric/cxf-spring-boot-starter-maven-plugin) " + | ||
"to generate the needed class files from your WSDL & XSDs", cause); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/de/codecentric/cxf/diagnostics/SeiNotFoundException.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,17 @@ | ||
package de.codecentric.cxf.diagnostics; | ||
|
||
import de.codecentric.cxf.common.BootStarterCxfException; | ||
|
||
/** | ||
* Thrown when the Service Endpoint Interface (SEI) itself isn´t found. | ||
* | ||
* @author jonashackt | ||
*/ | ||
public class SeiNotFoundException extends BootStarterCxfException { | ||
|
||
protected static final String MESSAGE = "The Service Endpoint Interface (SEI) could´nt be found - an interface that´s annotated with javax.jws.WebService"; | ||
|
||
public SeiNotFoundException() { | ||
super(MESSAGE); | ||
} | ||
} |
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
Oops, something went wrong.