protected Link retrieveLink(final HttpServletRequest httpServletRequest) { String uri = httpServletRequest .getRequestURI() .substring(httpServletRequest.getRequestURI().lastIndexOf("/") + 1); _log.debug("Extracted URI: " + uri); return Link.create(uri); }
private void setDefaultSchema(HttpServletRequest request) { String hibernateDefaultSchemaTab = (String) request.getSession().getAttribute("xava_hibernateDefaultSchemaTab"); if (hibernateDefaultSchemaTab != null) { request.getSession().removeAttribute("xava_hibernateDefaultSchemaTab"); XHibernate.setDefaultSchema(hibernateDefaultSchemaTab); } String jpaDefaultSchemaTab = (String) request.getSession().getAttribute("xava_jpaDefaultSchemaTab"); if (jpaDefaultSchemaTab != null) { request.getSession().removeAttribute("xava_jpaDefaultSchemaTab"); XPersistence.setDefaultSchema(jpaDefaultSchemaTab); } }
protected void doCommon(HttpServletRequest httpRequest, HttpServletResponse httpResponse) { try { if (log.isDebugEnabled()) log.debug(HttpUtils.fmtRequest(httpRequest)); // getRequestURL is the exact string used by the caller in the request. // Internally, it's the "request URI" that names the service // String requestURL = httpRequest.getRequestURL().toString() ; String uri = httpRequest.getRequestURI(); if (uri.length() > urlLimit) { httpResponse.setStatus(HttpServletResponse.SC_REQUEST_URI_TOO_LONG); return; } String serviceURI = chooseServiceURI(uri, httpRequest); serviceURI = Service.canonical(serviceURI); String sender = httpRequest.getRemoteAddr(); log.info("[" + sender + "] Service URI = <" + serviceURI + ">"); // MIME-Type String contentType = httpRequest.getContentType(); // if ( Joseki.contentSPARQLUpdate.equals(contentType) || // Joseki.contentSPARQLUpdate_X.equals(contentType) ) // {} Request request = setupRequest(serviceURI, httpRequest); request.setParam(Joseki.VERB, httpRequest.getMethod()); Response response = new ResponseHttp(request, httpRequest, httpResponse); Dispatcher.dispatch(serviceURI, request, response); } catch (Exception ex) { try { log.warn("Internal server error", ex); // httpResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR) ; // httpResponse.flushBuffer() ; // httpResponse.getWriter().close() ; httpResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } catch (Exception e) { } } }
public static boolean isHTMLForm(HttpServletRequest httpRequest) { String s = httpRequest.getContentType(); if (s == null) return false; AcceptItem aItem = new AcceptItem(s); String t1 = aItem.getType(); String t2 = aItem.getSubType(); return (t1.equalsIgnoreCase("application") && t2.equalsIgnoreCase("x-www-form-urlencoded")); }
// ------------------------------------------ public static String chooseServiceURI(String uri, HttpServletRequest httpRequest) { String serviceURI = uri; String contextPath = httpRequest.getContextPath(); if (contextPath != null && contextPath.length() > 0) serviceURI = serviceURI.substring(contextPath.length()); String servletPath = httpRequest.getServletPath(); // Suggested by Frank Hartman: helps make conf files more portable // between /joseki/myModel and /myModel but if the servlet is // explicitly named in web.xml, it strips that off // if ( servletPath != null && servletPath.length() > 0 ) // dispatchURI = dispatchURI.substring(servletPath.length()) ; // Suggested by damien_coraboeuf // TODO Test and verify // if ( servletPath != null && servletPath.length() > 0 ) // serviceURI = serviceURI.substring(servletPath.length()) ; // Example: // <servlet-mapping> // <servlet-name>JosekiServlet</servlet-name> // <url-pattern>/ws/joseki/*</url-pattern> // </servlet-mapping> if (log.isDebugEnabled()) { if (servletPath == null) servletPath = ""; if (contextPath == null) contextPath = ""; log.debug( "DispatchURI: " + uri + " => " + serviceURI + " (ContextPath = " + contextPath + ", ServletPath = " + servletPath + ")"); } return serviceURI; }
protected Request setupRequest(String serviceURI, HttpServletRequest httpRequest, String opType) throws IOException { // No reader. Done by standard servlet form processing. Request request = new Request(serviceURI, null); // params => request items @SuppressWarnings("unchecked") Enumeration<String> en = httpRequest.getParameterNames(); for (; en.hasMoreElements(); ) { String k = en.nextElement(); String[] x = httpRequest.getParameterValues(k); for (int i = 0; i < x.length; i++) { String s = x[i]; request.setParam(k, s); } } request.setParam(Joseki.OPERATION, opType); return request; }
@Override public void doPost(HttpServletRequest httpRequest, HttpServletResponse httpResponse) { String s = httpRequest.getContentType(); if (s != null && !isHTMLForm(httpRequest)) { try { httpResponse.sendError( HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "Must be application/x-www-form-urlencoded"); } catch (Exception ex) { } return; } doCommon(httpRequest, httpResponse); }
public int doStartTag() throws JspException { try { HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); ModuleContext context = (ModuleContext) request.getSession().getAttribute("context"); String viewObject = request.getParameter("viewObject"); viewObject = (viewObject == null || viewObject.equals("")) ? "xava_view" : viewObject; View view = (View) context.get(request, viewObject); MetaReference metaReference = view.getMetaReference(reference).cloneMetaReference(); metaReference.setName(reference); String prefix = request.getParameter("propertyPrefix"); prefix = prefix == null ? "" : prefix; String application = request.getParameter("application"); String module = request.getParameter("module"); String referenceKey = Ids.decorate(application, module, prefix + reference); request.setAttribute(referenceKey, metaReference); String editorURL = "reference.jsp?referenceKey=" + referenceKey + "&onlyEditor=true&frame=false&composite=false&descriptionsList=true"; String editorPrefix = Module.isPortlet() ? "/WEB-INF/jsp/xava/" : "/xava/"; try { pageContext.include(editorPrefix + editorURL); } catch (ServletException ex) { Throwable cause = ex.getRootCause() == null ? ex : ex.getRootCause(); log.error(cause.getMessage(), cause); pageContext.include(editorPrefix + "editors/notAvailableEditor.jsp"); } catch (Exception ex) { log.error(ex.getMessage(), ex); pageContext.include(editorPrefix + "editors/notAvailableEditor.jsp"); } } catch (Exception ex) { log.error(ex.getMessage(), ex); throw new JspException(XavaResources.getString("descriptionsList_tag_error", reference)); } return SKIP_BODY; }
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { Locales.setCurrent(request); if (Users.getCurrent() == null) { // for a bug in websphere portal 5.1 with Domino LDAP Users.setCurrent((String) request.getSession().getAttribute("xava.user")); } request.getParameter("application"); // for a bug in websphere 5.1 request.getParameter("module"); // for a bug in websphere 5.1 Tab tab = (Tab) request.getSession().getAttribute("xava_reportTab"); int[] selectedRowsNumber = (int[]) request.getSession().getAttribute("xava_selectedRowsReportTab"); Map[] selectedKeys = (Map[]) request.getSession().getAttribute("xava_selectedKeysReportTab"); int[] selectedRows = getSelectedRows(selectedRowsNumber, selectedKeys, tab); request.getSession().removeAttribute("xava_selectedRowsReportTab"); Integer columnCountLimit = (Integer) request.getSession().getAttribute("xava_columnCountLimitReportTab"); request.getSession().removeAttribute("xava_columnCountLimitReportTab"); setDefaultSchema(request); String user = (String) request.getSession().getAttribute("xava_user"); request.getSession().removeAttribute("xava_user"); Users.setCurrent(user); String uri = request.getRequestURI(); if (uri.endsWith(".pdf")) { InputStream is; JRDataSource ds; Map parameters = new HashMap(); synchronized (tab) { tab.setRequest(request); parameters.put("Title", tab.getTitle()); parameters.put("Organization", getOrganization()); parameters.put("Date", getCurrentDate()); for (String totalProperty : tab.getTotalPropertiesNames()) { parameters.put(totalProperty + "__TOTAL__", getTotal(request, tab, totalProperty)); } TableModel tableModel = getTableModel(request, tab, selectedRows, false, true, null); tableModel.getValueAt(0, 0); if (tableModel.getRowCount() == 0) { generateNoRowsPage(response); return; } is = getReport(request, response, tab, tableModel, columnCountLimit); ds = new JRTableModelDataSource(tableModel); } JasperPrint jprint = JasperFillManager.fillReport(is, parameters, ds); response.setContentType("application/pdf"); response.setHeader( "Content-Disposition", "inline; filename=\"" + getFileName(tab) + ".pdf\""); JasperExportManager.exportReportToPdfStream(jprint, response.getOutputStream()); } else if (uri.endsWith(".csv")) { String csvEncoding = XavaPreferences.getInstance().getCSVEncoding(); if (!Is.emptyString(csvEncoding)) { response.setCharacterEncoding(csvEncoding); } response.setContentType("text/x-csv"); response.setHeader( "Content-Disposition", "inline; filename=\"" + getFileName(tab) + ".csv\""); synchronized (tab) { tab.setRequest(request); response .getWriter() .print( TableModels.toCSV( getTableModel(request, tab, selectedRows, true, false, columnCountLimit))); } } else { throw new ServletException( XavaResources.getString("report_type_not_supported", "", ".pdf .csv")); } } catch (Exception ex) { log.error(ex.getMessage(), ex); throw new ServletException(XavaResources.getString("report_error")); } finally { request.getSession().removeAttribute("xava_reportTab"); } }
protected <T> T readRequest(final HttpServletRequest httpServletRequest, final Class<T> classOfT) throws IOException { final BufferedReader br = new BufferedReader(httpServletRequest.getReader()); Gson gson = new Gson(); return gson.fromJson(br, classOfT); }