Caused by: org.apache.axis2.AxisFault: Error reading XMLStreamReader: Undeclared namespace prefix "soapenv"
at [row,col {unknown-source}]: [1,56]
at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:508)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:368)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:414)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:225)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:150)
at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:533)
at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:509)
at com.pansoft.bi.util.TWSUtil.sendSoapRequest(TWSUtil.java:29)
at com.pansoft.bi.task.processor.TWSBaseProcessor.sendRequest(TWSBaseProcessor.java:150)
at com.pansoft.bi.task.processor.TWSBaseProcessor.processTask(TWSBaseProcessor.java:77)
at com.pansoft.bi.task.service.classes.TBITaskService.executeBITask(TBITaskService.java:311)
at com.pansoft.bi.invoker.TWSInvoker.invoke(TWSInvoker.java:27)
at com.pansoft.bi.task.bizlib.TBizBITaskService.invokeWS(TBizBITaskService.java:110)
at com.pansoft.hx.bi.THXTaskSynchService.sendTask(THXTaskSynchService.java:85)
at com.pansoft.hx.bi.THXTaskSynchService.sendTask(THXTaskSynchService.java:54)
... 34 more>
在tomcat上面使用axis2客户端调用没问题
但是部署到weblogic会报错,
客户端开发方式:根据报文拼接调用,代码如下
import java.text.ParseException;
import java.util.Iterator;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axiom.soap.SOAPHeaderBlock;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
public class test {
public static void getMsg(){
try {
String url = "http://IP/jxindependent/services/api/standardInterfaceObjectAdapter";
Options options = new Options();
// 指定调用WebService的URL
EndpointReference targetEPR = new EndpointReference(url);
options.setTo(targetEPR);
ServiceClient sender = new ServiceClient();
sender.setOptions(options);
OMFactory fac = OMAbstractFactory.getOMFactory();
String tns = "http://service.web.custom.baiwang.com";
// 命名空间,有时命名空间不增加没事,不过最好加上,因为有时有事,你懂的
OMNamespace omNs = fac.createOMNamespace(tns, "ser");
//SOAPFactory sOAPFactory = OMAbstractFactory.getSOAP11Factory();
OMElement header=fac.createOMElement("soapenv",omNs);
//SOAPHeaderBlock soapHeader = sOAPFactory.createSOAPHeaderBlock("soapenv", omNs);
sender.addHeader(header);
OMElement method = fac.createOMElement("collect", omNs);
OMElement requestInfo = fac.createOMElement("requestInfo", null);
OMElement content = fac.createOMElement("content", null);
OMElement head = fac.createOMElement("head", null);
method.addChild(requestInfo);
requestInfo.addChild(content);
requestInfo.addChild(head);
//requestInfo.build();
// 参数content
OMElement billingDate = fac.createOMElement("billingDate", null);
OMElement checkCode = fac.createOMElement("checkCode", null);
OMElement invoiceCode = fac.createOMElement("invoiceCode", null);
OMElement invoiceNumber = fac.createOMElement("invoiceNumber", null);
OMElement totalAmount = fac.createOMElement("totalAmount", null);
// 给参数赋值
billingDate.setText("2018-04-04");
checkCode.setText("884274");
invoiceCode.setText("051001700107");
invoiceNumber.setText("42689932");
totalAmount.setText("40212.27");
content.addChild(billingDate);
content.addChild(checkCode);
content.addChild(invoiceCode);
content.addChild(invoiceNumber);
content.addChild(totalAmount);
//content.build();
//head
OMElement accessKeyID = fac.createOMElement("accessKeyID", null);
OMElement signature = fac.createOMElement("signature", null);
OMElement signatureNonce = fac.createOMElement("signatureNonce", null);
OMElement timeStamp = fac.createOMElement("timeStamp", null);
OMElement version = fac.createOMElement("version", null);
accessKeyID.setText("999999999_1000");
signature.setText("1cfb3cdc9df3443d04de0192c4879797");
signatureNonce.setText("2b657438dae54689a0d9fa44b981013f");
timeStamp.setText("2019-01-28T09:57:51Z");
version.setText("1.0");
head.addChild(accessKeyID);
head.addChild(signature);
head.addChild(signatureNonce);
head.addChild(timeStamp);
head.addChild(version);
//head.build();
method.build();
OMElement result = sender.sendReceive(method);
@SuppressWarnings("rawtypes")
Iterator itr = result.getChildElements();
while (itr.hasNext()) {
OMElement ome_l2 = (OMElement) itr.next();
System.out.println(ome_l2.getText());//此为你服务端传过来的xml内容,下一步,你需要解析xml
}
System.out.println(result);
System.out.println(result.getText());
} catch (AxisFault axisFault) {
axisFault.printStackTrace();
}
}
public static void main(String[] args) throws ParseException {
getMsg();
JSONObject obj=new JSONObject();
List<String> contentlist=new ArrayList<String>();
contentlist.add("billingDate");
contentlist.add("checkCode");
contentlist.add("invoiceCode");
contentlist.add("invoiceNumber");
contentlist.add("totalAmount");
obj.put("content", contentlist);
List<String> string = (List<String>)obj.get("content");
for (String string2 : string) {
System.out.println(string2);
}
//Date date = new SimpleDateFormat("yyyyMMdd").parse("20050609");
//String now = new SimpleDateFormat("yyyy-MM-dd").format(date);
//System.out.println(now);
double a=-1212.4599999;
String s31 = new DecimalFormat("0.00").format(a);
System.out.println(s31);
}
}
经过排查,原来是缺少jar包:woodstox-core-as.jar下面是maven地址
<!-- https://mvnrepository.com/artifact/org.codehaus.woodstox/woodstox-core-asl -->
<dependency>
<groupId>org.codehaus.woodstox</groupId>
<artifactId>woodstox-core-asl</artifactId>
<version>4.1.0</version>
</dependency>