use of javax.xml.soap.Node in project tdi-studio-se by Talend.
the class MsDynamicsWrapper method login.
/**
* Retrieves data from the CRM 2011 Online
*
* @param entity CRM 2011 entity (e.g. account or opportunity)
* @param columns Entity fields (e.g. accountid, name etc.)
* @param csvFile name of the CSV file where the results will be stored
* @return number of rows retrieved
* @throws JaxenException issue with the response format
* @throws IOException generic IO issue
* @throws SOAPException issue with SOAP invocation
*/
// public int retrieveMultiple(String entity, String[] columns, String csvFile) throws IOException, SOAPException,
// JaxenException {
// int cnt = 0;
// CSVWriter cw = FileUtil.createUtf8CsvEscapingWriter(new File(csvFile));
// try {
// int pageNumber = 1;
// String cookie = "";
// boolean hasNext = true;
// while (hasNext) {
// List<Map<String, String>> ret = new ArrayList<Map<String, String>>();
// RetrievePageInfo info = retrievePage(entity, columns, pageNumber++, cookie, ret);
// for (Map<String, String> m : ret) {
// String[] row = new String[columns.length];
// for (int i = 0; i < columns.length; i++) {
// row[i] = m.get(columns[i]);
// }
// cw.writeNext(row);
// }
// cnt += ret.size();
// cw.flush();
// cookie = info.getPageCookie();
// if ("0".equalsIgnoreCase(info.getMoreRecords()))
// hasNext = false;
// }
// } finally {
// cw.close();
// }
// return cnt;
// }
/**
* Paging information holder
*/
// private class RetrievePageInfo {
//
// private String pageCookie;
//
// private String moreRecords;
//
// public RetrievePageInfo(String cookie, String more) {
// setPageCookie(cookie);
// setMoreRecords(more);
// }
//
// public String getPageCookie() {
// return pageCookie;
// }
//
// public void setPageCookie(String pageCookie) {
// this.pageCookie = pageCookie;
// }
//
// public String getMoreRecords() {
// return moreRecords;
// }
//
// public void setMoreRecords(String moreRecords) {
// this.moreRecords = moreRecords;
// }
// }
/**
* Retrieves a single page of RetrieveMultiple result
*
* @param entity CRM 2011 entity (e.g. account or opportunity)
* @param columns Entity fields (e.g. accountid, name etc.)
* @param pageNumber the result page number (1..N)
* @param cookie API paging cookie
* @param ret the List of Maps that will be populated with the data
* @return the RetrievePageInfo structure that describes the status of the retrieval
* @throws JaxenException issue with the response format
* @throws IOException generic IO issue
* @throws SOAPException issue with SOAP invocation
*/
// protected RetrievePageInfo retrievePage(String entity, String[] columns, int pageNumber, String cookie,
// List<Map<String, String>> ret) throws IOException, SOAPException, JaxenException {
// String msg = FileUtil.readStringFromClasspath("/com/gooddata/msdynamics/RetrieveMultiple.xml",
// MsDynamicsWrapper.class);
// msg = msg.replace(CRM_ORGANIZATION_PLACEHOLDER, getOrganization());
// msg = msg.replace(CRM_TICKET_PLACEHOLDER, getCrmTicket());
// msg = msg.replace(CRM_ENTITY_PLACEHOLDER, entity);
// msg = msg.replace(CRM_PAGE_NUMBER_PLACEHOLDER, Integer.toString(pageNumber));
// msg = msg.replace(CRM_PAGE_COUNT_PLACEHOLDER, Integer.toString(PAGE_COUNT));
// if (cookie != null && cookie.length() > 0) {
// msg = msg.replace(CRM_PAGE_COOKIE_PLACEHOLDER, "<ns4:PageCookie><![CDATA[" + cookie + "]]></ns4:PageCookie>");
// } else {
// msg = msg.replace(CRM_PAGE_COOKIE_PLACEHOLDER, "");
// }
// String columnsElement = "";
// for (int i = 0; i < columns.length; i++) {
// columnsElement += "<ns4:Attribute>" + columns[i] + "</ns4:Attribute>";
// }
// msg = msg.replace(CRM_ATTRIBUTES_PLACEHOLDER, columnsElement);
// SOAPMessage response = soap.execute(HTTPS + host + CRM_ENDPOINT, msg);
// XPath xp = soap.createXPath("//crm:RetrieveMultipleResult", response);
// xp.addNamespace("crm", RESULT_XMLNS);
// List result = xp.selectNodes(response.getSOAPBody());
// if (result != null && result.size() == 1) {
// SOAPElement e = (SOAPElement) result.get(0);
// String more = e.getAttribute("MoreRecords");
// String newCookie = e.getAttribute("PagingCookie");
// if (more != null && more.length() > 0 && newCookie != null && newCookie.length() > 0) {
// xp = soap.createXPath("//crm:BusinessEntity", response);
// xp.addNamespace("crm", ENTITY_XMLNS);
// result = xp.selectNodes(response.getSOAPBody());
// for (Object o : result) {
// e = (SOAPElement) o;
// Map<String, String> instance = new HashMap<String, String>();
// Iterator elements = e.getChildElements();
// while (elements.hasNext()) {
// SOAPElement name = (SOAPElement) elements.next();
// String value = name.getFirstChild().getNodeValue();
// instance.put(name.getElementName().getLocalName(), value);
// }
// ret.add(instance);
// }
// return new RetrievePageInfo(newCookie, more);
// } else {
// throw new SOAPException("RetrieveMultiple: Invalid response. The response doesn't contain either "
// + "the MoreRecords or the PagingCookie attributes.");
// }
//
// } else {
// throw new SOAPException("RetrieveMultiple: Invalid response. The response doesn't contain "
// + "the RetrieveMultipleResult element.");
// }
// }
/**
* Logs into the MS CRM 2011 Online
*
* @return the Live ID token
* @throws JaxenException issue with the response format
* @throws IOException generic IO issue
* @throws SOAPException issue with SOAP invocation
*/
public String login() throws IOException, SOAPException, JaxenException {
String msg = FileUtil.readStringFromClasspath("/org/talend/mscrm/login/passport/LiveIdLogin.xml", MsDynamicsWrapper.class);
msg = msg.replaceAll(LIVE_ID_SERVER_PLACEHOLDER, getHost());
msg = msg.replaceAll(LIVE_ID_USERNAME_PLACEHOLDER, getUsername());
msg = msg.replaceAll(LIVE_ID_PASSWORD_PLACEHOLDER, getPassword());
msg = msg.replaceAll(LIVE_ID_POLICY_PLACEHOLDER, getPolicy());
SOAPMessage response = soap.execute(HTTPS + LIVE_ID_HOST + LIVE_ID_ENDPOINT, msg);
XPath xp = soap.createXPath("//wsse:BinarySecurityToken/text()", response);
xp.addNamespace("wsse", WSSE_XMLNS);
Node result = (Node) xp.selectSingleNode(response.getSOAPBody());
return result.getValue();
}
Aggregations