Engineering Full Stack Apps with Java and JavaScript
We will further analyze the lab excercise done @ http://javajee.com/lab-creating-a-soap-web-service-bottoms-up-using-endp....
We had used the below SEI for creating the web service:
package com.javajee.ws.tsexample1;
@WebService
public interface TimeService
{
@WebMethod
String getTimeFromServer();
}
We compiled the classes and executed the end point publisher (TimeServicePublisher) with the end point as http://127.0.0.1:8888/ts.
The WSDL file will be generated at the URL @ http://127.0.0.1:8888/ts?wsdl.
This url is obtained by appending '?wsdl' to the end point url.
You can change the end point url to any other names (e.g. http://127.0.0.1:8888/PUBLISHER) and the wsdl url will be http://127.0.0.1:8888/PUBLISHER?wsdl.
Important observations from the generated wsdl (given below) are:
namespace is http://tsexample1.ws.javajee.com/
schemaLocation is "http://127.0.0.1:8888/ts?xsd=1"
messages are getTimeFromServer and getTimeFromServerResponse.
portType is TimeService
operation is getTimeFromServer
binding details:
transport is http
style is document
use is literal
service name is TimeServiceImplService
port name="TimeServiceImplPort"
binding="tns:TimeServiceImplPortBinding">
location="http://127.0.0.1:8888/ts"/>
<definitions
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utili..."
xmlns:wsp="http://www.w3.org/ns/wspolicy"
xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy"
xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://tsexample1.ws.javajee.com/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="http://tsexample1.ws.javajee.com/"
name="TimeServiceImplService"><types>
<xsd:schema>
<xsd:import namespace="http://tsexample1.ws.javajee.com/" schemaLocation="http://127.0.0.1:8888/ts?xsd=1"/>
</xsd:schema>
</types>
<message name="getTimeFromServer">
<part name="parameters" element="tns:getTimeFromServer"/>
</message>
<message name="getTimeFromServerResponse">
<part name="parameters" element="tns:getTimeFromServerResponse"/>
</message>
<portType name="TimeService">
<operation name="getTimeFromServer">
<input wsam:Action="http://tsexample1.ws.javajee.com/TimeService/getTimeFromServerRequest"
message="tns:getTimeFromServer"/><output wsam:Action="http://tsexample1.ws.javajee.com/TimeService/getTimeFromServerResponse"
message="tns:getTimeFromServerResponse"/></operation>
</portType>
<binding name="TimeServiceImplPortBinding" type="tns:TimeService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="getTimeFromServer">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="TimeServiceImplService">
<port name="TimeServiceImplPort" binding="tns:TimeServiceImplPortBinding">
<soap:address location="http://127.0.0.1:8888/ts"/>
</port>
</service>
</definitions>
You can look into the SOAP request and response with many tools such as TCPMon or wireshark. We will be using TCPMon here to make things simple.
Run build\tcpmon.bat form the tcpmon home folder (extracted folder).
Go to the Admin tab
Add listening port as 9999
Give the target host name and target port as per your publisher
Click add
Next, change the client code to change the port from 8888 to 9999.
Compile and execute the client code.
Verify the results in the tcpmon tab for port 9999:
There will be 2 requests and 2 responses:
First a GET request is made to get the wsdl
Server sends back the WSDL
Client makes another request with the SOAP request
Server sends back the SOAP response.
NOTE! You may also use a tool such as SOAP UI to create a SOAP request and send it to server.
GET /ts?wsdl HTTP/1.1
User-Agent: Java/1.8.0_60
Host: 127.0.0.1:9999
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alivePOST /ts HTTP/1.1
Accept: text/xml, multipart/related
Content-Type: text/xml; charset=utf-8
SOAPAction: "http://tsexample1.ws.javajee.com/TimeService/getTimeFromServerRequest"
User-Agent: JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e
Host: 127.0.0.1:9999
Connection: keep-alive
Content-Length: 209<?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:getTimeFromServer xmlns:ns2="http://tsexample1.ws.javajee.com/"></ns2:getTimeFromServer></S:Body></S:Envelope>
HTTP/1.1 200 OK
Date: Tue, 20 Oct 2015 04:45:27 GMT
Transfer-encoding: chunked
Content-type: text/xml;charset=utf-88cd
<?xml version="1.0" encoding="UTF-8"?><!-- Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. --><!-- Generated by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. --><definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utili..." xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://tsexample1.ws.javajee.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://tsexample1.ws.javajee.com/" name="TimeServiceImplService">
<types>
<xsd:schema>
<xsd:import namespace="http://tsexample1.ws.javajee.com/" schemaLocation="http://127.0.0.1:9999/ts?xsd=1"></xsd:import>
</xsd:schema>
</types>
<message name="getTimeFromServer">
<part name="parameters" element="tns:getTimeFromServer"></part>
</message>
<message name="getTimeFromServerResponse">
<part name="parameters" element="tns:getTimeFromServerResponse"></part>
</message>
<portType name="TimeService">
<operation name="getTimeFromServer">
<input wsam:Action="http://tsexample1.ws.javajee.com/TimeService/getTimeFromServerRequest" message="tns:getTimeFromServer"></input>
<output wsam:Action="http://tsexample1.ws.javajee.com/TimeService/getTimeFromServerResponse" message="tns:getTimeFromServerResponse"></output>
</operation>
</portType>
<binding name="TimeServiceImplPortBinding" type="tns:TimeService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"></soap:binding>
<operation name="getTimeFromServer">
<soap:operation soapAction=""></soap:operation>
<input>
<soap:body use="literal"></soap:body>
</input>
<output>
<soap:body use="literal"></soap:body>
</output>
</operation>
</binding>
<service name="TimeServiceImplService">
<port name="TimeServiceImplPort" binding="tns:TimeServiceImplPortBinding">
<soap:address location="http://127.0.0.1:9999/ts"></soap:address>
</port>
</service>
</definitions>
0HTTP/1.1 200 OK
Date: Tue, 20 Oct 2015 04:45:27 GMT
Transfer-encoding: chunked
Content-type: text/xml; charset=utf-810e
<?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:getTimeFromServerResponse xmlns:ns2="http://tsexample1.ws.javajee.com/"><return>Tue Oct 20 10:15:27 IST 2015</return></ns2:getTimeFromServerResponse></S:Body></S:Envelope>
0