springboot 集成webservice客户端调用报错

服务端生成的wsdl文件



package com.mochasoft.springws;

import java.math.BigInteger;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;


/**
 * <p>Java class for EmployeeType complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType name="EmployeeType">
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element name="Number" type="{http://www.w3.org/2001/XMLSchema}integer"/>
 *         &lt;element name="FirstName" type="{http://www.w3.org/2001/XMLSchema}string"/>
 *         &lt;element name="LastName" type="{http://www.w3.org/2001/XMLSchema}string"/>
 *       &lt;/sequence>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "EmployeeType", propOrder = {
    "number",
    "firstName",
    "lastName"
})
public class EmployeeType {
   

    @XmlElement(name = "Number", required = true)
    protected BigInteger number;
    @XmlElement(name = "FirstName", required = true)
    protected String firstName;
    @XmlElement(name = "LastName", required = true)
    protected String lastName;

    /**
     * Gets the value of the number property.
     * 
     * @return
     *     possible object is
     *     {@link BigInteger }
     *     
     */
    public BigInteger getNumber() {
        return number;
    }

    /**
     * Sets the value of the number property.
     * 
     * @param value
     *     allowed object is
     *     {@link BigInteger }
     *     
     */
    public void setNumber(BigInteger value) {
        this.number = value;
    }

    /**
     * Gets the value of the firstName property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getFirstName() {
        return firstName;
    }

    /**
     * Sets the value of the firstName property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setFirstName(String value) {
        this.firstName = value;
    }

    /**
     * Gets the value of the lastName property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getLastName() {
        return lastName;
    }

    /**
     * Sets the value of the lastName property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setLastName(String value) {
        this.lastName = value;
    }

}


package com.mochasoft.springws;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
import javax.xml.datatype.XMLGregorianCalendar;


/**
 * <p>Java class for HolidayType complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType name="HolidayType">
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element name="StartDate" type="{http://www.w3.org/2001/XMLSchema}date"/>
 *         &lt;element name="EndDate" type="{http://www.w3.org/2001/XMLSchema}date"/>
 *       &lt;/sequence>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "HolidayType", propOrder = {
    "startDate",
    "endDate"
})
public class HolidayType {
   

    @XmlElement(name = "StartDate", required = true)
    @XmlSchemaType(name = "date")
    protected XMLGregorianCalendar startDate;
    @XmlElement(name = "EndDate", required = true)
    @XmlSchemaType(name = "date")
    protected XMLGregorianCalendar endDate;

    /**
     * Gets the value of the startDate property.
     * 
     * @return
     *     possible object is
     *     {@link XMLGregorianCalendar }
     *     
     */
    public XMLGregorianCalendar getStartDate() {
        return startDate;
    }

    /**
     * Sets the value of the startDate property.
     * 
     * @param value
     *     allowed object is
     *     {@link XMLGregorianCalendar }
     *     
     */
    public void setStartDate(XMLGregorianCalendar value) {
        this.startDate = value;
    }

    /**
     * Gets the value of the endDate property.
     * 
     * @return
     *     possible object is
     *     {@link XMLGregorianCalendar }
     *     
     */
    public XMLGregorianCalendar getEndDate() {
        return endDate;
    }

    /**
     * Sets the value of the endDate property.
     * 
     * @param value
     *     allowed object is
     *     {@link XMLGregorianCalendar }
     *     
     */
    public void setEndDate(XMLGregorianCalendar value) {
        this.endDate = value;
    }

}


package com.mochasoft.springws;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;


/**
 * <p>Java class for anonymous complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType>
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;all>
 *         &lt;element name="Holiday" type="{http://mochasoft.com/springws/schemas}HolidayType"/>
 *       &lt;/all>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {

})
@XmlRootElement(name = "HolidayRequest")
public class HolidayRequest {
   

    @XmlElement(name = "Holiday", required = true)
    protected HolidayType holiday;
    @XmlElement(name = "Employee", required = true)
    protected EmployeeType employee;

    /**
     * Gets the value of the holiday property.
     * 
     * @return
     *     possible object is
     *     {@link HolidayType }
     *     
     */
    public HolidayType getHoliday() {
        return holiday;
    }

    /**
     * Sets the value of the holiday property.
     * 
     * @param value
     *     allowed object is
     *     {@link HolidayType }
     *     
     */
    public void setHoliday(HolidayType value) {
        this.holiday = value;
    }

    public EmployeeType getEmployee() {
        return employee;
    }

    public void setEmployee(EmployeeType employee) {
        this.employee = employee;
    }
}

package com.mochasoft.springws;

import javax.jws.Oneway;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.xml.bind.annotation.XmlSeeAlso;


/**
 * This class was generated by the JAX-WS RI.
 * JAX-WS RI 2.2.4-b01
 * Generated source version: 2.2
 * 
 */
@WebService(name = "HumanResource", targetNamespace = "http://mochasoft.com/springws")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
@XmlSeeAlso({
    ObjectFactory.class
})
public interface HumanResource {
   


    /**
     * 
     * @param holidayRequest
     */
    @WebMethod(operationName = "Holiday")
    @Oneway
    public void holiday(
        @WebParam(name = "HolidayRequest", targetNamespace = "http://mochasoft.com/springws", partName = "HolidayRequest")
        HolidayRequest holidayRequest);

}

package com.mochasoft.springws;

import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.WebServiceFeature;


/**
 * This class was generated by the JAX-WS RI.
 * JAX-WS RI 2.2.4-b01
 * Generated source version: 2.2
 * 
 */
@WebServiceClient(name = "HumanResourceService", targetNamespace = "http://mochasoft.com/springws", wsdlLocation = "file:/D:/Workspaces/IdeaProjects/spring-ws-client/src/main/resources/wsdl/hr.wsdl")
public class HumanResourceService
    extends Service
{
   

    private final static URL HUMANRESOURCESERVICE_WSDL_LOCATION;
    private final static WebServiceException HUMANRESOURCESERVICE_EXCEPTION;
    private final static QName HUMANRESOURCESERVICE_QNAME = new QName("http://mochasoft.com/springws", "HumanResourceService");

    static {
        URL url = null;
        WebServiceException e = null;
        try {
            url = new URL("file:/D:/Workspaces/IdeaProjects/spring-ws-client/src/main/resources/wsdl/hr.wsdl");
        } catch (MalformedURLException ex) {
            e = new WebServiceException(ex);
        }
        HUMANRESOURCESERVICE_WSDL_LOCATION = url;
        HUMANRESOURCESERVICE_EXCEPTION = e;
    }

    public HumanResourceService() {
        super(__getWsdlLocation(), HUMANRESOURCESERVICE_QNAME);
    }

    public HumanResourceService(WebServiceFeature... features) {
        super(__getWsdlLocation(), HUMANRESOURCESERVICE_QNAME, features);
    }

    public HumanResourceService(URL wsdlLocation) {
        super(wsdlLocation, HUMANRESOURCESERVICE_QNAME);
    }

    public HumanResourceService(URL wsdlLocation, WebServiceFeature... features) {
        super(wsdlLocation, HUMANRESOURCESERVICE_QNAME, features);
    }

    public HumanResourceService(URL wsdlLocation, QName serviceName) {
        super(wsdlLocation, serviceName);
    }

    public HumanResourceService(URL wsdlLocation, QName serviceName, WebServiceFeature... features) {
        super(wsdlLocation, serviceName, features);
    }

    /**
     * 
     * @return
     *     returns HumanResource
     */
    @WebEndpoint(name = "HumanResourceSoap11")
    public HumanResource getHumanResourceSoap11() {
        return super.getPort(new QName("http://mochasoft.com/springws", "HumanResourceSoap11"), HumanResource.class);
    }

    /**
     * 
     * @param features
     *     A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy.  Supported features not in the <code>features</code> parameter will have their default values.
     * @return
     *     returns HumanResource
     */
    @WebEndpoint(name = "HumanResourceSoap11")
    public HumanResource getHumanResourceSoap11(WebServiceFeature... features) {
        return super.getPort(new QName("http://mochasoft.com/springws", "HumanResourceSoap11"), HumanResource.class, features);
    }

    private static URL __getWsdlLocation() {
        if (HUMANRESOURCESERVICE_EXCEPTION!= null) {
            throw HUMANRESOURCESERVICE_EXCEPTION;
        }
        return HUMANRESOURCESERVICE_WSDL_LOCATION;
    }

}


package com.mochasoft.springws;

import javax.xml.bind.annotation.XmlRegistry;


/**
 * This object contains factory methods for each 
 * Java content interface and Java element interface 
 * generated in the com.mochasoft.springwsclient package. 
 * <p>An ObjectFactory allows you to programatically 
 * construct new instances of the Java representation 
 * for XML content. The Java representation of XML 
 * content can consist of schema derived interfaces 
 * and classes representing the binding of schema 
 * type definitions, element declarations and model 
 * groups.  Factory methods for each of these are 
 * provided in this class.
 * 
 */
@XmlRegistry
public class ObjectFactory {
   


    /**
     * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: com.mochasoft.springwsclient
     * 
     */
    public ObjectFactory() {
    }

    /**
     * Create an instance of {@link HolidayRequest }
     * 
     */
    public HolidayRequest createHolidayRequest() {
        return new HolidayRequest();
    }

    /**
     * Create an instance of {@link HolidayType }
     * 
     */
    public HolidayType createHolidayType() {
        return new HolidayType();
    }

    /**
     * Create an instance of {@link EmployeeType }
     * 
     */
    public EmployeeType createEmployeeType() {
        return new EmployeeType();
    }

}
@javax.xml.bind.annotation.XmlSchema(namespace = "http://mochasoft.com/springws", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package com.mochasoft.springws;

package com.mochasoft.springws;

import com.mochasoft.util.DateFormatUtil;
import org.springframework.ws.WebServiceMessage;
import org.springframework.ws.client.core.WebServiceMessageCallback;
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
import org.springframework.ws.soap.SoapMessage;
import org.springframework.xml.transform.StringResult;

import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Author 
 * @Date 2017/12/617:10
 */
public class WsClient extends WebServiceGatewaySupport {
   

   /* public int getCustomerCount() {
        HolidayRequest request = new HolidayRequest();
        HolidayType holidayType = new HolidayType();
       XMLGregorianCalendar xmlGregorianCalendar = DateFormatUtil.dateToXmlDate(new Date());
        holidayType.setEndDate(xmlGregorianCalendar);
        request.setHoliday(holidayType);


    }
    private static final String MESSAGE =
            "<message xmlns=\"http://tempuri.org\">Hello Web Service World</message>";

    private final WebServiceTemplate webServiceTemplate = new WebServiceTemplate();


    // send to the configured default URI
    public void simpleSendAndReceive() {
        StreamSource source = new StreamSource(new StringReader(MESSAGE));
        StreamResult result = new StreamResult(System.out);
        webServiceTemplate.sendSourceAndReceiveToResult(source, result);
    }

    // send to an explicit URI
    public void customSendAndReceive() {
        StreamSource source = new StreamSource(new StringReader(MESSAGE));
        StreamResult result = new StreamResult(System.out);
        webServiceTemplate.sendSourceAndReceiveToResult("http://localhost:8080/AnotherWebService",
                source, result);
    }*/
   public void test(){
       URL url = null;
       try {
           url = new URL("http://localhost:8090/springws/ws/hr.wsdl");
       } catch (MalformedURLException e) {
           e.printStackTrace();
       }
      /* HumanResourceService humanResourceService = new HumanResourceService(url);
       HumanResource humanResource= humanResourceService.getHumanResourceSoap11();*/
       HolidayRequest request = new HolidayRequest();
       HolidayType holidayType = new HolidayType();
       EmployeeType employeeType = new EmployeeType();
       employeeType.setFirstName("孙");
       employeeType.setLastName("");
       employeeType.setNumber(BigInteger.valueOf(10));
       XMLGregorianCalendar xmlGregorianCalendar = DateFormatUtil.dateToXmlDate(new Date());
       holidayType.setStartDate(xmlGregorianCalendar);
       holidayType.setEndDate(xmlGregorianCalendar);
       request.setHoliday(holidayType);
       request.setEmployee(employeeType);
       // humanResource.holiday(request);

       //服务描述中服务端点的限定名称  两个参数分别为 命名空间 服务名
       QName qName = new QName("http://mochasoft.com/springws", "HumanResourceService");
       //创建服务对象
       javax.xml.ws.Service service = javax.xml.ws.Service.create(url, qName);
       HumanResource humanResource=service.getPort(new QName("http://mochasoft.com/springws", "HumanResourceSoap11"), HumanResource.class);
       System.out.println("");
       humanResource.holiday(request);
       System.out.println("");
       /*
       WebServiceMessageCallback callback = new WebServiceMessageCallback() {

           public void doWithMessage(final WebServiceMessage message) throws IOException, TransformerException {
               String  connectSoapAction ="http://mochasoft.com/springws";
               ((SoapMessage) message).setSoapAction(connectSoapAction);
               Transformer newTransformer = TransformerFactory.newInstance().newTransformer();
               StringResult stringResult = new StringResult();
               newTransformer.transform(((SoapMessage) message).getSoapBody().getSource(), stringResult);
               System.out.println("send update message: " + stringResult.toString());
           }


       };
       getWebServiceTemplate().marshalSendAndReceive("http://localhost:8090/springws/ws/hr.wsdl",request,callback);*/
   }
    public  String sendGet(String url) {
        System.out.println("【sendGet中接收的url】============"+url);
        String result = "";
        String http_status = "";
        BufferedReader in = null;
        try {
            URL realUrl = new URL(url);
            // 打开和URL之间的连接
            URLConnection connection = realUrl.openConnection();
            // 设置通用的请求属性
            connection.setRequestProperty("accept", "*/*");
            connection.setRequestProperty("connection", "Keep-Alive");
            connection.setRequestProperty("user-agent",
                    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
            // 建立实际的连接
            connection.connect();
            // 获取所有响应头字段
            Map<String, List<String>> map = connection.getHeaderFields();
            // 遍历所有的响应头字段
           /* for (String key : map.keySet()) {
                System.out.println(key + "--->" + map.get(key));
                //System.out.println("【key为null】"+map.get(null));
                //null--->[HTTP/1.1 200 OK]
            }*/
            String k = map.get(null).toString();
            http_status =getNum(k).substring(2);
            //http_status = k.substring(k.indexOf(" "),k.lastIndexOf(" "));
            System.out.println("key==========="+http_status);
            // 定义 BufferedReader输入流来读取URL的响应
            in = new BufferedReader(new InputStreamReader(
                    connection.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) {
                result += line;
            }
        } catch (Exception e) {
            System.out.println("发送GET请求出现异常!" + e);
            e.printStackTrace();
        }
        // 使用finally块来关闭输入流
        finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        //return result;
        if("".equalsIgnoreCase(http_status.trim())){
            http_status="500";
        }
        return http_status;
    }
    public  String getNum(String str){
        //String str = "love23next234csdn3423javaeye";
        str=
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值