List of usage examples for org.apache.commons.httpclient.methods PostMethod addParameter
public void addParameter(String paramString1, String paramString2) throws IllegalArgumentException
From source file:org.extensiblecatalog.ncip.v2.millennium.MillenniumCheckOutItemService.java
/** * Handles a NCIP CheckOutItem service by returning hard-coded data. * * @param initData the CheckOutItemInitiationData * @param serviceManager provides access to remote services * @return CheckOutItemResponseData/*from w ww.ja v a 2 s .c o m*/ */ @Override public CheckOutItemResponseData performService(CheckOutItemInitiationData initData, ServiceContext serviceContext, RemoteServiceManager serviceManager) { final CheckOutItemResponseData responseData = new CheckOutItemResponseData(); MillenniumRemoteServiceManager millenniumSvcMgr = (MillenniumRemoteServiceManager) serviceManager; MillenniumConfiguration MillenniumConfig = millenniumSvcMgr.buildConfiguration(); String IIIClassicBaseUrl = MillenniumConfig.getURL(); String SNo = MillenniumConfig.getSearchScope(); String baseUrl = "https://" + IIIClassicBaseUrl + "/patroninfo"; //.html~S0"; //LOG.debug("CheckOut - baseURL: " + baseUrl); boolean foundUserId = false; boolean foundUserPass = false; List<Problem> problems = null; String userIdentifierType = null; final String getLDAPUserVarString = MillenniumConfig.getLdapUserVariable(); String[] getLDAPUserVarList = getLDAPUserVarString.split(","); final String getLDAPPasswordVarString = MillenniumConfig.getLdapPasswordVariable(); String[] getLDAPPasswordVarList = getLDAPPasswordVarString.split(","); final String getPatronUserVarString = MillenniumConfig.getPatronUserVariable(); String[] getPatronUserVarList = getPatronUserVarString.split(","); final String getPatronPasswordVarString = MillenniumConfig.getPatronPasswordVariable(); String[] getPatronPasswordVarList = getPatronPasswordVarString.split(","); boolean foundLDAPUser = false; boolean foundPatronUser = false; //boolean foundService = false; boolean foundCheckOut = false; //for (int x = 0; x < millenniumServicesList.length; x++) { // if (millenniumServicesList[x].trim().equals("CheckOut")) { // foundService = true; // } //} //if (foundService) { //for (int x = 0; x < millenniumFunctionsList.length; x++) { // if (millenniumFunctionsList[x].trim().equals("CheckOut")) { // foundCheckOut = true; // } //} //if (foundCheckOut) { authenticatedUserName = new ArrayList<String>(); authenticatedUserPassword = new ArrayList<String>(); for (AuthenticationInput authenticationInput : initData.getAuthenticationInputs()) { //LOG.debug("authenticationInput: " + authenticationInput.getAuthenticationInputData()); //LOG.debug("Type: " + authenticationInput.getAuthenticationInputType().getValue()); if ((authenticationInput.getAuthenticationInputType().getValue().toUpperCase().equals("LDAPUSERNAME")) || (authenticationInput.getAuthenticationInputType().getValue().toUpperCase() .equals("USERNAME"))) { userIdentifierType = authenticationInput.getAuthenticationInputType().getValue(); LOG.debug("RequestItem - userIdentifierType: " + userIdentifierType); if (authenticationInput.getAuthenticationInputData().trim().length() > 0) { authenticatedUserName.add(authenticationInput.getAuthenticationInputData()); foundUserId = true; } } if ((authenticationInput.getAuthenticationInputType().getValue().toUpperCase().equals("LDAPPASSWORD")) || (authenticationInput.getAuthenticationInputType().getValue().toUpperCase() .equals("PASSWORD")) || (authenticationInput.getAuthenticationInputType().getValue().toUpperCase().equals("PIN"))) { if (authenticationInput.getAuthenticationInputData().trim().length() > 0) { authenticatedUserPassword.add(authenticationInput.getAuthenticationInputData()); foundUserPass = true; } } } //LOG.debug("foundUser and foundPass: " + foundUserId + ", " + foundUserPass); if (foundUserId && foundUserPass) { //LOG.debug("1 - User: " + authenticatedUserName.size() + "=" + getLDAPUserVarList.length + "Pass: " + authenticatedUserPassword.size() + "=" + getLDAPPasswordVarList.length); testAuthUser = new ArrayList<PairGroup>(); testAuthPass = new ArrayList<PairGroup>(); authUserName = new ArrayList<PairGroup>(); authPassword = new ArrayList<PairGroup>(); htmlProperty authenticateStatus = null; if ((authenticatedUserName.size() == getLDAPUserVarList.length) && (authenticatedUserPassword.size() == getLDAPPasswordVarList.length)) { for (int x = 0; x < authenticatedUserName.size(); x++) { //LOG.debug("User pair: " + getLDAPUserVarList[x] + ", " + authenticatedUserName.get(x)); PairGroup userPair = millenniumSvcMgr.setPairGroup(getLDAPUserVarList[x], authenticatedUserName.get(x)); testAuthUser.add(userPair); } for (int y = 0; y < authenticatedUserPassword.size(); y++) { //LOG.debug("pass pair: " + getLDAPPasswordVarList[y] + ", " + authenticatedUserPassword.get(y)); PairGroup passPair = millenniumSvcMgr.setPairGroup(getLDAPPasswordVarList[y], authenticatedUserPassword.get(y)); testAuthPass.add(passPair); } authenticateStatus = millenniumSvcMgr.Authenticate(testAuthUser, testAuthPass, baseUrl); if (authenticateStatus.recordStatus.returnStatus) { authUserName = testAuthUser; authPassword = testAuthPass; foundLDAPUser = true; LOG.debug("LDAP authUserName.size() =" + authUserName.size()); } } //LOG.debug("2 - FoundLDAPUser: " + foundLDAPUser); if ((foundLDAPUser == false) && ((authenticatedUserName.size() == getPatronUserVarList.length) && (authenticatedUserPassword.size() == getPatronPasswordVarList.length))) { testAuthUser = new ArrayList<PairGroup>(); testAuthPass = new ArrayList<PairGroup>(); for (int x = 0; x < authenticatedUserName.size(); x++) { PairGroup userPair = millenniumSvcMgr.setPairGroup(getPatronUserVarList[x], authenticatedUserName.get(x)); testAuthUser.add(userPair); } for (int y = 0; y < authenticatedUserPassword.size(); y++) { PairGroup passPair = millenniumSvcMgr.setPairGroup(getPatronPasswordVarList[y], authenticatedUserPassword.get(y)); testAuthPass.add(passPair); } authenticateStatus = millenniumSvcMgr.Authenticate(testAuthUser, testAuthPass, baseUrl); if (authenticateStatus.recordStatus.returnStatus) { authUserName = testAuthUser; authPassword = testAuthPass; foundPatronUser = true; LOG.debug("Patron authUserName.size() =" + authUserName.size()); } } String itemBarCode = initData.getItemId().getItemIdentifierValue(); LOG.debug("CheckOut - itemBarCode: " + itemBarCode); int barCodeIndex = 0; //htmlProperty authenticateStatus = millenniumSvcMgr.Authenticate(authenticatedUserName, authenticatedUserPassword, baseUrl); if (foundLDAPUser || foundPatronUser) { LOG.debug("CheckOut - Login Success!"); boolean getItems = false; String strSessionId = authenticateStatus.sessionId; String redirectedUrl = authenticateStatus.url; LOG.debug("CheckOut - redirectedUrl: " + redirectedUrl); authenticatedUserId = authenticateStatus.userid; LOG.debug("CheckOut - authenticatedUserId: " + authenticatedUserId); String html = authenticateStatus.html; String pageItem = authenticateStatus.pageItem.toLowerCase().trim(); //LOG.debug("CheckOut - itempage: " + authenticateStatus.pageItem); //LOG.debug("CheckOut - SNo: " + SNo); if (pageItem.equals("items") || html.contains("<a href=\"/patroninfo~" + SNo + "/" + authenticatedUserId + "/items")) { getItems = true; } LOG.debug("CheckOut - Found - Items: " + getItems); if (getItems) { LOG.debug("CheckOut - Found Items Currently Checked out"); StatusString getItemsStatus = millenniumSvcMgr.getAuthenticationItemsPage(authenticatedUserId, strSessionId, "items"); if (getItemsStatus.recordStatus.returnStatus) { LOG.debug("CheckOut - Success received items page. HTML char: " + getItemsStatus.statusValue.length()); ArrayList<AuthenticationItemsInfo> itemsCheckedOutList = null;//millenniumSvcMgr.getItemsCheckedOut(authenticatedUserId, strSessionId, "items"); UserItemInfo itemsCheckOutStatus = millenniumSvcMgr .getItemsCheckedOut(getItemsStatus.statusValue, foundCheckOut); if (itemsCheckOutStatus.recordStatus.returnStatus) { LOG.debug("CheckOut - Success received items page array information"); itemsCheckedOutList = itemsCheckOutStatus.itemsList; boolean foundBarCode = false; for (int x = 0; x < itemsCheckedOutList.size(); x++) { if (itemsCheckedOutList.get(x).iBarcode.contains(itemBarCode)) { foundBarCode = true; barCodeIndex = x; } } if (foundBarCode) { LOG.debug("CheckOut - Found item barcode in items page at index: " + barCodeIndex); //LOG.debug("CheckOut - Mark id: " + itemsCheckedOutList.get(barCodeIndex).iMark); //LOG.debug("CheckOut - Mark Value: " + itemsCheckedOutList.get(barCodeIndex).iMarkValue); String url = null; if (strFunction.Rightstr(redirectedUrl, "/").equals("items")) { url = redirectedUrl; } else { url = redirectedUrl.replace(pageItem, "items"); } LOG.debug("CheckOut - url: " + url); PostMethod postMethod = new PostMethod(url); postMethod.addParameter(itemsCheckedOutList.get(barCodeIndex).iMark, itemsCheckedOutList.get(barCodeIndex).iMarkValue); postMethod.addParameter("renewsome", "YES"); StatusString renewStatus = millenniumSvcMgr.LogInWebActionForm(postMethod, strSessionId); if (renewStatus.recordStatus.returnStatus) { //LOG.debug("html lenght: " + renewStatus.statusValue.length()); UserItemInfo itemRenewStatus = millenniumSvcMgr .getItemsCheckedOut(renewStatus.statusValue, foundCheckOut); if (itemRenewStatus.recordStatus.returnStatus) { ArrayList<AuthenticationItemsInfo> renewItemList = itemRenewStatus.itemsList; if (itemsCheckedOutList.size() == renewItemList.size()) { LOG.debug("Checkout Status is: " + itemsCheckedOutList.get(barCodeIndex).iStatus); LOG.debug("Checkout Status is: " + renewItemList.get(barCodeIndex).iStatus); if (itemsCheckedOutList.get(barCodeIndex).iStatus .equals(renewItemList.get(barCodeIndex).iStatus) == false) { StatusString newDueDateString = millenniumSvcMgr .setRenewSimpleDateFormat( renewItemList.get(barCodeIndex).iStatus); if (newDueDateString.recordStatus.returnStatus) { //Date dueDate = null; // set to null SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yy"); try { Date dueDate = dateFormat.parse(newDueDateString.statusValue .trim().replace("-", "/")); LOG.debug("CheckOut - NewDueDate: " + dueDate); //Date newDueDate = millenniumSvcMgr.setRenewSimpleDateFormat(renewItemList.get(barCodeIndex).iStatus); GregorianCalendar DueDateCalendar = new GregorianCalendar( TimeZone.getTimeZone("UTC")); DueDateCalendar.setTime(dueDate); responseData.setDateDue(DueDateCalendar); ItemId itemId = new ItemId(); itemId.setItemIdentifierValue(itemBarCode); responseData.setItemId(itemId); } catch (ParseException pe) { LOG.error("setRenewSimpleDateFormat ERROR: Cannot parse \"" + newDueDateString.statusValue + "\""); problems = ServiceHelper.generateProblems( Version1LookupItemProcessingError.UNKNOWN_ITEM, "CheckOut Error", null, "Date format error for: " + itemBarCode); } } else { LOG.error("CheckOut - " + newDueDateString.statusValue.trim() + " for Item Barcode: " + itemBarCode + "."); String errorMsg = newDueDateString.statusValue.trim() + " for Item Barcode '" + itemBarCode + "'."; problems = ServiceHelper.generateProblems( Version1LookupItemProcessingError.UNKNOWN_ITEM, "CheckOut Error", null, errorMsg); } } else { LOG.error("CheckOut - Couldn't Renew Item for Item Barcode: " + itemBarCode); problems = ServiceHelper.generateProblems( Version1LookupItemProcessingError.UNKNOWN_ITEM, "CheckOut Error", null, "Couldn't Renew Item for Item Barcode: " + itemBarCode); } } else { LOG.error("CheckOut - Renew Item array list not match"); problems = ServiceHelper.generateProblems( Version1LookupItemProcessingError.UNKNOWN_ITEM, "Item Array not match", null, "Renew Item array list not match"); } // if (itemsCheckedOutList.size() == renewItemList.size()) } else { LOG.error("CheckOut - False received renew items page array information"); problems = ServiceHelper.generateProblems( Version1LookupUserProcessingError.USER_AUTHENTICATION_FAILED, "Failed to get Items Array", null, itemRenewStatus.recordStatus.returnMsg); } // if (itemRenewStatus.recordStatus.returnStatus) } else { LOG.error("CheckOut - Couldn't receive Renewitem page!"); //LOG.debug ("Error: " + renewStatus.recordStatus.returnMsg); problems = ServiceHelper.generateProblems( Version1LookupUserProcessingError.USER_AUTHENTICATION_FAILED, "Failed to get Renew Confirmation", null, renewStatus.recordStatus.returnMsg); } // if (renewStatus.recordStatus.returnStatus) } else { LOG.error("CheckOut - Couldn't find the Barcode: " + itemBarCode + " in Items Page of user: " + authenticatedUserName); problems = ServiceHelper.generateProblems( Version1LookupItemProcessingError.UNKNOWN_ITEM, "BarCode not Found", null, "Couldn't find the Barcode: " + itemBarCode + " in Items Page of user: " + authenticatedUserName); } } else { LOG.error("CheckOut - False received checkout items page array information"); problems = ServiceHelper.generateProblems( Version1LookupUserProcessingError.USER_AUTHENTICATION_FAILED, "Failed to get Items Array", null, itemsCheckOutStatus.recordStatus.returnMsg); } // if (foundLDAPUser || foundPatronUser) } else { LOG.error("CheckOut - False received items page"); problems = ServiceHelper.generateProblems( Version1LookupUserProcessingError.USER_AUTHENTICATION_FAILED, "False received items page", null, getItemsStatus.recordStatus.returnMsg); } // if (getItemsStatus.recordStatus.returnStatus) } else { // if (getItems) LOG.error("CheckOut - Couldn't found Item page"); problems = ServiceHelper.generateProblems( Version1LookupUserProcessingError.USER_AUTHENTICATION_FAILED, "Items page not found", null, "Couldn't found Item page!"); } } else { LOG.error("CheckOut - Incorrect User Id or Password!"); problems = ServiceHelper.generateProblems( Version1LookupUserProcessingError.USER_AUTHENTICATION_FAILED, "User Authentication Failed", null, "False to login - Incorrect User Id or Password!"); } } else { LOG.error("User Id or Password is missing!"); problems = ServiceHelper.generateProblems(Version1LookupUserProcessingError.USER_AUTHENTICATION_FAILED, "Missing User Id or Password", null, "User Id or Password is missing!"); } // } else { // LOG.error("CheckOut - Function Renew is not support!"); // problems = ServiceHelper.generateProblems(Version1LookupUserProcessingError.USER_AUTHENTICATION_FAILED, // "Function is not support", null, "Function is not support!"); // } // if (foundRenew) // } else { // LOG.error("CheckOut - Services is not support!"); // problems = ServiceHelper.generateProblems(Version1LookupUserProcessingError.USER_AUTHENTICATION_FAILED, // "Services is not support", null, "Services is not support!"); // } // if (foundService) if (problems != null) { //LOG.debug("main 3 - " + problems.size()); responseData.setProblems(problems); if (foundLDAPUser || foundPatronUser) { baseUrl = "https://" + IIIClassicBaseUrl + "/logout"; millenniumSvcMgr.LogOut(baseUrl); } return responseData; } else { LOG.debug("CheckOut - Success received all information"); user.setUserIdentifierValue(authUserName.get(0).secondValue); try { user.setUserIdentifierType(UserIdentifierType.find(null, userIdentifierType)); } catch (ServiceException e) { e.printStackTrace(); } responseData.setUserId(user); baseUrl = "https://" + IIIClassicBaseUrl + "/logout"; millenniumSvcMgr.LogOut(baseUrl); return responseData; } }
From source file:org.extensiblecatalog.ncip.v2.millennium.MillenniumRemoteServiceManager.java
public htmlProperty Authenticate(ArrayList<PairGroup> authUserName, ArrayList<PairGroup> authUserPassword, String baseUrl) {//w w w .ja v a 2 s. c o m String strSessionId = null; String redirectedUrl = null; String userId = null; String itemPage = null; String html = null; Status iStatus = new Status(); htmlProperty authenticateStatus = new htmlProperty(); StatusString sessionIdStatus = getIIISessionId(baseUrl); if (sessionIdStatus.recordStatus.returnStatus) { strSessionId = sessionIdStatus.statusValue; LOG.debug("Authenticate - strSessionId: " + strSessionId); StatusString redirectedUrlStatus = getRedirectedUrl(baseUrl, strSessionId); if (redirectedUrlStatus.recordStatus.returnStatus) { String redirectUrl = redirectedUrlStatus.statusValue; LOG.debug("Authenticate - redirectUrl: " + redirectUrl); // create post method htmlProperty loginFormStatus; PostMethod loginForm = new PostMethod(redirectUrl); // Set up authentication types for (int x = 0; x < authUserName.size(); x++) { loginForm.addParameter(authUserName.get(x).firstValue, authUserName.get(x).secondValue); //LOG.debug("User Pair: " + authUserName.get(x).firstValue + ", " + authUserName.get(x).secondValue); } for (int x = 0; x < authUserPassword.size(); x++) { loginForm.addParameter(authUserPassword.get(x).firstValue, authUserPassword.get(x).secondValue); //LOG.debug("Pass Pair: " + authUserPassword.get(x).firstValue + ", " + authUserPassword.get(x).secondValue); } loginFormStatus = LogIntoWebForm(loginForm, strSessionId); if (loginFormStatus.recordStatus.returnStatus) { iStatus.returnStatus = true; iStatus.returnMsg = loginFormStatus.recordStatus.returnMsg; authenticateStatus.recordStatus = iStatus; authenticateStatus.sessionId = strSessionId; authenticateStatus.url = loginFormStatus.url; authenticateStatus.pageItem = loginFormStatus.pageItem; authenticateStatus.userid = loginFormStatus.userid; authenticateStatus.html = loginFormStatus.html; } else { iStatus.returnStatus = false; iStatus.returnMsg = loginFormStatus.recordStatus.returnMsg; authenticateStatus.recordStatus = iStatus; authenticateStatus.sessionId = strSessionId; authenticateStatus.url = loginFormStatus.url; authenticateStatus.pageItem = loginFormStatus.pageItem; authenticateStatus.userid = loginFormStatus.userid; authenticateStatus.html = loginFormStatus.html; } } else { iStatus.returnStatus = false; iStatus.returnMsg = redirectedUrlStatus.recordStatus.returnMsg; authenticateStatus.recordStatus = iStatus; authenticateStatus.sessionId = strSessionId; authenticateStatus.url = redirectedUrl; authenticateStatus.pageItem = itemPage; authenticateStatus.userid = userId; authenticateStatus.html = html; } // if (redirectedUrlStatus.recordStatus.returnStatus) } else { iStatus.returnStatus = false; iStatus.returnMsg = sessionIdStatus.recordStatus.returnMsg; authenticateStatus.recordStatus = iStatus; authenticateStatus.sessionId = strSessionId; authenticateStatus.url = redirectedUrl; authenticateStatus.pageItem = itemPage; authenticateStatus.userid = userId; authenticateStatus.html = html; } // if (sessionIdStatus.recordStatus.returnStatus) return authenticateStatus; }
From source file:org.extensiblecatalog.ncip.v2.millennium.MillenniumRemoteServiceManager.java
/** * Attempts a login using the given PostMethod by adding the needed form * parameters.//from w w w . j a v a2 s. c o m * * @param postMethod * - the PostMethod with all other needed params already * inserted. * @return the response as a String. */ public htmlProperty LogIntoWebForm(PostMethod postMethod, String sessionId) { String url = null; String redirectLocation = null; String userId = null; String itemPage = null; String html = null; Status iStatus = new Status(); htmlProperty loginStatus = new htmlProperty(); // set the login params postMethod.addRequestHeader("Cookie", "III_SESSION_ID=" + sessionId); //postMethod.addParameter("submit.x", "0"); //postMethod.addParameter("submit.y", "0"); postMethod.addParameter("pat_submit", "xxx"); // Since login returns a 302, we have to make another GET request after the POST. GetMethod getMethod = null; try { int statusCode = client.executeMethod(postMethod); URI uri = postMethod.getURI(); url = uri.toString(); // We're redirecting on the first request LOG.debug("lenght of postMethod.getResponseBodyAsString(): " + postMethod.getResponseBodyAsString().length()); if (statusCode == 302) { LOG.debug("LoginWebForm - Success submited Page (StatusCode = 302)"); redirectLocation = postMethod.getResponseHeader("Location").getValue(); //LOG.debug("LoginWebForm - redirectLocation: " + redirectLocation); itemPage = strFunction.Rightstr(url, "/"); //LOG.debug("LoginWebForm - itemPage 1: " + itemPage); url = url.substring(0, url.indexOf("/" + itemPage)) + redirectLocation; //LOG.debug("LoginWebForm - url: " + url); itemPage = strFunction.Rightstr(url, "/"); //LOG.debug("LoginWebForm - itemPage: " + itemPage); int start = url.indexOf(SNo); int end = url.indexOf("/" + itemPage); userId = url.substring(start, end).replace(SNo, "").replace("/", ""); //LOG.debug("LoginWebForm - userId: " + userId); getMethod = new GetMethod(url); getMethod.addRequestHeader("Cookie", "III_SESSION_ID=" + sessionId); statusCode = client.executeMethod(getMethod); //LOG.debug("LoginWebForm - Received contents statusCode: " + statusCode); if (statusCode == 200) { LOG.debug("LoginWebForm - statusCode(" + statusCode + ") - Success received Login page"); html = getMethod.getResponseBodyAsString(); //LOG.debug("LoginWebForm - html.length: " + html.length()); iStatus.returnStatus = true; iStatus.returnMsg = "MillenniumRemoteServiceManager-LogIntoWebForm - Success"; loginStatus.recordStatus = iStatus; loginStatus.sessionId = sessionId; loginStatus.url = url; loginStatus.pageItem = itemPage.trim(); loginStatus.userid = userId; loginStatus.html = html; } else { LOG.debug("LoginWebForm - statusCode(" + statusCode + ") - false received Login page"); iStatus.returnStatus = false; iStatus.returnMsg = "MillenniumRemoteServiceManager-LogIntoWebForm - statusCode(" + statusCode + "). " + errorCodeMsg.ErrorMessage(470); loginStatus.recordStatus = iStatus; loginStatus.sessionId = sessionId; loginStatus.url = url; loginStatus.pageItem = itemPage; loginStatus.userid = userId; loginStatus.html = html; } } /* else if (statusCode == 200) { LOG.debug("LoginWebForm - statusCode(" + statusCode + ") - Success received Login page"); redirectLocation = postMethod.getResponseHeader("Location").getValue(); //LOG.debug("LoginWebForm - redirectLocation: " + redirectLocation); itemPage = strFunction.Rightstr(url, "/"); //LOG.debug ("LoginWebForm - itemPage 1: " + itemPage); url = url.substring(0, url.indexOf("/" + itemPage)) + redirectLocation; //LOG.debug("LoginWebForm - url: " + url); itemPage = strFunction.Rightstr(url, "/"); //LOG.debug ("LoginWebForm - itemPage: " + itemPage); int start = url.indexOf(SNo); int end = url.indexOf("/" + itemPage); userId = url.substring(start, end).replace(SNo, "").replace("/", ""); //LOG.debug("LoginWebForm - userId: " + userId); html = postMethod.getResponseBodyAsString(); //LOG.debug("LoginWebForm - html.length: " + html.length()); iStatus.returnStatus = true; iStatus.returnMsg = "MillenniumRemoteServiceManager-LogIntoWebForm - Success"; loginStatus.recordStatus = iStatus; loginStatus.sessionId = sessionId; loginStatus.url = url; loginStatus.pageItem = itemPage.trim(); loginStatus.userid = userId; loginStatus.html = html; } */ else { LOG.error("LoginWebForm - LDAP False to Login or others false to Login - statusCode(" + statusCode + "). "); iStatus.returnStatus = false; iStatus.returnMsg = "MillenniumRemoteServiceManager-LogIntoWebForm - statusCode(" + statusCode + "). " + errorCodeMsg.ErrorMessage(470); loginStatus.recordStatus = iStatus; loginStatus.sessionId = sessionId; loginStatus.url = url; loginStatus.pageItem = itemPage; loginStatus.userid = userId; loginStatus.html = html; } } catch (HttpException e1) { LOG.error("LoginWebForm - Error! HttpException."); //e1.printStackTrace(); iStatus.returnStatus = false; iStatus.returnMsg = "MillenniumRemoteServiceManager-LogIntoWebForm - " + errorCodeMsg.ErrorMessage(490); loginStatus.recordStatus = iStatus; loginStatus.sessionId = sessionId; loginStatus.url = url; loginStatus.pageItem = itemPage; loginStatus.userid = userId; loginStatus.html = html; } catch (IOException e1) { LOG.error("LoginWebForm - Error! IOException."); //e1.printStackTrace(); iStatus.returnStatus = false; iStatus.returnMsg = "MillenniumRemoteServiceManager-LogIntoWebForm - " + errorCodeMsg.ErrorMessage(480); ; loginStatus.recordStatus = iStatus; loginStatus.sessionId = sessionId; loginStatus.url = url; loginStatus.pageItem = itemPage; loginStatus.userid = userId; loginStatus.html = html; } finally { if (postMethod != null) { postMethod.releaseConnection(); } if (getMethod != null) { getMethod.releaseConnection(); } } return loginStatus; }
From source file:org.extensiblecatalog.ncip.v2.millennium.MillenniumRemoteServiceManager.java
public StatusString RequestItemLogIn(ArrayList<PairGroup> authUserName, ArrayList<PairGroup> authUserPassword, String pickupLocation, String baseUrl) { Status iStatus = new Status(); StatusString loginStatus = new StatusString(); PostMethod getRequestItemLoginStatus = new PostMethod(baseUrl); for (int x = 0; x < authUserName.size(); x++) { getRequestItemLoginStatus.addParameter(authUserName.get(x).firstValue, authUserName.get(x).secondValue); //LOG.debug("User Pair: " + authUserName.get(x).firstValue + ", " + authUserName.get(x).secondValue); }/*from www . j a v a 2 s .com*/ for (int x = 0; x < authUserPassword.size(); x++) { getRequestItemLoginStatus.addParameter(authUserPassword.get(x).firstValue, authUserPassword.get(x).secondValue); //LOG.debug("Pass Pair: " + authUserPassword.get(x).firstValue + ", " + authUserPassword.get(x).secondValue); } getRequestItemLoginStatus.addParameter("locx00", pickupLocation); getRequestItemLoginStatus.addParameter("pat_submit", "xxx"); StatusString getLoginStatus = SingleLogInForm(getRequestItemLoginStatus); if (getLoginStatus.recordStatus.returnStatus) { iStatus.returnStatus = true; iStatus.returnMsg = "RequestItemLogIn - " + getLoginStatus.recordStatus.returnMsg; loginStatus.recordStatus = iStatus; loginStatus.statusValue = getLoginStatus.statusValue; } else { iStatus.returnStatus = false; iStatus.returnMsg = "RequestItemLogIn - " + getLoginStatus.recordStatus.returnMsg; loginStatus.recordStatus = iStatus; loginStatus.statusValue = null; } return loginStatus; }
From source file:org.extensiblecatalog.ncip.v2.millennium.MillenniumRemoteServiceManager.java
public StatusString RequestItemPickLocation(String pickupLocation, int getYear, int getMonth, int getDate, String baseUrl) {/*from w w w. j a v a 2 s .c om*/ Status iStatus = new Status(); StatusString loginStatus = new StatusString(); PostMethod getRequestItemLoginStatus = new PostMethod(baseUrl); //LOG.debug("Year/Month/Date: " + Integer.toString(getYear) + "/" + Integer.toString(getMonth) + "/" + Integer.toString(getDate)); String sgetMonth = Integer.toString(getMonth); if (sgetMonth.length() < 2) { sgetMonth = "0" + sgetMonth; } String sgetDate = Integer.toString(getDate); if (sgetDate.length() < 2) { sgetDate = "0" + sgetDate; } String sgetYear = Integer.toString(getYear); //LOG.debug("Year/Month/Date: " + sgetYear + "/" + sgetMonth + "/" + sgetDate); getRequestItemLoginStatus.addParameter("pat_submit", "xxx"); //LOG.debug("RequestItemPickLocation-PickupLocation: " + pickupLocation); //LOG.debug("RequestItemPickLocation-Month: " + sgetMonth); //LOG.debug("RequestItemPickLocation-Date: " + sgetDate); //LOG.debug("RequestItemPickLocation-Year " + sgetYear); getRequestItemLoginStatus.addParameter("locx00", pickupLocation); getRequestItemLoginStatus.addParameter("needby_Month", sgetMonth); getRequestItemLoginStatus.addParameter("needby_Day", sgetDate); getRequestItemLoginStatus.addParameter("needby_Year", sgetYear); StatusString getLoginStatus = SingleLogInForm(getRequestItemLoginStatus); if (getLoginStatus.recordStatus.returnStatus) { iStatus.returnStatus = true; iStatus.returnMsg = "MillenniumRemoteServiceManager-RequestItemPickLocation - Success"; loginStatus.recordStatus = iStatus; loginStatus.statusValue = getLoginStatus.statusValue; } else { iStatus.returnStatus = false; iStatus.returnMsg = "RequestItemPickLocation - " + getLoginStatus.recordStatus.returnMsg; loginStatus.recordStatus = iStatus; loginStatus.statusValue = null; } return loginStatus; }
From source file:org.extensiblecatalog.ncip.v2.millennium.MillenniumRemoteServiceManager.java
public StatusString RequestItemConfirmLogIn(ArrayList<PairGroup> authUserName, ArrayList<PairGroup> authUserPassword, String pickupLocation, int getYear, int getMonth, int getDate, String itemValue, String baseUrl) { Status iStatus = new Status(); StatusString loginStatus = new StatusString(); PostMethod getRequestItemLoginStatus = new PostMethod(baseUrl); //LOG.debug("user, pw, item, loc: " + authenticatedUserName + ", " + authenticatedUserPassword + ", " + itemValue + ", " + pickupLocation); getRequestItemLoginStatus.addParameter("radio", itemValue); for (int x = 0; x < authUserName.size(); x++) { getRequestItemLoginStatus.addParameter(authUserName.get(x).firstValue, authUserName.get(x).secondValue); //LOG.debug("User Pair: " + authUserName.get(x).firstValue + ", " + authUserName.get(x).secondValue); }/*from ww w.ja v a 2 s. co m*/ for (int x = 0; x < authUserPassword.size(); x++) { getRequestItemLoginStatus.addParameter(authUserPassword.get(x).firstValue, authUserPassword.get(x).secondValue); //LOG.debug("Pass Pair: " + authUserPassword.get(x).firstValue + ", " + authUserPassword.get(x).secondValue); } //LOG.debug("Year/Month/Date: " + Integer.toString(getYear) + "/" + Integer.toString(getMonth) + "/" + Integer.toString(getDate)); String sgetMonth = Integer.toString(getMonth); if (sgetMonth.length() < 2) { sgetMonth = "0" + sgetMonth; } String sgetDate = Integer.toString(getDate); if (sgetDate.length() < 2) { sgetDate = "0" + sgetDate; } String sgetYear = Integer.toString(getYear); //LOG.debug("Year/Month/Date: " + sgetYear + "/" + sgetMonth + "/" + sgetDate); getRequestItemLoginStatus.addParameter("pat_submit", "xxx"); LOG.debug("RequestItemConfirmLogIn-PickupLocation: " + pickupLocation); LOG.debug("RequestItemConfirmLogIn-Month: " + sgetMonth); LOG.debug("RequestItemConfirmLogIn-Date: " + sgetDate); LOG.debug("RequestItemConfirmLogIn-Year " + sgetYear); getRequestItemLoginStatus.addParameter("locx00", pickupLocation); getRequestItemLoginStatus.addParameter("needby_Month", sgetMonth); getRequestItemLoginStatus.addParameter("needby_Day", sgetDate); getRequestItemLoginStatus.addParameter("needby_Year", sgetYear); StatusString getLoginStatus = SingleLogInForm(getRequestItemLoginStatus); if (getLoginStatus.recordStatus.returnStatus) { iStatus.returnStatus = true; iStatus.returnMsg = "MillenniumRemoteServiceManager-RequestItemConfirmLogIn - Success"; loginStatus.recordStatus = iStatus; loginStatus.statusValue = getLoginStatus.statusValue; } else { iStatus.returnStatus = false; iStatus.returnMsg = "RequestItemConfirmLogIn - " + getLoginStatus.recordStatus.returnMsg; loginStatus.recordStatus = iStatus; loginStatus.statusValue = null; } return loginStatus; }
From source file:org.extensiblecatalog.ncip.v2.millennium.MillenniumRenewItemService.java
/** * Handles a NCIP RenewItem service by returning XML data. * /*from w w w . j a v a2s . co m*/ * @param initData * the LookupUserInitiationData * @param serviceManager * provides access to remote services * @return LookupUserResponseData */ @Override public RenewItemResponseData performService(RenewItemInitiationData initData, ServiceContext serviceContext, RemoteServiceManager serviceManager) { MillenniumRemoteServiceManager millenniumSvcMgr = (MillenniumRemoteServiceManager) serviceManager; MillenniumConfiguration MillenniumConfig = millenniumSvcMgr.buildConfiguration(); String IIIClassicBaseUrl = MillenniumConfig.getURL(); String baseUrl = "https://" + IIIClassicBaseUrl + "/patroninfo"; //.html~S0"; // LOG.debug("RenewItem - baseURL: " + baseUrl); boolean foundUserId = false; boolean foundUserPass = false; List<Problem> problems = null; final RenewItemResponseData responseData = new RenewItemResponseData(); String userIdentifierType = null; final String getLDAPUserVarString = MillenniumConfig.getLdapUserVariable(); String[] getLDAPUserVarList = getLDAPUserVarString.split(","); final String getLDAPPasswordVarString = MillenniumConfig.getLdapPasswordVariable(); String[] getLDAPPasswordVarList = getLDAPPasswordVarString.split(","); final String getPatronUserVarString = MillenniumConfig.getPatronUserVariable(); String[] getPatronUserVarList = getPatronUserVarString.split(","); final String getPatronPasswordVarString = MillenniumConfig.getPatronPasswordVariable(); String[] getPatronPasswordVarList = getPatronPasswordVarString.split(","); boolean foundLDAPUser = false; boolean foundPatronUser = false; //boolean foundService = false; boolean foundRenew = false; //for (int x = 0; x < millenniumServicesList.length; x++) { // if (millenniumServicesList[x].trim().equals("RenewItem")) { // foundService = true; // } //} //if (foundService) { final String[] millenniumFunctionsList = MillenniumConfig.getFunctions().split(","); for (int x = 0; x < millenniumFunctionsList.length; x++) { if (millenniumFunctionsList[x].trim().equals("Renew")) { foundRenew = true; } } if (foundRenew) { authenticatedUserName = new ArrayList<String>(); authenticatedUserPassword = new ArrayList<String>(); for (AuthenticationInput authenticationInput : initData.getAuthenticationInputs()) { //LOG.debug("authenticationInput: " + authenticationInput.getAuthenticationInputData()); //LOG.debug("Type: " + authenticationInput.getAuthenticationInputType().getValue()); if ((authenticationInput.getAuthenticationInputType().getValue().toUpperCase() .equals("LDAPUSERNAME")) || (authenticationInput.getAuthenticationInputType().getValue().toUpperCase() .equals("USERNAME"))) { userIdentifierType = authenticationInput.getAuthenticationInputType().getValue(); LOG.debug("RequestItem - userIdentifierType: " + userIdentifierType); if (authenticationInput.getAuthenticationInputData().trim().length() > 0) { authenticatedUserName.add(authenticationInput.getAuthenticationInputData()); foundUserId = true; } } if ((authenticationInput.getAuthenticationInputType().getValue().toUpperCase() .equals("LDAPPASSWORD")) || (authenticationInput.getAuthenticationInputType().getValue().toUpperCase() .equals("PASSWORD")) || (authenticationInput.getAuthenticationInputType().getValue().toUpperCase() .equals("PIN"))) { if (authenticationInput.getAuthenticationInputData().trim().length() > 0) { authenticatedUserPassword.add(authenticationInput.getAuthenticationInputData()); foundUserPass = true; } } } //LOG.debug("foundUser and foundPass: " + foundUserId + ", " + foundUserPass); if (foundUserId && foundUserPass) { //LOG.debug("1 - User: " + authenticatedUserName.size() + "=" + getLDAPUserVarList.length + "Pass: " + authenticatedUserPassword.size() + "=" + getLDAPPasswordVarList.length); testAuthUser = new ArrayList<PairGroup>(); testAuthPass = new ArrayList<PairGroup>(); authUserName = new ArrayList<PairGroup>(); authPassword = new ArrayList<PairGroup>(); htmlProperty authenticateStatus = null; if ((authenticatedUserName.size() == getLDAPUserVarList.length) && (authenticatedUserPassword.size() == getLDAPPasswordVarList.length)) { for (int x = 0; x < authenticatedUserName.size(); x++) { //LOG.debug("User pair: " + getLDAPUserVarList[x] + ", " + authenticatedUserName.get(x)); PairGroup userPair = millenniumSvcMgr.setPairGroup(getLDAPUserVarList[x], authenticatedUserName.get(x)); testAuthUser.add(userPair); } for (int y = 0; y < authenticatedUserPassword.size(); y++) { //LOG.debug("pass pair: " + getLDAPPasswordVarList[y] + ", " + authenticatedUserPassword.get(y)); PairGroup passPair = millenniumSvcMgr.setPairGroup(getLDAPPasswordVarList[y], authenticatedUserPassword.get(y)); testAuthPass.add(passPair); } authenticateStatus = millenniumSvcMgr.Authenticate(testAuthUser, testAuthPass, baseUrl); if (authenticateStatus.recordStatus.returnStatus) { authUserName = testAuthUser; authPassword = testAuthPass; foundLDAPUser = true; LOG.debug("LDAP authUserName.size() =" + authUserName.size()); } } //LOG.debug("2 - FoundLDAPUser: " + foundLDAPUser); if ((foundLDAPUser == false) && ((authenticatedUserName.size() == getPatronUserVarList.length) && (authenticatedUserPassword.size() == getPatronPasswordVarList.length))) { testAuthUser = new ArrayList<PairGroup>(); testAuthPass = new ArrayList<PairGroup>(); for (int x = 0; x < authenticatedUserName.size(); x++) { PairGroup userPair = millenniumSvcMgr.setPairGroup(getPatronUserVarList[x], authenticatedUserName.get(x)); testAuthUser.add(userPair); } for (int y = 0; y < authenticatedUserPassword.size(); y++) { PairGroup passPair = millenniumSvcMgr.setPairGroup(getPatronPasswordVarList[y], authenticatedUserPassword.get(y)); testAuthPass.add(passPair); } authenticateStatus = millenniumSvcMgr.Authenticate(testAuthUser, testAuthPass, baseUrl); if (authenticateStatus.recordStatus.returnStatus) { authUserName = testAuthUser; authPassword = testAuthPass; foundPatronUser = true; LOG.debug("Patron authUserName.size() =" + authUserName.size()); } } String itemBarCode = initData.getItemId().getItemIdentifierValue(); LOG.debug("RenewItem - itemBarCode: " + itemBarCode); int barCodeIndex = 0; //htmlProperty authenticateStatus = millenniumSvcMgr.Authenticate(authenticatedUserName, authenticatedUserPassword, baseUrl); if (foundLDAPUser || foundPatronUser) { LOG.debug("RenewItem - Login Success!"); boolean getItems = false; String strSessionId = authenticateStatus.sessionId; String redirectedUrl = authenticateStatus.url; LOG.debug("RenewItem - redirectedUrl: " + redirectedUrl); authenticatedUserId = authenticateStatus.userid; LOG.debug("RenewItem - authenticatedUserId: " + authenticatedUserId); String html = authenticateStatus.html; String pageItem = authenticateStatus.pageItem.toLowerCase().trim(); //LOG.debug("RenewItem - itempage: " + authenticateStatus.pageItem); //LOG.debug("RenewItem - SNo: " + SNo); String SNo = MillenniumConfig.getSearchScope(); if (pageItem.equals("items") || html .contains("<a href=\"/patroninfo~" + SNo + "/" + authenticatedUserId + "/items")) { getItems = true; } LOG.debug("RenewItem - Found - Items: " + getItems); if (getItems) { LOG.debug("RenewItem - Found Items Currently Checked out"); StatusString getItemsStatus = millenniumSvcMgr .getAuthenticationItemsPage(authenticatedUserId, strSessionId, "items"); if (getItemsStatus.recordStatus.returnStatus) { LOG.debug("RenewItem - Success received items page. HTML char: " + getItemsStatus.statusValue.length()); ArrayList<AuthenticationItemsInfo> itemsCheckedOutList = null;//millenniumSvcMgr.getItemsCheckedOut(authenticatedUserId, strSessionId, "items"); UserItemInfo itemsCheckOutStatus = millenniumSvcMgr .getItemsCheckedOut(getItemsStatus.statusValue, foundRenew); if (itemsCheckOutStatus.recordStatus.returnStatus) { LOG.debug("RenewItem - Success received items page array information"); itemsCheckedOutList = itemsCheckOutStatus.itemsList; boolean foundBarCode = false; for (int x = 0; x < itemsCheckedOutList.size(); x++) { if (itemsCheckedOutList.get(x).iBarcode.contains(itemBarCode)) { foundBarCode = true; barCodeIndex = x; } } if (foundBarCode) { LOG.debug("RenewItem - Found item barcode in items page at index: " + barCodeIndex); //LOG.debug("RenewItem - Mark id: " + itemsCheckedOutList.get(barCodeIndex).iMark); //LOG.debug("RenewItem - Mark Value: " + itemsCheckedOutList.get(barCodeIndex).iMarkValue); String url = null; if (strFunction.Rightstr(redirectedUrl, "/").equals("items")) { url = redirectedUrl; } else { url = redirectedUrl.replace(pageItem, "items"); } LOG.debug("RenewItem - url: " + url); PostMethod postMethod = new PostMethod(url); postMethod.addParameter(itemsCheckedOutList.get(barCodeIndex).iMark, itemsCheckedOutList.get(barCodeIndex).iMarkValue); postMethod.addParameter("renewsome", "YES"); StatusString renewStatus = millenniumSvcMgr.LogInWebActionForm(postMethod, strSessionId); if (renewStatus.recordStatus.returnStatus) { //LOG.debug("html lenght: " + renewStatus.statusValue.length()); UserItemInfo itemRenewStatus = millenniumSvcMgr .getItemsCheckedOut(renewStatus.statusValue, foundRenew); if (itemRenewStatus.recordStatus.returnStatus) { ArrayList<AuthenticationItemsInfo> renewItemList = itemRenewStatus.itemsList; if (itemsCheckedOutList.size() == renewItemList.size()) { LOG.debug("Checkout Status is: " + itemsCheckedOutList.get(barCodeIndex).iStatus); LOG.debug("Renew Status is: " + renewItemList.get(barCodeIndex).iStatus); if (itemsCheckedOutList.get(barCodeIndex).iStatus .equals(renewItemList.get(barCodeIndex).iStatus) == false) { StatusString newDueDateString = millenniumSvcMgr .setRenewSimpleDateFormat( renewItemList.get(barCodeIndex).iStatus); if (newDueDateString.recordStatus.returnStatus) { //Date dueDate = null; // set to null SimpleDateFormat dateFormat = new SimpleDateFormat( "MM/dd/yy"); try { Date dueDate = dateFormat .parse(newDueDateString.statusValue.trim() .replace("-", "/")); LOG.debug("RenewItem - NewDueDate: " + dueDate); //Date newDueDate = millenniumSvcMgr.setRenewSimpleDateFormat(renewItemList.get(barCodeIndex).iStatus); GregorianCalendar DueDateCalendar = new GregorianCalendar( TimeZone.getTimeZone("UTC")); DueDateCalendar.setTime(dueDate); responseData.setDateDue(DueDateCalendar); ItemId itemId = new ItemId(); itemId.setItemIdentifierValue(itemBarCode); responseData.setItemId(itemId); String renewalCount = millenniumSvcMgr.getRenewalCount( renewItemList.get(barCodeIndex).iStatus); responseData .setRenewalCount(new BigDecimal(renewalCount)); } catch (ParseException pe) { LOG.error( "setRenewSimpleDateFormat ERROR: Cannot parse \"" + newDueDateString.statusValue + "\""); problems = ServiceHelper.generateProblems( Version1RenewItemProcessingError.ITEM_NOT_RENEWABLE, "RenewItem Error", null, "Date format error for: " + itemBarCode); } } else { LOG.error("RenewItem - " + newDueDateString.statusValue.trim() + " for Item Barcode: " + itemBarCode + "."); String errorMsg = newDueDateString.statusValue.trim() + " for Item Barcode '" + itemBarCode + "'."; problems = ServiceHelper.generateProblems( Version1RenewItemProcessingError.ITEM_NOT_RENEWABLE, "Item maybe renew with error!", null, errorMsg); } } else { LOG.error("RenewItem - Couldn't Renew Item for Item Barcode: " + itemBarCode); problems = ServiceHelper.generateProblems( Version1RenewItemProcessingError.ITEM_NOT_RENEWABLE, "RenewItem Error", null, "Couldn't Renew Item for Item Barcode: " + itemBarCode); } } else { LOG.error("RenewItem - Renew Item array list not match"); problems = ServiceHelper.generateProblems( Version1RenewItemProcessingError.UNKNOWN_ITEM, "Item Array not match", null, "Renew Item array list not match"); } // if (itemsCheckedOutList.size() == renewItemList.size()) } else { LOG.error( "RenewItem - False received renew items page array information"); problems = ServiceHelper.generateProblems( Version1RenewItemProcessingError.USER_AUTHENTICATION_FAILED, "Failed to get Items Array", null, itemRenewStatus.recordStatus.returnMsg); } // if (itemRenewStatus.recordStatus.returnStatus) } else { LOG.error("RenewItem - Couldn't receive Renewitem page!"); //LOG.debug ("Error: " + renewStatus.recordStatus.returnMsg); problems = ServiceHelper.generateProblems( Version1RenewItemProcessingError.USER_AUTHENTICATION_FAILED, "Failed to get Renew Confirmation", null, renewStatus.recordStatus.returnMsg); } // if (renewStatus.recordStatus.returnStatus) } else { LOG.error("RenewItem - Couldn't find the Barcode: " + itemBarCode + " in Items Page of user: " + authenticatedUserName); problems = ServiceHelper.generateProblems( Version1RenewItemProcessingError.ITEM_NOT_CHECKED_OUT, "BarCode not Found", null, "Couldn't find the Barcode: " + itemBarCode + " in Items Page of user: " + authenticatedUserName); } } else { LOG.error("RenewItem - False received checkout items page array information"); problems = ServiceHelper.generateProblems( Version1RenewItemProcessingError.USER_AUTHENTICATION_FAILED, "Failed to get Items Array", null, itemsCheckOutStatus.recordStatus.returnMsg); } // if (foundLDAPUser || foundPatronUser) } else { LOG.error("RenewItem - False received items page"); problems = ServiceHelper.generateProblems( Version1RenewItemProcessingError.USER_AUTHENTICATION_FAILED, "False received items page", null, getItemsStatus.recordStatus.returnMsg); } // if (getItemsStatus.recordStatus.returnStatus) } else { // if (getItems) LOG.error("RenewItem - Couldn't found Item page"); problems = ServiceHelper.generateProblems( Version1RenewItemProcessingError.USER_AUTHENTICATION_FAILED, "Items page not found", null, "Couldn't found Item page!"); } } else { LOG.error("RenewItem - Incorrect User Id or Password!"); problems = ServiceHelper.generateProblems( Version1RenewItemProcessingError.USER_AUTHENTICATION_FAILED, "User Authentication Failed", null, "False to login - Incorrect Username or Password!"); } } else { LOG.error("User Id or Password is missing!"); problems = ServiceHelper.generateProblems( Version1LookupUserProcessingError.USER_AUTHENTICATION_FAILED, "Missing User Id or Password", null, "User Id or Password is missing!"); } } else { LOG.error("RenewItem - Function Renew is not support!"); problems = ServiceHelper.generateProblems(Version1LookupUserProcessingError.USER_AUTHENTICATION_FAILED, "Function is not support", null, "Function is not support!"); } // if (foundRenew) //} else { // LOG.error("RenewItem - Services is not support!"); // problems = ServiceHelper.generateProblems(Version1LookupUserProcessingError.USER_AUTHENTICATION_FAILED, // "Services is not support", null, "Services is not support!"); //} // if (foundService) if (problems != null) { //LOG.debug("main 3 - " + problems.size()); responseData.setProblems(problems); if (foundLDAPUser || foundPatronUser) { baseUrl = "https://" + IIIClassicBaseUrl + "/logout"; millenniumSvcMgr.LogOut(baseUrl); } return responseData; } else { LOG.debug("RenewItem - Success received all information"); user.setUserIdentifierValue(authUserName.get(0).secondValue); try { user.setUserIdentifierType(UserIdentifierType.find(null, userIdentifierType)); } catch (ServiceException e) { e.printStackTrace(); } responseData.setUserId(user); baseUrl = "https://" + IIIClassicBaseUrl + "/logout"; millenniumSvcMgr.LogOut(baseUrl); return responseData; } }
From source file:org.fusesource.fabric.itests.paxexam.mq.MQDistroTest.java
@Test public void testMQ() throws Exception { // send message via webconsole, consume from jms openwire HttpClient client = new HttpClient(); // set credentials client.getState().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(USER_NAME_ND_PASSWORD, USER_NAME_ND_PASSWORD)); // need to first get the secret GetMethod get = new GetMethod(WEB_CONSOLE_URL + "send.jsp"); get.setDoAuthentication(true);/*from w w w. ja v a 2 s . co m*/ // Give console some time to start for (int i = 0; i < 20; i++) { Thread.currentThread().sleep(1000); try { i = client.executeMethod(get); } catch (java.net.ConnectException ignored) { } } assertEquals("get succeeded on " + get, 200, get.getStatusCode()); String response = get.getResponseBodyAsString(); final String secretMarker = "<input type=\"hidden\" name=\"secret\" value=\""; String secret = response.substring(response.indexOf(secretMarker) + secretMarker.length()); secret = secret.substring(0, secret.indexOf("\"/>")); final String destination = "validate.console.send"; final String content = "Hi for the " + Math.random() + "' time"; PostMethod post = new PostMethod(WEB_CONSOLE_URL + "sendMessage.action"); post.setDoAuthentication(true); post.addParameter("secret", secret); post.addParameter("JMSText", content); post.addParameter("JMSDestination", destination); post.addParameter("JMSDestinationType", "queue"); // execute the send assertEquals("post succeeded, " + post, 302, client.executeMethod(post)); // consume what we sent ActiveMQConnection connection = (ActiveMQConnection) new ActiveMQConnectionFactory() .createConnection(USER_NAME_ND_PASSWORD, USER_NAME_ND_PASSWORD); connection.start(); try { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); TextMessage textMessage = (TextMessage) session.createConsumer(new ActiveMQQueue(destination)) .receive(10 * 1000); assertNotNull("got a message", textMessage); assertEquals("it is ours", content, textMessage.getText()); } finally { connection.close(); } // verify osgi registration of cf ConnectionFactory connectionFactory = getOsgiService(ConnectionFactory.class); assertTrue(connectionFactory instanceof ActiveMQConnectionFactory); ActiveMQConnection connectionFromOsgiFactory = (ActiveMQConnection) connectionFactory .createConnection(USER_NAME_ND_PASSWORD, USER_NAME_ND_PASSWORD); connectionFromOsgiFactory.start(); try { assertEquals("same broker", connection.getBrokerName(), connectionFromOsgiFactory.getBrokerName()); } finally { connectionFromOsgiFactory.close(); } // verify mq-client Process process = Runtime.getRuntime() .exec("java -jar extras" + File.separator + "mq-client.jar producer --count 1 --user " + USER_NAME_ND_PASSWORD + " --password " + USER_NAME_ND_PASSWORD, null, // env new File(System.getProperty("user.dir"))); process.waitFor(); assertEquals("producer worked, exit(0)?", 0, process.exitValue()); process = Runtime.getRuntime() .exec("java -jar extras" + File.separator + "mq-client.jar consumer --count 1 --user " + USER_NAME_ND_PASSWORD + " --password " + USER_NAME_ND_PASSWORD, null, // env new File(System.getProperty("user.dir"))); process.waitFor(); assertEquals("consumer worked, exit(0)?", 0, process.exitValue()); }
From source file:org.fusesource.mq.itests.MQDistroTest.java
@Test public void testWebConsoleAndClient() throws Exception { // send message via webconsole, consume from jms openwire HttpClient client = new HttpClient(); // set credentials client.getState().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(USER_NAME_ND_PASSWORD, USER_NAME_ND_PASSWORD)); // need to first get the secret GetMethod get = new GetMethod(WEB_CONSOLE_URL + "send.jsp"); get.setDoAuthentication(true);/* w ww . ja v a 2 s .c om*/ // Give console some time to start for (int i = 0; i < 20; i++) { Thread.currentThread().sleep(1000); try { i = client.executeMethod(get); } catch (java.net.ConnectException ignored) { } } assertEquals("get succeeded on " + get, 200, get.getStatusCode()); String response = get.getResponseBodyAsString(); final String secretMarker = "<input type=\"hidden\" name=\"secret\" value=\""; String secret = response.substring(response.indexOf(secretMarker) + secretMarker.length()); secret = secret.substring(0, secret.indexOf("\"/>")); final String destination = "validate.console.send"; final String content = "Hi for the " + Math.random() + "' time"; PostMethod post = new PostMethod(WEB_CONSOLE_URL + "sendMessage.action"); post.setDoAuthentication(true); post.addParameter("secret", secret); post.addParameter("JMSText", content); post.addParameter("JMSDestination", destination); post.addParameter("JMSDestinationType", "queue"); // execute the send assertEquals("post succeeded, " + post, 302, client.executeMethod(post)); // consume what we sent ActiveMQConnection connection = (ActiveMQConnection) new ActiveMQConnectionFactory() .createConnection(USER_NAME_ND_PASSWORD, USER_NAME_ND_PASSWORD); connection.start(); try { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); TextMessage textMessage = (TextMessage) session.createConsumer(new ActiveMQQueue(destination)) .receive(10 * 1000); assertNotNull("got a message", textMessage); assertEquals("it is ours", content, textMessage.getText()); } finally { connection.close(); } // verify osgi registration of cf ConnectionFactory connectionFactory = getOsgiService(ConnectionFactory.class); assertTrue(connectionFactory instanceof ActiveMQConnectionFactory); ActiveMQConnection connectionFromOsgiFactory = (ActiveMQConnection) connectionFactory .createConnection(USER_NAME_ND_PASSWORD, USER_NAME_ND_PASSWORD); connectionFromOsgiFactory.start(); try { assertEquals("same broker", connection.getBrokerName(), connectionFromOsgiFactory.getBrokerName()); } finally { connectionFromOsgiFactory.close(); } // verify mq-client Process process = Runtime.getRuntime() .exec("java -jar extras" + File.separator + "mq-client.jar producer --count 1 --user " + USER_NAME_ND_PASSWORD + " --password " + USER_NAME_ND_PASSWORD, null, // env new File(System.getProperty("user.dir"))); process.waitFor(); assertEquals("producer worked, exit(0)?", 0, process.exitValue()); process = Runtime.getRuntime() .exec("java -jar extras" + File.separator + "mq-client.jar consumer --count 1 --user " + USER_NAME_ND_PASSWORD + " --password " + USER_NAME_ND_PASSWORD, null, // env new File(System.getProperty("user.dir"))); process.waitFor(); assertEquals("consumer worked, exit(0)?", 0, process.exitValue()); System.out.println(executeCommand("activemq:bstat")); }
From source file:org.gc.googleAnalytics.PostData.java
/** * Executes post request to collect data on Event Tracking * in owner google analytics account.// ww w .j a v a 2s.co m * * @param category : String * @param action : String * @param name : String, suppose to be id or name of api * @param value : String, number of access * @return boolean value, if request is ok then true else false. */ public boolean eventTracking(String category, String action, String name, String value) { //check category and action if (category == null || action == null) { logger.error("In Event Tracking, Category and Action are required."); return false; } //set request HttpClient client = new HttpClient(); PostMethod method = new PostMethod(ENDPOINT); method.addParameter(PROTOCAL_VERSION, "1"); method.addParameter(TRACKING_ID, trackingID); method.addParameter(CLIENT_ID, clientID); method.addParameter(HIT_TYPE, "event"); method.addParameter(APPLICATION_NAME, appName); method.addParameter(APPLICATION_VERSION, (!(this.appVersion == null || this.appVersion.length() == 0)) ? this.appVersion : DEFAULT_VERSION); method.addParameter(EVENT_CATEGORY, category); method.addParameter(EVENT_ACTION, action); method.addParameter(EVENT_LABEL, name);//name/id of api method.addParameter(EVENT_VALUE, value);//1 try { // Checks that value is a valid number. Integer.parseInt(value); //execute request int returnCode = client.executeMethod(method); return (returnCode == HttpStatus.SC_OK); } catch (NumberFormatException e) { throw new RuntimeException("Only valid number is allowed", e); } catch (Exception e) { logger.error("ERROR: {}", e.getMessage()); return false; } }