Java Code Examples for org.wso2.carbon.apimgt.impl.APIConstants#APISTORE_LOGIN_URL
The following examples show how to use
org.wso2.carbon.apimgt.impl.APIConstants#APISTORE_LOGIN_URL .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: 103335311.java From docs-apim with Apache License 2.0 | 5 votes |
/** * Authenticate to external APIStore * * @param httpContext HTTPContext */ private boolean authenticateAPIM(APIStore store,HttpContext httpContext) throws APIManagementException { try { // create a post request to addAPI. HttpClient httpclient = new DefaultHttpClient(); String storeEndpoint=store.getEndpoint(); if(store.getEndpoint().contains("/store")){ storeEndpoint=store.getEndpoint().split("store")[0]+"publisher"+APIConstants.APISTORE_LOGIN_URL; } else if(!generateEndpoint(store.getEndpoint())){ storeEndpoint=storeEndpoint+ APIConstants.APISTORE_LOGIN_URL; } HttpPost httppost = new HttpPost(storeEndpoint); // Request parameters and other properties. List<NameValuePair> params = new ArrayList<NameValuePair>(3); params.add(new BasicNameValuePair(APIConstants.API_ACTION, APIConstants.API_LOGIN_ACTION)); params.add(new BasicNameValuePair(APIConstants.APISTORE_LOGIN_USERNAME, store.getUsername())); params.add(new BasicNameValuePair(APIConstants.APISTORE_LOGIN_PASSWORD, store.getPassword())); httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); HttpResponse response = httpclient.execute(httppost, httpContext); HttpEntity entity = response.getEntity(); String responseString = EntityUtils.toString(entity, "UTF-8"); boolean isError=Boolean.parseBoolean(responseString.split(",")[0].split(":")[1].split("}")[0].trim()); if (isError) { String errorMsg=responseString.split(",")[1].split(":")[1].split("}")[0].trim(); throw new APIManagementException(" Authentication with external APIStore - "+store.getDisplayName()+ " failed due to "+errorMsg+".API publishing to APIStore- "+store.getDisplayName()+" failed."); } else{ return true; } } catch (IOException e) { throw new APIManagementException("Error while accessing the external store : "+ store.getDisplayName() +" : "+e.getMessage(), e); } }
Example 2
Source File: 103335311.java From docs-apim with Apache License 2.0 | 5 votes |
/** * Login out from external APIStore * * @param httpContext HTTPContext */ private boolean logoutFromExternalStore(APIStore store,HttpContext httpContext) throws APIManagementException { try { // create a post request to addAPI. HttpClient httpclient = new DefaultHttpClient(); String storeEndpoint=store.getEndpoint(); if(store.getEndpoint().contains("/store")){ storeEndpoint=store.getEndpoint().split("store")[0]+"publisher"+APIConstants.APISTORE_LOGIN_URL; } else if(!generateEndpoint(store.getEndpoint())){ storeEndpoint=storeEndpoint+ APIConstants.APISTORE_LOGIN_URL; } HttpPost httppost = new HttpPost(storeEndpoint); // Request parameters and other properties. List<NameValuePair> params = new ArrayList<NameValuePair>(3); params.add(new BasicNameValuePair(APIConstants.API_ACTION, APIConstants.API_LOGOUT_ACTION)); httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); HttpResponse response = httpclient.execute(httppost, httpContext); HttpEntity entity = response.getEntity(); String responseString = EntityUtils.toString(entity, "UTF-8"); boolean isError=Boolean.parseBoolean(responseString.split(",")[0].split(":")[1].split("}")[0].trim()); if (isError) { String errorMsg=responseString.split(",")[1].split(":")[1].split("}")[0].trim(); throw new APIManagementException(" Log out from external APIStore - "+store.getDisplayName()+ " failed due to -"+errorMsg); } else{ return true; } } catch (Exception e) { throw new APIManagementException("Error while login out from : "+store.getDisplayName(), e); } }