<?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions name="CurrentTimeService" targetNamespace="http://artspb.me/cts" xmlns:tns="http://artspb.me/cts" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"> <wsdl:types> <xsd:schema targetNamespace="http://artspb.me/cts"> <xsd:element name="timeZoneId" nillable="true" type="xsd:string"/> <xsd:element name="currentTime" type="xsd:dateTime"/> </xsd:schema> </wsdl:types> <wsdl:message name="getCurrentTimeMsg"> <wsdl:part element="tns:timeZoneId" name="timeZoneId"/> </wsdl:message> <wsdl:message name="currentTimeMsg"> <wsdl:part element="tns:currentTime" name="currentTime"/> </wsdl:message> <wsdl:portType name="CurrentTimeService"> <wsdl:operation name="getCurrentTime"> <wsdl:input message="tns:getCurrentTimeMsg" name="getCurrentTime"/> <wsdl:output message="tns:currentTimeMsg" name="currentTime"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="CurrentTimeService_HttpBinding" type="tns:CurrentTimeService"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="getCurrentTime"> <soap:operation soapAction="http://artspb.me/cts" style="document"/> <wsdl:input name="getCurrentTime"> <soap:body use="literal"/> </wsdl:input> <wsdl:output name="currentTime"> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="CurrentTimeService_HttpService"> <wsdl:port binding="tns:CurrentTimeService_HttpBinding" name="CurrentTimeService_HttpPort"> <soap:address location="http://localhost:8080/YetAnotherService/service/currentTimeService"/> </wsdl:port> </wsdl:service> </wsdl:definitions>
<?xml version="1.0"?> <project name="BuildObject"> <property name="cxf.home" value="/home/art/tools/apache-cxf-2.5.2"/> <path id="cxf.classpath"> <fileset dir="${cxf.home}/lib"> <include name="*.jar"/> </fileset> </path> <target name="cxfWSDLToJava"> <java classname="org.apache.cxf.tools.wsdlto.WSDLToJava" fork="true"> <arg value="-verbose"/> <arg value="-d"/> <arg value="../ObjectLibrary/src/main/java"/> <arg value="../ObjectLibrary/src/main/resources/CurrentTimeService.wsdl"/> <classpath> <path refid="cxf.classpath"/> </classpath> </java> </target> <target name="regenerate.object.library"> <delete dir="../ObjectLibrary/src/main/java"/> <antcall target="cxfWSDLToJava"/> </target> </project>
package me.artspb.cts; 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; /** * This class was generated by Apache CXF 2.5.2 * 2012-02-02T17:39:35.466+04:00 * Generated source version: 2.5.2 * */ @WebService(targetNamespace = "http://artspb.me/cts", name = "CurrentTimeService") @XmlSeeAlso({ObjectFactory.class}) @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE) public interface CurrentTimeService { @WebResult(name = "currentTime", targetNamespace = "http://artspb.me/cts", partName = "currentTime") @WebMethod(action = "http://artspb.me/cts") public javax.xml.datatype.XMLGregorianCalendar getCurrentTime( @WebParam(partName = "timeZoneId", name = "timeZoneId", targetNamespace = "http://artspb.me/cts") java.lang.String timeZoneId ); }
package me.artspb.cts; import org.apache.log4j.Logger; import javax.jws.WebParam; import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; import java.util.GregorianCalendar; import java.util.TimeZone; public class CurrentTimeServiceImpl implements CurrentTimeService { private Logger logger = Logger.getLogger(CurrentTimeServiceImpl.class); public XMLGregorianCalendar getCurrentTime( @WebParam(partName = "timeZoneId", name = "timeZoneId", targetNamespace = "http://artspb.me/cts") String timeZoneId) { logger.debug("Operation getCurrentTime was requested."); XMLGregorianCalendar gregorianCalendar; try { gregorianCalendar = getXmlGregorianCalendar(timeZoneId); } catch (DatatypeConfigurationException e) { throw new RuntimeException(e); } logger.debug("Successful."); return gregorianCalendar; } private XMLGregorianCalendar getXmlGregorianCalendar(String id) throws DatatypeConfigurationException { TimeZone timeZone; if (!"".equals(id)) { logger.debug("TimeZoneId isn't null: " + id); timeZone = TimeZone.getTimeZone(id); } else { logger.debug("TimeZoneId is null. Will use default value."); timeZone = TimeZone.getDefault(); } GregorianCalendar gregorianCalendar = new GregorianCalendar(timeZone); return DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar); } }
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cts="http://artspb.me/cts"> <soapenv:Header/> <soapenv:Body> <cts:timeZoneId>PST</cts:timeZoneId> </soapenv:Body> </soapenv:Envelope>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <currentTime xmlns="http://artspb.me/cts">2012-02-02T08:48:24.402-08:00</currentTime> </soap:Body> </soap:Envelope>
Source: https://habr.com/ru/post/137543/
All Articles