aixs2客户端调axis1服务

aixs2客户端调axis1服务 通常 用rpc 的方式

package client;
 
import java.util.Map;


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.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;


import tools.AxiomParseXML;


public class NXopenModeTestRPC {
        private static EndpointReference targetEPR = new EndpointReference("http://135.193.100.100:99999/services/CrmOcs");
        public static void main(String[] args) {
                try {
        String xml = "<USERSTATREQUEST><MSGHEADER><MSGTYPE>02</MSGTYPE><RECORDTYPE>902</RECORDTYPE><VERSION>01</VERSION></MSGHEADER><MSGBODY><MSISDN>13199998888</MSISDN><STATE>A</STATE><DATE>20151026153901</DATE></MSGBODY></USERSTATREQUEST>";


                        OMFactory fac = OMAbstractFactory.getOMFactory();
                        OMNamespace ns = fac.createOMNamespace("http://crm.ocs.xxxx.com", "intf");
                        OMElement payload = fac.createOMElement("UserStatRequest", ns);
                        payload.setText(xml);
                        Options options = new Options();
                        ServiceClient client = new ServiceClient();
                        options.setTo(targetEPR);
                        client.setOptions(options); 
                        //Blocking invocation
                        OMElement result = client.sendReceive(payload);
                        String rspxml=result.toString().replaceAll("&lt;", "<");
                        System.out.println("rspxml=\n"+rspxml);
                        Map map=AxiomParseXML.getResults(result);
                        String sessionid=(String)map.get("SESSIONID");
                        String resultcode=(String)map.get("RESULTCODE");
                        System.out.println("resultcode="+resultcode);
                } catch (AxisFault axisFault) {
                        axisFault.printStackTrace();
                }


        }
}

以报文方式处理:

package client;


import java.io.ByteArrayInputStream;
import java.io.UnsupportedEncodingException;
import java.util.Iterator;
import java.util.Map;


import javax.xml.stream.XMLStreamException;


import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.ServiceClient;
import org.apache.log4j.Logger;


import tools.AxiomParseXML;


public class NXopenModeTest {
public String invokeOpenModeService(String msisdn){
String result="";
try{
ServiceClient serviceClient = new ServiceClient();
serviceClient.setTargetEPR(new EndpointReference("http://100.100.7.159:9999999/services/CrmOcs")); 
//serviceClient.getOptions().setAction("urn:");

java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat("yyyyMMddHHmmss");
String cur_time=sdf.format(System.currentTimeMillis());
//String xml = "<USERSTATREQUEST><MSGHEADER><MSGTYPE>02</MSGTYPE><RECORDTYPE>902</RECORDTYPE><VERSION>01</VERSION></MSGHEADER><MSGBODY><MSISDN>"+msisdn+"</MSISDN><STATE>A</STATE><DATE>"+cur_time+"</DATE></MSGBODY></USERSTATREQUEST>";
            String reqxml= "\t\t<UserStatRequest>\n" +
                    "\t\t\t<xmlRequest><![CDATA[\n" +
                    "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>\n" +
                    "<USERSTATREQUEST>\n" +
                    "\t<MSGHEADER>\n" +
                    "\t\t<MSGTYPE>02</MSGTYPE>\n" +
                    "\t\t<RECORDTYPE>902</RECORDTYPE>\n" +
                    "\t\t<VERSION>01</VERSION>\n" +
                    "\t</MSGHEADER>\n" +
                    "\t<MSGBODY>\n" +
                    "\t\t<MSISDN>"+msisdn+"</MSISDN>\n" +
                    "\t\t<STATE>A</STATE>\n" +
                    "\t\t<DATE>"+cur_time+"</DATE>\n" +
                    "\t</MSGBODY>\n" +
                    "</USERSTATREQUEST>\n" +
                    "\n" +
                    "]]></xmlRequest>\n" +
                    "</UserStatRequest>\n";
                 
OMElement reqele=toOMElement(reqxml,"UTF-8");
 
System.out.println("reqxml=\n"+reqxml);
OMElement response1 = serviceClient.sendReceive(reqele);
   String rspxml=response1.toString().replaceAll("&lt;", "<");
            System.out.println("rspxml=\n"+rspxml);

            OMElement UserStatRequestReturnEle  = response1.getFirstElement();
            OMElement conentRootEle = (new StAXOMBuilder(new ByteArrayInputStream(UserStatRequestReturnEle.getText().getBytes("UTF-8")))).getDocumentElement();
            
            
            Iterator<OMElement> iter = conentRootEle.getChildElements();
            while(iter.hasNext()){
                OMElement node = iter.next();
                if(node.getLocalName().equals("MSGBODY")){
                Map map=AxiomParseXML.getResults(node);
                    
                    String sessionid=(String)map.get("SESSIONID");
                    result=(String)map.get("RESULTCODE");
                    System.out.println("resultcode="+result);
                    break;
                }
            }
            
            
}catch(Exception e){
e.printStackTrace();
Logger.getLogger("").error("修改"+msisdn+"的用户状态出现异常 :"+e.getMessage());
System.out.println("修改"+msisdn+"的用户状态出现异常 :"+e.getMessage());
}
return result;
}

 


private OMElement toOMElement(String xmlStr, String encoding)
{
OMElement xmlValue;
try {
xmlValue = (new StAXOMBuilder(new ByteArrayInputStream(xmlStr.getBytes(encoding)))).getDocumentElement();
return xmlValue;
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XMLStreamException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;

}
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("---------x");
NXopenModeTest test=new NXopenModeTest();
test.invokeOpenModeService("13079594017");
 
}


}

使用soap-ui测试报文:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://crm.xxxx.xxxx.com">
<SOAP-ENV:Body>
<ns1:UserStatRequest>
<ns1:xmlRequest><![CDATA[
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<USERSTATREQUEST>
<MSGHEADER>
<MSGTYPE>02</MSGTYPE>
<RECORDTYPE>902</RECORDTYPE>
<VERSION>01</VERSION>
</MSGHEADER>
<MSGBODY>
<MSISDN>13079594017</MSISDN>
<STATE>A</STATE>
<DATE>20151026171900</DATE>
</MSGBODY>
</USERSTATREQUEST>


]]></ns1:xmlRequest>
</ns1:UserStatRequest>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>


 axis2简易rpc调用例子

http://blog.csdn.net/maotongbin/article/details/10110711

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值