-
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.
working Detection of WebServiceClient class added
- Loading branch information
1 parent
7625c6f
commit 8908f41
Showing
4 changed files
with
100 additions
and
0 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
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
50 changes: 50 additions & 0 deletions
50
src/main/java/de/codecentric/cxf/autodetection/WebServiceAutoDetector.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,50 @@ | ||
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 javax.xml.ws.Service; | ||
import javax.xml.ws.WebServiceClient; | ||
import java.lang.reflect.Constructor; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.List; | ||
|
||
|
||
public class WebServiceAutoDetector { | ||
|
||
public static Service searchWebServiceClient() throws BootStarterCxfException { | ||
|
||
try { | ||
Class webServiceClientClass = scanForClassWithExtendJavaxXmlWsService(); | ||
|
||
Constructor<?> constructor = webServiceClientClass.getConstructor(); | ||
|
||
Object webServiceClient = constructor.newInstance(); | ||
|
||
return (Service) webServiceClient; | ||
|
||
} catch (ClassNotFoundException | | ||
NoSuchMethodException | | ||
IllegalAccessException | | ||
InstantiationException | | ||
InvocationTargetException exception) { | ||
throw new BootStarterCxfException("WebServiceClient Class not found", exception); | ||
} | ||
|
||
} | ||
|
||
private static Class scanForClassWithExtendJavaxXmlWsService() throws ClassNotFoundException { | ||
// see https://github.com/lukehutch/fast-classpath-scanner/wiki/1.-Usage#mechanism-2 | ||
FastClasspathScanner fastClasspathScanner = new FastClasspathScanner(); | ||
|
||
ScanResult scanResult = fastClasspathScanner.scan(); | ||
|
||
List<String> namesOfClassesWithAnnotation = scanResult.getNamesOfClassesWithAnnotation(WebServiceClient.class); | ||
|
||
String webServiceClientClassName = namesOfClassesWithAnnotation.get(0); | ||
System.out.println("Class found: " + webServiceClientClassName); | ||
|
||
return Class.forName(webServiceClientClassName); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/test/java/de/codecentric/cxf/autodetection/WebServiceAutoDetectorTest.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,41 @@ | ||
package de.codecentric.cxf.autodetection; | ||
|
||
import de.codecentric.cxf.autodetection.WebServiceAutoDetector; | ||
import de.codecentric.cxf.common.BootStarterCxfException; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
import javax.xml.namespace.QName; | ||
import javax.xml.ws.Service; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.core.Is.is; | ||
import static org.hamcrest.core.IsEqual.equalTo; | ||
import static org.hamcrest.core.IsNull.notNullValue; | ||
import static org.mockito.Matchers.contains; | ||
|
||
|
||
@RunWith(SpringRunner.class) | ||
public class WebServiceAutoDetectorTest { | ||
|
||
@Test | ||
public void isWebServiceSuccessfullyDetected() { | ||
|
||
|
||
|
||
assertThat(false, is(true)); | ||
} | ||
|
||
@Test | ||
public void isWebServiceClientSuccessfullyDetected() throws BootStarterCxfException { | ||
|
||
Service webServiceClient = WebServiceAutoDetector.searchWebServiceClient(); | ||
|
||
assertThat(webServiceClient, is(notNullValue())); | ||
|
||
QName serviceNameQName = webServiceClient.getServiceName(); | ||
assertThat(serviceNameQName.getLocalPart(), is(equalTo("Weather"))); | ||
} | ||
} |