Cordys Java 后台模拟登入 且获取 WebService数据
2015-05-27 15:26
489 查看
import java.io.ByteArrayInputStream; import java.io.InputStream; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.methods.InputStreamRequestEntity; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.RequestEntity; import org.apache.xpath.XPathAPI; import org.w3c.dom.Document; import org.w3c.dom.Node; public class HttpClientSoap { private static final String soapRequestOfSaml = "<SOAP:Envelope xmlns:SOAP=\"http://schemas.xmlsoap.org/soap/envelope/\">" + " <SOAP:Header>" + " <wsse:Security xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">" + " <wsse:UsernameToken xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">" + " <wsse:Username>201613</wsse:Username>" + " <wsse:Password>201613</wsse:Password>" + " </wsse:UsernameToken>" + " </wsse:Security>" + " </SOAP:Header>" + " <SOAP:Body>" + " <samlp:Request xmlns:samlp=\"urn:oasis:names:tc:SAML:1.0:protocol\" MajorVersion=\"1\" MinorVersion=\"1\">" + " <samlp:AuthenticationQuery>" + " <saml:Subject xmlns:saml=\"urn:oasis:names:tc:SAML:1.0:assertion\">" + " <saml:NameIdentifier Format=\"urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified\">201613</saml:NameIdentifier>" + " </saml:Subject>" + " </samlp:AuthenticationQuery>" + " </samlp:Request>" + " </SOAP:Body>" + " </SOAP:Envelope>"; private static final String soapRequestOfTargetService ="" +"<SOAP:Envelope xmlns:SOAP=\"http://schemas.xmlsoap.org/soap/envelope/\">" +"<SOAP:Body>" +"<GetDepartmentByParentID xmlns=\"http://schemas.cordys.com/CommonPackage\" preserveSpace=\"no\" qAccess=\"0\" qValues=\"\">" +"<ParentID>29</ParentID>" +"</GetDepartmentByParentID>" +"</SOAP:Body>" +"</SOAP:Envelope>"; public static void Test() { try { System.out.println(soapRequestOfSaml); PostMethod postmethod = new PostMethod("http://192.168.100.122/comac/com.eibus.web.soap.Gateway.wcp"); byte[] b = soapRequestOfSaml.getBytes("UTF-8"); InputStream is = new ByteArrayInputStream(b, 0, b.length); RequestEntity re = new InputStreamRequestEntity(is, b.length, "application/xop+xml; charset=UTF-8; type=\"text/xml\""); postmethod.setRequestEntity(re); HttpClient httpClient = new HttpClient(); int statusCode = httpClient.executeMethod(postmethod); System.err.println("statuscode = " + statusCode); String soapResponseData = postmethod.getResponseBodyAsString(); System.out.println(soapResponseData); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document dom = builder.parse(postmethod.getResponseBodyAsStream()); Node samlArtifact = XPathAPI.selectSingleNode(dom, "//*[local-name()='AssertionArtifact']"); System.err.println("SamlArtifact = " + samlArtifact.getTextContent()); //System.out.println(samlArtifact.getAttributes().getNamedItem("xmlns:samlp").getNodeValue()); System.out.println(soapRequestOfTargetService); postmethod = new PostMethod("http://192.168.100.122/comac/com.eibus.web.soap.Gateway.wcp?SAMLart=" + samlArtifact.getTextContent()); b = soapRequestOfTargetService.getBytes("UTF-8"); is = new ByteArrayInputStream(b, 0, b.length); re = new InputStreamRequestEntity(is, b.length, "application/xop+xml; charset=UTF-8; type=\"text/xml\""); postmethod.setRequestEntity(re); //httpClient = new HttpClient(); statusCode = httpClient.executeMethod(postmethod); System.err.println("statuscode = " + statusCode); soapResponseData = postmethod.getResponseBodyAsString(); System.out.println(soapResponseData); } catch (Exception ex) { ex.printStackTrace(); } } }
相关文章推荐
- Java 代码获取Cordys令牌,获取Cordys相应WebService数据
- 用Angular实时获取本地Localstorage数据,实现一个模拟后台数据登入的效果
- Java 服务端 使用WebService 模拟客户端从第三个平台获取数据
- Java接收Cordys中webservice接口的返回数据并解析xml获取相应节点数据
- 使用java ssm框架后台模拟post上传文件并提交表单数据
- java SpringMVC + Mybatis 一套前台到后台完整获取数据的步骤
- java后台获取xml文件数据()
- java后台 通过HTTP接口获取json数据
- java后台设计简单的json数据接口,设置可跨域访问,前端ajax获取json数据
- java后台设计简单的json数据接口,设置可跨域访问,前端ajax获取json数据
- Java后台 如何获取 application/json的 字符串的形式的json数据
- ajax接收java后台传过来的json数据乱码及获取字段undefind问题
- java后台通过url获取返回数据
- java后台通过url获取json数据
- Java前台模拟后台数据
- java实现模拟登录itunes后台收入,抓取收入数据,校对收入
- Java模拟httpGet请求并获取返回的数据
- java 后台模拟post表单请求发送key-value数据乱码
- Java获取后台数据,动态生成多行多列复选框
- ECharts开发实战(1) ---- ECharts获取Java后台JSON数据,渲染显示图表