Demontrating SOAP web service application using JAX-WS (Java EE6).
FYI: I'm using JBoss EAP 6.4.3, Java 1.8. Maven and Git should be also installed.
Clone the quickstart project, I cloned the 6.4.x
branch:
git clone -b 6.4.x --single-branch https://github.com/jboss-developer/jboss-eap-quickstarts.git
Check the branch:
cd jboss-eap-quickstarts
git branch
Move to the web service sample project:
cd helloworld-ws
src
├── main
│ ├── java
│ │ └── org
│ │ └── jboss
│ │ └── as
│ │ └── quickstarts
│ │ └── wshelloworld
│ │ ├── HelloWorldService.java
│ │ └── HelloWorldServiceImpl.java
│ └── webapp
│ ├── WEB-INF
│ │ └── beans.xml
│ └── index.html
└── test
├── java
│ └── org
│ └── jboss
│ └── as
│ └── quickstarts
│ └── wshelloworld
│ ├── Client.java
│ ├── ClientArqTest.java
│ └── ClientTest.java
└── resources
└── arquillian.xml
Interface file that define the Web Service: src/main/java/org/jboss/as/quickstarts/wshelloworld/HelloWorldService.java
@WebService(targetNamespace = "http://www.jboss.org/eap/quickstarts/wshelloworld/HelloWorld")
public interface HelloWorldService {
@WebMethod
public String sayHello();
@WebMethod
public String sayHelloToName(String name);
@WebMethod
public String sayHelloToNames(List<String> names);
}
Java class implenting the above interface: src/main/java/org/jboss/as/quickstarts/wshelloworld/HelloWorldServiceImpl.java
@WebService(serviceName = "HelloWorldService", portName = "HelloWorld", name = "HelloWorld",
endpointInterface = "org.jboss.as.quickstarts.wshelloworld.HelloWorldService",
targetNamespace = "http://www.jboss.org/eap/quickstarts/wshelloworld/HelloWorld")
public class HelloWorldServiceImpl implements HelloWorldService {
@Override
public String sayHello() {
//...
}
@Override
public String sayHelloToName(final String name) {
//...
}
@Override
public String sayHelloToNames(final List<String> names) {
//...
}
private String createNameListString(final List<String> names) {
//...
}
}
Build and package to create WAR file
mvn clean install
Deploy target/jboss-helloworld-ws.war
to JBoss EAP
Test by accessing WSDL file http://localhost:8080/jboss-helloworld-ws/HelloWorldService?wsdl
WSDL file:
<?xml version='1.0' encoding='UTF-8'?><wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://www.jboss.org/eap/quickstarts/wshelloworld/HelloWorld" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="HelloWorldService" targetNamespace="http://www.jboss.org/eap/quickstarts/wshelloworld/HelloWorld">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.jboss.org/eap/quickstarts/wshelloworld/HelloWorld" elementFormDefault="unqualified" targetNamespace="http://www.jboss.org/eap/quickstarts/wshelloworld/HelloWorld" version="1.0">
<xs:element name="sayHello" type="tns:sayHello"/>
<xs:element name="sayHelloResponse" type="tns:sayHelloResponse"/>
<xs:element name="sayHelloToName" type="tns:sayHelloToName"/>
<xs:element name="sayHelloToNameResponse" type="tns:sayHelloToNameResponse"/>
<xs:element name="sayHelloToNames" type="tns:sayHelloToNames"/>
<xs:element name="sayHelloToNamesResponse" type="tns:sayHelloToNamesResponse"/>
<xs:complexType name="sayHelloToNames">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="arg0" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="sayHelloToNamesResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="sayHello">
<xs:sequence/>
</xs:complexType>
<xs:complexType name="sayHelloResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="sayHelloToName">
<xs:sequence>
<xs:element minOccurs="0" name="arg0" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="sayHelloToNameResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="sayHelloToNames">
<wsdl:part element="tns:sayHelloToNames" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="sayHello">
<wsdl:part element="tns:sayHello" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="sayHelloToNameResponse">
<wsdl:part element="tns:sayHelloToNameResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="sayHelloToNamesResponse">
<wsdl:part element="tns:sayHelloToNamesResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="sayHelloResponse">
<wsdl:part element="tns:sayHelloResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="sayHelloToName">
<wsdl:part element="tns:sayHelloToName" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="HelloWorldService">
<wsdl:operation name="sayHelloToNames">
<wsdl:input message="tns:sayHelloToNames" name="sayHelloToNames">
</wsdl:input>
<wsdl:output message="tns:sayHelloToNamesResponse" name="sayHelloToNamesResponse">
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="sayHello">
<wsdl:input message="tns:sayHello" name="sayHello">
</wsdl:input>
<wsdl:output message="tns:sayHelloResponse" name="sayHelloResponse">
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="sayHelloToName">
<wsdl:input message="tns:sayHelloToName" name="sayHelloToName">
</wsdl:input>
<wsdl:output message="tns:sayHelloToNameResponse" name="sayHelloToNameResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="HelloWorldServiceSoapBinding" type="tns:HelloWorldService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="sayHelloToNames">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="sayHelloToNames">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="sayHelloToNamesResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="sayHello">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="sayHello">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="sayHelloResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="sayHelloToName">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="sayHelloToName">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="sayHelloToNameResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="HelloWorldService">
<wsdl:port binding="tns:HelloWorldServiceSoapBinding" name="HelloWorld">
<soap:address location="http://localhost:8480/jboss-helloworld-ws/HelloWorldService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Test using SOAP UI or simply use curl
command.
Create SOAP request message. Create a file with name request1.xml
:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:hel="http://www.jboss.org/eap/quickstarts/wshelloworld/HelloWorld">
<soapenv:Header/>
<soapenv:Body>
<hel:sayHello/>
</soapenv:Body>
</soapenv:Envelope>
Run curl
to send the above message as a HTTP POST to the web service application:
curl --header "Content-Type: text/xml;charset=UTF-8" --header "SOAPAction: \"\"" --data @request1.xml http://localhost:8480/jboss-helloworld-ws/HelloWorldService -v
Output:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:sayHelloResponse xmlns:ns2="http://www.jboss.org/eap/quickstarts/wshelloworld/HelloWorld"><return>Hello World!</return></ns2:sayHelloResponse></soap:Body></soap:Envelope>