WebServiceClient.java
4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package StSys.RoyoTech;
import StSys.RoyoTech.client.AdapterService;
import StSys.RoyoTech.client.IWSAdapter;
import com.myproject.bean.update.Barcode;
import com.myproject.util.XmlUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.List;
/**
* Created by sunke on 2019/10/12.
*/
public class WebServiceClient {
protected static final transient Logger log = LogManager.getLogger(WebServiceClient.class);
private static IWSAdapter adapter = null;
public static String NotifyCarrierNew(String barcode, String pn){
log.info("扫到条码["+barcode+"]通知纬创接口");
String commandStr = "<XmlCommand><Command>NotifyCarrierNew</Command><Parameter><FieldList><Field key=\"CARRIER\" value=\""+barcode+"\" /><Field key=\"ARTICLE\" value=\""+pn+"\" /></FieldList></Parameter></XmlCommand>";
//commandStr = "<XmlCommand><Command>NotifyCarrierNew</Command><Parameter><FieldList><Field key=\"CARRIER\" value=\"M680174253219ACBT\" /><Field key=\"ARTICLE\" value=\"68.8R2BN.201\" /></FieldList></Parameter></XmlCommand>";
String resultXml = exeCommand(commandStr);
String errorCode = XmlUtil.getNodeBody("Errorcode",resultXml);
if(!"0".equals(errorCode)){
return XmlUtil.getNodeBody("Message",resultXml);
}
return "";
}
/**
* 3.2.1 RequestLoad
*/
public static String RequestLoad(String barcode){
log.info("验证["+barcode+"]是否可以入库");
String commandStr = "<XmlCommand><Command>RequestLoad</Command><Parameter><FieldList><Field key=\"CARRIER\" value=\""+barcode+"\" /></FieldList></Parameter></XmlCommand>";
String resultXml = exeCommand(commandStr);
String errorCode = XmlUtil.getNodeBody("Errorcode",resultXml);
if(!"0".equals(errorCode)){
return XmlUtil.getNodeBody("Message",resultXml);
}
return "";
}
public static void NotifyCarrierLoad(String barcode, String cid){
log.info("通知["+barcode+"]入库完成");
String commandStr = "<XmlCommand><Command>NotifyCarrierLoad</Command><Parameter><FieldList><Field key=\"CARRIER\" value=\""+barcode+"\" /><Field key=\"TOWER\" value=\""+cid+"\" /></FieldList></Parameter></XmlCommand>";
exeCommand(commandStr);
//String errorCode = XmlUtil.getNodeBody("Errorcode",resultXml);
}
/**
* 3.2.1 RequestUnload
*/
public static String RequestUnload(String barcode){
log.info("验证["+barcode+"]是否可以出库");
String commandStr = "<XmlCommand><Command>RequestUnload</Command><Parameter><FieldList><Field key=\"CARRIER\" value=\""+barcode+"\" /></FieldList></Parameter></XmlCommand>";
String resultXml = exeCommand(commandStr);
String errorCode = XmlUtil.getNodeBody("Errorcode",resultXml);
if(!"0".equals(errorCode)){
return XmlUtil.getNodeBody("Message",resultXml);
}
return "";
}
public static String NotifyCarrierUnload(String barcode, String cid){
log.info("通知["+barcode+"] 出库完成");
String commandStr = "<XmlCommand><Command>NotifyCarrierUnload</Command><Parameter><FieldList><Field key=\"CARRIER\" value=\""+barcode+"\" /><Field key=\"TOWER\" value=\""+cid+"\" /></FieldList></Parameter></XmlCommand>";
String result = exeCommand(commandStr);
return result;
}
// public static Barcode RequestCarrierData(String barcode){
// String commandStr = "<XmlCommand><Command>RequestCarrierData</Command><Parameter><FieldList><Field key=\"CARRIER\" value=\""+barcode+"\" /></FieldList></Parameter></XmlCommand>";
// String resultXml = exeCommand(commandStr);
//
// }
public static void reloadAdapter(String wsdlUrl){
AdapterService.init(wsdlUrl);
adapter = new AdapterService().getBasicHttpBindingIWSAdapter();
}
private static String exeCommand(String commandStr){
try {
if(adapter == null){
adapter = new AdapterService().getBasicHttpBindingIWSAdapter();
}
log.info("execute: " + commandStr);
String result = adapter.adapterCommand(commandStr);
log.info("result:" + result);
return result;
}catch (Exception e){
log.error("执行命令出错",e);
}
return "";
}
public static void main(String args[]) throws Exception{
String barcode = "M780174253919WFH9";
String pn = "78.10520.5SL";
String cid = "wczt001";
WebServiceClient.NotifyCarrierNew(barcode,pn);
//WebServiceClient.RequestLoad(barcode);
//WebServiceClient.NotifyCarrierLoad(barcode,cid);
//WebServiceClient.RequestUnload(barcode);
//WebServiceClient.NotifyCarrierUnload(barcode,cid);
}
}