Skip to content

Commit

Permalink
working Detection of WebServiceClient class added
Browse files Browse the repository at this point in the history
  • Loading branch information
jonashackt committed Nov 4, 2016
1 parent 7625c6f commit 8908f41
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ private CxfAutoConfiguration cxfAutoConfiguration;
* REST-Healthstatus-Endpoints, that check whether the soap-Services (dynamic?!) are available - using Swagger/Springfox
* Support for WS-Security-Token (e.g. used in [BiPro]
* Discribe already supported Client-Mode for JAX-WS-Services that are not hostet, but used
* Complete Automation of Endpoint Initialization: Auto-Detect javax.jws.WebService annotated, through to jaxws-maven-plugin generated Class Files representing your SEI and Auto-Initializing them, if found

# Contribution

Expand Down
8 changes: 8 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@
<artifactId>fluent-hc</artifactId>
<version>${fluent-hc.version}</version>
</dependency>

<!-- Autodetection of WebService and WebServiceClient classes for Endpoint Initialization -->
<dependency>
<groupId>io.github.lukehutch</groupId>
<artifactId>fast-classpath-scanner</artifactId>
<version>2.0.6</version>
</dependency>

<!-- Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
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);
}
}
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")));
}
}

0 comments on commit 8908f41

Please sign in to comment.