@WebService(name = "ElectronicsWebServiceSoap", targetNamespace = "http://tempuri.org/")
@XmlSeeAlso({ ObjectFactory.class })
public interface ElectronicsWebServiceSoap {
@WebMethod(operationName = "UpdateCartGrade", action = "http://tempuri.org/UpdateCartGrade")
@WebResult(name = "UpdateCartGradeResult", targetNamespace = "http://tempuri.org/")
@RequestWrapper(localName = "UpdateCartGrade", targetNamespace = "http://tempuri.org/")
@ResponseWrapper(localName = "UpdateCartGradeResponse", targetNamespace = "http://tempuri.org/")
public String updateCartGrade(@WebParam(name = "version", targetNamespace = "http://tempuri.org/") String version,
@WebParam(name = "carno", targetNamespace = "http://tempuri.org/") String carno,
@WebParam(name = "pc", targetNamespace = "http://tempuri.org/") int pc,
@WebParam(name = "weight", targetNamespace = "http://tempuri.org/") double weight,
@WebParam(name = "volume", targetNamespace = "http://tempuri.org/") double volume,
@WebParam(name = "guide", targetNamespace = "http://tempuri.org/") String guide,
@WebParam(name = "remark", targetNamespace = "http://tempuri.org/") String remark);
}
@Component
public class ClientService {
// @Autowired
// private SystemVersion systemVersion;
private Client client;
private final Logger log = LoggerFactory.getLogger(getClass());
@Autowired
private ClientService(SystemVersion systemVersion) throws Exception {
if (client == null) {
synchronized (this) {
if (client == null) {
try {
// 创建动态客户端
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
client = dcf.createClient(systemVersion.getUrl());
} catch (Exception e) {
log.error("接口连接异常", e);
client = null;
}
}
}
}
}
public Client getInstance() {
return client;
}
}
public String updateCartGrade(CartGradeReq cartGradeReq) {
log.info("entry updateCartGrade mehtod ---- ");
try {
Client client = clientService.getInstance();
Endpoint endpoint = client.getEndpoint();
// 获取方法名所在的包名
QName opName = new QName(endpoint.getService().getName().getNamespaceURI(), "UpdateCartGrade");
BindingInfo bindingInfo = endpoint.getEndpointInfo().getBinding();
if (bindingInfo.getOperation(opName) == null) {
for (BindingOperationInfo operationInfo : bindingInfo.getOperations()) {
String name = operationInfo.getName().getLocalPart();
if ("UpdateCartGrade".equals(name)) {
opName = operationInfo.getName();
break;
}
}
}
Object[] objects = null;
// 调用代理接口的方法调用并返回结果
objects = client.invoke(opName, new Object[] {httpClient.getVersion(), cartGradeReq.getCarNo(), cartGradeReq.getPc(), cartGradeReq.getWeight(),
cartGradeReq.getVolume(), cartGradeReq.getGuide(), cartGradeReq.getRemark()});
BaseHttpRes res = (BaseHttpRes) JSON.parseObject(objects[0].toString(),BaseHttpRes.class);
if (res.getRetCode() == 100) {
return "";
}
} catch (Exception e) {
// TODO Auto-generated catch block
log.error("CartGradeServiceImpl exception : ", e);
}
return null;
}