diff --git a/README.md b/README.md
index 3496f8a0..9bcb1f17 100644
--- a/README.md
+++ b/README.md
@@ -34,6 +34,7 @@ The QuickBooks Online Java SDK provides a set of Java class libraries that make
* ipp-v3-java-devkit-assembly - builds final deployment package (zip) which includes everything
* ipp-v3-java-devkit-shaded-assembly - builds lightweight version (some dependencies excluded)
* ipp-v3-java-devkit-javadoc - contains javadoc for data and devkit classes
+* ipp-java-qbapihelper - contains Quickbooks API Helper methods for OAuth, Disconnect and Reconnect API
## System Requirements
The SDK works on JDK 1.6 and above.
diff --git a/ipp-java-qbapihelper/pom.xml b/ipp-java-qbapihelper/pom.xml
new file mode 100644
index 00000000..e101bfb6
--- /dev/null
+++ b/ipp-java-qbapihelper/pom.xml
@@ -0,0 +1,147 @@
+
+
+
+
+
+ 4.0.0
+
+ ipp-v3-java-devkit-pom
+ com.intuit.quickbooks-online
+ 2.9.0
+
+ ipp-java-qbapihelper
+ 2.9.0
+ jar
+ Quickbooks API Helper for Oauth
+ Quickbooks API Helper Project for OAuth, Disconnect and Reconnect
+
+
+
+
+ testng.xml
+
+
+
+
+
+
+ oauth.signpost
+ signpost-core
+ 1.2.1.1
+
+
+ oauth.signpost
+ signpost-commonshttp4
+ 1.2
+
+
+ net.sf.kxml
+ kxml2
+ 2.2.2
+
+
+ org.testng
+ testng
+ 6.1.1
+ test
+
+
+ javax.servlet
+ servlet-api
+ 2.4
+ provided
+
+
+ org.apache.httpcomponents
+ httpcore
+ 4.4.5
+
+
+ org.apache.httpcomponents
+ httpclient
+ 4.5.2
+
+
+ org.openid4java
+ openid4java
+ 0.9.8
+
+
+ org.slf4j
+ slf4j-api
+ 1.6.4
+
+
+
+
+
+
+
+
+ ${basedir}/src/test/resources
+
+
+
+
+ ${basedir}/src/main/resources
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 2.5.1
+
+ 1.6
+ 1.6
+
+
+
+ maven-jar-plugin
+
+
+
+ fully.qualified.MainClass
+
+
+
+
+
+
+ maven-assembly-plugin
+
+ ${project.artifactId}-${project.version}
+
+ jar-with-dependencies
+
+
+
+
+ qb-helper
+ package
+
+ single
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ipp-java-qbapihelper/src/main/java/com/intuit/ia/connection/IAPlatformClient.java b/ipp-java-qbapihelper/src/main/java/com/intuit/ia/connection/IAPlatformClient.java
new file mode 100644
index 00000000..46f9ce7c
--- /dev/null
+++ b/ipp-java-qbapihelper/src/main/java/com/intuit/ia/connection/IAPlatformClient.java
@@ -0,0 +1,184 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Intuit
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *******************************************************************************/
+
+package com.intuit.ia.connection;
+
+/**
+ *
+ * This class exposes APIs for disconnect (disconnect) and fetching blue dot menu dropdown(getAppMenu)
+ */
+
+import java.util.List;
+import java.util.Map;
+
+import org.openid4java.discovery.Identifier;
+
+import com.intuit.ia.exception.ConnectionException;
+import com.intuit.ia.exception.OAuthException;
+import com.intuit.ia.exception.OpenIdException;
+
+public class IAPlatformClient {
+
+ private PlatformHttpClient httpClient;
+
+ private OAuthHelper oAuthHelper;
+ private OpenIdHelper openIdHelper;
+
+ public IAPlatformClient() {
+ openIdHelper = new OpenIdHelper();
+ oAuthHelper = new OAuthHelper();
+ }
+
+ /**
+ * Disconnects the user from quickbooks
+ *
+ * @throws ConnectionException
+ */
+ public PlatformResponse disconnect(String consumerKey, String consumerSecret,
+ String accessToken, String accessTokenSecret)
+ throws ConnectionException {
+ httpClient = new PlatformHttpClient(consumerKey, consumerSecret,
+ accessToken, accessTokenSecret);
+ return this.httpClient.disconnect();
+ }
+ /**
+ * getCurrentUser the user from quickbooks
+ *
+ * @throws ConnectionException
+ */
+ public User getcurrentUser(String consumerKey, String consumerSecret,
+ String accessToken, String accessTokenSecret)
+ throws ConnectionException {
+ httpClient = new PlatformHttpClient(consumerKey, consumerSecret,
+ accessToken, accessTokenSecret);
+ User user = null;;
+ try {
+ user = this.httpClient.getCurrentUser();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return user;
+ }
+
+ /**
+ * Get App Menu returns list of all the applications that are linked with
+ * the selected company
+ *
+ * @return List: Returns HTML as a list of Strings
+ * @throws ConnectionException
+ *
+ */
+ public List getAppMenu(String consumerKey, String consumerSecret,
+ String accessToken, String accessTokenSecret)
+ throws ConnectionException {
+ try {
+ List menulist;
+ httpClient = new PlatformHttpClient(consumerKey, consumerSecret,
+ accessToken, accessTokenSecret);
+ menulist = this.httpClient.getAppMenu();
+ return menulist;
+ } catch (ConnectionException conEx) {
+ throw conEx;
+ } catch (Exception e) {
+ throw new ConnectionException("Failed to fetch appmenu: "
+ + e.getMessage());
+ }
+ }
+
+ public Map getRequestTokenAndSecret(String consumerKey,
+ String consumerSecret) throws OAuthException {
+ return oAuthHelper.getRequestToken(consumerKey, consumerSecret);
+ }
+
+ /**
+ *
+ * @param requestToken
+ * @return authorizeUrl
+ * @throws OAuthException
+ *
+ * This API will prepare the authorization URL and return it back
+ */
+
+ public String getOauthAuthorizeUrl(String requestToken)
+ throws OAuthException {
+
+ return oAuthHelper.getAuthorizeUrl(requestToken);
+
+ }
+
+ /**
+ *
+ * Gets the accesstoken and accesstokensecret
+ *
+ * @param verofierCode
+ * @param requestToken
+ * (After the user authorization)
+ * @param requestTokensecret
+ * @return Map : where accesstoken will be in the key "accessToken"
+ * and accesstokensecret will be in key "accessTokenSecret"
+ *
+ */
+
+ public Map getOAuthAccessToken(String verifierCode,
+ String requestToken, String requestTokenSecret, String consumerKey,
+ String consumerSecret) throws OAuthException {
+
+ return oAuthHelper.getAccessToken(verifierCode, requestToken,
+ requestTokenSecret, consumerKey, consumerSecret);
+ }
+
+ /**
+ * Gets the authorization url for OpenId
+ *
+ * @throws
+ *
+ *
+ */
+
+ public String getOpenIdAuthorizeUrl() throws OpenIdException {
+
+ return openIdHelper.initOpenIdFlow();
+ }
+
+ /**
+ *
+ * @param receivingUrl
+ * @param parameterMap
+ * @return Identifier : the OpenId Identifier
+ * @throws OpenIdException
+ */
+ public Identifier verifyOpenIdResponse(String receivingUrl,
+ Map parameterMap) throws OpenIdException {
+ return openIdHelper.verifyResponse(receivingUrl, parameterMap);
+ }
+
+ /**
+ *
+ * @param consumerKey
+ * @param consumerSecret
+ * @param accessToken
+ * @param accessTokenSecret
+ * @throws ConnectionException
+ */
+ public PlatformResponse reConnect(String consumerKey, String consumerSecret,
+ String accessToken, String accessTokenSecret)
+ throws ConnectionException {
+
+ httpClient = new PlatformHttpClient(consumerKey, consumerSecret,
+ accessToken, accessTokenSecret);
+ return this.httpClient.reConnect();
+ }
+}
diff --git a/ipp-java-qbapihelper/src/main/java/com/intuit/ia/connection/OAuthHelper.java b/ipp-java-qbapihelper/src/main/java/com/intuit/ia/connection/OAuthHelper.java
new file mode 100644
index 00000000..b2b6d9f4
--- /dev/null
+++ b/ipp-java-qbapihelper/src/main/java/com/intuit/ia/connection/OAuthHelper.java
@@ -0,0 +1,212 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Intuit
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *******************************************************************************/
+
+package com.intuit.ia.connection;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.util.HashMap;
+import java.util.Map;
+
+import oauth.signpost.OAuthConsumer;
+import oauth.signpost.basic.DefaultOAuthConsumer;
+import oauth.signpost.exception.OAuthCommunicationException;
+import oauth.signpost.exception.OAuthExpectationFailedException;
+import oauth.signpost.exception.OAuthMessageSignerException;
+import oauth.signpost.http.HttpParameters;
+
+import org.slf4j.Logger;
+
+import com.intuit.ia.exception.OAuthException;
+import com.intuit.ia.utils.IAHelperConfig;
+import com.intuit.ia.utils.LoggerImpl;
+import com.intuit.ia.utils.PlatformConstants;
+
+class OAuthHelper {
+
+ private IAHelperConfig config;
+
+ public OAuthHelper() {
+ config = IAHelperConfig.getInstance();
+ }
+
+ protected Logger logger = LoggerImpl.getInstance();
+
+ public Map getRequestToken(String consumerkey,
+ String consumersecret) throws OAuthException {
+
+ logger.debug("Inside getRequestToken, Consumer Key and Secret: "
+ + consumerkey + " " + consumersecret);
+ String callback_url = config
+ .getProperty(PlatformConstants.OAUTH_CALLBACK_URL);
+ logger.debug("callback URL: " + callback_url);
+ OAuthConsumer ouathconsumer = new DefaultOAuthConsumer(consumerkey,
+ consumersecret);
+ try {
+ HttpParameters additionalParams = new HttpParameters();
+ additionalParams.put("oauth_callback",
+ URLEncoder.encode(callback_url, "UTF-8"));
+ ouathconsumer.setAdditionalParameters(additionalParams);
+ } catch (UnsupportedEncodingException e) {
+ logger.debug("Failed to get request token :" + e.getMessage());
+ throw new OAuthException(e.getMessage(), e);
+ }
+
+ String requestret = "";
+ String requestToken = "";
+ String requestTokenSecret = "";
+
+ try {
+ String signedRequestTokenUrl = ouathconsumer.sign(config
+ .getProperty(PlatformConstants.REQUEST_TOKEN_URL));
+ logger.debug("signedRequestTokenUrl: " + signedRequestTokenUrl);
+
+ URL url;
+
+ url = new URL(signedRequestTokenUrl);
+
+ HttpURLConnection httpconnection = (HttpURLConnection) url
+ .openConnection();
+
+ httpconnection.setRequestMethod("GET");
+ httpconnection
+ .setRequestProperty("Content-type", "application/xml");
+ httpconnection.setRequestProperty("Content-Length", "0");
+ if (httpconnection != null) {
+ BufferedReader rd = new BufferedReader(new InputStreamReader(
+ httpconnection.getInputStream()));
+ StringBuffer sb = new StringBuffer();
+ String line;
+ while ((line = rd.readLine()) != null) {
+ sb.append(line);
+
+ }
+ rd.close();
+ requestret = sb.toString();
+ }
+ String[] requestTokenSections = requestret.split("&");
+
+ for (int i = 0; i < requestTokenSections.length; i++) {
+ String[] currentElements = requestTokenSections[i].split("=");
+
+ if (currentElements[0].equalsIgnoreCase("oauth_token")) {
+ requestToken = currentElements[1];
+ } else if (currentElements[0]
+ .equalsIgnoreCase("oauth_token_secret")) {
+ requestTokenSecret = currentElements[1];
+ }
+ }
+
+ Map requesttokenmap = new HashMap();
+ requesttokenmap.put("requestToken", requestToken);
+ requesttokenmap.put("requestTokenSecret", requestTokenSecret);
+ return requesttokenmap;
+
+ } catch (OAuthMessageSignerException e) {
+ // LOG.error(e.getLocalizedMessage());
+ } catch (OAuthExpectationFailedException e) {
+ // LOG.error(e.getLocalizedMessage());
+ } catch (OAuthCommunicationException e) {
+ // LOG.error(e.getLocalizedMessage());
+ } catch (MalformedURLException e) {
+ // LOG.error(e.getLocalizedMessage());
+ } catch (IOException e) {
+ // LOG.error(e.getLocalizedMessage());
+ }
+ logger.debug("Error: Failed to get request token.");
+ return null;
+
+ }
+
+ public String getAuthorizeUrl(String requestToken) throws OAuthException {
+
+ String authorizeURL = "";
+
+ try {
+ authorizeURL = config.getProperty(PlatformConstants.AUTHORIZE_URL)
+ + "?oauth_token=" + requestToken;
+ } catch (Exception e) {
+ // LOG.error(e.getLocalizedMessage());
+
+ }
+
+ logger.debug("Authorize URL: " + authorizeURL);
+ return authorizeURL;
+
+ }
+
+ public Map getAccessToken(String verifierCode,
+ String requestToken, String requestTokenSecret, String consumerkey,
+ String consumersecret) throws OAuthException {
+ String accessToken = "";
+ String accessTokenSecret = "";
+ String accesTokenUrl = "";
+ Map accesstokenmap = new HashMap();
+ try {
+ OAuthConsumer consumer = new DefaultOAuthConsumer(consumerkey,
+ consumersecret);
+ consumer.setTokenWithSecret(requestToken, requestTokenSecret);
+ HttpParameters additionalParams = new HttpParameters();
+ additionalParams.put("oauth_callback", "oob");
+ additionalParams.put("oauth_verifier", verifierCode);
+ consumer.setAdditionalParameters(additionalParams);
+ accesTokenUrl = IAHelperConfig.getInstance().getProperty(
+ PlatformConstants.ACCESS_TOKEN_URL);
+ logger.debug("Access token url : " + accesTokenUrl);
+ String signedURL = consumer.sign(accesTokenUrl);
+ URL url = new URL(signedURL);
+ HttpURLConnection urlConnection = (HttpURLConnection) url
+ .openConnection();
+ urlConnection.setRequestMethod("GET");
+ urlConnection.setRequestProperty("Content-type", "application/xml");
+ urlConnection.setRequestProperty("Content-Length", "0");
+
+ String accesstokenresponse = "";
+ if (urlConnection != null) {
+ BufferedReader rd = new BufferedReader(new InputStreamReader(
+ urlConnection.getInputStream()));
+ StringBuffer sb = new StringBuffer();
+ String line;
+ while ((line = rd.readLine()) != null) {
+ sb.append(line);
+ }
+ rd.close();
+ accesstokenresponse = sb.toString();
+ }
+ if (accesstokenresponse != null) {
+ String[] responseElements = accesstokenresponse.split("&");
+ if (responseElements.length > 1) {
+ accessToken = responseElements[1].split("=")[1];
+ accessTokenSecret = responseElements[0].split("=")[1];
+ accesstokenmap.put("accessToken", accessToken);
+ accesstokenmap.put("accessTokenSecret", accessTokenSecret);
+ return accesstokenmap;
+ }
+ }
+ } catch (Exception e) {
+ logger.debug("Failed to get access token :" + e.getMessage());
+ throw new OAuthException(e.getMessage(), e);
+ }
+ return accesstokenmap;
+ }
+
+}
diff --git a/ipp-java-qbapihelper/src/main/java/com/intuit/ia/connection/OpenIdHelper.java b/ipp-java-qbapihelper/src/main/java/com/intuit/ia/connection/OpenIdHelper.java
new file mode 100644
index 00000000..4b729006
--- /dev/null
+++ b/ipp-java-qbapihelper/src/main/java/com/intuit/ia/connection/OpenIdHelper.java
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Intuit
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *******************************************************************************/
+
+package com.intuit.ia.connection;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.openid4java.OpenIDException;
+import org.openid4java.association.AssociationSessionType;
+import org.openid4java.consumer.ConsumerException;
+import org.openid4java.consumer.ConsumerManager;
+import org.openid4java.consumer.InMemoryConsumerAssociationStore;
+import org.openid4java.consumer.InMemoryNonceVerifier;
+import org.openid4java.consumer.VerificationResult;
+import org.openid4java.discovery.DiscoveryException;
+import org.openid4java.discovery.DiscoveryInformation;
+import org.openid4java.discovery.Identifier;
+import org.openid4java.message.AuthRequest;
+import org.openid4java.message.MessageException;
+import org.openid4java.message.ParameterList;
+import org.openid4java.message.ax.FetchRequest;
+import org.slf4j.Logger;
+
+import com.intuit.ia.exception.OpenIdException;
+import com.intuit.ia.utils.IAHelperConfig;
+import com.intuit.ia.utils.LoggerImpl;
+import com.intuit.ia.utils.PlatformConstants;
+
+/*
+ * This is a utility class for OpenID routines.
+ */
+
+public class OpenIdHelper {
+
+ private Logger logger = LoggerImpl.getInstance();
+ private ConsumerManager consumerManager = null;
+ private DiscoveryInformation discoveryInfo;
+
+ /**
+ *
+ * @param receivingUrl
+ * @param parameterMap
+ * @return OpenId Identifier
+ * @throws OpenIdException
+ */
+ public Identifier verifyResponse(String receivingUrl,
+ Map parameterMap) throws OpenIdException {
+ try {
+
+ if (consumerManager == null) {
+ logger.debug("The ConsumerManager is null");
+ }
+ final ParameterList response = new ParameterList(parameterMap);
+ final VerificationResult verification = consumerManager.verify(
+ receivingUrl, response, discoveryInfo);
+
+ // Examine the verification result
+ final Identifier verified = verification.getVerifiedId();
+ return verified; // Success.
+
+ } catch (OpenIDException e) {
+ logger.debug("OpenID exception :" + e.getMessage());
+ throw new OpenIdException(e.getMessage());
+ }
+ }
+
+ /**
+ *
+ * @return String:the openID auth url
+ * @throws OpenIdException
+ * @throws OpenIDException
+ */
+ public String initOpenIdFlow() throws OpenIdException {
+
+ final List discoveries = new ArrayList();
+ consumerManager = new ConsumerManager();
+ consumerManager.setAssociations(new InMemoryConsumerAssociationStore());
+ consumerManager.setNonceVerifier(new InMemoryNonceVerifier(5000));
+ consumerManager.setMinAssocSessEnc(AssociationSessionType.DH_SHA256);
+ DiscoveryInformation discovered = null;
+ String openIdProviderUrl;
+ openIdProviderUrl = IAHelperConfig.getInstance().getProperty(PlatformConstants.OPENID_PROVIDER_URL);
+ try {
+ logger.debug("OpenID Provider URL = " + openIdProviderUrl);
+ discovered = new DiscoveryInformation(new URL(openIdProviderUrl));
+ } catch (DiscoveryException e) {
+ logger.debug("Failed to obtain discovery information :" + e.getMessage());
+ throw new OpenIdException(e.getMessage(),e);
+ } catch (MalformedURLException me) {
+ logger.debug("Malformed URL :" + me.getMessage());
+ throw new OpenIdException(me.getMessage(),me);
+ }
+ discoveries.add(discovered);
+ discoveryInfo = consumerManager.associate(discoveries);
+ final FetchRequest fetch = FetchRequest.createFetchRequest();
+ try {
+ fetch.addAttribute("FirstName",
+ "http://axschema.org/namePerson/first", true);
+ fetch.addAttribute("LastName",
+ "http://axschema.org/namePerson/last", true);
+ fetch.addAttribute("Email", "http://axschema.org/contact/email",
+ true);
+ fetch.addAttribute("RealmId", "http://axschema.org/intuit/realmId",
+ true);
+ } catch (MessageException e) {
+ // LOG.error(e.getLocalizedMessage());
+ throw new OpenIdException(e.getMessage(), e);
+ }
+
+ fetch.setCount("Email", 3);
+ String openIdReturnUrl;
+ openIdReturnUrl = IAHelperConfig.getInstance().getProperty(PlatformConstants.OPENID_RETURN_URL);
+ AuthRequest authReq = null;
+ logger.debug("openIdReturnUrl = " + openIdReturnUrl);
+ try {
+ authReq = consumerManager.authenticate(discoveryInfo,openIdReturnUrl);
+ authReq.addExtension(fetch);
+ } catch (MessageException e) {
+ logger.debug("Message exception while init flow : " + e.getMessage());
+ } catch (ConsumerException e) {
+ logger.debug("Consumer exception : " + e.getMessage());
+ }
+
+ return authReq.getDestinationUrl(true);
+ }
+
+}
diff --git a/ipp-java-qbapihelper/src/main/java/com/intuit/ia/connection/PlatformHttpClient.java b/ipp-java-qbapihelper/src/main/java/com/intuit/ia/connection/PlatformHttpClient.java
new file mode 100644
index 00000000..468e9363
--- /dev/null
+++ b/ipp-java-qbapihelper/src/main/java/com/intuit/ia/connection/PlatformHttpClient.java
@@ -0,0 +1,252 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Intuit
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *******************************************************************************/
+package com.intuit.ia.connection;
+/**
+ *
+ * This class implements the disconnect and getAppMenu API by invoking appropriate end point urls configured
+ */
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.InetSocketAddress;
+import java.net.Proxy;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import org.kxml2.kdom.Document;
+import org.kxml2.kdom.Element;
+import org.slf4j.Logger;
+
+import com.intuit.ia.exception.ConnectionException;
+import com.intuit.ia.utils.IAHelperConfig;
+import com.intuit.ia.utils.LoggerImpl;
+import com.intuit.ia.utils.PlatformConstants;
+import com.intuit.ia.utils.WebUtils;
+
+import oauth.signpost.OAuthConsumer;
+import oauth.signpost.basic.DefaultOAuthConsumer;
+import oauth.signpost.signature.AuthorizationHeaderSigningStrategy;
+
+class PlatformHttpClient {
+
+
+ private Map requestHeaders = new Hashtable();
+ private HttpURLConnection connection;
+ private int timeout = 1200;
+ private OAuthConsumer oauthConsumer;
+ private String urlString;
+ Logger logger = LoggerImpl.getInstance();
+ public PlatformHttpClient(String consumerKey,String consumerSecret,String accessToken,String accessTokenSecret) {
+
+ this.oauthConsumer = new DefaultOAuthConsumer(consumerKey, consumerSecret);
+ oauthConsumer.setTokenWithSecret(accessToken, accessTokenSecret);
+ oauthConsumer.setSigningStrategy(new AuthorizationHeaderSigningStrategy());
+ }
+
+ private void openConnection() throws Exception {
+ requestHeaders.put("Content-type", "application/xml");
+ requestHeaders.put("Content-Length", "0");
+ doGet();
+ }
+
+ public PlatformResponse disconnect() throws ConnectionException {
+
+ try {
+ urlString = IAHelperConfig.getInstance().getProperty(PlatformConstants.DISCON_URL_KEY);
+
+ openConnection();
+ if (connection != null) {
+
+ Document respDoc = getResponseXmlDocument();
+
+ PlatformResponse response = new PlatformResponse();
+ response.setErrorCode(WebUtils.getElementText(respDoc.getRootElement(), "ErrorCode"));
+ response.setErrorMessage(WebUtils.getElementText(respDoc.getRootElement(), "ErrorMessage"));
+ response.setServerTime(WebUtils.getElementText(respDoc.getRootElement(), "ServerTime"));
+
+ if (!response.getErrorCode().equals("0")) {
+ throw new ConnectionException(response.getErrorMessage(), response.getErrorCode());
+ }
+ return response;
+ }
+
+ } catch (ConnectionException conEx) {
+ throw conEx;
+ }
+
+ catch (Exception e) {
+ throw new ConnectionException("Failed to disconnect: "
+ + e.getCause() + " " + e.getMessage());
+ }
+ return null;
+ }
+
+ public List getAppMenu() throws Exception {
+ List respList = new ArrayList();
+
+ try {
+ urlString = IAHelperConfig.getInstance().getProperty(PlatformConstants.APP_URL_KEY);
+ logger.debug("The url string is :" + urlString);
+ openConnection();
+ StringBuffer sb = new StringBuffer();
+
+ if (connection != null) {
+ BufferedReader rd = new BufferedReader(new InputStreamReader(
+ connection.getInputStream()));
+ String line;
+ while ((line = rd.readLine()) != null) {
+ sb.append(line);
+ respList.add(line);
+ }
+ rd.close();
+ }
+ } catch (Exception e) {
+ throw new Exception("Failed to get App Menu: " + e.getCause() + " "
+ + e.getMessage());
+ }
+
+ return respList;
+ }
+
+ private void doGet() throws Exception {
+
+ String timeOutString;
+ URL url = new URL(urlString);
+ Proxy httpProxy = null;
+ String host;
+ String port;
+ try {
+ host = IAHelperConfig.getInstance().getProperty(PlatformConstants.HTTP_PROXY_HOST_KEY);
+ port = IAHelperConfig.getInstance().getProperty(PlatformConstants.HTTP_PROXY_PORT_KEY);
+ if (host != null && port != null) {
+ httpProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(
+ host, Integer.parseInt(port)));
+ this.connection = (HttpURLConnection) url
+ .openConnection(httpProxy);
+ } else {
+ this.connection = (HttpURLConnection) url.openConnection();
+ }
+
+ } catch (ClassCastException e) {
+ throw new IllegalArgumentException("Not an HTTP URL");
+ }
+ try{
+ // Set the request method
+ this.connection.setRequestMethod(PlatformConstants.HTTP_VERB_GET);
+ timeOutString = IAHelperConfig.getInstance().getProperty("time_out");
+ if(timeOutString != null)
+ timeout = Integer.parseInt(timeOutString);
+ this.connection.setConnectTimeout(timeout);
+ logger.debug("Proceeding for signing");
+ // For OAuth authentication.
+ if (oauthConsumer != null) {
+ oauthConsumer.sign(this.connection);
+ }
+ }
+ catch(Exception e)
+ {
+
+ logger.debug("Exception occured in preparing the request :" + e.getMessage());
+ }
+ }
+
+ public Document getResponseXmlDocument() throws IOException {
+
+ InputStream inputStream = null;
+ Document responseDocument;
+ try {
+
+ inputStream = connection.getInputStream();
+ responseDocument = WebUtils.createXmlDocument(inputStream);
+ } finally {
+ if (inputStream != null) {
+ inputStream.close();
+ }
+ this.connection.disconnect();
+ this.connection = null;
+ }
+ return responseDocument;
+ }
+
+ public PlatformResponse reConnect() throws ConnectionException {
+
+ try {
+
+ urlString = IAHelperConfig.getInstance().getProperty(PlatformConstants.RECONNECT_URL_KEY);
+ openConnection();
+ if (connection != null) {
+
+ Document respDoc = getResponseXmlDocument();
+
+ PlatformResponse response = new PlatformResponse();
+ response.setErrorCode(WebUtils.getElementText(respDoc.getRootElement(), "ErrorCode"));
+ response.setErrorMessage(WebUtils.getElementText(respDoc.getRootElement(), "ErrorMessage"));
+ response.setOauthToken(WebUtils.getElementText(respDoc.getRootElement(), "OAuthToken"));
+ response.setOauthTokenSecret(WebUtils.getElementText(respDoc.getRootElement(), "OAuthTokenSecret"));
+ response.setServerTime(WebUtils.getElementText(respDoc.getRootElement(), "ServerTime"));
+
+ if (!response.getErrorCode().equals("0")) {
+ throw new ConnectionException(response.getErrorMessage(), response.getErrorCode());
+ }
+ return response;
+ }
+
+ } catch (ConnectionException conEx) {
+ throw conEx;
+ }
+
+ catch (Exception e) {
+ throw new ConnectionException("Failed to reconnect: "
+ + e.getCause() + " " + e.getMessage());
+ }
+ return null;
+ }
+ public User getCurrentUser() throws Exception {
+ User user = null;
+
+ try {
+ urlString = IAHelperConfig.getInstance().getProperty(PlatformConstants.CURRENT_USER_URL);
+ logger.debug("The url string is :" + urlString);
+ openConnection();
+
+ if (connection != null) {
+ Document respDoc = getResponseXmlDocument();
+ String errorCode = WebUtils.getElementText(respDoc.getRootElement(), "ErrorCode");
+ String errorMsg = WebUtils.getElementText(respDoc.getRootElement(), "ErrorMessage");
+ if (!errorCode.equals("0")) {
+ throw new ConnectionException(errorMsg, errorCode);
+ }else
+ {
+ user= new User();
+ Element e = WebUtils.getElementByTagName(respDoc.getRootElement(), "User");
+ user.setEmailAddress(WebUtils.getElementText(e, "EmailAddress"));
+ user.setFirstName(WebUtils.getElementText(respDoc.getRootElement(), "FirstName"));
+ user.setIsVerified(WebUtils.getElementText(respDoc.getRootElement(), "IsVerified"));
+ user.setLastName(WebUtils.getElementText(respDoc.getRootElement(), "LastName"));
+ }
+ }
+ } catch (Exception e) {
+ throw new Exception("Failed to get CurrentUser: " + e.getCause() + " "
+ + e.getMessage());
+ }
+ return user;
+ }
+}
diff --git a/ipp-java-qbapihelper/src/main/java/com/intuit/ia/connection/PlatformResponse.java b/ipp-java-qbapihelper/src/main/java/com/intuit/ia/connection/PlatformResponse.java
new file mode 100644
index 00000000..13d794cd
--- /dev/null
+++ b/ipp-java-qbapihelper/src/main/java/com/intuit/ia/connection/PlatformResponse.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Intuit
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *******************************************************************************/
+package com.intuit.ia.connection;
+
+/**
+ * Class to hold response entities for disconnect/reconnect endpoint
+ *
+ * @author dderose
+ *
+ */
+public class PlatformResponse {
+
+ private String errorCode;
+
+ private String errorMessage;
+
+ private String serverTime;
+
+ private String oauthToken;
+
+ private String oauthTokenSecret;
+
+ public String getErrorCode() {
+ return errorCode;
+ }
+
+ public void setErrorCode(String errorCode) {
+ this.errorCode = errorCode;
+ }
+
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+
+ public void setErrorMessage(String errorMessage) {
+ this.errorMessage = errorMessage;
+ }
+
+ public String getServerTime() {
+ return serverTime;
+ }
+
+ public void setServerTime(String serverTime) {
+ this.serverTime = serverTime;
+ }
+
+ public String getOauthToken() {
+ return oauthToken;
+ }
+
+ public void setOauthToken(String oauthToken) {
+ this.oauthToken = oauthToken;
+ }
+
+ public String getOauthTokenSecret() {
+ return oauthTokenSecret;
+ }
+
+ public void setOauthTokenSecret(String oauthTokenSecret) {
+ this.oauthTokenSecret = oauthTokenSecret;
+ }
+
+}
diff --git a/ipp-java-qbapihelper/src/main/java/com/intuit/ia/connection/User.java b/ipp-java-qbapihelper/src/main/java/com/intuit/ia/connection/User.java
new file mode 100644
index 00000000..9921a0fc
--- /dev/null
+++ b/ipp-java-qbapihelper/src/main/java/com/intuit/ia/connection/User.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Intuit
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *******************************************************************************/
+
+package com.intuit.ia.connection;
+
+/**
+ * @author PVIJAYAKUMAR
+ *
+ */
+public class User {
+
+ /**
+ * @return the firstName
+ */
+ public String getFirstName() {
+ return firstName;
+ }
+ /**
+ * @param firstName the firstName to set
+ */
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+ /**
+ * @return the lastName
+ */
+ public String getLastName() {
+ return lastName;
+ }
+ /**
+ * @param lastName the lastName to set
+ */
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+ /**
+ * @return the emailAddress
+ */
+ public String getEmailAddress() {
+ return emailAddress;
+ }
+ /**
+ * @param emailAddress the emailAddress to set
+ */
+ public void setEmailAddress(String emailAddress) {
+ this.emailAddress = emailAddress;
+ }
+ /**
+ * @return the isVerified
+ */
+ public String getIsVerified() {
+ return isVerified;
+ }
+ /**
+ * @param isVerified the isVerified to set
+ */
+ public void setIsVerified(String isVerified) {
+ this.isVerified = isVerified;
+ }
+
+
+ private String firstName;
+ private String lastName;
+ private String emailAddress;
+ private String isVerified;
+
+
+
+}
diff --git a/ipp-java-qbapihelper/src/main/java/com/intuit/ia/exception/ConnectionException.java b/ipp-java-qbapihelper/src/main/java/com/intuit/ia/exception/ConnectionException.java
new file mode 100644
index 00000000..9ebfcd25
--- /dev/null
+++ b/ipp-java-qbapihelper/src/main/java/com/intuit/ia/exception/ConnectionException.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Intuit
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *******************************************************************************/
+package com.intuit.ia.exception;
+
+public class ConnectionException extends IAException {
+
+ private static final long serialVersionUID = 12222114441L;
+
+public ConnectionException(String errorMessage){
+ super(errorMessage);
+
+}
+
+
+public ConnectionException(String errorMessage,String errorCode){
+ super(errorMessage,errorCode);
+}
+public ConnectionException(String errorMessage,Throwable e){
+ super(errorMessage,e);
+}
+
+
+}
diff --git a/ipp-java-qbapihelper/src/main/java/com/intuit/ia/exception/IAException.java b/ipp-java-qbapihelper/src/main/java/com/intuit/ia/exception/IAException.java
new file mode 100644
index 00000000..f9c16c32
--- /dev/null
+++ b/ipp-java-qbapihelper/src/main/java/com/intuit/ia/exception/IAException.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Intuit
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *******************************************************************************/
+package com.intuit.ia.exception;
+/**
+ * This class represents the connection exception thrown by the jar
+ */
+public class IAException extends Exception {
+
+
+ private static final long serialVersionUID = 1222211112L;
+
+ private String errorMessage;
+ private String errorCode;
+
+ public IAException(String errorMessage,String errorCode){
+ super(errorMessage);
+ this.errorMessage = errorMessage;
+ this.errorCode = errorCode;
+ }
+ public IAException(String errorMessage){
+ super(errorMessage);
+ this.errorMessage = errorMessage;
+ }
+ public IAException(String errorMessage,Throwable cause){
+ super(errorMessage,cause);
+ this.errorMessage = errorMessage;
+
+ }
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+
+ public String getErrorCode() {
+ return errorCode;
+ }
+
+
+ @Override
+ public String toString(){
+
+ return "Error Code: " + errorCode + ",Error Message: "+ errorMessage;
+
+ }
+
+
+}
diff --git a/ipp-java-qbapihelper/src/main/java/com/intuit/ia/exception/OAuthException.java b/ipp-java-qbapihelper/src/main/java/com/intuit/ia/exception/OAuthException.java
new file mode 100644
index 00000000..c832379e
--- /dev/null
+++ b/ipp-java-qbapihelper/src/main/java/com/intuit/ia/exception/OAuthException.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Intuit
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *******************************************************************************/
+package com.intuit.ia.exception;
+
+public class OAuthException extends IAException {
+
+ private static final long serialVersionUID = 12222113331L;
+
+ public OAuthException(String errorMessage,String errorCode){
+ super(errorMessage,errorCode);
+
+ }
+ public OAuthException(String errorMessage){
+ super(errorMessage);
+ }
+
+
+ public OAuthException(String errorMessage,Throwable e){
+ super(errorMessage,e);
+ }
+
+}
diff --git a/ipp-java-qbapihelper/src/main/java/com/intuit/ia/exception/OpenIdException.java b/ipp-java-qbapihelper/src/main/java/com/intuit/ia/exception/OpenIdException.java
new file mode 100644
index 00000000..f8b13d4b
--- /dev/null
+++ b/ipp-java-qbapihelper/src/main/java/com/intuit/ia/exception/OpenIdException.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Intuit
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *******************************************************************************/
+package com.intuit.ia.exception;
+
+/**
+ *
+ * This represents a custom OpenId Exception
+ *
+ */
+public class OpenIdException extends IAException {
+
+ private static final long serialVersionUID = 12222115551L;
+
+ public OpenIdException(String errorMessage,String errorCode){
+ super(errorMessage,errorCode);
+
+ }
+ public OpenIdException(String errorMessage){
+ super(errorMessage);
+ }
+
+ public OpenIdException(String errorMessage,Throwable e){
+ super(errorMessage,e);
+ }
+
+
+}
diff --git a/ipp-java-qbapihelper/src/main/java/com/intuit/ia/utils/IAHelperConfig.java b/ipp-java-qbapihelper/src/main/java/com/intuit/ia/utils/IAHelperConfig.java
new file mode 100644
index 00000000..6ffc565a
--- /dev/null
+++ b/ipp-java-qbapihelper/src/main/java/com/intuit/ia/utils/IAHelperConfig.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Intuit
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *******************************************************************************/
+package com.intuit.ia.utils;
+
+import java.io.InputStream;
+import java.util.Properties;
+
+public class IAHelperConfig {
+
+ private static final String PROP_FILE_NAME = "ia.properties";
+ private static Properties prop = new Properties();
+ private static IAHelperConfig configObj = null;
+
+ private IAHelperConfig() {
+
+ }
+
+ public static synchronized IAHelperConfig getInstance() {
+
+ if (configObj == null) {
+ configObj = new IAHelperConfig();
+ configObj.readProperties();
+ }
+ return configObj;
+ }
+
+ private void readProperties() {
+
+ InputStream input = null;
+ try {
+
+ input = getClass().getClassLoader().getResourceAsStream(PROP_FILE_NAME);
+ prop.load(input);
+
+ } catch (Exception e) {
+
+ } finally {
+ if (input != null) {
+ try {
+ input.close();
+ } catch (Exception e) {
+
+ }
+ }
+ }
+
+ }
+
+ public String getProperty(String key) {
+ return prop.getProperty(key);
+ }
+}
diff --git a/ipp-java-qbapihelper/src/main/java/com/intuit/ia/utils/LoggerImpl.java b/ipp-java-qbapihelper/src/main/java/com/intuit/ia/utils/LoggerImpl.java
new file mode 100644
index 00000000..5e03919a
--- /dev/null
+++ b/ipp-java-qbapihelper/src/main/java/com/intuit/ia/utils/LoggerImpl.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Intuit
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *******************************************************************************/
+package com.intuit.ia.utils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Wrapper class for our chosen log provider. Currently java.util.logging. If you want to route logging through
+ * another logger, check the documentation of that logger on how to intercept java.util.logging.
+ *
+ * @see http://www.oracle.com/technology/pub/articles/hunter_logging.html.
+ * @see http://www.slf4j.org/legacy.html
+ */
+public class LoggerImpl {
+
+ private volatile Logger slf4jLogger;
+
+ private static Logger sInstance;
+
+ public static Logger getInstance() {
+ if (null == sInstance) {
+ sInstance = new LoggerImpl().getLogger();
+
+ }
+ return sInstance;
+ }
+
+ /**
+ * Initializes the Logger using the ipp-logging.properties file (as a resource from classpath). If
+ * this fails it attempts to reset the configuration to JVM defaults.
+ */
+ private LoggerImpl() {}
+
+ public Logger getLogger() {
+ if (null == slf4jLogger) {
+ synchronized (this) {
+ if (null == slf4jLogger) {
+ slf4jLogger = LoggerFactory.getLogger("com.intuit.iahelper");
+ }
+ }
+ }
+ return slf4jLogger;
+ }
+
+}
diff --git a/ipp-java-qbapihelper/src/main/java/com/intuit/ia/utils/PlatformConstants.java b/ipp-java-qbapihelper/src/main/java/com/intuit/ia/utils/PlatformConstants.java
new file mode 100644
index 00000000..37f0698f
--- /dev/null
+++ b/ipp-java-qbapihelper/src/main/java/com/intuit/ia/utils/PlatformConstants.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Intuit
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *******************************************************************************/
+package com.intuit.ia.utils;
+
+public class PlatformConstants {
+
+
+ public static final String OAUTH_CONSUMER_KEY="oauth_consumer_key";
+ public static final String OAUTH_CONSUMER_SECRET="oauth_consumer_secret";
+ public static final String OAUTH_CALLBACK_URL="oauth_callback_url";
+ public static final String REQUEST_TOKEN_URL="request_token_url";
+ public static final String AUTHORIZE_URL="authorize_url";
+ public static final String ACCESS_TOKEN_URL="access_token_url";
+ public static final String OPENID_PROVIDER_URL="openid_provider_url";
+ public static final String OPENID_RETURN_URL="openid_return_url";
+ public static final String RECONNECT_URL_KEY="reconnect_url";
+ public static final String HTTP_VERB_GET = "GET";
+ public static final String APP_URL_KEY = "app_menu_url";
+ public static final String CURRENT_USER_URL = "current_user_url";
+ public static final String DISCON_URL_KEY = "disconnect_url";
+ public static final String HTTP_PROXY_HOST_KEY = "http.proxy.host";
+ public static final String HTTP_PROXY_PORT_KEY = "http.proxy.port";
+ public static final String KEYSTORE = "keystore";
+ public static final String KEYSTORE_PASSWORD = "keystore.password";
+}
diff --git a/ipp-java-qbapihelper/src/main/java/com/intuit/ia/utils/WebUtils.java b/ipp-java-qbapihelper/src/main/java/com/intuit/ia/utils/WebUtils.java
new file mode 100644
index 00000000..c80ed340
--- /dev/null
+++ b/ipp-java-qbapihelper/src/main/java/com/intuit/ia/utils/WebUtils.java
@@ -0,0 +1,114 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Intuit
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *******************************************************************************/
+package com.intuit.ia.utils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Vector;
+
+import org.kxml2.io.KXmlParser;
+import org.kxml2.kdom.Document;
+import org.kxml2.kdom.Element;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
+public class WebUtils {
+
+ static public XmlPullParser createUTF8Parser(InputStream inputStream)
+ throws XmlPullParserException {
+ XmlPullParser parser = new KXmlParser();
+ parser.setInput(inputStream, "UTF-8");
+ return parser;
+ }
+
+ static public Document createXmlDocument(InputStream inputStream)
+ throws IOException {
+ Document document = null;
+ try {
+ XmlPullParser parser = createUTF8Parser(inputStream);
+ parser.setInput(new InputStreamReader(inputStream));
+ parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
+ document = new Document();
+ document.parse(parser);
+ } catch (XmlPullParserException e) {
+ e.printStackTrace();
+ }
+
+ return document;
+ }
+
+ public static String getElementText(Element element, String childElementName) {
+ Element node = getElementByTagName(element, childElementName);
+ if (node != null) {
+ return getElementText(node);
+ }
+ return null;
+ }
+
+ static public String getElementText(Element element) {
+ String elementText = null;
+
+ if (element != null) {
+ int numChildren = element.getChildCount();
+ if (numChildren == 0) {
+ elementText = null;
+ } else if (numChildren == 1) {
+ elementText = element.getText(0);
+ } else {
+ // compound value - treat as multiline
+ StringBuffer stringBuffer = new StringBuffer();
+ for (int i = 0; i < numChildren; i++) {
+ Object childNode = element.getChild(i);
+ if (childNode instanceof String) {
+ stringBuffer.append(childNode);
+ }
+ }
+ elementText = stringBuffer.toString();
+ }
+ }
+ return elementText;
+ }
+ static public Element getElementByTagName(Element element,
+ String elementName) {
+ Element[] elements = getElementsByTagName(element, elementName);
+ if (elements.length == 1) {
+ return elements[0];
+ } else {
+ return null;
+ }
+ }
+
+ static public Element[] getElementsByTagName(Element element,
+ String elementName) {
+ Vector elementList = new Vector();
+ int lastFoundIndex = element.indexOf(null, elementName, 0);
+ while (lastFoundIndex != -1) {
+ elementList.addElement(element.getElement(lastFoundIndex));
+ if (lastFoundIndex != -1) {
+ lastFoundIndex = element.indexOf(null, elementName,
+ lastFoundIndex + 1);
+ }
+ }
+ Element[] elements = new Element[elementList.size()];
+ elementList.copyInto(elements);
+ return elements;
+ }
+
+
+
+
+}
diff --git a/ipp-java-qbapihelper/src/main/resources/ia.properties b/ipp-java-qbapihelper/src/main/resources/ia.properties
new file mode 100644
index 00000000..000dfd1c
--- /dev/null
+++ b/ipp-java-qbapihelper/src/main/resources/ia.properties
@@ -0,0 +1,19 @@
+###############################################################################
+# Copyright (c) 2017 Intuit
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+###############################################################################
+app_menu_url=https://appcenter.intuit.com/api/v1/Account/AppMenu
+current_user_url=https://appcenter.intuit.com/api/v1/user/current
+disconnect_url=https://appcenter.intuit.com/api/v1/Connection/Disconnect
+reconnect_url=https://appcenter.intuit.com/api/v1/Connection/reconnect
\ No newline at end of file
diff --git a/ipp-java-qbapihelper/src/test/java/com/intuit/ia/connection/IATest.java b/ipp-java-qbapihelper/src/test/java/com/intuit/ia/connection/IATest.java
new file mode 100644
index 00000000..78919b0e
--- /dev/null
+++ b/ipp-java-qbapihelper/src/test/java/com/intuit/ia/connection/IATest.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Intuit
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *******************************************************************************/
+package com.intuit.ia.connection;
+
+import java.util.List;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import com.intuit.ia.exception.ConnectionException;
+import com.intuit.ia.utils.IAHelperConfig;
+
+public class IATest {
+
+ @Test
+ public void testOAuthIAAPIs() {
+
+ IAPlatformClient clientObj = new IAPlatformClient();
+ invokeAPIs(clientObj);
+ }
+
+ private void invokeAPIs(IAPlatformClient clientObj) {
+ List appMenuList = null;
+ User user = null;
+ boolean isException = false;
+ IAHelperConfig conObj = IAHelperConfig.getInstance();
+ String consumerKey = conObj.getProperty("oauth_consumer_key");
+ String consumerSecret = conObj.getProperty("oauth_consumer_secret");
+ String accessToken = conObj.getProperty("access_token");
+ String accessTokenSecret = conObj.getProperty("access_token_secret");
+
+ try {
+ appMenuList = clientObj.getAppMenu(consumerKey, consumerSecret,
+ accessToken, accessTokenSecret);
+ Assert.assertNotNull(appMenuList);
+ Assert.assertNotSame(appMenuList.size(), 0);
+ System.out.println(appMenuList.toString());
+ } catch (Exception e1) {
+ isException = true;
+ }
+ try {
+ user = clientObj.getcurrentUser(consumerKey, consumerSecret,
+ accessToken, accessTokenSecret);
+ Assert.assertNotNull(user.getEmailAddress());
+ System.out.println(user.getEmailAddress());
+ } catch (Exception e1) {
+ isException = true;
+ }
+ try {
+
+ clientObj.reConnect(consumerKey, consumerSecret, accessToken,
+ accessTokenSecret);
+
+ } catch (ConnectionException e) {
+ // isException = true;
+ System.out.println(e.toString());
+ }
+ /*try {
+ clientObj.disconnect(consumerKey, consumerSecret, accessToken,
+ accessTokenSecret);
+ } catch (ConnectionException e) {
+ isException = true;
+ System.out.println(e.toString());
+ }
+ Assert.assertFalse(isException, "Failed to perform the operation");*/
+
+ }
+
+}
diff --git a/ipp-java-qbapihelper/src/test/resources/ia.properties b/ipp-java-qbapihelper/src/test/resources/ia.properties
new file mode 100644
index 00000000..1000ff29
--- /dev/null
+++ b/ipp-java-qbapihelper/src/test/resources/ia.properties
@@ -0,0 +1,77 @@
+###############################################################################
+# Copyright (c) 2017 Intuit
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+###############################################################################
+#This is the properties file for connection helper jar
+
+#Specify the Blue dot AppMenu URL here
+app_menu_url=https://appcenter.intuit.com/api/v1/Account/AppMenu
+
+#Specify the get Current User URL here
+current_user_url=https://appcenter.intuit.com/api/v1/user/current
+
+#Specify the Disconnect URL here
+disconnect_url=https://appcenter.intuit.com/api/v1/Connection/Disconnect
+
+#specify the reconnect url
+reconnect_url=https://appcenter.intuit.com/api/v1/Connection/Reconnect
+
+#Specify the Consumer Secret
+oauth_consumer_secret=
+
+#Specify the Consumer Key
+oauth_consumer_key=
+
+#Specify the access token
+access_token=
+
+#Specify Acces token secret
+access_token_secret=
+
+#Specify Http Timeout
+time_out=1200
+
+#This is the request token url
+request_token_url=https://oauth.intuit.com/oauth/v1/get_request_token
+
+# The following 2 URLs point to the OAuth and OpenID servlets on your site:
+openid_return_url=http://localhost:8080/IntuitAnywhere/verifyopenid.htm
+
+oauth_callback_url=http://localhost:8080/IntuitAnywhere/accesstoken.htm
+
+
+# The next URL is used in the menuProxy and grantUrl parameters of the intuit.ipp.anywhere.setup()
+# call in the JSP files.
+app_url=http://localhost:8080/IntuitAnywhere
+
+# The next 3 URLs point to intuit.com services.
+openid_provider_url=https://openid.intuit.com/OpenId/Provider
+
+oauth_url=https://oauth.intuit.com
+
+appcenter_url=https://appcenter.intuit.com
+
+authorize_url=https://appcenter.intuit.com/Connect/Begin
+
+access_token_url=https://oauth.intuit.com/oauth/v1/get_access_token
+#Configuring HTTP Proxy
+#------------------------------------------------
+
+#Specify the HTTP Proxy Host
+#http_proxy_host=localhost
+
+#Specify the HTTP Proxy Port
+#http_proxy_port=8888
+
+
diff --git a/ipp-java-qbapihelper/testng-full.xml b/ipp-java-qbapihelper/testng-full.xml
new file mode 100644
index 00000000..254c989f
--- /dev/null
+++ b/ipp-java-qbapihelper/testng-full.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ipp-java-qbapihelper/testng.xml b/ipp-java-qbapihelper/testng.xml
new file mode 100644
index 00000000..91bbe266
--- /dev/null
+++ b/ipp-java-qbapihelper/testng.xml
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+
diff --git a/pom.xml b/pom.xml
index d2f92e2e..8e6d27c4 100755
--- a/pom.xml
+++ b/pom.xml
@@ -14,6 +14,7 @@
ipp-v3-java-data
ipp-v3-java-devkit
+ ipp-java-qbapihelper