我是春季启动的新手,我正试图从here消费肥皂服务
以某种方式使用spring boot我的代码似乎不起作用。我已经生成了wsdl
中保存在generated-sources文件夹中的类。如何正确使用远程wsdl
?
生成的类文件夹
生成的类代码
package net.webservicex;
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.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"fromCurrency",
"toCurrency"
})
@XmlRootElement(name = "ConversionRate")
public class ConversionRate {
@XmlElement(name = "FromCurrency", required = true)
@XmlSchemaType(name = "string")
protected Currency fromCurrency;
@XmlElement(name = "ToCurrency", required = true)
@XmlSchemaType(name = "string")
protected Currency toCurrency;
public Currency getFromCurrency() {
return fromCurrency;
}
public void setFromCurrency(Currency value) {
this.fromCurrency = value;
}
public Currency getToCurrency() {
return toCurrency;
}
public void setToCurrency(Currency value) {
this.toCurrency = value;
}
}
ConversionRateResponse.java
package net.webservicex;
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;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"conversionRateResult"
})
@XmlRootElement(name = "ConversionRateResponse")
public class ConversionRateResponse {
@XmlElement(name = "ConversionRateResult")
protected double conversionRateResult;
public double getConversionRateResult() {
return conversionRateResult;
}
public void setConversionRateResult(double value) {
this.conversionRateResult = value;
}
}
Country.java
package net.webservicex;
import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlType;
@XmlType(name = "Currency")
@XmlEnum
public enum Currency {
AFA,
ALL,
DZD,
ARS,
USD,
TRY;
/*Removed some country codes*/
public String value() {
return name();
}
public static Currency fromValue(String v) {
return valueOf(v);
}
}
ObjectFactory.java
package net.webservicex;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlElementDecl;
import javax.xml.bind.annotation.XmlRegistry;
import javax.xml.namespace.QName;
@XmlRegistry
public class ObjectFactory {
private final static QName _Double_QNAME = new QName("http://www.webserviceX.NET/", "double");
public ObjectFactory() {
}
public ConversionRate createConversionRate() {
return new ConversionRate();
}
public ConversionRateResponse createConversionRateResponse() {
return new ConversionRateResponse();
}
@XmlElementDecl(namespace = "http://www.webserviceX.NET/", name = "double")
public JAXBElement<Double> createDouble(Double value) {
return new JAXBElement<Double>(_Double_QNAME, Double.class, null, value);
}
}
而且我从这里调用服务,不知怎的,这不起作用。
package com.wsdl;
import net.webservicex.ConversionRate;
import net.webservicex.ConversionRateResponse;
import net.webservicex.Currency;
import net.webservicex.ObjectFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Created by tenten on 2017/02/15.
*/
@RestController
public class Testing {
@RequestMapping("/ConversionRate")
public double conversionRate() {
ObjectFactory objectFactory = new ObjectFactory();
ConversionRate conversionRate = objectFactory.createConversionRate();
ConversionRateResponse conversionRateResponse = objectFactory.createConversionRateResponse();
Currency usd = Currency.USD;
usd.value();
Currency btn = Currency.BTN;
btn.value();
conversionRate.setToCurrency(usd);
conversionRate.setFromCurrency(btn);
conversionRateResponse.setConversionRateResult(12.00);
return conversionRateResponse.getConversionRateResult();
}
}