By default, a Java SOAP-based web service is wrapped doc/lit, that is, wrapped document style with literal encoding. We're going to create an unwrapped document/literal web service and analyze the WSDL and Request/Response structure.
I'm using same set of the classes used in my previous blog with little modification in Service Implementation Bean to make it unwrapped document/literal style.
TeamService.java
package ch01.team;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.ParameterStyle;
import javax.jws.soap.SOAPBinding.Style;
@WebService
@SOAPBinding(parameterStyle=ParameterStyle.BARE)
public class Teams {
private TeamsUtility utils;
public Teams() {
utils = new TeamsUtility();
utils.make_test_teams();
}
@WebMethod(operationName="getTeamDetails")
public Team getTeam(@WebParam(name="teamQuery",partName="teamQueryPart") TeamQuery query) { return utils.getTeam(query.getTeamQueryParams()); }
}
ParameterStyle.BARE makes this a doc/lit unwrapped implementation.
The WSDL reflects these changes. Like other document style implementation, <types> element contains the schema definition for data types.
Input <message> element contains operation name and part details specified in Teams.java.
The schema definition is below. The wrapper classes for Request and Response is missing. There is no XML schema data type for Request and Response wrappers.
Let's create a client for invoking this webservice using wsimport utility that ships with JAX-WS.
%wsimport -p unwrapped -keep http://localhost:8888/teams?wsdl
Running this command creates below classes in 'unwrapped' package. In addition to Service and JAXB classes, there is a class for every data type specified in XML schema name.
Running this command for same web service in doc/lit wrapped mode would have created two additional classes; a wrapper for Request and Response XMLs (will see that later).
See the Teams.java below:
package unwrapped;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.xml.bind.annotation.XmlSeeAlso;
@WebService(name = "Teams", targetNamespace = "http://team.ch01/")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
@XmlSeeAlso({
ObjectFactory.class
})
public interface Teams {
@WebMethod
@WebResult(name = "getTeamDetailsResponse", targetNamespace = "http://team.ch01/", partName = "getTeamDetailsResponse")
public Team getTeamDetails(
@WebParam(name = "teamQuery", targetNamespace = "http://team.ch01/", partName = "teamQueryPart")
TeamQuery teamQueryPart);
}
There is no wrapper for Request and Response here.
Let's create client for invoking the service operations.
Client.java
package unwrapped;
public class Client {
public static void main(String s[]){
TeamsService service = new TeamsService();//Invoke the Service
Teams port = service.getTeamsPort();//Get access to the the port
//Prepare query parameters
TeamQuery query = new TeamQuery();
query.setTeamQueryParams(("Burns and Allen"));
Team team = port.getTeamDetails(query);
System.out.println("Team name: "+ team.getName());
for(Player p: team.getPlayers()){
System.out.println("Player name: "+ p.getName());
System.out.println("Player nick name: "+ p.getNickname());
}
}
}
And here are the Request and Response XMLs. There is no '<getTeamDetails>' element to wrap the service call for this operation. In its 'unwrapped' form, doc/lit misses an important element that dispatches the service call to the appropriate operation, and I don't see any practical use for this kind of web service implementation.
Request.xml
<?xml version="1.0"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:teamQuery xmlns:ns2="http://team.ch01/">
<teamQueryParams>Burns and Allen</teamQueryParams>
</ns2:teamQuery>
</S:Body>
</S:Envelope>
Response.xml
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getTeamDetailsResponse xmlns:ns2="http://team.ch01/">
<name>Burns and Allen</name>
<players>
<name>George Burns</name>
<nickname>George</nickname>
</players>
<players>
<name>Gracie Allen</name>
<nickname>Gracie</nickname>
</players>
</ns2:getTeamDetailsResponse>
</S:Body>
</S:Envelope>
Let's implement the same web service in 'Document/lit wrapped' style.
To make this happen, we will have to modify our Teams service class to specify appropriate SOAP binding.
package ch01.team;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
@WebService
@SOAPBinding(style=Style.DOCUMENT)
public class Teams {
private TeamsUtility utils;
public Teams() {
utils = new TeamsUtility();
utils.make_test_teams();
}
@WebMethod(operationName="getTeamDetails")
public Team getTeam(@WebParam(name="teamQuery") TeamQuery query) { return utils.getTeam(query.getTeamQueryParams()); }
}
I'm using same set of the classes used in my previous blog with little modification in Service Implementation Bean to make it unwrapped document/literal style.
TeamService.java
package ch01.team;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.ParameterStyle;
import javax.jws.soap.SOAPBinding.Style;
@WebService
@SOAPBinding(parameterStyle=ParameterStyle.BARE)
public class Teams {
private TeamsUtility utils;
public Teams() {
utils = new TeamsUtility();
utils.make_test_teams();
}
@WebMethod(operationName="getTeamDetails")
public Team getTeam(@WebParam(name="teamQuery",partName="teamQueryPart") TeamQuery query) { return utils.getTeam(query.getTeamQueryParams()); }
}
ParameterStyle.BARE makes this a doc/lit unwrapped implementation.
The WSDL reflects these changes. Like other document style implementation, <types> element contains the schema definition for data types.
Input <message> element contains operation name and part details specified in Teams.java.
The schema definition is below. The wrapper classes for Request and Response is missing. There is no XML schema data type for Request and Response wrappers.
Let's create a client for invoking this webservice using wsimport utility that ships with JAX-WS.
%wsimport -p unwrapped -keep http://localhost:8888/teams?wsdl
Running this command creates below classes in 'unwrapped' package. In addition to Service and JAXB classes, there is a class for every data type specified in XML schema name.
Running this command for same web service in doc/lit wrapped mode would have created two additional classes; a wrapper for Request and Response XMLs (will see that later).
See the Teams.java below:
package unwrapped;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.xml.bind.annotation.XmlSeeAlso;
@WebService(name = "Teams", targetNamespace = "http://team.ch01/")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
@XmlSeeAlso({
ObjectFactory.class
})
public interface Teams {
@WebMethod
@WebResult(name = "getTeamDetailsResponse", targetNamespace = "http://team.ch01/", partName = "getTeamDetailsResponse")
public Team getTeamDetails(
@WebParam(name = "teamQuery", targetNamespace = "http://team.ch01/", partName = "teamQueryPart")
TeamQuery teamQueryPart);
}
There is no wrapper for Request and Response here.
Let's create client for invoking the service operations.
Client.java
package unwrapped;
public class Client {
public static void main(String s[]){
TeamsService service = new TeamsService();//Invoke the Service
Teams port = service.getTeamsPort();//Get access to the the port
//Prepare query parameters
TeamQuery query = new TeamQuery();
query.setTeamQueryParams(("Burns and Allen"));
Team team = port.getTeamDetails(query);
System.out.println("Team name: "+ team.getName());
for(Player p: team.getPlayers()){
System.out.println("Player name: "+ p.getName());
System.out.println("Player nick name: "+ p.getNickname());
}
}
}
And here are the Request and Response XMLs. There is no '<getTeamDetails>' element to wrap the service call for this operation. In its 'unwrapped' form, doc/lit misses an important element that dispatches the service call to the appropriate operation, and I don't see any practical use for this kind of web service implementation.
Request.xml
<?xml version="1.0"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:teamQuery xmlns:ns2="http://team.ch01/">
<teamQueryParams>Burns and Allen</teamQueryParams>
</ns2:teamQuery>
</S:Body>
</S:Envelope>
Response.xml
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getTeamDetailsResponse xmlns:ns2="http://team.ch01/">
<name>Burns and Allen</name>
<players>
<name>George Burns</name>
<nickname>George</nickname>
</players>
<players>
<name>Gracie Allen</name>
<nickname>Gracie</nickname>
</players>
</ns2:getTeamDetailsResponse>
</S:Body>
</S:Envelope>
Let's implement the same web service in 'Document/lit wrapped' style.
To make this happen, we will have to modify our Teams service class to specify appropriate SOAP binding.
package ch01.team;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
@WebService
@SOAPBinding(style=Style.DOCUMENT)
public class Teams {
private TeamsUtility utils;
public Teams() {
utils = new TeamsUtility();
utils.make_test_teams();
}
@WebMethod(operationName="getTeamDetails")
public Team getTeam(@WebParam(name="teamQuery") TeamQuery query) { return utils.getTeam(query.getTeamQueryParams()); }
}
'style' is changed to DOCUMENT and 'partName' is removed from WebParam because that is not supported by doc/lit wrapped.
No comments:
Post a Comment