I successfully deployed a Web Service on Wildfly 27 with jakarta.jakartaee-api 10.0.0.
But I just can't get a junit test to access the web service.
I can call the wsdl via the browser and already tried all kinds of package imports to get the client to run, but I'm always getting package errors.
Have already read numerous posts and tried out the suggested package imports but all fails.
This is the wildfly console after deployment
address=http://localhost:8080/ejb-server-basic-jaxws/AccountWS
implementor=cs.edu.appserver.jaxws.AccountWS
serviceName={http://jaxws.appserver.edu.cs/}AccountWSService
portName={http://jaxws.appserver.edu.cs/}AccountWSPort
annotationWsdlLocation=null
wsdlLocationOverride=null
mtomEnabled=false
publishedEndpointUrl=http://localhost:8080/ejb-server-basic-jaxws/AccountWS
this is the wsdl
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://jaxws.appserver.edu.cs/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="AccountWSService" targetNamespace="http://jaxws.appserver.edu.cs/">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://jaxws.appserver.edu.cs/" elementFormDefault="unqualified" targetNamespace="http://jaxws.appserver.edu.cs/" version="1.0">
<xs:element name="account" type="tns:account"/>
<xs:element name="deposit" type="tns:deposit"/>
<xs:element name="depositResponse" type="tns:depositResponse"/>
<xs:element name="findAccountByName" type="tns:findAccountByName"/>
<xs:element name="findAccountByNameResponse" type="tns:findAccountByNameResponse"/>
<xs:element name="newAccount" type="tns:newAccount"/>
<xs:element name="newAccountResponse" type="tns:newAccountResponse"/>
<xs:element name="withdraw" type="tns:withdraw"/>
<xs:element name="withdrawResponse" type="tns:withdrawResponse"/>
<xs:complexType name="withdraw">
<xs:sequence>
<xs:element minOccurs="0" name="arg0" type="xs:string"/>
<xs:element name="arg1" type="xs:long"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="withdrawResponse">
<xs:sequence/>
</xs:complexType>
<xs:complexType name="deposit">
<xs:sequence>
<xs:element minOccurs="0" name="arg0" type="xs:string"/>
<xs:element name="arg1" type="xs:long"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="depositResponse">
<xs:sequence/>
</xs:complexType>
<xs:complexType name="findAccountByName">
<xs:sequence>
<xs:element minOccurs="0" name="arg0" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="findAccountByNameResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="tns:account"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="account">
<xs:sequence>
<xs:element name="amount" type="xs:long"/>
<xs:element minOccurs="0" name="id" type="xs:long"/>
<xs:element minOccurs="0" name="name" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="newAccount">
<xs:sequence>
<xs:element minOccurs="0" name="arg0" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="newAccountResponse">
<xs:sequence/>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="findAccountByNameResponse">
<wsdl:part element="tns:findAccountByNameResponse" name="parameters"> </wsdl:part>
</wsdl:message>
<wsdl:message name="depositResponse">
<wsdl:part element="tns:depositResponse" name="parameters"> </wsdl:part>
</wsdl:message>
<wsdl:message name="findAccountByName">
<wsdl:part element="tns:findAccountByName" name="parameters"> </wsdl:part>
</wsdl:message>
<wsdl:message name="withdrawResponse">
<wsdl:part element="tns:withdrawResponse" name="parameters"> </wsdl:part>
</wsdl:message>
<wsdl:message name="withdraw">
<wsdl:part element="tns:withdraw" name="parameters"> </wsdl:part>
</wsdl:message>
<wsdl:message name="deposit">
<wsdl:part element="tns:deposit" name="parameters"> </wsdl:part>
</wsdl:message>
<wsdl:message name="newAccountResponse">
<wsdl:part element="tns:newAccountResponse" name="parameters"> </wsdl:part>
</wsdl:message>
<wsdl:message name="newAccount">
<wsdl:part element="tns:newAccount" name="parameters"> </wsdl:part>
</wsdl:message>
<wsdl:portType name="AccountWSItf">
<wsdl:operation name="withdraw">
<wsdl:input message="tns:withdraw" name="withdraw"> </wsdl:input>
<wsdl:output message="tns:withdrawResponse" name="withdrawResponse"> </wsdl:output>
</wsdl:operation>
<wsdl:operation name="deposit">
<wsdl:input message="tns:deposit" name="deposit"> </wsdl:input>
<wsdl:output message="tns:depositResponse" name="depositResponse"> </wsdl:output>
</wsdl:operation>
<wsdl:operation name="findAccountByName">
<wsdl:input message="tns:findAccountByName" name="findAccountByName"> </wsdl:input>
<wsdl:output message="tns:findAccountByNameResponse" name="findAccountByNameResponse"> </wsdl:output>
</wsdl:operation>
<wsdl:operation name="newAccount">
<wsdl:input message="tns:newAccount" name="newAccount"> </wsdl:input>
<wsdl:output message="tns:newAccountResponse" name="newAccountResponse"> </wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="AccountWSServiceSoapBinding" type="tns:AccountWSItf">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="withdraw">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="withdraw">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="withdrawResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="deposit">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="deposit">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="depositResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="findAccountByName">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="findAccountByName">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="findAccountByNameResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="newAccount">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="newAccount">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="newAccountResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="AccountWSService">
<wsdl:port binding="tns:AccountWSServiceSoapBinding" name="AccountWSPort">
<soap:address location="http://localhost:8080/ejb-server-basic-jaxws/AccountWS"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
this is my current pom
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cs.edu.appserver</groupId>
<artifactId>ejb-server-basic-jaxws</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.server.bom>21.0.1.Final</version.server.bom>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<jakartaee.version>10.0.0</jakartaee.version>
<version.wildfly.maven.plugin>2.0.0.Final</version.wildfly.maven.plugin>
<apache.log4j2.version>2.20.0</apache.log4j2.version>
<junit.version>5.3.1</junit.version>
<skipTests>true</skipTests>
<version.wildfly>26.1.1.Final</version.wildfly>
</properties>
<dependencies>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-ejb-client-bom</artifactId>
<type>pom</type>
<scope>compile</scope>
<version>${version.wildfly}</version>
</dependency>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-ri</artifactId>
<version>2.3.2</version>
<scope>test</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>rt</artifactId>
<version>2.3.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>${jakartaee.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${apache.log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${apache.log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>${version.wildfly.maven.plugin}</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
<configuration>
<filename>${project.build.finalName}.war</filename>
<add-user>
<users>
<user>
<username>xxxx</username>
<password>yyyy</password>
</user>
</users>
</add-user>
</configuration>
</plugin>
</plugins>
</build>
</project>
this is my junit test
public void testWebService() {
String name = "John Smith";
try {
URL url = new URL("http://localhost:8080/ejb-server-basic-jaxws/AccountWS?wsdl");
QName qname = new QName("http://jaxws.appserver.edu.cs/", "AccountWSService");
Service service = Service.create(url, qname);
AccountWSItf ws = service.getPort(AccountWSItf.class);
ws.newAccount(name);
System.out.println("Created account name " + name);
ws.deposit(name, 1000);
System.out.println("Deposit $ 1000 ");
ws.withdraw(name, 500);
System.out.println("Withdraw $ 500 ");
Account account = ws.findAccountByName(name);
assertNotNull(account);
long money = account.getAmount();
assertEquals(500l, money);
System.out.println("Account balance is " + account.getAmount());
} catch (Exception e) {
e.printStackTrace();
System.out.println("Exception: " + e);
}
}
and this is the console when I run the test
com.sun.xml.ws.model.RuntimeModelerException: Eine WebService-Annotation ist in Klasse nicht vorhanden: cs.edu.appserver.jaxws.AccountWSItf
at com.sun.xml.ws.model.RuntimeModeler.getPortTypeName(RuntimeModeler.java:1581)
at com.sun.xml.ws.model.RuntimeModeler.getPortTypeName(RuntimeModeler.java:1572)
at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:428)
at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:449)
at javax.xml.ws.Service.getPort(Service.java:210)
at cs.edu.appserver.jaxws.test.ServiceTest.testWebService(ServiceTest.java:60)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727)
at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:86)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:217)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:213)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:138)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:68)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1507)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1507)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
Exception: com.sun.xml.ws.model.RuntimeModelerException: Eine WebService-Annotation ist in Klasse nicht vorhanden: cs.edu.appserver.jaxws.AccountWSItf
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:147)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:127)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:90)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:55)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:102)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:54)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:95)
at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:91)
at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:60)
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:98)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:40)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:529)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:756)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
the line
Eine WebService-Annotation ist in Klasse nicht vorhanden: cs.edu.appserver.jaxws.AccountWSItf
says that there is no web service annotation in class AccountWSItf
this is the interface AccountWSItf
import jakarta.jws.WebMethod;
import jakarta.jws.WebService;
@WebService
public interface AccountWSItf {
@WebMethod
public void newAccount( String name);
@WebMethod
public void withdraw(String name, long amount) throws RuntimeException;
@WebMethod
public void deposit(String name, long amount);
@WebMethod
public Account findAccountByName(String name);
}
this is its implementation
import jakarta.inject.Inject;
import jakarta.jws.WebParam;
import jakarta.jws.WebResult;
import jakarta.jws.WebService;
import jakarta.jws.soap.SOAPBinding;
@WebService
@SOAPBinding(style= SOAPBinding.Style.RPC)
public class AccountWS implements AccountWSItf{
@Inject
AccountManager ejb;
public void newAccount(@WebParam(name = "name") String name) {
ejb.createAccount(name);
}
public void withdraw(@WebParam(name = "name") String name,
@WebParam(name = "amount") long amount) throws RuntimeException {
ejb.withdraw(name, amount);
}
public void deposit(@WebParam(name = "name") String name,
@WebParam(name = "amount") long amount) {
ejb.deposit(name, amount);
}
@WebResult(name = "BankAccount")
public Account findAccountByName(String name) {
return ejb.findAccount(name);
}
}
followed numerous tutorials and posts on stackoverflow but just can't get the junit test to run.