List of usage examples for javax.servlet.http HttpServletRequest getLocalAddr
public String getLocalAddr();
From source file:net.shopxx.plugin.alipayDualPayment.AlipayDualPaymentPlugin.java
@Override public Map<String, Object> getParameterMap(String sn, String description, HttpServletRequest request) { Setting setting = SystemUtils.getSetting(); PluginConfig pluginConfig = getPluginConfig(); PaymentLog paymentLog = getPaymentLog(sn); Map<String, Object> parameterMap = new HashMap<String, Object>(); parameterMap.put("service", "trade_create_by_buyer"); parameterMap.put("partner", pluginConfig.getAttribute("partner")); parameterMap.put("_input_charset", "utf-8"); parameterMap.put("sign_type", "MD5"); parameterMap.put("return_url", getNotifyUrl(PaymentPlugin.NotifyMethod.sync)); parameterMap.put("notify_url", getNotifyUrl(PaymentPlugin.NotifyMethod.async)); parameterMap.put("out_trade_no", sn); parameterMap.put("subject", StringUtils.abbreviate(description.replaceAll("[^0-9a-zA-Z\\u4e00-\\u9fa5 ]", ""), 60)); parameterMap.put("body", StringUtils.abbreviate(description.replaceAll("[^0-9a-zA-Z\\u4e00-\\u9fa5 ]", ""), 600)); parameterMap.put("payment_type", "1"); parameterMap.put("logistics_type", "EXPRESS"); parameterMap.put("logistics_fee", "0"); parameterMap.put("logistics_payment", "SELLER_PAY"); parameterMap.put("price", paymentLog.getAmount().setScale(2).toString()); parameterMap.put("quantity", "1"); parameterMap.put("seller_id", pluginConfig.getAttribute("partner")); parameterMap.put("total_fee", paymentLog.getAmount().setScale(2).toString()); parameterMap.put("show_url", setting.getSiteUrl()); parameterMap.put("paymethod", "directPay"); parameterMap.put("extend_param", "isv^1860648a1"); parameterMap.put("exter_invoke_ip", request.getLocalAddr()); parameterMap.put("extra_common_param", "shopxx"); parameterMap.put("sign", generateSign(parameterMap)); return parameterMap; }
From source file:net.shopxx.plugin.alipayEscowPayment.AlipayEscowPaymentPlugin.java
@Override public Map<String, Object> getParameterMap(String sn, String description, HttpServletRequest request) { Setting setting = SystemUtils.getSetting(); PluginConfig pluginConfig = getPluginConfig(); PaymentLog paymentLog = getPaymentLog(sn); Map<String, Object> parameterMap = new HashMap<String, Object>(); parameterMap.put("service", "create_partner_trade_by_buyer"); parameterMap.put("partner", pluginConfig.getAttribute("partner")); parameterMap.put("_input_charset", "utf-8"); parameterMap.put("sign_type", "MD5"); parameterMap.put("return_url", getNotifyUrl(PaymentPlugin.NotifyMethod.sync)); parameterMap.put("notify_url", getNotifyUrl(PaymentPlugin.NotifyMethod.async)); parameterMap.put("out_trade_no", sn); parameterMap.put("subject", StringUtils.abbreviate(description.replaceAll("[^0-9a-zA-Z\\u4e00-\\u9fa5 ]", ""), 60)); parameterMap.put("body", StringUtils.abbreviate(description.replaceAll("[^0-9a-zA-Z\\u4e00-\\u9fa5 ]", ""), 600)); parameterMap.put("payment_type", "1"); parameterMap.put("logistics_type", "EXPRESS"); parameterMap.put("logistics_fee", "0"); parameterMap.put("logistics_payment", "SELLER_PAY"); parameterMap.put("price", paymentLog.getAmount().setScale(2).toString()); parameterMap.put("quantity", "1"); parameterMap.put("seller_id", pluginConfig.getAttribute("partner")); parameterMap.put("total_fee", paymentLog.getAmount().setScale(2).toString()); parameterMap.put("show_url", setting.getSiteUrl()); parameterMap.put("paymethod", "directPay"); parameterMap.put("extend_param", "isv^1860648a1"); parameterMap.put("exter_invoke_ip", request.getLocalAddr()); parameterMap.put("extra_common_param", "shopxx"); parameterMap.put("sign", generateSign(parameterMap)); return parameterMap; }
From source file:com.jd.survey.web.settings.SurveyDefinitionController.java
/** * Deletes a survey definition //from ww w .j ava 2 s. com * @param id * @param uiModel * @param httpServletRequest * @return */ @Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" }) @RequestMapping(value = "/{id}", method = RequestMethod.DELETE, produces = "text/html") public String delete(@PathVariable("id") Long id, Principal principal, Model uiModel, HttpServletRequest httpServletRequest) { log.info("delete(): id=" + id); try { String login = principal.getName(); User user = userService.user_findByLogin(login); SurveyDefinition surveyDefinition = surveySettingsService.surveyDefinition_findById(id); Long departmentId = surveyDefinition.getDepartment().getId(); //Check if the user is authorized if (!securityService.userIsAuthorizedToManageSurvey(id, user)) { log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo() + " attempted by user login:" + principal.getName() + "from IP:" + httpServletRequest.getLocalAddr()); return "accessDenied"; } if (surveyDefinition.getStatus().equals(SurveyDefinitionStatus.P) || surveyDefinition.getStatus().equals(SurveyDefinitionStatus.D)) { //you may not delete a survey that has been published log.warn("Attempt to delete a survey that has been published path:" + httpServletRequest.getPathInfo() + " attempted by user login:" + principal.getName() + "from IP:" + httpServletRequest.getLocalAddr()); return "accessDenied"; } surveySettingsService.surveyDefinition_remove(surveyDefinition); uiModel.asMap().clear(); return "redirect:/settings/surveyDefinitions/"; } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:com.jd.survey.web.settings.SurveyDefinitionController.java
/** * Prepares the page for creating a new survey definition * @param departmentId/*from w w w .j a v a 2 s . c om*/ * @param principal * @param uiModel * @param httpServletRequest * @return */ @Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" }) @RequestMapping(value = "/{id}", params = "create", produces = "text/html") public String createGet(@PathVariable("id") Long departmentId, Principal principal, Model uiModel, HttpServletRequest httpServletRequest) { if (surveySettingsService.department_getCount() > 0) { try { String login = principal.getName(); User user = userService.user_findByLogin(login); SurveyDefinition surveyDefinition; if (departmentId != null && departmentId != 0) { //Check if the user is authorized if (!securityService.userBelongsToDepartment(departmentId, user)) { log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo() + " attempted by user login:" + principal.getName() + "from IP:" + httpServletRequest.getLocalAddr()); return "accessDenied"; } Department department = surveySettingsService.department_findById(departmentId); surveyDefinition = new SurveyDefinition(department, surveySettingsService.velocityTemplate_findById(SURVEY_INVITATION_EMAIL_TEMPLATE_ID) .getDefinition(), surveySettingsService .velocityTemplate_findById(SURVEY_COMPLETED_PAGE_CONTENT_TEMPLATE_ID) .getDefinition()); } else { surveyDefinition = new SurveyDefinition( surveySettingsService.velocityTemplate_findById(SURVEY_INVITATION_EMAIL_TEMPLATE_ID) .getDefinition(), surveySettingsService .velocityTemplate_findById(SURVEY_COMPLETED_PAGE_CONTENT_TEMPLATE_ID) .getDefinition()); } populateEditForm(uiModel, surveyDefinition, user); return "settings/surveyDefinitions/create"; } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } } else { return "redirect:/settings/surveyDefinitions/"; } }
From source file:com.jd.survey.web.settings.SurveyDefinitionController.java
/** * Shows a survey definition/*from www. j a v a 2 s .c om*/ * @param id * @param uiModel * @return */ @Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" }) @RequestMapping(value = "/{id}", produces = "text/html") public String show(@PathVariable("id") Long id, Principal principal, Model uiModel, HttpServletRequest httpServletRequest) { try { String login = principal.getName(); User user = userService.user_findByLogin(login); SurveyDefinition surveyDefinition = surveySettingsService.surveyDefinition_findById(id); //String surveyLink =messageSource.getMessage(EXTERNAL_SITE_BASE_URL, null, LocaleContextHolder.getLocale()); String surveyLink = externalBaseUrl; //Check if the user is authorized if (!securityService.userIsAuthorizedToManageSurvey(id, user)) { log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo() + " attempted by user login:" + principal.getName() + "from IP:" + httpServletRequest.getLocalAddr()); return "accessDenied"; } if (surveyDefinition.getIsPublic()) { if (surveyLink.endsWith("/")) { surveyLink = surveyLink + "open/" + id + "?list"; } else { surveyLink = surveyLink + "/open/" + id + "?list"; } } else { if (surveyLink.endsWith("/")) { surveyLink = surveyLink + "private/" + id + "?list"; } else { surveyLink = surveyLink + "/private/" + id + "?list"; } } for (SurveyDefinitionPage page : surveyDefinition.getPages()) { for (Question question : page.getQuestions()) { //if (question.getType()== QuestionType.DATASET_DROP_DOWN){ //DataSet dataset = surveySettingsService.dataset_findByName(question.getDataSetCode()); //.addAttribute("datasetItems" + "p"+ page.getOrder() + "q"+ question.getOrder(),surveySettingsService.datasetItem_findByDataSetId(dataset.getId(), 0, 10)); //} } } uiModel.addAttribute("surveyLink", surveyLink); uiModel.addAttribute("surveyDefinition", surveySettingsService.surveyDefinition_findById(id)); /*uiModel.addAttribute("isPublishReady", true);*/ uiModel.addAttribute("isShow", true); uiModel.addAttribute("itemId", id); return "settings/surveyDefinitions/show"; } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:com.esd.cs.statistics.ReportController.java
/** * /*from ww w. java 2 s .com*/ * * @param type * @param year * @param request * @return */ @RequestMapping(value = "/export/{type}/{year}", method = RequestMethod.POST) @ResponseBody public String export(@PathVariable(value = "type") String type, @PathVariable(value = "year") String year, HttpServletRequest request, HttpSession session) { List<ReportViewModel> list = null; // ?? String url = request.getServletContext().getRealPath("/"); // CommonUtil.chineseFolder(url, uploadPath, companyPath); // ?? String uuid = UUID.randomUUID().toString(); // ? String exportPath = url + uploadPath + File.separator + companyPath + File.separator + uuid + ".xls"; // ??? ReportModel model = new ReportModel(); model.setCreateCompany(createTabCompany);// ? model.setCreateData("" + CommonUtil.formatData());// model.setCreatePeople("" + session.getAttribute(Constants.USER_REAL_NAME).toString());// // // ?? if (StringUtils.equals("nature", type)) { list = reportViewService.getByCompanyType(year); model.setType("??");// model.setTitle("??");// } // if (StringUtils.equals("area", type)) { list = reportViewService.getByArea(year); model.setType("");// model.setTitle("");// } // ? if (StringUtils.equals("economytype", type)) { list = reportViewService.getByArea(year); model.setType("?");// model.setTitle("?");// } // ? PoiCreateExcel.createRepeaExcel(exportPath, list, model); String destPath = request.getLocalAddr() + ":" + request.getLocalPort() + request.getContextPath(); // ? String loaddown = "http://" + destPath + "/" + uploadPath + "/" + companyPath + "/" + uuid + ".xls"; return loaddown; }
From source file:org.apache.nifi.processors.standard.HandleHttpRequest.java
@Override public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException { try {//from w ww .ja va 2 s .c om if (!initialized.get()) { initializeServer(context); } } catch (Exception e) { context.yield(); throw new ProcessException("Failed to initialize the server", e); } final HttpRequestContainer container = containerQueue.poll(); if (container == null) { return; } final long start = System.nanoTime(); final HttpServletRequest request = container.getRequest(); FlowFile flowFile = session.create(); try { flowFile = session.importFrom(request.getInputStream(), flowFile); } catch (final IOException e) { getLogger().error("Failed to receive content from HTTP Request from {} due to {}", new Object[] { request.getRemoteAddr(), e }); session.remove(flowFile); return; } final String charset = request.getCharacterEncoding() == null ? context.getProperty(URL_CHARACTER_SET).getValue() : request.getCharacterEncoding(); final String contextIdentifier = UUID.randomUUID().toString(); final Map<String, String> attributes = new HashMap<>(); try { putAttribute(attributes, HTTPUtils.HTTP_CONTEXT_ID, contextIdentifier); putAttribute(attributes, "mime.type", request.getContentType()); putAttribute(attributes, "http.servlet.path", request.getServletPath()); putAttribute(attributes, "http.context.path", request.getContextPath()); putAttribute(attributes, "http.method", request.getMethod()); putAttribute(attributes, "http.local.addr", request.getLocalAddr()); putAttribute(attributes, HTTPUtils.HTTP_LOCAL_NAME, request.getLocalName()); final String queryString = request.getQueryString(); if (queryString != null) { putAttribute(attributes, "http.query.string", URLDecoder.decode(queryString, charset)); } putAttribute(attributes, HTTPUtils.HTTP_REMOTE_HOST, request.getRemoteHost()); putAttribute(attributes, "http.remote.addr", request.getRemoteAddr()); putAttribute(attributes, "http.remote.user", request.getRemoteUser()); putAttribute(attributes, HTTPUtils.HTTP_REQUEST_URI, request.getRequestURI()); putAttribute(attributes, "http.request.url", request.getRequestURL().toString()); putAttribute(attributes, "http.auth.type", request.getAuthType()); putAttribute(attributes, "http.requested.session.id", request.getRequestedSessionId()); final DispatcherType dispatcherType = request.getDispatcherType(); if (dispatcherType != null) { putAttribute(attributes, "http.dispatcher.type", dispatcherType.name()); } putAttribute(attributes, "http.character.encoding", request.getCharacterEncoding()); putAttribute(attributes, "http.locale", request.getLocale()); putAttribute(attributes, "http.server.name", request.getServerName()); putAttribute(attributes, HTTPUtils.HTTP_PORT, request.getServerPort()); final Enumeration<String> paramEnumeration = request.getParameterNames(); while (paramEnumeration.hasMoreElements()) { final String paramName = paramEnumeration.nextElement(); final String value = request.getParameter(paramName); attributes.put("http.param." + paramName, value); } final Cookie[] cookies = request.getCookies(); if (cookies != null) { for (final Cookie cookie : cookies) { final String name = cookie.getName(); final String cookiePrefix = "http.cookie." + name + "."; attributes.put(cookiePrefix + "value", cookie.getValue()); attributes.put(cookiePrefix + "domain", cookie.getDomain()); attributes.put(cookiePrefix + "path", cookie.getPath()); attributes.put(cookiePrefix + "max.age", String.valueOf(cookie.getMaxAge())); attributes.put(cookiePrefix + "version", String.valueOf(cookie.getVersion())); attributes.put(cookiePrefix + "secure", String.valueOf(cookie.getSecure())); } } if (queryString != null) { final String[] params = URL_QUERY_PARAM_DELIMITER.split(queryString); for (final String keyValueString : params) { final int indexOf = keyValueString.indexOf("="); if (indexOf < 0) { // no =, then it's just a key with no value attributes.put("http.query.param." + URLDecoder.decode(keyValueString, charset), ""); } else { final String key = keyValueString.substring(0, indexOf); final String value; if (indexOf == keyValueString.length() - 1) { value = ""; } else { value = keyValueString.substring(indexOf + 1); } attributes.put("http.query.param." + URLDecoder.decode(key, charset), URLDecoder.decode(value, charset)); } } } } catch (final UnsupportedEncodingException uee) { throw new ProcessException("Invalid character encoding", uee); // won't happen because charset has been validated } final Enumeration<String> headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { final String headerName = headerNames.nextElement(); final String headerValue = request.getHeader(headerName); putAttribute(attributes, "http.headers." + headerName, headerValue); } final Principal principal = request.getUserPrincipal(); if (principal != null) { putAttribute(attributes, "http.principal.name", principal.getName()); } final X509Certificate certs[] = (X509Certificate[]) request .getAttribute("javax.servlet.request.X509Certificate"); final String subjectDn; if (certs != null && certs.length > 0) { final X509Certificate cert = certs[0]; subjectDn = cert.getSubjectDN().getName(); final String issuerDn = cert.getIssuerDN().getName(); putAttribute(attributes, HTTPUtils.HTTP_SSL_CERT, subjectDn); putAttribute(attributes, "http.issuer.dn", issuerDn); } else { subjectDn = null; } flowFile = session.putAllAttributes(flowFile, attributes); final HttpContextMap contextMap = context.getProperty(HTTP_CONTEXT_MAP) .asControllerService(HttpContextMap.class); final boolean registered = contextMap.register(contextIdentifier, request, container.getResponse(), container.getContext()); if (!registered) { getLogger().warn( "Received request from {} but could not process it because too many requests are already outstanding; responding with SERVICE_UNAVAILABLE", new Object[] { request.getRemoteAddr() }); try { container.getResponse().setStatus(Status.SERVICE_UNAVAILABLE.getStatusCode()); container.getResponse().flushBuffer(); container.getContext().complete(); } catch (final Exception e) { getLogger().warn("Failed to respond with SERVICE_UNAVAILABLE message to {} due to {}", new Object[] { request.getRemoteAddr(), e }); } session.remove(flowFile); return; } final long receiveMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start); session.getProvenanceReporter().receive(flowFile, HTTPUtils.getURI(attributes), "Received from " + request.getRemoteAddr() + (subjectDn == null ? "" : " with DN=" + subjectDn), receiveMillis); session.transfer(flowFile, REL_SUCCESS); getLogger().info("Transferring {} to 'success'; received from {}", new Object[] { flowFile, request.getRemoteAddr() }); }
From source file:com.jd.survey.web.settings.InvitationController.java
/** * Sends email invitations to the list of invitees from csv file. * @param file//from ww w . j a v a2s.c o m * @param surveyDefinitionId * @param proceed * @param principal * @param uiModel * @param httpServletRequest * @return */ @SuppressWarnings("unchecked") @Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" }) @RequestMapping(value = "/upload", method = RequestMethod.POST, produces = "text/html") public String sendInvitations(@RequestParam("file") MultipartFile file, @RequestParam("id") Long surveyDefinitionId, @RequestParam(value = "_proceed", required = false) String proceed, Principal principal, Model uiModel, HttpServletRequest httpServletRequest) { try { short firstNameFieldIndex = 0; short middleNameFieldIndex = 1; short lastNameFieldIndex = 2; short emailNameFieldIndex = 3; if (proceed != null) { //prepare the base url links String emailSubject = messageSource.getMessage(INVITATION_EMAIL_TITLE, null, LocaleContextHolder.getLocale()); //String surveyLink =messageSource.getMessage(EXTERNAL_SITE_BASE_URL, null, LocaleContextHolder.getLocale()); String surveyLink = externalBaseUrl; //String trackingImageLink =messageSource.getMessage(INTERNAL_SITE_BASE_URL, null, LocaleContextHolder.getLocale()); String trackingImageLink = internalBaseUrl; SurveyDefinition surveyDefinition = surveySettingsService .surveyDefinition_findById(surveyDefinitionId); User user = userService.user_findByLogin(principal.getName()); Set<SurveyDefinition> surveyDefinitions = surveySettingsService .surveyDefinition_findAllCompletedInternal(user); //Check if the user is authorized if (!securityService.userIsAuthorizedToManageSurvey(surveyDefinitionId, user)) { log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo() + " attempted by user login:" + principal.getName() + "from IP:" + httpServletRequest.getLocalAddr()); return "accessDenied"; } if (trackingImageLink.endsWith("/")) { trackingImageLink = trackingImageLink + "public/w/"; } else { trackingImageLink = trackingImageLink + "/public/w/"; } if (surveyDefinition.getIsPublic()) { if (surveyLink.endsWith("/")) { surveyLink = surveyLink + "open/"; } else { surveyLink = surveyLink + "/open/"; } } else { if (surveyLink.endsWith("/")) { surveyLink = surveyLink + "private/"; } else { surveyLink = surveyLink + "/private/"; } } String emailContent; if (!file.isEmpty() && ((file.getContentType().equalsIgnoreCase("application/vnd.ms-excel")) || (file.getContentType().equalsIgnoreCase("text/csv")) || (file.getContentType().equalsIgnoreCase("text/plain")))) { CSVReader csvReader = new CSVReader(new InputStreamReader(file.getInputStream())); String[] nextLine; nextLine = csvReader.readNext(); //skip the first row the continue on with loop while ((nextLine = csvReader.readNext()) != null) { emailContent = ""; StringWriter sw = new StringWriter(); // Prevents IndexOutOfBoundException by skipping line if there are not enough elements in the array nextLine. if (nextLine.length < 4) { //Continues if a blank line is present without setting an error message (if a new line character is present CSVReader will return and array with one empty string at index 0). if (nextLine.length == 1 && nextLine[0].isEmpty()) { continue; } uiModel.addAttribute("fileContentError", true); continue; } //Prevents exception from attempting to send an email with an empty string for an email address. if (nextLine[3].isEmpty()) { uiModel.addAttribute("fileContentError", true); continue; } //creating the Invitation Invitation invitation = new Invitation(nextLine[firstNameFieldIndex].trim(), nextLine[middleNameFieldIndex].trim(), nextLine[lastNameFieldIndex].trim(), nextLine[emailNameFieldIndex].trim(), surveyDefinition); Map model = new HashMap(); //survey name model.put(messageSource.getMessage(SURVEY_NAME, null, LocaleContextHolder.getLocale()) .replace("${", "").replace("}", ""), surveyDefinition.getName()); //full name model.put( messageSource.getMessage(INVITEE_FULLNAME_PARAMETER_NAME, null, LocaleContextHolder.getLocale()).replace("${", "").replace("}", ""), invitation.getFullName()); //survey link model.put( messageSource.getMessage(INVITE_FILL_SURVEY_LINK_PARAMETER_NAME, null, LocaleContextHolder.getLocale()).replace("${", "").replace("}", ""), "<a href='" + surveyLink + surveyDefinition.getId() + "?list'>" + messageSource.getMessage(INVITE_FILL_SURVEY_LINK_LABEL, null, LocaleContextHolder.getLocale()) + "</a>"); VelocityContext velocityContext = new VelocityContext(model); Velocity.evaluate(velocityContext, sw, "velocity-log", surveyDefinition.getEmailInvitationTemplate()); emailContent = sw.toString().trim(); if (emailContent.length() > 14 && emailContent.substring(emailContent.length() - 14) .toUpperCase().equalsIgnoreCase("</BODY></HTML>")) { emailContent = emailContent.substring(0, emailContent.length() - 14) + "<img src='" + trackingImageLink + invitation.getUuid() + "'/></BODY></HTML>"; emailContent = "<BODY><HTML>" + emailContent; } else { // template is incorrect or not html do not include tracking white gif emailContent = emailContent + "<img src='" + trackingImageLink + invitation.getUuid() + "'/></BODY></HTML>"; } surveySettingsService.invitation_send(invitation, emailSubject, emailContent); } return "redirect:/settings/invitations/list?id=" + encodeUrlPathSegment(surveyDefinitionId.toString(), httpServletRequest); } else { uiModel.addAttribute("surveyDefinitions", surveyDefinitions); uiModel.addAttribute("surveyDefinition", surveyDefinition); uiModel.addAttribute("emptyFileError", true); return "settings/invitations/upload"; } } else { return "redirect:/settings/invitations/list?id=" + encodeUrlPathSegment(surveyDefinitionId.toString(), httpServletRequest); } } catch (Exception e) { log.error(e.getMessage(), e); throw new RuntimeException(e); } }
From source file:org.bibalex.wamcp.application.WAMCPUiActionListener.java
public void generatePrintableMetadataHTMLFiles(ActionEvent ev) { String dirUrlStr = URLPathStrUtils.appendParts(this.galleryBean.getGalleryRootUrlStr(), "XML"); HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext() .getRequest();//from w w w . j av a2 s .co m String uri = request.getRequestURL().toString(); String[] splited = uri.split("/"); // host = http://172.16.0.17:80/ // String host = splited[0]+"//"+splited[2]+"/"; String host = splited[0] + "//" + request.getLocalAddr() + ":" + request.getLocalPort() + "/"; try { List<String> childrenFilesStr = BAGStorage.listChildren(dirUrlStr, FileType.FILE); int statusCode = 0; for (String childStr : childrenFilesStr) { System.out.println("childStr: " + childStr); int extIndx = childStr.indexOf('.'); String localOaiId = childStr.substring(0, extIndx); BAOAIIDBuilder oaiIdBuilder = new BAOAIIDBuilder(); String oaiId = oaiIdBuilder.buildId(localOaiId); System.out.println("oaiId: " + oaiId); String urlMetadataHtml = host + "BAG-API/rest/desc/" + oaiId + "/transform?type=meta"; statusCode = WAMCPStorage.myGetHttp(urlMetadataHtml); System.out.println(urlMetadataHtml + " ==> status code: " + statusCode); } } catch (BAGException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.bibalex.wamcp.application.WAMCPUiActionListener.java
public void generatePortletHTMLFiles(ActionEvent ev) { String dirUrlStr = URLPathStrUtils.appendParts(this.galleryBean.getGalleryRootUrlStr(), "XML"); HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext() .getRequest();// w w w.ja va 2 s. c o m String uri = request.getRequestURL().toString(); String[] splited = uri.split("/"); // host = http://172.16.0.17:80/ // String host = splited[0]+"//"+splited[2]+"/"; String host = splited[0] + "//" + request.getLocalAddr() + ":" + request.getLocalPort() + "/"; try { List<String> childrenFilesStr = BAGStorage.listChildren(dirUrlStr, FileType.FILE); int statusCode = 0; for (String childStr : childrenFilesStr) { System.out.println("childStr: " + childStr); int extIndx = childStr.indexOf('.'); String localOaiId = childStr.substring(0, extIndx); BAOAIIDBuilder oaiIdBuilder = new BAOAIIDBuilder(); String oaiId = oaiIdBuilder.buildId(localOaiId); System.out.println("oaiId: " + oaiId); String url = host + "BAG-API/rest/desc/" + oaiId + "/transform?type=html"; statusCode = WAMCPStorage.myGetHttp(url); System.out.println(url + " ==> status code: " + statusCode); // System.out.println(oaiId+" {Html}: "+statusCode); String urlDivOpt = host + "BAG-API/rest/desc/" + oaiId + "/transform?divOpt=true&type=html"; statusCode = WAMCPStorage.myGetHttp(urlDivOpt); // System.out.println(oaiId+" {Html, div}: "+statusCode); System.out.println(urlDivOpt + " ==> status code: " + statusCode); // WAMCPStorage.transformXMLtoHTML(rootUrlStr, tempUserName, // localOaiId, true); // WAMCPStorage.transformXMLtoHTML(rootUrlStr, tempUserName, // localOaiId, false); } } catch (BAGException e) { // TODO Auto-generated catch block e.printStackTrace(); } }