Compare commits
No commits in common. 'master' and 'freiburg_nutzungsstatistik' have entirely different histories.
master
...
freiburg_n
2496 changed files with 498139 additions and 2007202 deletions
@ -1,16 +0,0 @@ |
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
|
||||||
<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType"> |
|
||||||
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_AFTER_CLEAN_TARGETS" value="get_git_info,"/> |
|
||||||
<stringAttribute key="org.eclipse.ant.ui.ATTR_ANT_MANUAL_TARGETS" value="get_git_info,"/> |
|
||||||
<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/> |
|
||||||
<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/> |
|
||||||
<booleanAttribute key="org.eclipse.debug.core.ATTR_REFRESH_RECURSIVE" value="false"/> |
|
||||||
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${working_set:<?xml version="1.0" encoding="UTF-8"?> <resources/>}"/> |
|
||||||
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/> |
|
||||||
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/> |
|
||||||
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/> |
|
||||||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="superx"/> |
|
||||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="/home/superx/git/kern/superx-build/build.xml"/> |
|
||||||
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,"/> |
|
||||||
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/> |
|
||||||
</launchConfiguration> |
|
||||||
@ -1,270 +1,46 @@ |
|||||||
# agent and copilot context - local/temporary files |
# ignore all log files |
||||||
.github/ |
*.log |
||||||
|
*.err |
||||||
|
*.log.* |
||||||
|
|
||||||
# Gradle build output and wrapper cache |
|
||||||
build/ |
|
||||||
.gradle/ |
|
||||||
|
|
||||||
# ignore /dist/* |
# ignore all CVS + sub dirs |
||||||
*dist/ |
*CVS/ |
||||||
|
|
||||||
# ignore swap files |
|
||||||
superx/WEB-INF/reports/swap_* |
|
||||||
|
|
||||||
# ignore eclipse settings |
|
||||||
.settings/org.eclipse.ltk.core.refactoring.prefs |
|
||||||
|
|
||||||
# vim .swp files |
|
||||||
*.swp |
|
||||||
|
|
||||||
# ignore gradle bin |
|
||||||
scripts/gradle/bin/ |
|
||||||
scripts/gradle/.gradle/ |
|
||||||
|
|
||||||
# cobertura |
|
||||||
superx-build/cobertura* |
|
||||||
|
|
||||||
# classes |
|
||||||
superx/WEB-INF/classes/ |
|
||||||
|
|
||||||
# tag files |
|
||||||
**/tags |
|
||||||
|
|
||||||
# .orig files |
|
||||||
**/*.orig |
|
||||||
|
|
||||||
# datum.alt files |
|
||||||
**/superx.datum.alt |
|
||||||
|
|
||||||
# script artefacts |
|
||||||
scripts/**/build/ |
|
||||||
scripts/**/log/ |
|
||||||
|
|
||||||
# build artefacts |
|
||||||
superx-build/declared-jars.txt |
|
||||||
superx-build/cobertura_build_tests/ |
|
||||||
superx-build/cobertura_build_classes/ |
|
||||||
superx-build/coveragereport/ |
|
||||||
superx-build/results/ |
|
||||||
superx-build/tmp_build/ |
|
||||||
|
|
||||||
# Eclipse launch configurations are causing conflicts on 'pull' if you've got local ones; so they should not be under SCM |
|
||||||
scripts/eclipseExternalTools/ |
|
||||||
|
|
||||||
# extracted h1-modules. These should only be links to folders in cs.bia.his_components |
|
||||||
src-modules/module/prom/ |
|
||||||
src-modules/module/res/ |
|
||||||
src-modules/module/astat/ |
|
||||||
src-modules/module/tt/ |
|
||||||
src-modules/module/star/ |
|
||||||
src-modules/module/kern_s/ |
|
||||||
src-modules/module/res_s/ |
|
||||||
# also ignore symlinks on linux |
|
||||||
src-modules/module/prom |
|
||||||
src-modules/module/res |
|
||||||
src-modules/module/astat |
|
||||||
src-modules/module/tt |
|
||||||
src-modules/module/star |
|
||||||
src-modules/module/kern_s |
|
||||||
src-modules/module/res_s |
|
||||||
src-modules/module/biad |
|
||||||
|
|
||||||
# artifact folders for reduced/cleaned modules |
|
||||||
superx/WEB-INF/conf/edustore/db/module/prom/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/res/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/zul/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/sos/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/sva/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/ivs/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/astat/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/tt/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/lm/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/etl/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/star/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/cob/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/kern_s/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/res_s/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/bau/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/fin/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/biad/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/gang/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/erfolg/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/man/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/kenn/ |
|
||||||
superx/WEB-INF/conf/edustore/db/module/kennx/ |
|
||||||
|
|
||||||
# module generation artifacts for module fin |
|
||||||
src/edustore/edustore_fin.xml |
|
||||||
superx/WEB-INF/fin_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/fin_dbforms-config_pg.xml |
|
||||||
|
|
||||||
# module generation artifacts for module bau |
|
||||||
src/edustore/edustore_bau.xml |
|
||||||
superx/WEB-INF/bau_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/bau_dbforms-config_pg.xml |
|
||||||
|
|
||||||
# module generation artifacts for module prom |
|
||||||
src/edustore/edustore_prom.xml |
|
||||||
superx/WEB-INF/prom_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/prom_dbforms-config_pg.xml |
|
||||||
superx/edit/prom/ |
|
||||||
|
|
||||||
# module generation artifacts for module res |
|
||||||
src/edustore/edustore_res.xml |
|
||||||
superx/WEB-INF/res_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/res_dbforms-config_pg.xml |
|
||||||
|
|
||||||
# module generation artifacts for module gang |
|
||||||
src/edustore/edustore_gang.xml |
|
||||||
superx/WEB-INF/gang_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/gang_dbforms-config_pg.xml |
|
||||||
superx/edit/gang/*edit.jsp |
|
||||||
superx/edit/gang/*list.jsp |
|
||||||
|
|
||||||
|
# ignore java classes |
||||||
|
*classes/ |
||||||
|
|
||||||
# module generation artifacts for module kenn |
# ignore files in directory rohdaten |
||||||
src/edustore/edustore_kenn.xml |
superx/WEB-INF/conf/edustore/db/module/*/rohdaten/unl/*.unl |
||||||
superx/WEB-INF/kenn_dbforms-config_ids.xml |
superx/WEB-INF/conf/edustore/db/install/rohdaten/unl/*.unl |
||||||
superx/WEB-INF/kenn_dbforms-config_pg.xml |
|
||||||
superx/edit/kenn/*edit.jsp |
|
||||||
superx/edit/kenn/*list.jsp |
|
||||||
|
|
||||||
# module generation artifacts for module kennx |
# ignore temporary files |
||||||
src/edustore/edustore_kennx.xml |
*.tmp |
||||||
superx/WEB-INF/kennx_dbforms-config_ids.xml |
*.tmp.sql |
||||||
superx/WEB-INF/kennx_dbforms-config_pg.xml |
temp.xml |
||||||
superx/edit/kennx/*edit.jsp |
tmp.fo |
||||||
superx/edit/kennx/*list.jsp |
|
||||||
|
|
||||||
|
# ignore auto generated files |
||||||
|
db.properties |
||||||
|
dbforms-config.xml |
||||||
|
superx/WEB-INF/dbforms-config.old |
||||||
|
superx.datum |
||||||
|
|
||||||
# module generation artifacts for module man |
# ignore iReport Designer |
||||||
src/edustore/edustore_man.xml |
*.jasper |
||||||
superx/WEB-INF/man_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/man_dbforms-config_pg.xml |
|
||||||
superx/edit/man/catdesc.jsp |
|
||||||
superx/edit/man/cat.jsp |
|
||||||
superx/edit/man/grouping.jsp |
|
||||||
superx/edit/man/man_reports.jsp |
|
||||||
superx/edit/man/organigramm_dialog.jsp |
|
||||||
superx/edit/man/rpt.jsp |
|
||||||
superx/edit/man/*edit.jsp |
|
||||||
superx/edit/man/*list.jsp |
|
||||||
|
|
||||||
# module generation artifacts for module erfolg |
|
||||||
src/edustore/edustore_erfolg.xml |
|
||||||
superx/WEB-INF/erfolg_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/erfolg_dbforms-config_pg.xml |
|
||||||
|
|
||||||
# module generation artifacts for module sos |
|
||||||
src/edustore/edustore_sos.xml |
|
||||||
superx/WEB-INF/sos_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/sos_dbforms-config_pg.xml |
|
||||||
superx/edit/sos/hoererstatus_edit.jsp |
|
||||||
superx/edit/sos/koepfe_oder_faelle_edit.jsp |
|
||||||
superx/edit/sos/lehr_stg_ab_edit.jsp |
|
||||||
superx/edit/sos/semester_edit.jsp |
|
||||||
superx/edit/sos/semester_list.jsp |
|
||||||
superx/edit/sos/sos_status_edit.jsp |
|
||||||
superx/edit/sos/sos_stichtag_edit.jsp |
|
||||||
superx/edit/sos/sos_stichtag_list.jsp |
|
||||||
superx/edit/sos/statistik_edit.jsp |
|
||||||
superx/edit/sos/studierendenuebertragung_edit.jsp |
|
||||||
|
|
||||||
# module generation artifacts for module sva |
|
||||||
src/edustore/edustore_sva.xml |
|
||||||
superx/WEB-INF/sva_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/sva_dbforms-config_pg.xml |
|
||||||
superx/edit/sva/konstanten_sva_edit.jsp |
|
||||||
superx/edit/sva/sichten_sva_dienstart_edit.jsp |
|
||||||
superx/edit/sva/sichten_sva_klr_geldgeber_kurz_edit.jsp |
|
||||||
superx/edit/sva/sva_stichtag_list.jsp |
|
||||||
superx/edit/sva/sx_repository_sva_edit.jsp |
|
||||||
superx/edit/sva/user_sva.jsp |
|
||||||
superx/edit/sva/user_sva_manuell.jsp |
|
||||||
|
|
||||||
# module generation artifacts for module ivs |
|
||||||
src/edustore/edustore_ivs.xml |
|
||||||
superx/edit/ivs/user_inventar_edit.jsp |
|
||||||
superx/WEB-INF/ivs_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/ivs_dbforms-config_pg.xml |
|
||||||
|
|
||||||
# module generation artifacts for module zul |
|
||||||
src/edustore/edustore_zul.xml |
|
||||||
superx/WEB-INF/zul_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/zul_dbforms-config_pg.xml |
|
||||||
|
|
||||||
# module generation artifacts for module astat |
|
||||||
src/edustore/edustore_astat.xml |
|
||||||
superx/WEB-INF/astat_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/astat_dbforms-config_pg.xml |
|
||||||
|
|
||||||
# module generation artifacts for module tt |
|
||||||
src/edustore/edustore_tt.xml |
|
||||||
superx/WEB-INF/tt_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/tt_dbforms-config_pg.xml |
|
||||||
superx/edit/tt/ |
|
||||||
|
|
||||||
# module generation artifacts for module lm |
|
||||||
src/edustore/edustore_lm.xml |
|
||||||
superx/WEB-INF/lm_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/lm_dbforms-config_pg.xml |
|
||||||
superx/edit/lm/ |
|
||||||
|
|
||||||
# module generation artifacts for module etl |
|
||||||
src/edustore/edustore_etl.xml |
|
||||||
superx/WEB-INF/etl_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/etl_dbforms-config_pg.xml |
|
||||||
superx/edit/etl/etl_job_edit.jsp |
|
||||||
superx/edit/etl/etl_step_edit.jsp |
|
||||||
superx/edit/etl/etl_step_type_list.jsp |
|
||||||
|
|
||||||
# module generation artifacts for module star |
|
||||||
src/edustore/edustore_star.xml |
|
||||||
superx/WEB-INF/star_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/star_dbforms-config_pg.xml |
|
||||||
|
|
||||||
# module generation artifacts for module cob |
|
||||||
src/edustore/edustore_cob.xml |
|
||||||
superx/WEB-INF/cob_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/cob_dbforms-config_pg.xml |
|
||||||
superx/edit/cob/sx_repository_cob_edit.jsp |
|
||||||
|
|
||||||
# module generation artifacts for module kern_s |
|
||||||
src/edustore/edustore_kern_s.xml |
|
||||||
superx/WEB-INF/kern_s_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/kern_s_dbforms-config_pg.xml |
|
||||||
|
|
||||||
# module generation artifacts for module res_s |
|
||||||
src/edustore/edustore_res_s.xml |
|
||||||
superx/WEB-INF/res_s_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/res_s_dbforms-config_pg.xml |
|
||||||
|
|
||||||
# module generation artifacts for module biad |
|
||||||
src/edustore/edustore_biad.xml |
|
||||||
superx/WEB-INF/biad_dbforms-config_ids.xml |
|
||||||
superx/WEB-INF/biad_dbforms-config_pg.xml |
|
||||||
|
|
||||||
# dbt project generation backups |
|
||||||
superx/dbt/projects/*_backup/ |
|
||||||
|
|
||||||
# Saiku his icons |
|
||||||
superx/saiku/css/saiku/src/saiku_his.css |
|
||||||
|
|
||||||
# Dateifunktionalität im kenn und kennx Modul |
|
||||||
superx\WEB-INF\downloads |
|
||||||
|
|
||||||
# vscode personal settings |
# ignore /dist/* |
||||||
.vscode/ |
*dist/ |
||||||
.metadata/ |
|
||||||
|
|
||||||
# edustore.xml soll nicht mehr ausgeliefert werden siehe #313658 |
# ignore swap files |
||||||
src/edustore/edustore.xml |
superx/WEB-INF/reports/swap_* |
||||||
|
|
||||||
# package folder und config file für statisch generierte JSPs |
src/edustore/edustore_*.xml |
||||||
src/de/superx/jsp/ |
|
||||||
superx/WEB-INF/jsp_servlet_config.xml |
|
||||||
|
|
||||||
# jaspers werden nicht mehr commitet, sondern im build gebaut |
# ignore eclipse settings |
||||||
*.jasper |
.settings/org.eclipse.ltk.core.refactoring.prefs |
||||||
# updateUnmodifiedJars backup |
#rpta files: |
||||||
superx/WEB-INF/lib/backup/ |
superx/WEB-INF/reports/simple_table.jrtx |
||||||
|
superx/WEB-INF/reports/tabelle_jrxml_a4_quer.xsl.jrxml |
||||||
|
superx/xml/jr_templates.xsl |
||||||
|
superx/xml/rpta_assistent.xsl |
||||||
|
|||||||
@ -1,901 +0,0 @@ |
|||||||
/* |
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
||||||
* |
|
||||||
* Copyright (c) 2010-2013 Oracle and/or its affiliates. All rights reserved. |
|
||||||
* |
|
||||||
* The contents of this file are subject to the terms of either the GNU |
|
||||||
* General Public License Version 2 only ("GPL") or the Common Development |
|
||||||
* and Distribution License("CDDL") (collectively, the "License"). You |
|
||||||
* may not use this file except in compliance with the License. You can |
|
||||||
* obtain a copy of the License at |
|
||||||
* http://glassfish.java.net/public/CDDL+GPL_1_1.html
|
|
||||||
* or packager/legal/LICENSE.txt. See the License for the specific |
|
||||||
* language governing permissions and limitations under the License. |
|
||||||
* |
|
||||||
* When distributing the software, include this License Header Notice in each |
|
||||||
* file and include the License file at packager/legal/LICENSE.txt. |
|
||||||
* |
|
||||||
* GPL Classpath Exception: |
|
||||||
* Oracle designates this particular file as subject to the "Classpath" |
|
||||||
* exception as provided by Oracle in the GPL Version 2 section of the License |
|
||||||
* file that accompanied this code. |
|
||||||
* |
|
||||||
* Modifications: |
|
||||||
* If applicable, add the following below the License Header, with the fields |
|
||||||
* enclosed by brackets [] replaced by your own identifying information: |
|
||||||
* "Portions Copyright [year] [name of copyright owner]" |
|
||||||
* |
|
||||||
* Contributor(s): |
|
||||||
* If you wish your version of this file to be governed by only the CDDL or |
|
||||||
* only the GPL Version 2, indicate your decision by adding "[Contributor] |
|
||||||
* elects to include this software in this distribution under the [CDDL or GPL |
|
||||||
* Version 2] license." If you don't indicate a single choice of license, a |
|
||||||
* recipient has the option to distribute your version of this file under |
|
||||||
* either the CDDL, the GPL Version 2 or to extend the choice of license to |
|
||||||
* its licensees as provided above. However, if you add GPL Version 2 code |
|
||||||
* and therefore, elected the GPL Version 2 license, then the option applies |
|
||||||
* only if the new code is made subject to such option by the copyright |
|
||||||
* holder. |
|
||||||
*/ |
|
||||||
|
|
||||||
/* gepatchtes class-File: |
|
||||||
* im Rahmen von #331613 muss mit dem Update auf Tomcat 10 auch die Anwendung von Serlvet API 4.0 auf 6.0 umgestellt werden. |
|
||||||
* Dies leistet ein Migrationstool, welches in erster Linie den Packagenamen von 'javax' auf 'jakarta' umstellt. |
|
||||||
* Allerdings bestand danach immer noch in der 'jersey-bunde-1.19.4.jar' ein Zugriff auf die entfernte Methode |
|
||||||
* 'HttpServletResponse.setStatus(int, String)', welcher beim Laden von Saiku zu einer Exception geführt hat, |
|
||||||
* wodurch das Frontend in der Ladeanzeige geblieben ist. |
|
||||||
* Der Patch ändert die Klasse derart, dass sie die noch vorhandene Methode 'HttpServletResponse.setStatus(int)' aufruft, |
|
||||||
* was zu funktionieren scheint. |
|
||||||
* Ursprung entspricht https://github.com/javaee/jersey-1.x/blob/864a01d7be490ab93d2424da3e446ad8eb84b1e8/jersey-servlet/src/main/java/com/sun/jersey/spi/container/servlet/WebComponent.java
|
|
||||||
*/ |
|
||||||
|
|
||||||
package com.sun.jersey.spi.container.servlet; |
|
||||||
|
|
||||||
import java.io.BufferedInputStream; |
|
||||||
import java.io.IOException; |
|
||||||
import java.io.InputStream; |
|
||||||
import java.io.OutputStream; |
|
||||||
import java.lang.reflect.Constructor; |
|
||||||
import java.lang.reflect.Proxy; |
|
||||||
import java.lang.reflect.Type; |
|
||||||
import java.net.URI; |
|
||||||
import java.security.Principal; |
|
||||||
import java.util.ArrayList; |
|
||||||
import java.util.Arrays; |
|
||||||
import java.util.Enumeration; |
|
||||||
import java.util.HashMap; |
|
||||||
import java.util.Iterator; |
|
||||||
import java.util.LinkedList; |
|
||||||
import java.util.List; |
|
||||||
import java.util.Map; |
|
||||||
import java.util.logging.Level; |
|
||||||
import java.util.logging.Logger; |
|
||||||
|
|
||||||
import javax.ws.rs.WebApplicationException; |
|
||||||
import javax.ws.rs.core.Application; |
|
||||||
import javax.ws.rs.core.Context; |
|
||||||
import javax.ws.rs.core.GenericEntity; |
|
||||||
import javax.ws.rs.core.MediaType; |
|
||||||
import javax.ws.rs.core.MultivaluedMap; |
|
||||||
import javax.ws.rs.core.Response; |
|
||||||
import javax.ws.rs.core.SecurityContext; |
|
||||||
|
|
||||||
import javax.naming.NamingException; |
|
||||||
import jakarta.servlet.ServletContext; |
|
||||||
import jakarta.servlet.ServletException; |
|
||||||
import jakarta.servlet.http.HttpServletRequest; |
|
||||||
import jakarta.servlet.http.HttpServletResponse; |
|
||||||
|
|
||||||
import com.sun.jersey.api.container.ContainerException; |
|
||||||
import com.sun.jersey.api.container.MappableContainerException; |
|
||||||
import com.sun.jersey.api.core.ApplicationAdapter; |
|
||||||
import com.sun.jersey.api.core.ClasspathResourceConfig; |
|
||||||
import com.sun.jersey.api.core.PackagesResourceConfig; |
|
||||||
import com.sun.jersey.api.core.ResourceConfig; |
|
||||||
import com.sun.jersey.api.core.TraceInformation; |
|
||||||
import com.sun.jersey.api.core.servlet.WebAppResourceConfig; |
|
||||||
import com.sun.jersey.api.representation.Form; |
|
||||||
import com.sun.jersey.core.header.InBoundHeaders; |
|
||||||
import com.sun.jersey.core.header.MediaTypes; |
|
||||||
import com.sun.jersey.core.reflection.ReflectionHelper; |
|
||||||
import com.sun.jersey.core.util.ReaderWriter; |
|
||||||
import com.sun.jersey.server.impl.InitialContextHelper; |
|
||||||
import com.sun.jersey.server.impl.ThreadLocalInvoker; |
|
||||||
import com.sun.jersey.server.impl.application.DeferredResourceConfig; |
|
||||||
import com.sun.jersey.server.impl.cdi.CDIComponentProviderFactoryInitializer; |
|
||||||
import com.sun.jersey.server.impl.container.servlet.JSPTemplateProcessor; |
|
||||||
import com.sun.jersey.server.impl.ejb.EJBComponentProviderFactoryInitilizer; |
|
||||||
import com.sun.jersey.server.impl.managedbeans.ManagedBeanComponentProviderFactoryInitilizer; |
|
||||||
import com.sun.jersey.server.impl.model.method.dispatch.FormDispatchProvider; |
|
||||||
import com.sun.jersey.server.impl.monitoring.GlassFishMonitoringInitializer; |
|
||||||
import com.sun.jersey.server.probes.UriRuleProbeProvider; |
|
||||||
import com.sun.jersey.spi.container.ContainerListener; |
|
||||||
import com.sun.jersey.spi.container.ContainerNotifier; |
|
||||||
import com.sun.jersey.spi.container.ContainerRequest; |
|
||||||
import com.sun.jersey.spi.container.ContainerResponse; |
|
||||||
import com.sun.jersey.spi.container.ContainerResponseWriter; |
|
||||||
import com.sun.jersey.spi.container.ReloadListener; |
|
||||||
import com.sun.jersey.spi.container.WebApplication; |
|
||||||
import com.sun.jersey.spi.container.WebApplicationFactory; |
|
||||||
import com.sun.jersey.spi.inject.SingletonTypeInjectableProvider; |
|
||||||
import java.security.AccessController; |
|
||||||
import java.security.PrivilegedActionException; |
|
||||||
|
|
||||||
/** |
|
||||||
* An abstract Web component that may be extended a Servlet and/or |
|
||||||
* Filter implementation, or encapsulated by a Servlet or Filter implementation. |
|
||||||
* |
|
||||||
* @author Paul Sandoz (paul.sandoz at oracle.com) |
|
||||||
*/ |
|
||||||
public class WebComponent implements ContainerListener { |
|
||||||
/** |
|
||||||
* The servlet initialization property whose value is a fully qualified |
|
||||||
* class name of a class that implements {@link ResourceConfig} or |
|
||||||
* {@link Application}. |
|
||||||
*/ |
|
||||||
public static final String APPLICATION_CONFIG_CLASS = |
|
||||||
"javax.ws.rs.Application"; |
|
||||||
|
|
||||||
/** |
|
||||||
* The servlet initialization property whose value is a fully qualified |
|
||||||
* class name of a class that implements {@link ResourceConfig} or |
|
||||||
* {@link Application}. |
|
||||||
*/ |
|
||||||
public static final String RESOURCE_CONFIG_CLASS = |
|
||||||
"com.sun.jersey.config.property.resourceConfigClass"; |
|
||||||
|
|
||||||
/** |
|
||||||
* The base path in the Web Pages where JSP templates, associated with |
|
||||||
* viewables of resource classes, are located. |
|
||||||
* <p/> |
|
||||||
* If this property is not set then the base path will be the root path |
|
||||||
* of the Web Pages. |
|
||||||
*/ |
|
||||||
public static final String JSP_TEMPLATES_BASE_PATH = |
|
||||||
"com.sun.jersey.config.property.JSPTemplatesBasePath"; |
|
||||||
|
|
||||||
|
|
||||||
private static final Logger LOGGER = |
|
||||||
Logger.getLogger(WebComponent.class.getName()); |
|
||||||
|
|
||||||
private final ThreadLocalInvoker<HttpServletRequest> requestInvoker = |
|
||||||
new ThreadLocalInvoker<HttpServletRequest>(); |
|
||||||
|
|
||||||
private final ThreadLocalInvoker<HttpServletResponse> responseInvoker = |
|
||||||
new ThreadLocalInvoker<HttpServletResponse>(); |
|
||||||
|
|
||||||
|
|
||||||
private WebConfig config; |
|
||||||
|
|
||||||
private ResourceConfig resourceConfig; |
|
||||||
|
|
||||||
private WebApplication application; |
|
||||||
|
|
||||||
public WebComponent() { |
|
||||||
} |
|
||||||
|
|
||||||
public WebComponent(Application app) { |
|
||||||
if (app == null) |
|
||||||
throw new IllegalArgumentException(); |
|
||||||
|
|
||||||
if (app instanceof ResourceConfig) { |
|
||||||
resourceConfig = (ResourceConfig) app; |
|
||||||
} else { |
|
||||||
resourceConfig = new ApplicationAdapter(app); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Get the Web configuration. |
|
||||||
* |
|
||||||
* @return the Web configuration. |
|
||||||
*/ |
|
||||||
public WebConfig getWebConfig() { |
|
||||||
return config; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Get the resource configuration. |
|
||||||
* |
|
||||||
* @return the resource configuration. |
|
||||||
*/ |
|
||||||
public ResourceConfig getResourceConfig() { |
|
||||||
return resourceConfig; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Initiate the Web component. |
|
||||||
* |
|
||||||
* @param webConfig the Web configuration. |
|
||||||
* @throws javax.servlet.ServletException in case of any initialization error |
|
||||||
*/ |
|
||||||
public void init(WebConfig webConfig) throws ServletException { |
|
||||||
config = webConfig; |
|
||||||
|
|
||||||
if (resourceConfig == null) |
|
||||||
resourceConfig = createResourceConfig(config); |
|
||||||
|
|
||||||
load(); |
|
||||||
|
|
||||||
Object o = resourceConfig.getProperties().get( |
|
||||||
ResourceConfig.PROPERTY_CONTAINER_NOTIFIER); |
|
||||||
if (o instanceof List) { |
|
||||||
List list = (List) o; |
|
||||||
for (Object elem : list) { |
|
||||||
if (elem instanceof ContainerNotifier) { |
|
||||||
ContainerNotifier crf = (ContainerNotifier) elem; |
|
||||||
crf.addListener(this); |
|
||||||
} |
|
||||||
} |
|
||||||
} else if (o instanceof ContainerNotifier) { |
|
||||||
ContainerNotifier crf = (ContainerNotifier) o; |
|
||||||
crf.addListener(this); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Destroy this Web component. |
|
||||||
* <p/> |
|
||||||
* This will destroy the Web application created by this this Web component. |
|
||||||
*/ |
|
||||||
public void destroy() { |
|
||||||
if (application != null) |
|
||||||
application.destroy(); |
|
||||||
} |
|
||||||
|
|
||||||
private final static class Writer extends OutputStream implements ContainerResponseWriter { |
|
||||||
final HttpServletResponse response; |
|
||||||
|
|
||||||
ContainerResponse cResponse; |
|
||||||
|
|
||||||
long contentLength; |
|
||||||
|
|
||||||
OutputStream out; |
|
||||||
|
|
||||||
boolean statusAndHeadersWritten = false; |
|
||||||
|
|
||||||
Writer(HttpServletResponse response) { |
|
||||||
this.response = response; |
|
||||||
} |
|
||||||
|
|
||||||
public OutputStream writeStatusAndHeaders(long contentLength, |
|
||||||
ContainerResponse cResponse) throws IOException { |
|
||||||
this.contentLength = contentLength; |
|
||||||
this.cResponse = cResponse; |
|
||||||
this.statusAndHeadersWritten = false; |
|
||||||
return this; |
|
||||||
} |
|
||||||
|
|
||||||
public void finish() throws IOException { |
|
||||||
if (statusAndHeadersWritten) |
|
||||||
return; |
|
||||||
|
|
||||||
// Note that the writing of headers MUST be performed before
|
|
||||||
// the invocation of sendError as on some Servlet implementations
|
|
||||||
// modification of the response headers will have no effect
|
|
||||||
// after the invocation of sendError.
|
|
||||||
writeHeaders(); |
|
||||||
|
|
||||||
|
|
||||||
writeStatus(); |
|
||||||
} |
|
||||||
|
|
||||||
private void writeStatus() { |
|
||||||
Response.StatusType statusType = cResponse.getStatusType(); |
|
||||||
final String reasonPhrase = statusType.getReasonPhrase(); |
|
||||||
|
|
||||||
// if (reasonPhrase != null) {
|
|
||||||
// response.setStatus(statusType.getStatusCode(), reasonPhrase);
|
|
||||||
// } else {
|
|
||||||
response.setStatus(statusType.getStatusCode()); |
|
||||||
// }
|
|
||||||
} |
|
||||||
|
|
||||||
public void write(int b) throws IOException { |
|
||||||
initiate(); |
|
||||||
out.write(b); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void write(byte b[]) throws IOException { |
|
||||||
if (b.length > 0) { |
|
||||||
initiate(); |
|
||||||
out.write(b); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void write(byte b[], int off, int len) throws IOException { |
|
||||||
if (len > 0) { |
|
||||||
initiate(); |
|
||||||
out.write(b, off, len); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void flush() throws IOException { |
|
||||||
writeStatusAndHeaders(); |
|
||||||
if (out != null) |
|
||||||
out.flush(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void close() throws IOException { |
|
||||||
initiate(); |
|
||||||
out.close(); |
|
||||||
} |
|
||||||
|
|
||||||
void initiate() throws IOException { |
|
||||||
if (out == null) { |
|
||||||
writeStatusAndHeaders(); |
|
||||||
out = response.getOutputStream(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void writeStatusAndHeaders() { |
|
||||||
if (statusAndHeadersWritten) |
|
||||||
return; |
|
||||||
|
|
||||||
writeHeaders(); |
|
||||||
writeStatus(); |
|
||||||
statusAndHeadersWritten = true; |
|
||||||
} |
|
||||||
|
|
||||||
void writeHeaders() { |
|
||||||
if (contentLength != -1 && contentLength < Integer.MAX_VALUE) |
|
||||||
response.setContentLength((int) contentLength); |
|
||||||
|
|
||||||
MultivaluedMap<String, Object> headers = cResponse.getHttpHeaders(); |
|
||||||
for (Map.Entry<String, List<Object>> e : headers.entrySet()) { |
|
||||||
for (Object v : e.getValue()) { |
|
||||||
response.addHeader(e.getKey(), ContainerResponse.getHeaderValue(v)); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Dispatch client requests to a resource class. |
|
||||||
* |
|
||||||
* @param baseUri the base URI of the request. |
|
||||||
* @param requestUri the URI of the request. |
|
||||||
* @param request the {@link HttpServletRequest} object that |
|
||||||
* contains the request the client made to |
|
||||||
* the Web component. |
|
||||||
* @param response the {@link HttpServletResponse} object that |
|
||||||
* contains the response the Web component returns |
|
||||||
* to the client. |
|
||||||
* @return the status code of the response. |
|
||||||
* @throws IOException if an input or output error occurs |
|
||||||
* while the Web component is handling the |
|
||||||
* HTTP request. |
|
||||||
* @throws ServletException if the HTTP request cannot |
|
||||||
* be handled. |
|
||||||
*/ |
|
||||||
public int service(URI baseUri, URI requestUri, |
|
||||||
final HttpServletRequest request, |
|
||||||
final HttpServletResponse response) |
|
||||||
throws ServletException, IOException { |
|
||||||
// Copy the application field to local instance to ensure that the
|
|
||||||
// currently loaded web application is used to process
|
|
||||||
// request
|
|
||||||
final WebApplication _application = application; |
|
||||||
|
|
||||||
final ContainerRequest cRequest = createRequest( |
|
||||||
_application, |
|
||||||
request, |
|
||||||
baseUri, |
|
||||||
requestUri); |
|
||||||
|
|
||||||
cRequest.setSecurityContext(new SecurityContext() { |
|
||||||
public Principal getUserPrincipal() { |
|
||||||
return request.getUserPrincipal(); |
|
||||||
} |
|
||||||
|
|
||||||
public boolean isUserInRole(String role) { |
|
||||||
return request.isUserInRole(role); |
|
||||||
} |
|
||||||
|
|
||||||
public boolean isSecure() { |
|
||||||
return request.isSecure(); |
|
||||||
} |
|
||||||
|
|
||||||
public String getAuthenticationScheme() { |
|
||||||
return request.getAuthType(); |
|
||||||
} |
|
||||||
}); |
|
||||||
|
|
||||||
try { |
|
||||||
// Check if any servlet filters have consumed a request entity
|
|
||||||
// of the media type application/x-www-form-urlencoded
|
|
||||||
// This can happen if a filter calls request.getParameter(...)
|
|
||||||
filterFormParameters(request, cRequest); |
|
||||||
|
|
||||||
UriRuleProbeProvider.requestStart(requestUri); |
|
||||||
|
|
||||||
requestInvoker.set(request); |
|
||||||
responseInvoker.set(response); |
|
||||||
|
|
||||||
final Writer w = new Writer(response); |
|
||||||
_application.handleRequest(cRequest, w); |
|
||||||
return w.cResponse.getStatus(); |
|
||||||
} catch (WebApplicationException ex) { |
|
||||||
final Response exResponse = ex.getResponse(); |
|
||||||
final String entity = exResponse.getEntity() != null ? exResponse.getEntity().toString() : null; |
|
||||||
|
|
||||||
response.sendError(exResponse.getStatus(), entity); |
|
||||||
|
|
||||||
return exResponse.getStatus(); |
|
||||||
} catch (MappableContainerException ex) { |
|
||||||
traceOnException(cRequest, response); |
|
||||||
throw new ServletException(ex.getCause()); |
|
||||||
} catch (ContainerException ex) { |
|
||||||
traceOnException(cRequest, response); |
|
||||||
throw new ServletException(ex); |
|
||||||
} catch (RuntimeException ex) { |
|
||||||
traceOnException(cRequest, response); |
|
||||||
throw ex; |
|
||||||
} finally { |
|
||||||
UriRuleProbeProvider.requestEnd(); |
|
||||||
requestInvoker.set(null); |
|
||||||
responseInvoker.set(null); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Extension point for creating your custom container request. |
|
||||||
* |
|
||||||
* @param app the web app |
|
||||||
* @param request the current servlet api request |
|
||||||
* @param baseUri the base uri |
|
||||||
* @param requestUri the request uri |
|
||||||
* @return the request container |
|
||||||
* @throws IOException if any error occurs when getting the input stream |
|
||||||
*/ |
|
||||||
protected ContainerRequest createRequest(WebApplication app, |
|
||||||
HttpServletRequest request, URI baseUri, URI requestUri) throws IOException { |
|
||||||
return new ContainerRequest( |
|
||||||
app, |
|
||||||
request.getMethod(), |
|
||||||
baseUri, |
|
||||||
requestUri, |
|
||||||
getHeaders(request), |
|
||||||
request.getInputStream()); |
|
||||||
} |
|
||||||
|
|
||||||
private void traceOnException(final ContainerRequest cRequest, final HttpServletResponse response) { |
|
||||||
if (cRequest.isTracingEnabled()) { |
|
||||||
final TraceInformation ti = (TraceInformation) cRequest.getProperties(). |
|
||||||
get(TraceInformation.class.getName()); |
|
||||||
|
|
||||||
ti.addTraceHeaders(new TraceInformation.TraceHeaderListener() { |
|
||||||
public void onHeader(String name, String value) { |
|
||||||
response.addHeader(name, value); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Create a new instance of a {@link WebApplication}. |
|
||||||
* |
|
||||||
* @return the {@link WebApplication} instance. |
|
||||||
*/ |
|
||||||
protected WebApplication create() { |
|
||||||
return WebApplicationFactory.createWebApplication(); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* A helper class for creating an injectable provider that supports |
|
||||||
* {@link Context} with a type and constant value. |
|
||||||
* |
|
||||||
* @param <T> the type of the constant value. |
|
||||||
*/ |
|
||||||
protected static class ContextInjectableProvider<T> extends |
|
||||||
SingletonTypeInjectableProvider<Context, T> { |
|
||||||
|
|
||||||
/** |
|
||||||
* Create a new instance. |
|
||||||
* |
|
||||||
* @param type the type of the constant value. |
|
||||||
* @param instance the constant value. |
|
||||||
*/ |
|
||||||
protected ContextInjectableProvider(Type type, T instance) { |
|
||||||
super(type, instance); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Configure the {@link ResourceConfig}. |
|
||||||
* <p/> |
|
||||||
* The {@link ResourceConfig} is configured such that the following classes |
|
||||||
* may be injected onto the field of a root resource class or a parameter |
|
||||||
* of a method of root resource class that is annotated with |
|
||||||
* {@link javax.ws.rs.core.Context}: {@link HttpServletRequest}, {@link HttpServletResponse} |
|
||||||
* , {@link ServletContext} and {@link WebConfig}. |
|
||||||
* <p/> |
|
||||||
* Any root resource class in registered in the resource configuration |
|
||||||
* that is an interface is processed as follows. |
|
||||||
* If the class is an interface and there exists a JNDI named object |
|
||||||
* with the fully qualified class name as the JNDI name then that named |
|
||||||
* object is added as a singleton root resource and the class is removed |
|
||||||
* from the set of root resource classes. |
|
||||||
* <p/> |
|
||||||
* An inheriting class may override this method to configure the |
|
||||||
* {@link ResourceConfig} to provide alternative or additional instances |
|
||||||
* that are resource or provider classes or instances, and may modify the |
|
||||||
* features and properties of the {@link ResourceConfig}. For an inheriting |
|
||||||
* class to extend configuration behaviour the overriding method MUST call |
|
||||||
* <code>super.configure(servletConfig, rc, wa)</code> as the first statement |
|
||||||
* of that method. |
|
||||||
* <p/> |
|
||||||
* This method will be called only once at initiation. Subsequent |
|
||||||
* reloads of the Web application will not result in subsequence calls to |
|
||||||
* this method. |
|
||||||
* |
|
||||||
* @param wc the Web configuration |
|
||||||
* @param rc the Resource configuration |
|
||||||
* @param wa the Web application |
|
||||||
*/ |
|
||||||
protected void configure(WebConfig wc, ResourceConfig rc, WebApplication wa) { |
|
||||||
configureJndiResources(rc); |
|
||||||
|
|
||||||
rc.getSingletons().add(new ContextInjectableProvider<HttpServletRequest>( |
|
||||||
HttpServletRequest.class, |
|
||||||
(HttpServletRequest) Proxy.newProxyInstance( |
|
||||||
this.getClass().getClassLoader(), |
|
||||||
new Class[]{HttpServletRequest.class}, |
|
||||||
requestInvoker))); |
|
||||||
|
|
||||||
rc.getSingletons().add(new ContextInjectableProvider<HttpServletResponse>( |
|
||||||
HttpServletResponse.class, |
|
||||||
(HttpServletResponse) Proxy.newProxyInstance( |
|
||||||
this.getClass().getClassLoader(), |
|
||||||
new Class[]{HttpServletResponse.class}, |
|
||||||
responseInvoker))); |
|
||||||
|
|
||||||
GenericEntity<ThreadLocal<HttpServletRequest>> requestThreadLocal = |
|
||||||
new GenericEntity<ThreadLocal<HttpServletRequest>>(requestInvoker.getImmutableThreadLocal()) { |
|
||||||
}; |
|
||||||
rc.getSingletons().add(new ContextInjectableProvider<ThreadLocal<HttpServletRequest>>( |
|
||||||
requestThreadLocal.getType(), requestThreadLocal.getEntity())); |
|
||||||
|
|
||||||
GenericEntity<ThreadLocal<HttpServletResponse>> responseThreadLocal = |
|
||||||
new GenericEntity<ThreadLocal<HttpServletResponse>>(responseInvoker.getImmutableThreadLocal()) { |
|
||||||
}; |
|
||||||
rc.getSingletons().add(new ContextInjectableProvider<ThreadLocal<HttpServletResponse>>( |
|
||||||
responseThreadLocal.getType(), responseThreadLocal.getEntity())); |
|
||||||
|
|
||||||
rc.getSingletons().add(new ContextInjectableProvider<ServletContext>( |
|
||||||
ServletContext.class, |
|
||||||
wc.getServletContext())); |
|
||||||
|
|
||||||
rc.getSingletons().add(new ContextInjectableProvider<WebConfig>( |
|
||||||
WebConfig.class, |
|
||||||
wc)); |
|
||||||
|
|
||||||
rc.getClasses().add(JSPTemplateProcessor.class); |
|
||||||
|
|
||||||
// TODO
|
|
||||||
// If CDI is enabled should EJB injection be disabled?
|
|
||||||
EJBComponentProviderFactoryInitilizer.initialize(rc); |
|
||||||
|
|
||||||
CDIComponentProviderFactoryInitializer.initialize(wc, rc, wa); |
|
||||||
|
|
||||||
// TODO
|
|
||||||
// If CDI is enabled then no need to initialize managed beans
|
|
||||||
ManagedBeanComponentProviderFactoryInitilizer.initialize(rc); |
|
||||||
|
|
||||||
GlassFishMonitoringInitializer.initialize(); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Initiate the {@link WebApplication}. |
|
||||||
* <p/> |
|
||||||
* This method will be called once at initiation and for |
|
||||||
* each reload of the Web application. |
|
||||||
* <p/> |
|
||||||
* An inheriting class may override this method to initiate the |
|
||||||
* Web application with different parameters. |
|
||||||
* |
|
||||||
* @param rc the Resource configuration |
|
||||||
* @param wa the Web application |
|
||||||
*/ |
|
||||||
protected void initiate(ResourceConfig rc, WebApplication wa) { |
|
||||||
wa.initiate(rc); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* Load the Web application. This will create, configure and initiate |
|
||||||
* the web application. |
|
||||||
*/ |
|
||||||
public void load() { |
|
||||||
WebApplication _application = create(); |
|
||||||
configure(config, resourceConfig, _application); |
|
||||||
initiate(resourceConfig, _application); |
|
||||||
application = _application; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Get the default resource configuration if one is not declared in the |
|
||||||
* web.xml. |
|
||||||
* <p/> |
|
||||||
* This implementation returns an instance of {@link WebAppResourceConfig} |
|
||||||
* that scans in files and directories as declared by the |
|
||||||
* {@link ClasspathResourceConfig#PROPERTY_CLASSPATH} if present, otherwise |
|
||||||
* in the "WEB-INF/lib" and "WEB-INF/classes" directories. |
|
||||||
* <p/> |
|
||||||
* An inheriting class may override this method to supply a different |
|
||||||
* default resource configuration implementation. |
|
||||||
* |
|
||||||
* @param props the properties to pass to the resource configuration. |
|
||||||
* @param wc the web configuration. |
|
||||||
* @return the default resource configuration. |
|
||||||
* @throws javax.servlet.ServletException in case of any issues with providing \ |
|
||||||
* the default resource configuration |
|
||||||
*/ |
|
||||||
protected ResourceConfig getDefaultResourceConfig(Map<String, Object> props, |
|
||||||
WebConfig wc) throws ServletException { |
|
||||||
return getWebAppResourceConfig(props, wc); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
// ContainerListener
|
|
||||||
|
|
||||||
/** |
|
||||||
* Reload the Web application. This will create and initiate the web |
|
||||||
* application using the same {@link ResourceConfig} implementation |
|
||||||
* that was used to load the Web application. |
|
||||||
* <p/> |
|
||||||
* This method may be called at runtime, more than once, to reload the |
|
||||||
* Web application. For example, if a {@link ResourceConfig} implementation |
|
||||||
* is capable of detecting changes to resource classes (addition or removal) |
|
||||||
* or providers then this method may be invoked to reload the web |
|
||||||
* application for such changes to take effect. |
|
||||||
* <p/> |
|
||||||
* If this method is called when there are pending requests then such |
|
||||||
* requests will be processed using the previously loaded web application. |
|
||||||
*/ |
|
||||||
public void onReload() { |
|
||||||
WebApplication oldApplication = application; |
|
||||||
WebApplication newApplication = create(); |
|
||||||
initiate(resourceConfig, newApplication); |
|
||||||
application = newApplication; |
|
||||||
|
|
||||||
if (resourceConfig instanceof ReloadListener) |
|
||||||
((ReloadListener) resourceConfig).onReload(); |
|
||||||
|
|
||||||
oldApplication.destroy(); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
/* package */ ResourceConfig getWebAppResourceConfig(Map<String, Object> props, |
|
||||||
WebConfig webConfig) throws ServletException { |
|
||||||
// Default to using Web app resource config
|
|
||||||
return new WebAppResourceConfig(props, webConfig.getServletContext()); |
|
||||||
} |
|
||||||
|
|
||||||
private ResourceConfig createResourceConfig(WebConfig webConfig) |
|
||||||
throws ServletException { |
|
||||||
final Map<String, Object> props = getInitParams(webConfig); |
|
||||||
final ResourceConfig rc = createResourceConfig(webConfig, props); |
|
||||||
rc.setPropertiesAndFeatures(props); |
|
||||||
return rc; |
|
||||||
} |
|
||||||
|
|
||||||
private ResourceConfig createResourceConfig(WebConfig webConfig, Map<String, Object> props) |
|
||||||
throws ServletException { |
|
||||||
// Check if the resource config class property is present
|
|
||||||
String resourceConfigClassName = webConfig.getInitParameter(RESOURCE_CONFIG_CLASS); |
|
||||||
// Otherwise check if the JAX-RS application config class property is
|
|
||||||
// present
|
|
||||||
if (resourceConfigClassName == null) |
|
||||||
resourceConfigClassName = webConfig.getInitParameter(APPLICATION_CONFIG_CLASS); |
|
||||||
|
|
||||||
// If no resource config class property is present
|
|
||||||
if (resourceConfigClassName == null) { |
|
||||||
// If the packages property is present then
|
|
||||||
// use the packages resource config
|
|
||||||
String packages = webConfig.getInitParameter( |
|
||||||
PackagesResourceConfig.PROPERTY_PACKAGES); |
|
||||||
if (packages != null) { |
|
||||||
props.put(PackagesResourceConfig.PROPERTY_PACKAGES, packages); |
|
||||||
return new PackagesResourceConfig(props); |
|
||||||
} |
|
||||||
|
|
||||||
ResourceConfig defaultConfig = webConfig.getDefaultResourceConfig(props); |
|
||||||
if (defaultConfig != null) |
|
||||||
return defaultConfig; |
|
||||||
|
|
||||||
return getDefaultResourceConfig(props, webConfig); |
|
||||||
} |
|
||||||
|
|
||||||
try { |
|
||||||
Class<?> resourceConfigClass = AccessController.doPrivileged(ReflectionHelper. |
|
||||||
classForNameWithExceptionPEA(resourceConfigClassName)); |
|
||||||
|
|
||||||
// TODO add support for WebAppResourceConfig
|
|
||||||
if (resourceConfigClass == ClasspathResourceConfig.class) { |
|
||||||
String[] paths = getPaths(webConfig.getInitParameter( |
|
||||||
ClasspathResourceConfig.PROPERTY_CLASSPATH)); |
|
||||||
props.put(ClasspathResourceConfig.PROPERTY_CLASSPATH, paths); |
|
||||||
return new ClasspathResourceConfig(props); |
|
||||||
} else if (ResourceConfig.class.isAssignableFrom(resourceConfigClass)) { |
|
||||||
try { |
|
||||||
Constructor constructor = resourceConfigClass.getConstructor(Map.class); |
|
||||||
if (ClasspathResourceConfig.class.isAssignableFrom(resourceConfigClass)) { |
|
||||||
String[] paths = getPaths(webConfig.getInitParameter( |
|
||||||
ClasspathResourceConfig.PROPERTY_CLASSPATH)); |
|
||||||
props.put(ClasspathResourceConfig.PROPERTY_CLASSPATH, paths); |
|
||||||
} |
|
||||||
return (ResourceConfig) constructor.newInstance(props); |
|
||||||
} catch (NoSuchMethodException ex) { |
|
||||||
// Pass through and try the default constructor
|
|
||||||
} catch (Exception e) { |
|
||||||
throw new ServletException(e); |
|
||||||
} |
|
||||||
|
|
||||||
return new DeferredResourceConfig(resourceConfigClass.asSubclass(ResourceConfig.class)); |
|
||||||
} else if (Application.class.isAssignableFrom(resourceConfigClass)) { |
|
||||||
return new DeferredResourceConfig(resourceConfigClass.asSubclass(Application.class)); |
|
||||||
} else { |
|
||||||
String message = "Resource configuration class, " + resourceConfigClassName + |
|
||||||
", is not a super class of " + Application.class; |
|
||||||
throw new ServletException(message); |
|
||||||
} |
|
||||||
} catch (ClassNotFoundException e) { |
|
||||||
String message = "Resource configuration class, " + resourceConfigClassName + |
|
||||||
", could not be loaded"; |
|
||||||
throw new ServletException(message, e); |
|
||||||
} catch (PrivilegedActionException e) { |
|
||||||
String message = "Resource configuration class, " + resourceConfigClassName + |
|
||||||
", could not be loaded"; |
|
||||||
throw new ServletException(message, e.getCause()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private Map<String, Object> getInitParams(WebConfig webConfig) { |
|
||||||
Map<String, Object> props = new HashMap<String, Object>(); |
|
||||||
Enumeration names = webConfig.getInitParameterNames(); |
|
||||||
while (names.hasMoreElements()) { |
|
||||||
String name = (String) names.nextElement(); |
|
||||||
props.put(name, webConfig.getInitParameter(name)); |
|
||||||
} |
|
||||||
return props; |
|
||||||
} |
|
||||||
|
|
||||||
private String[] getPaths(String classpath) throws ServletException { |
|
||||||
final ServletContext context = config.getServletContext(); |
|
||||||
if (classpath == null) { |
|
||||||
String[] paths = { |
|
||||||
context.getRealPath("/WEB-INF/lib"), |
|
||||||
context.getRealPath("/WEB-INF/classes") |
|
||||||
}; |
|
||||||
if (paths[0] == null && paths[1] == null) { |
|
||||||
String message = "The default deployment configuration that scans for " + |
|
||||||
"classes in /WEB-INF/lib and /WEB-INF/classes is not supported " + |
|
||||||
"for the application server." + |
|
||||||
"Try using the package scanning configuration, see the JavaDoc for " + |
|
||||||
PackagesResourceConfig.class.getName() + " and the property " + |
|
||||||
PackagesResourceConfig.PROPERTY_PACKAGES + "."; |
|
||||||
throw new ServletException(message); |
|
||||||
} |
|
||||||
return paths; |
|
||||||
} else { |
|
||||||
String[] virtualPaths = classpath.split(";"); |
|
||||||
List<String> resourcePaths = new ArrayList<String>(); |
|
||||||
for (String virtualPath : virtualPaths) { |
|
||||||
virtualPath = virtualPath.trim(); |
|
||||||
if (virtualPath.length() == 0) continue; |
|
||||||
String path = context.getRealPath(virtualPath); |
|
||||||
if (path != null) resourcePaths.add(path); |
|
||||||
} |
|
||||||
if (resourcePaths.isEmpty()) { |
|
||||||
String message = "None of the declared classpath locations, " + |
|
||||||
classpath + |
|
||||||
", could be resolved. " + |
|
||||||
"This could be because the default deployment configuration that scans for " + |
|
||||||
"classes in classpath locations is not supported. " + |
|
||||||
"Try using the package scanning configuration, see the JavaDoc for " + |
|
||||||
PackagesResourceConfig.class.getName() + " and the property " + |
|
||||||
PackagesResourceConfig.PROPERTY_PACKAGES + "."; |
|
||||||
throw new ServletException(message); |
|
||||||
} |
|
||||||
return resourcePaths.toArray(new String[resourcePaths.size()]); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void configureJndiResources(ResourceConfig rc) { |
|
||||||
// Obtain any instances that are registered in JNDI
|
|
||||||
// Assumes such instances are singletons
|
|
||||||
// Registered classes have to be interfaces
|
|
||||||
javax.naming.Context x = InitialContextHelper.getInitialContext(); |
|
||||||
if (x != null) { |
|
||||||
Iterator<Class<?>> i = rc.getClasses().iterator(); |
|
||||||
while (i.hasNext()) { |
|
||||||
Class<?> c = i.next(); |
|
||||||
if (!c.isInterface()) continue; |
|
||||||
|
|
||||||
try { |
|
||||||
Object o = x.lookup(c.getName()); |
|
||||||
if (o != null) { |
|
||||||
i.remove(); |
|
||||||
rc.getSingletons().add(o); |
|
||||||
LOGGER.log(Level.INFO, |
|
||||||
"An instance of the class " + c.getName() + |
|
||||||
" is found by JNDI look up using the class name as the JNDI name. " + |
|
||||||
"The instance will be registered as a singleton."); |
|
||||||
} |
|
||||||
} catch (NamingException ex) { |
|
||||||
LOGGER.log(Level.CONFIG, |
|
||||||
"JNDI lookup failed for Jersey application resource " + c.getName(), |
|
||||||
ex); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void filterFormParameters(HttpServletRequest servletRequest, ContainerRequest containerRequet) throws IOException { |
|
||||||
if (MediaTypes.typeEquals(MediaType.APPLICATION_FORM_URLENCODED_TYPE, containerRequet.getMediaType()) |
|
||||||
&& !isEntityPresent(containerRequet)) { |
|
||||||
Form f = new Form(); |
|
||||||
|
|
||||||
Enumeration e = servletRequest.getParameterNames(); |
|
||||||
while (e.hasMoreElements()) { |
|
||||||
String name = (String) e.nextElement(); |
|
||||||
String[] values = servletRequest.getParameterValues(name); |
|
||||||
|
|
||||||
f.put(name, Arrays.asList(values)); |
|
||||||
} |
|
||||||
|
|
||||||
if (!f.isEmpty()) { |
|
||||||
containerRequet.getProperties().put(FormDispatchProvider.FORM_PROPERTY, f); |
|
||||||
if (LOGGER.isLoggable(Level.WARNING)) { |
|
||||||
LOGGER.log(Level.WARNING, |
|
||||||
"A servlet request, to the URI " + containerRequet.getRequestUri() + ", " + |
|
||||||
"contains form parameters in " + |
|
||||||
"the request body but the request body has been consumed " + |
|
||||||
"by the servlet or a servlet filter accessing the request " + |
|
||||||
"parameters. Only resource methods using @FormParam " + |
|
||||||
"will work as expected. Resource methods consuming the " + |
|
||||||
"request body by other means will not work as expected."); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private boolean isEntityPresent(ContainerRequest cr) throws IOException { |
|
||||||
InputStream in = cr.getEntityInputStream(); |
|
||||||
if (!in.markSupported()) { |
|
||||||
in = new BufferedInputStream(in, ReaderWriter.BUFFER_SIZE); |
|
||||||
cr.setEntityInputStream(in); |
|
||||||
} |
|
||||||
|
|
||||||
in.mark(1); |
|
||||||
if (in.read() == -1) |
|
||||||
return false; |
|
||||||
else { |
|
||||||
in.reset(); |
|
||||||
return true; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private InBoundHeaders getHeaders(HttpServletRequest request) { |
|
||||||
InBoundHeaders rh = new InBoundHeaders(); |
|
||||||
|
|
||||||
for (Enumeration<String> names = request.getHeaderNames(); names.hasMoreElements();) { |
|
||||||
String name = names.nextElement(); |
|
||||||
List<String> valueList = new LinkedList<String>(); |
|
||||||
for (Enumeration<String> values = request.getHeaders(name); values.hasMoreElements();) { |
|
||||||
valueList.add(values.nextElement()); |
|
||||||
} |
|
||||||
rh.put(name, valueList); |
|
||||||
} |
|
||||||
|
|
||||||
return rh; |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,366 +0,0 @@ |
|||||||
/* |
|
||||||
* $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/util/MultipartRequest.java,v 1.19 2005/02/19 21:26:32 hkollmann Exp $ |
|
||||||
* $Revision: 1.19 $ |
|
||||||
* $Date: 2005/02/19 21:26:32 $ |
|
||||||
* |
|
||||||
* DbForms - a Rapid Application Development Framework |
|
||||||
* Copyright (C) 2001 Joachim Peer <joepeer@excite.com> |
|
||||||
* |
|
||||||
* This library is free software; you can redistribute it and/or |
|
||||||
* modify it under the terms of the GNU Lesser General Public |
|
||||||
* License as published by the Free Software Foundation; either |
|
||||||
* version 2.1 of the License, or (at your option) any later version. |
|
||||||
* |
|
||||||
* This library is distributed in the hope that it will be useful, |
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
||||||
* Lesser General Public License for more details. |
|
||||||
* |
|
||||||
* You should have received a copy of the GNU Lesser General Public |
|
||||||
* License along with this library; if not, write to the Free Software |
|
||||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
||||||
*/ |
|
||||||
|
|
||||||
package org.dbforms.util; |
|
||||||
|
|
||||||
import org.apache.commons.fileupload.DiskFileUpload; |
|
||||||
import org.apache.commons.fileupload.FileItem; |
|
||||||
import org.apache.commons.logging.Log; |
|
||||||
import org.apache.commons.logging.LogFactory; |
|
||||||
|
|
||||||
import java.io.File; |
|
||||||
import java.io.IOException; |
|
||||||
import java.io.InputStream; |
|
||||||
|
|
||||||
import java.util.Enumeration; |
|
||||||
import java.util.Hashtable; |
|
||||||
import java.util.Iterator; |
|
||||||
import java.util.List; |
|
||||||
import java.util.Vector; |
|
||||||
|
|
||||||
import jakarta.servlet.ServletRequest; |
|
||||||
import jakarta.servlet.ServletRequestWrapper; |
|
||||||
import jakarta.servlet.http.HttpServletRequest; |
|
||||||
import org.dbforms.util.external.FileUtil; |
|
||||||
|
|
||||||
import de.superx.util.multipart.support.DefaultMultipartHttpServletRequest; |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* A utility class to handle <code>multipart/form-data</code> requests, the |
|
||||||
* kind of requests that support file uploads. This class emulates the interface
|
|
||||||
* of <code>HttpServletRequest</code>, making it familiar to use. It uses a |
|
||||||
* "push" model where any incoming files are read and saved directly to disk in |
|
||||||
* the constructor. If you wish to have more flexibility, e.g. write the files |
|
||||||
* to a database, use the "pull" model <code>MultipartParser</code> instead. |
|
||||||
* <p> |
|
||||||
* This class can receive arbitrarily large files (up to an artificial limit you |
|
||||||
* can set), and fairly efficiently too. It cannot handle nested data (multipart |
|
||||||
* content within multipart content) or internationalized content (such as non |
|
||||||
* Latin-1 filenames). |
|
||||||
* </p> |
|
||||||
* <p> |
|
||||||
* See the included <a href="upload.war">upload.war </a> for an example of how |
|
||||||
* to use this class. |
|
||||||
* <p> |
|
||||||
* The full file upload specification is contained in experimental RFC 1867, |
|
||||||
* available at <a href="http://www.ietf.org/rfc/rfc1867.txt" |
|
||||||
* http://www.ietf.org/rfc/rfc1867.txt </a>.
|
|
||||||
* </p> |
|
||||||
* <p> |
|
||||||
* PLEASE NOTE: this class uses Multipart Support Classes by Jason Hunter. |
|
||||||
* Copyright (C) 1998 by Jason Hunter. All rights reserved. |
|
||||||
* Use of this class is limited. Please see the LICENSE for more information. |
|
||||||
* Make sure that you project meets the requierements defined by Jason Hunter |
|
||||||
* respective O'reilly! |
|
||||||
* </p> |
|
||||||
* |
|
||||||
* @see MultipartParser |
|
||||||
* |
|
||||||
* @author Jason Hunter |
|
||||||
* @author Geoff Soutter |
|
||||||
* @author Joe Peer - _changed_ it for use in DbForms (i apologize) |
|
||||||
*/ |
|
||||||
/* Witt: am 28.05.2026 als Basis für gepatchte Datei nach 'src-patches' übernommen, Basis waren meine |
|
||||||
* lokalen 'dbforms_2.5_20050226' Sourcen */ |
|
||||||
public class MultipartRequest { |
|
||||||
private static Log logCat = LogFactory.getLog(MultipartRequest.class); // logging category
|
|
||||||
private Hashtable files = new Hashtable(); // name - UploadedFile
|
|
||||||
|
|
||||||
// for this class
|
|
||||||
//private File dir;
|
|
||||||
private Hashtable parameters = new Hashtable(); // name - Vector of values
|
|
||||||
|
|
||||||
/** |
|
||||||
* Constructs a new MultipartRequest to handle the specified request, |
|
||||||
* {saving any uploaded files to the given directory}, and limiting the |
|
||||||
* upload size to the specified length. If the content is too large, an |
|
||||||
* IOException is thrown. This constructor actually parses the |
|
||||||
* <tt>multipart/form-data</tt> and throws an IOException if there's any |
|
||||||
* problem reading or parsing the request. |
|
||||||
* |
|
||||||
* @param request |
|
||||||
* the servlet request. |
|
||||||
* @param maxPostSize |
|
||||||
* the maximum size of the POST content. |
|
||||||
* @exception IOException |
|
||||||
* if the uploaded content is larger than |
|
||||||
* <tt>maxPostSize</tt> or there's a problem reading or |
|
||||||
* parsing the request. |
|
||||||
*/ |
|
||||||
public MultipartRequest(HttpServletRequest request, |
|
||||||
int maxPostSize) |
|
||||||
throws IOException { |
|
||||||
// Sanity check values
|
|
||||||
if (request == null) { |
|
||||||
throw new IllegalArgumentException("request cannot be null"); |
|
||||||
} |
|
||||||
|
|
||||||
// Create a new file upload handler
|
|
||||||
DiskFileUpload upload = new DiskFileUpload(); |
|
||||||
|
|
||||||
// Set upload parameters
|
|
||||||
upload.setSizeMax(maxPostSize); |
|
||||||
|
|
||||||
String tmpDir = System.getProperty("java.io.tmpdir"); |
|
||||||
upload.setRepositoryPath(tmpDir); |
|
||||||
|
|
||||||
// Parse the request
|
|
||||||
try { |
|
||||||
// we initilize this list with 'null', as the following unwrapping code should do the work - contrary to the 'org.dbforms.util.MultipartRequest code, from which this is copied
|
|
||||||
List<FileItem> items = null; //upload.parseRequest(request);
|
|
||||||
|
|
||||||
if (items == null || items.size() == 0) { |
|
||||||
ServletRequest originalRequest = request; |
|
||||||
DefaultMultipartHttpServletRequest dmhsr = null; |
|
||||||
while (originalRequest instanceof ServletRequestWrapper) { |
|
||||||
if (originalRequest instanceof DefaultMultipartHttpServletRequest) { |
|
||||||
dmhsr = (DefaultMultipartHttpServletRequest) originalRequest; |
|
||||||
items = dmhsr.getFileItems(); |
|
||||||
break; |
|
||||||
} |
|
||||||
originalRequest = ((ServletRequestWrapper) originalRequest).getRequest(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
Iterator iter = items.iterator(); |
|
||||||
|
|
||||||
while (iter.hasNext()) { |
|
||||||
FileItem item = (FileItem) iter.next(); |
|
||||||
String name = item.getFieldName(); |
|
||||||
|
|
||||||
if (item.isFormField()) { |
|
||||||
String value = item.getString(); |
|
||||||
|
|
||||||
// plain parameters get allways into parameters structure
|
|
||||||
Vector existingValues = (Vector) parameters.get(name); |
|
||||||
|
|
||||||
if (existingValues == null) { |
|
||||||
existingValues = new Vector(); |
|
||||||
parameters.put(name, existingValues); |
|
||||||
} |
|
||||||
|
|
||||||
existingValues.addElement(value); |
|
||||||
} else { |
|
||||||
String fileName = item.getName(); |
|
||||||
|
|
||||||
if (!Util.isNull(fileName)) { |
|
||||||
File f = new File(fileName); |
|
||||||
// 2004-08-05-HKK/Dziugas Baltrunas:
|
|
||||||
// FileItem always returns the full pathname!
|
|
||||||
fileName = FileUtil.filename(f.getName()); |
|
||||||
|
|
||||||
// The part actually contained a file
|
|
||||||
// #changes by joe peer:
|
|
||||||
// we must delay storing the file-inputstream (into
|
|
||||||
// database, filesystem or whatever)
|
|
||||||
// until we know exactly what should happen with it
|
|
||||||
FileHolder fileHolder = new FileHolder(fileName, item); |
|
||||||
files.put(name, fileHolder); |
|
||||||
logCat.info("buffered and now added as " + name |
|
||||||
+ " the following fileHolder:" |
|
||||||
+ fileHolder.getFileName()); |
|
||||||
|
|
||||||
// #changes by joe peer:
|
|
||||||
// if a file parameter is not null it gets into the
|
|
||||||
// parameters structures as well
|
|
||||||
// this is important to provide a simple access to
|
|
||||||
// request (no distinction between files and plain
|
|
||||||
// params)
|
|
||||||
Vector existingValues = (Vector) parameters.get(name); |
|
||||||
|
|
||||||
if (existingValues == null) { |
|
||||||
existingValues = new Vector(); |
|
||||||
parameters.put(name, existingValues); |
|
||||||
} |
|
||||||
|
|
||||||
existingValues.addElement(fileName); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} catch (Exception e) { |
|
||||||
logCat.error("MultipartRequest", e); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Returns the content type of the specified file (as supplied by the client |
|
||||||
* browser), or null if the file was not included in the upload. |
|
||||||
* |
|
||||||
* @param name |
|
||||||
* the file name. |
|
||||||
* @return the content type of the file. |
|
||||||
*/ |
|
||||||
public String getContentType(String name) { |
|
||||||
try { |
|
||||||
//#changed by joe peer
|
|
||||||
//UploadedFile file = (UploadedFile)files.get(name);
|
|
||||||
FileHolder filePart = (FileHolder) files.get(name); |
|
||||||
|
|
||||||
return filePart.getContentType(); // may be null
|
|
||||||
} catch (Exception e) { |
|
||||||
return null; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* Returns a FilePart object for the specified file this method was added by |
|
||||||
* joe peer |
|
||||||
* |
|
||||||
* @param name |
|
||||||
* the file name. |
|
||||||
* @return a FilePart object for the named file. |
|
||||||
*/ |
|
||||||
public FileHolder getFileHolder(String name) { |
|
||||||
try { |
|
||||||
return (FileHolder) files.get(name); |
|
||||||
} catch (Exception e) { |
|
||||||
return null; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* Returns a InputStream object for the specified file saved on the server's |
|
||||||
* filesystem, or null if the file was not included in the upload. |
|
||||||
* |
|
||||||
* @param name |
|
||||||
* the file name. |
|
||||||
* @return a InputStream object for the named file. |
|
||||||
*/ |
|
||||||
public InputStream getFileInputStream(String name) { |
|
||||||
try { |
|
||||||
//#changed by joe peer
|
|
||||||
//UploadedFile file = (UploadedFile)files.get(name);
|
|
||||||
FileHolder filePart = (FileHolder) files.get(name); |
|
||||||
|
|
||||||
return filePart.getInputStreamFromBuffer(); // may be null
|
|
||||||
} catch (Exception e) { |
|
||||||
return null; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* Returns the names of all the uploaded files as an Enumeration of Strings. |
|
||||||
* It returns an empty Enumeration if there are no uploaded files. Each file |
|
||||||
* name is the name specified by the form, not by the user. |
|
||||||
* |
|
||||||
* @return the names of all the uploaded files as an Enumeration of Strings. |
|
||||||
*/ |
|
||||||
public Enumeration getFileNames() { |
|
||||||
return files.keys(); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* Returns the filesystem name of the specified file, or null if the file |
|
||||||
* was not included in the upload. A filesystem name is the name specified |
|
||||||
* by the user. It is also the name under which the file is actually saved. |
|
||||||
* |
|
||||||
* @param name |
|
||||||
* the file name. |
|
||||||
* @return the filesystem name of the file. |
|
||||||
*/ |
|
||||||
public String getFilesystemName(String name) { |
|
||||||
try { |
|
||||||
//#changed by joe peer
|
|
||||||
//UploadedFile file = (UploadedFile)files.get(name);
|
|
||||||
FileHolder filePart = (FileHolder) files.get(name); |
|
||||||
|
|
||||||
return filePart.getFileName(); // may be null
|
|
||||||
} catch (Exception e) { |
|
||||||
return null; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* Returns the value of the named parameter as a String, or null if the |
|
||||||
* parameter was not sent or was sent without a value. The value is |
|
||||||
* guaranteed to be in its normal, decoded form. If the parameter has |
|
||||||
* multiple values, only the last one is returned (for backward |
|
||||||
* compatibility). For parameters with multiple values, it's possible the |
|
||||||
* last "value" may be null. |
|
||||||
* |
|
||||||
* @param name |
|
||||||
* the parameter name. |
|
||||||
* @return the parameter value. |
|
||||||
*/ |
|
||||||
public String getParameter(String name) { |
|
||||||
try { |
|
||||||
Vector values = (Vector) parameters.get(name); |
|
||||||
|
|
||||||
if ((values == null) || (values.size() == 0)) { |
|
||||||
return null; |
|
||||||
} |
|
||||||
|
|
||||||
String value = (String) values.elementAt(0); |
|
||||||
|
|
||||||
return value; |
|
||||||
} catch (Exception e) { |
|
||||||
return null; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* Returns the names of all the parameters as an Enumeration of Strings. It |
|
||||||
* returns an empty Enumeration if there are no parameters. |
|
||||||
* |
|
||||||
* @return the names of all the parameters as an Enumeration of Strings. |
|
||||||
*/ |
|
||||||
public Enumeration getParameterNames() { |
|
||||||
return parameters.keys(); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* Returns the values of the named parameter as a String array, or null if |
|
||||||
* the parameter was not sent. The array has one entry for each parameter |
|
||||||
* field sent. If any field was sent without a value that entry is stored in |
|
||||||
* the array as a null. The values are guaranteed to be in their normal, |
|
||||||
* decoded form. A single value is returned as a one-element array. |
|
||||||
* |
|
||||||
* @param name |
|
||||||
* the parameter name. |
|
||||||
* @return the parameter values. |
|
||||||
*/ |
|
||||||
public String[] getParameterValues(String name) { |
|
||||||
try { |
|
||||||
Vector values = (Vector) parameters.get(name); |
|
||||||
|
|
||||||
if ((values == null) || (values.size() == 0)) { |
|
||||||
return null; |
|
||||||
} |
|
||||||
|
|
||||||
String[] valuesArray = new String[values.size()]; |
|
||||||
values.copyInto(valuesArray); |
|
||||||
|
|
||||||
return valuesArray; |
|
||||||
} catch (Exception e) { |
|
||||||
return null; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,699 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2002-2016 the original author or authors. |
|
||||||
* |
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||||
* you may not use this file except in compliance with the License. |
|
||||||
* You may obtain a copy of the License at |
|
||||||
* |
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* |
|
||||||
* Unless required by applicable law or agreed to in writing, software |
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, |
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||||
* See the License for the specific language governing permissions and |
|
||||||
* limitations under the License. |
|
||||||
*/ |
|
||||||
|
|
||||||
/* taken/copied from 'spring-security-web-6.2.8.jar' as a base for patching */ |
|
||||||
|
|
||||||
package org.springframework.security.web.util; |
|
||||||
|
|
||||||
import java.io.IOException; |
|
||||||
import java.io.PrintWriter; |
|
||||||
import java.util.Locale; |
|
||||||
|
|
||||||
import jakarta.servlet.ServletOutputStream; |
|
||||||
import jakarta.servlet.WriteListener; |
|
||||||
import jakarta.servlet.http.HttpServletResponse; |
|
||||||
import jakarta.servlet.http.HttpServletResponseWrapper; |
|
||||||
|
|
||||||
/** |
|
||||||
* Base class for response wrappers which encapsulate the logic for handling an event when |
|
||||||
* the {@link jakarta.servlet.http.HttpServletResponse} is committed. |
|
||||||
* |
|
||||||
* @author Rob Winch |
|
||||||
* @since 4.0.2 |
|
||||||
*/ |
|
||||||
public abstract class OnCommittedResponseWrapper extends HttpServletResponseWrapper { |
|
||||||
|
|
||||||
private boolean disableOnCommitted; |
|
||||||
|
|
||||||
/** |
|
||||||
* The Content-Length response header. If this is greater than 0, then once |
|
||||||
* {@link #contentWritten} is larger than or equal the response is considered |
|
||||||
* committed. |
|
||||||
*/ |
|
||||||
private long contentLength; |
|
||||||
|
|
||||||
/** |
|
||||||
* The size of data written to the response body. The field will only be updated when |
|
||||||
* {@link #disableOnCommitted} is false. |
|
||||||
*/ |
|
||||||
private long contentWritten; |
|
||||||
|
|
||||||
/** |
|
||||||
* @param response the response to be wrapped |
|
||||||
*/ |
|
||||||
public OnCommittedResponseWrapper(HttpServletResponse response) { |
|
||||||
super(response); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void addHeader(String name, String value) { |
|
||||||
checkContentLengthHeader(name, value); |
|
||||||
super.addHeader(name, value); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void addIntHeader(String name, int value) { |
|
||||||
checkContentLengthHeader(name, value); |
|
||||||
super.addIntHeader(name, value); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void setHeader(String name, String value) { |
|
||||||
checkContentLengthHeader(name, value); |
|
||||||
super.setHeader(name, value); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void setIntHeader(String name, int value) { |
|
||||||
checkContentLengthHeader(name, value); |
|
||||||
super.setIntHeader(name, value); |
|
||||||
} |
|
||||||
|
|
||||||
private void checkContentLengthHeader(String name, int value) { |
|
||||||
if ("Content-Length".equalsIgnoreCase(name)) { |
|
||||||
setContentLength(value); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void checkContentLengthHeader(String name, String value) { |
|
||||||
if ("Content-Length".equalsIgnoreCase(name)) { |
|
||||||
setContentLength(Long.parseLong(value)); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void setContentLength(int len) { |
|
||||||
setContentLength((long) len); |
|
||||||
super.setContentLength(len); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void setContentLengthLong(long len) { |
|
||||||
setContentLength(len); |
|
||||||
super.setContentLengthLong(len); |
|
||||||
} |
|
||||||
|
|
||||||
private void setContentLength(long len) { |
|
||||||
this.contentLength = len; |
|
||||||
checkContentLength(0); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Invoke this method to disable invoking |
|
||||||
* {@link OnCommittedResponseWrapper#onResponseCommitted()} when the |
|
||||||
* {@link jakarta.servlet.http.HttpServletResponse} is committed. This can be useful |
|
||||||
* in the event that Async Web Requests are made. |
|
||||||
*/ |
|
||||||
protected void disableOnResponseCommitted() { |
|
||||||
this.disableOnCommitted = true; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Returns true if {@link #onResponseCommitted()} will be invoked when the response is |
|
||||||
* committed, else false. |
|
||||||
* @return if {@link #onResponseCommitted()} is enabled |
|
||||||
*/ |
|
||||||
protected boolean isDisableOnResponseCommitted() { |
|
||||||
return this.disableOnCommitted; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Implement the logic for handling the |
|
||||||
* {@link jakarta.servlet.http.HttpServletResponse} being committed |
|
||||||
*/ |
|
||||||
protected abstract void onResponseCommitted(); |
|
||||||
|
|
||||||
/** |
|
||||||
* Makes sure {@link OnCommittedResponseWrapper#onResponseCommitted()} is invoked |
|
||||||
* before calling the superclass <code>sendError()</code> |
|
||||||
*/ |
|
||||||
@Override |
|
||||||
public final void sendError(int sc) throws IOException { |
|
||||||
doOnResponseCommitted(); |
|
||||||
super.sendError(sc); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Makes sure {@link OnCommittedResponseWrapper#onResponseCommitted()} is invoked |
|
||||||
* before calling the superclass <code>sendError()</code> |
|
||||||
*/ |
|
||||||
@Override |
|
||||||
public final void sendError(int sc, String msg) throws IOException { |
|
||||||
doOnResponseCommitted(); |
|
||||||
super.sendError(sc, msg); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Makes sure {@link OnCommittedResponseWrapper#onResponseCommitted()} is invoked |
|
||||||
* before calling the superclass <code>sendRedirect()</code> |
|
||||||
*/ |
|
||||||
@Override |
|
||||||
public final void sendRedirect(String location) throws IOException { |
|
||||||
doOnResponseCommitted(); |
|
||||||
super.sendRedirect(location); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Makes sure {@link OnCommittedResponseWrapper#onResponseCommitted()} is invoked |
|
||||||
* before calling the calling <code>getOutputStream().close()</code> or |
|
||||||
* <code>getOutputStream().flush()</code> |
|
||||||
*/ |
|
||||||
@Override |
|
||||||
public ServletOutputStream getOutputStream() throws IOException { |
|
||||||
return new SaveContextServletOutputStream(super.getOutputStream()); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Makes sure {@link OnCommittedResponseWrapper#onResponseCommitted()} is invoked |
|
||||||
* before calling the <code>getWriter().close()</code> or |
|
||||||
* <code>getWriter().flush()</code> |
|
||||||
*/ |
|
||||||
@Override |
|
||||||
public PrintWriter getWriter() throws IOException { |
|
||||||
return new SaveContextPrintWriter(super.getWriter()); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Makes sure {@link OnCommittedResponseWrapper#onResponseCommitted()} is invoked |
|
||||||
* before calling the superclass <code>flushBuffer()</code> |
|
||||||
*/ |
|
||||||
@Override |
|
||||||
public void flushBuffer() throws IOException { |
|
||||||
doOnResponseCommitted(); |
|
||||||
super.flushBuffer(); |
|
||||||
} |
|
||||||
|
|
||||||
private void trackContentLength(boolean content) { |
|
||||||
if (!this.disableOnCommitted) { |
|
||||||
checkContentLength(content ? 4 : 5); // TODO Localization
|
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void trackContentLength(char content) { |
|
||||||
if (!this.disableOnCommitted) { |
|
||||||
checkContentLength(1); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void trackContentLength(Object content) { |
|
||||||
if (!this.disableOnCommitted) { |
|
||||||
trackContentLength(String.valueOf(content)); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void trackContentLength(byte[] content) { |
|
||||||
if (!this.disableOnCommitted) { |
|
||||||
checkContentLength((content != null) ? content.length : 0); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void trackContentLength(char[] content) { |
|
||||||
if (!this.disableOnCommitted) { |
|
||||||
checkContentLength((content != null) ? content.length : 0); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void trackContentLength(int content) { |
|
||||||
if (!this.disableOnCommitted) { |
|
||||||
trackContentLength(String.valueOf(content)); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void trackContentLength(float content) { |
|
||||||
if (!this.disableOnCommitted) { |
|
||||||
trackContentLength(String.valueOf(content)); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void trackContentLength(double content) { |
|
||||||
if (!this.disableOnCommitted) { |
|
||||||
trackContentLength(String.valueOf(content)); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void trackContentLengthLn() { |
|
||||||
if (!this.disableOnCommitted) { |
|
||||||
trackContentLength("\r\n"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
private void trackContentLength(String content) { |
|
||||||
if (!this.disableOnCommitted) { |
|
||||||
int contentLength = (content != null) ? content.length() : 4; |
|
||||||
checkContentLength(contentLength); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Adds the contentLengthToWrite to the total contentWritten size and checks to see if |
|
||||||
* the response should be written. |
|
||||||
* @param contentLengthToWrite the size of the content that is about to be written. |
|
||||||
*/ |
|
||||||
private void checkContentLength(long contentLengthToWrite) { |
|
||||||
this.contentWritten += contentLengthToWrite; |
|
||||||
boolean isBodyFullyWritten = this.contentLength > 0 && this.contentWritten >= this.contentLength; |
|
||||||
int bufferSize = getBufferSize(); |
|
||||||
boolean requiresFlush = bufferSize > 0 && this.contentWritten >= bufferSize; |
|
||||||
if (isBodyFullyWritten || requiresFlush) { |
|
||||||
doOnResponseCommitted(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Calls <code>onResponseCommmitted()</code> with the current contents as long as |
|
||||||
* {@link #disableOnResponseCommitted()} was not invoked. |
|
||||||
*/ |
|
||||||
private void doOnResponseCommitted() { |
|
||||||
if (!this.disableOnCommitted) { |
|
||||||
onResponseCommitted(); |
|
||||||
disableOnResponseCommitted(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Ensures {@link OnCommittedResponseWrapper#onResponseCommitted()} is invoked before |
|
||||||
* calling the prior to methods that commit the response. We delegate all methods to |
|
||||||
* the original {@link java.io.PrintWriter} to ensure that the behavior is as close to |
|
||||||
* the original {@link java.io.PrintWriter} as possible. See SEC-2039 |
|
||||||
* |
|
||||||
* @author Rob Winch |
|
||||||
*/ |
|
||||||
private class SaveContextPrintWriter extends PrintWriter { |
|
||||||
|
|
||||||
private final PrintWriter delegate; |
|
||||||
|
|
||||||
SaveContextPrintWriter(PrintWriter delegate) { |
|
||||||
super(delegate); |
|
||||||
this.delegate = delegate; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void flush() { |
|
||||||
doOnResponseCommitted(); |
|
||||||
this.delegate.flush(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void close() { |
|
||||||
doOnResponseCommitted(); |
|
||||||
this.delegate.close(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public boolean equals(Object obj) { |
|
||||||
return this.delegate.equals(obj); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public int hashCode() { |
|
||||||
return this.delegate.hashCode(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public String toString() { |
|
||||||
return getClass().getName() + "[delegate=" + this.delegate.toString() + "]"; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public boolean checkError() { |
|
||||||
return this.delegate.checkError(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void write(int c) { |
|
||||||
trackContentLength(c); |
|
||||||
this.delegate.write(c); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void write(char[] buf, int off, int len) { |
|
||||||
checkContentLength(len); |
|
||||||
this.delegate.write(buf, off, len); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void write(char[] buf) { |
|
||||||
trackContentLength(buf); |
|
||||||
this.delegate.write(buf); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void write(String s, int off, int len) { |
|
||||||
checkContentLength(len); |
|
||||||
this.delegate.write(s, off, len); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void write(String s) { |
|
||||||
trackContentLength(s); |
|
||||||
this.delegate.write(s); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(boolean b) { |
|
||||||
trackContentLength(b); |
|
||||||
this.delegate.print(b); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(char c) { |
|
||||||
trackContentLength(c); |
|
||||||
this.delegate.print(c); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(int i) { |
|
||||||
trackContentLength(i); |
|
||||||
this.delegate.print(i); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(long l) { |
|
||||||
trackContentLength(l); |
|
||||||
this.delegate.print(l); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(float f) { |
|
||||||
trackContentLength(f); |
|
||||||
this.delegate.print(f); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(double d) { |
|
||||||
trackContentLength(d); |
|
||||||
this.delegate.print(d); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(char[] s) { |
|
||||||
trackContentLength(s); |
|
||||||
this.delegate.print(s); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(String s) { |
|
||||||
trackContentLength(s); |
|
||||||
this.delegate.print(s); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(Object obj) { |
|
||||||
trackContentLength(obj); |
|
||||||
this.delegate.print(obj); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println() { |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(boolean x) { |
|
||||||
trackContentLength(x); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(x); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(char x) { |
|
||||||
trackContentLength(x); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(x); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(int x) { |
|
||||||
trackContentLength(x); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(x); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(long x) { |
|
||||||
trackContentLength(x); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(x); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(float x) { |
|
||||||
trackContentLength(x); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(x); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(double x) { |
|
||||||
trackContentLength(x); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(x); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(char[] x) { |
|
||||||
trackContentLength(x); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(x); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(String x) { |
|
||||||
trackContentLength(x); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(x); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(Object x) { |
|
||||||
trackContentLength(x); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(x); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public PrintWriter printf(String format, Object... args) { |
|
||||||
return this.delegate.printf(format, args); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public PrintWriter printf(Locale l, String format, Object... args) { |
|
||||||
return this.delegate.printf(l, format, args); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public PrintWriter format(String format, Object... args) { |
|
||||||
return this.delegate.format(format, args); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public PrintWriter format(Locale l, String format, Object... args) { |
|
||||||
return this.delegate.format(l, format, args); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public PrintWriter append(CharSequence csq) { |
|
||||||
checkContentLength(csq.length()); |
|
||||||
return this.delegate.append(csq); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public PrintWriter append(CharSequence csq, int start, int end) { |
|
||||||
checkContentLength(end - start); |
|
||||||
return this.delegate.append(csq, start, end); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public PrintWriter append(char c) { |
|
||||||
trackContentLength(c); |
|
||||||
return this.delegate.append(c); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Ensures{@link OnCommittedResponseWrapper#onResponseCommitted()} is invoked before |
|
||||||
* calling methods that commit the response. We delegate all methods to the original |
|
||||||
* {@link jakarta.servlet.ServletOutputStream} to ensure that the behavior is as close |
|
||||||
* to the original {@link jakarta.servlet.ServletOutputStream} as possible. See |
|
||||||
* SEC-2039 |
|
||||||
* |
|
||||||
* @author Rob Winch |
|
||||||
*/ |
|
||||||
private class SaveContextServletOutputStream extends ServletOutputStream { |
|
||||||
|
|
||||||
private final ServletOutputStream delegate; |
|
||||||
|
|
||||||
SaveContextServletOutputStream(ServletOutputStream delegate) { |
|
||||||
this.delegate = delegate; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void write(int b) throws IOException { |
|
||||||
trackContentLength(b); |
|
||||||
this.delegate.write(b); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void flush() throws IOException { |
|
||||||
doOnResponseCommitted(); |
|
||||||
this.delegate.flush(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void close() throws IOException { |
|
||||||
doOnResponseCommitted(); |
|
||||||
this.delegate.close(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(boolean b) throws IOException { |
|
||||||
trackContentLength(b); |
|
||||||
this.delegate.print(b); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(char c) throws IOException { |
|
||||||
trackContentLength(c); |
|
||||||
this.delegate.print(c); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(double d) throws IOException { |
|
||||||
trackContentLength(d); |
|
||||||
this.delegate.print(d); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(float f) throws IOException { |
|
||||||
trackContentLength(f); |
|
||||||
this.delegate.print(f); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(int i) throws IOException { |
|
||||||
trackContentLength(i); |
|
||||||
this.delegate.print(i); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(long l) throws IOException { |
|
||||||
trackContentLength(l); |
|
||||||
this.delegate.print(l); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void print(String s) throws IOException { |
|
||||||
trackContentLength(s); |
|
||||||
this.delegate.print(s); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println() throws IOException { |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(boolean b) throws IOException { |
|
||||||
trackContentLength(b); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(b); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(char c) throws IOException { |
|
||||||
trackContentLength(c); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(c); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(double d) throws IOException { |
|
||||||
trackContentLength(d); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(d); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(float f) throws IOException { |
|
||||||
trackContentLength(f); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(f); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(int i) throws IOException { |
|
||||||
trackContentLength(i); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(i); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(long l) throws IOException { |
|
||||||
trackContentLength(l); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(l); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void println(String s) throws IOException { |
|
||||||
trackContentLength(s); |
|
||||||
trackContentLengthLn(); |
|
||||||
this.delegate.println(s); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void write(byte[] b) throws IOException { |
|
||||||
trackContentLength(b); |
|
||||||
this.delegate.write(b); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void write(byte[] b, int off, int len) throws IOException { |
|
||||||
checkContentLength(len); |
|
||||||
this.delegate.write(b, off, len); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public boolean isReady() { |
|
||||||
return this.delegate.isReady(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void setWriteListener(WriteListener writeListener) { |
|
||||||
this.delegate.setWriteListener(writeListener); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public boolean equals(Object obj) { |
|
||||||
return this.delegate.equals(obj); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public int hashCode() { |
|
||||||
return this.delegate.hashCode(); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public String toString() { |
|
||||||
return getClass().getName() + "[delegate=" + this.delegate.toString() + "]"; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,262 @@ |
|||||||
|
package de.memtext.db; |
||||||
|
|
||||||
|
import java.io.File; |
||||||
|
import java.io.IOException; |
||||||
|
import java.security.InvalidKeyException; |
||||||
|
import java.security.NoSuchAlgorithmException; |
||||||
|
import java.security.SignatureException; |
||||||
|
import java.security.spec.InvalidKeySpecException; |
||||||
|
import java.sql.Connection; |
||||||
|
import java.sql.DriverManager; |
||||||
|
import java.sql.ResultSet; |
||||||
|
import java.sql.SQLException; |
||||||
|
import java.sql.Statement; |
||||||
|
import java.util.Properties; |
||||||
|
|
||||||
|
import javax.xml.transform.TransformerConfigurationException; |
||||||
|
|
||||||
|
import org.apache.commons.dbcp.ConnectionFactory; |
||||||
|
import org.apache.commons.dbcp.DriverManagerConnectionFactory; |
||||||
|
import org.apache.commons.dbcp.PoolableConnectionFactory; |
||||||
|
import org.apache.commons.dbcp.PoolingDriver; |
||||||
|
import org.apache.commons.pool.impl.GenericObjectPool; |
||||||
|
|
||||||
|
import de.memtext.baseobjects.NamedObjectI; |
||||||
|
import de.memtext.tree.KeyParentEqualException; |
||||||
|
import de.memtext.util.DSAHandler; |
||||||
|
|
||||||
|
/** |
||||||
|
* A new Connection pool making use of Jakarta Commons dbcp. |
||||||
|
*/ |
||||||
|
public class MemtextPool extends GenericObjectPool implements NamedObjectI { |
||||||
|
|
||||||
|
private String name, subpath; |
||||||
|
private String nameNoAppendix; |
||||||
|
|
||||||
|
private Properties props = new Properties(); |
||||||
|
private String privateKeyEncoded = null; |
||||||
|
private String publicKeyEncoded = null; |
||||||
|
private DSAHandler dsaHandler; |
||||||
|
|
||||||
|
public MemtextPool(String name, String nameAppendix, String subpath) |
||||||
|
throws SQLException, IOException, DBServletException { |
||||||
|
this.subpath = subpath; |
||||||
|
nameNoAppendix = name; |
||||||
|
this.setName(name + nameAppendix); |
||||||
|
try { |
||||||
|
readPropertiesAndUrl(); |
||||||
|
System.out |
||||||
|
.print(" (" + props.getProperty("connectionURL") + ") .."); |
||||||
|
} catch (Exception e) { |
||||||
|
System.out |
||||||
|
.println("Konnte properties / Passwort nicht lesen. " + e); |
||||||
|
e.printStackTrace(); |
||||||
|
throw new DBServletException( |
||||||
|
"Konnte properties / Passwort nicht lesen. " + e); |
||||||
|
} |
||||||
|
try { |
||||||
|
|
||||||
|
Class.forName(props.getProperty("driverName")); |
||||||
|
} catch (ClassNotFoundException e1) { |
||||||
|
throw new DBServletException("Treiber " |
||||||
|
+ props.getProperty("driverName") |
||||||
|
+ " nicht gefunden. Ggfs. nach tomcat/common/lib kopieren."); |
||||||
|
} |
||||||
|
|
||||||
|
initLogging(); |
||||||
|
this.setTestOnBorrow(true); |
||||||
|
|
||||||
|
int minIdle = 5; |
||||||
|
if (props.getProperty("minIdle") != null |
||||||
|
&& !props.getProperty("minIdle").trim().equals("")) { |
||||||
|
minIdle = Integer.parseInt(props.getProperty("minIdle")); |
||||||
|
} |
||||||
|
this.setMinIdle(minIdle); |
||||||
|
int maxIdle = -1; |
||||||
|
if (props.getProperty("maxIdle") != null |
||||||
|
&& !props.getProperty("maxIdle").trim().equals("")) { |
||||||
|
maxIdle = Integer.parseInt(props.getProperty("maxIdle")); |
||||||
|
} |
||||||
|
if (maxIdle != -1) |
||||||
|
setMaxIdle(maxIdle); |
||||||
|
|
||||||
|
int maxActive = -1; |
||||||
|
if (props.getProperty("maxActive") != null |
||||||
|
&& !props.getProperty("maxActive").trim().equals("")) { |
||||||
|
maxActive = Integer.parseInt(props.getProperty("maxActive")); |
||||||
|
} |
||||||
|
if (maxActive != -1) |
||||||
|
setMaxActive(maxActive); |
||||||
|
|
||||||
|
ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( |
||||||
|
props.getProperty("connectionURL"), props); |
||||||
|
PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory( |
||||||
|
connectionFactory, this, null, "select count(*) from xdummy;" //validationQuery
|
||||||
|
, false, true); |
||||||
|
int i = 1; |
||||||
|
try { |
||||||
|
// PoolingDriver driver = new PoolingDriver();
|
||||||
|
Class.forName("org.apache.commons.dbcp.PoolingDriver"); |
||||||
|
} catch (ClassNotFoundException e2) { |
||||||
|
throw new DBServletException( |
||||||
|
"ConnectionPool Klasse org.apache.commons.dbcp.PoolingDriver nicht gefunden.\ncommons-dbcp nach tomcat/common/lib stellen."); |
||||||
|
} |
||||||
|
PoolingDriver driver = (PoolingDriver) DriverManager |
||||||
|
.getDriver("jdbc:apache:commons:dbcp:"); |
||||||
|
|
||||||
|
driver.registerPool(this.getName(), this); |
||||||
|
|
||||||
|
Object x = driver.getConnectionPool(this.getName()); |
||||||
|
try { |
||||||
|
Connection con = this.getConnection(); |
||||||
|
Statement st = con.createStatement(); |
||||||
|
ResultSet rs = st |
||||||
|
.executeQuery("select value from properties where name='privatekey'"); |
||||||
|
while (rs.next()) { |
||||||
|
privateKeyEncoded = rs.getString(1); |
||||||
|
} |
||||||
|
rs.close(); |
||||||
|
rs = st |
||||||
|
.executeQuery("select value from properties where name='publickey'"); |
||||||
|
while (rs.next()) { |
||||||
|
publicKeyEncoded = rs.getString(1); |
||||||
|
} |
||||||
|
rs.close(); |
||||||
|
st.close(); |
||||||
|
con.close(); |
||||||
|
|
||||||
|
} catch (SQLException e) { |
||||||
|
String msg = "Fehler beim Aufbau des ConnectionPools "; |
||||||
|
if (!getName().startsWith("default")) |
||||||
|
msg += " für Mandant: " + getName(); |
||||||
|
msg += "\nKonnte keine Connection aus dem Pool holen.\n" + e; |
||||||
|
|
||||||
|
throw new SQLException(msg); |
||||||
|
} |
||||||
|
if (privateKeyEncoded != null) |
||||||
|
initDSAHandler(); |
||||||
|
} |
||||||
|
|
||||||
|
protected void initLogging() throws IOException { |
||||||
|
/* |
||||||
|
* LogUtils.initRawFile("superx_" + getName(), getLogDir() + "/superx_" + |
||||||
|
* name + ".log", 2000, 1, false, true); LogUtils.initRawFile("superx_" + |
||||||
|
* getName() + "_xml", getLogDir() + "/superx_" + name + "_xml.log", |
||||||
|
* 2000, 1, false, true); |
||||||
|
* |
||||||
|
* Level lev = Level.SEVERE; |
||||||
|
* |
||||||
|
* try { if (props.getProperty("logLevelSQL") != null) lev = |
||||||
|
* Level.parse(props.getProperty("logLevelSQL")); } catch |
||||||
|
* (IllegalArgumentException e) { String msg = "Ungültiger Level für |
||||||
|
* sqlLogger "; if (!this.getName().equals("default")) msg += "(Mandant :" + |
||||||
|
* getName() + ") "; msg += " :" + props.getProperty("logLevelSQL"); |
||||||
|
* System.out.println(msg); } Logger.getLogger("superx_" + |
||||||
|
* getName()).setLevel(lev); lev = Level.SEVERE; |
||||||
|
* |
||||||
|
* try { if (props.getProperty("logLevelXML") != null) lev = |
||||||
|
* Level.parse(props.getProperty("logLevelXML")); } catch |
||||||
|
* (IllegalArgumentException e) { String msg = "Ungültiger Level für |
||||||
|
* XMLLogger "; if (!this.getName().equals("default")) msg += "(Mandant :" + |
||||||
|
* getName() + ") "; msg += " :" + props.getProperty("logLevelXML"); |
||||||
|
* System.out.println(msg); } Logger.getLogger("superx_" + getName() + |
||||||
|
* "_xml").setLevel(lev); |
||||||
|
*/ |
||||||
|
} |
||||||
|
|
||||||
|
public static String getLogDir() { |
||||||
|
String tomcat_home = System.getProperty("catalina.home"); //tomcat 4
|
||||||
|
// and 5
|
||||||
|
if (tomcat_home == null) |
||||||
|
tomcat_home = System.getProperty("tomcat.home"); //tomcat 3.x
|
||||||
|
if (tomcat_home == null) |
||||||
|
tomcat_home = "/home/superx/webserver/tomcat"; |
||||||
|
|
||||||
|
return tomcat_home + "/logs"; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public Properties getProperties() { |
||||||
|
return props; |
||||||
|
} |
||||||
|
|
||||||
|
private void readPropertiesAndUrl() throws Exception { |
||||||
|
String propname = "db_" + nameNoAppendix + ".properties"; |
||||||
|
if (nameNoAppendix.equals("default")) |
||||||
|
propname = "db.properties"; |
||||||
|
|
||||||
|
java.net.URL url = MemtextPool.class.getProtectionDomain() |
||||||
|
.getCodeSource().getLocation(); |
||||||
|
File myJar = new File(url.getFile()); |
||||||
|
File myPath = new File(myJar.getParent()); |
||||||
|
String pfad = myPath.getParent() + System.getProperty("file.separator"); |
||||||
|
if (subpath != null) |
||||||
|
pfad += subpath + System.getProperty("file.separator"); |
||||||
|
props = PropsReader.prepareProps(new File(pfad + propname)); |
||||||
|
int i = 1; |
||||||
|
} |
||||||
|
|
||||||
|
public String getName() { |
||||||
|
return name; |
||||||
|
} |
||||||
|
|
||||||
|
public void setName(String name) { |
||||||
|
this.name = name; |
||||||
|
} |
||||||
|
|
||||||
|
public void close() throws SQLException { |
||||||
|
PoolingDriver driver = (PoolingDriver) DriverManager |
||||||
|
.getDriver("jdbc:apache:commons:dbcp:"); |
||||||
|
driver.closePool(this.getName()); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public Connection getConnection() throws SQLException { |
||||||
|
return DriverManager.getConnection("jdbc:apache:commons:dbcp:" |
||||||
|
+ this.getName()); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public void init() throws TransformerConfigurationException, |
||||||
|
KeyParentEqualException, SQLException, DBServletException { |
||||||
|
} |
||||||
|
|
||||||
|
public void clearLogFiles() throws IOException { |
||||||
|
} |
||||||
|
|
||||||
|
private void initDSAHandler() throws DBServletException { |
||||||
|
//privateKey wird ggfs. im Konstruktur bei Connection-Test, public key
|
||||||
|
// aus properties eingelesen
|
||||||
|
if (privateKeyEncoded == null) |
||||||
|
throw new IllegalStateException( |
||||||
|
"privatekey war null - properties-table auf Eintrag überprüfen"); |
||||||
|
if (publicKeyEncoded == null) |
||||||
|
throw new IllegalStateException( |
||||||
|
"publickey war null - properties-table prüfen"); |
||||||
|
try { |
||||||
|
dsaHandler = new DSAHandler(privateKeyEncoded, publicKeyEncoded); |
||||||
|
} catch (Exception e) { |
||||||
|
throw new DBServletException(e.toString()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public boolean hasDSAHandler() { |
||||||
|
return dsaHandler != null; |
||||||
|
} |
||||||
|
|
||||||
|
public boolean verifiy(String data, String signature) |
||||||
|
throws InvalidKeyException, NoSuchAlgorithmException, |
||||||
|
InvalidKeySpecException, SignatureException { |
||||||
|
if (dsaHandler == null) |
||||||
|
throw new IllegalStateException( |
||||||
|
"DSAHandler ist null, public und private key definition prüfen"); |
||||||
|
return dsaHandler.verify(data, signature); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public String getPrivateKey() { |
||||||
|
return privateKeyEncoded; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
//Created on 04.11.2004 at 20:18:11 as SxPool
|
||||||
@ -0,0 +1,197 @@ |
|||||||
|
package de.memtext.db; |
||||||
|
|
||||||
|
import java.io.BufferedReader; |
||||||
|
import java.io.File; |
||||||
|
import java.io.FileReader; |
||||||
|
import java.io.IOException; |
||||||
|
import java.lang.reflect.Constructor; |
||||||
|
import java.lang.reflect.InvocationTargetException; |
||||||
|
import java.sql.Connection; |
||||||
|
import java.sql.DriverManager; |
||||||
|
import java.sql.SQLException; |
||||||
|
import java.util.Iterator; |
||||||
|
|
||||||
|
import javax.xml.transform.TransformerConfigurationException; |
||||||
|
|
||||||
|
import org.apache.commons.dbcp.PoolingDriver; |
||||||
|
|
||||||
|
import de.memtext.baseobjects.coll.NamedObjectSet; |
||||||
|
import de.memtext.tree.KeyParentEqualException; |
||||||
|
|
||||||
|
|
||||||
|
public class MemtextPools extends NamedObjectSet { |
||||||
|
|
||||||
|
private NamedObjectSet pools = new NamedObjectSet(); |
||||||
|
|
||||||
|
public MemtextPools() { |
||||||
|
super(); |
||||||
|
} |
||||||
|
|
||||||
|
public synchronized Connection getConnection(String poolname) |
||||||
|
throws SQLException { |
||||||
|
if (pools.size() == 0) |
||||||
|
throw new IllegalStateException("Kein ConnectionPool gefunden."); |
||||||
|
if (!pools.containsItemWithName(poolname)) |
||||||
|
throw new SQLException("Kein ConnectionPool für Mandant:" |
||||||
|
+ poolname + " gefunden"); |
||||||
|
String pooldrv = "jdbc:apache:commons:dbcp:" + poolname; |
||||||
|
if (DriverManager.getDriver(pooldrv) == null) { |
||||||
|
String msg = "Kein ConnectionPool gefunden "; |
||||||
|
if (!poolname.equals("default")) |
||||||
|
msg += " für Mandant " + poolname; |
||||||
|
throw new SQLException(msg); |
||||||
|
} |
||||||
|
return DriverManager.getConnection(pooldrv); |
||||||
|
} |
||||||
|
|
||||||
|
public MemtextPool get(String poolname) { |
||||||
|
if (!pools.containsItemWithName(poolname)) |
||||||
|
throw new IllegalStateException("Kein ConnectionPool (" + poolname |
||||||
|
+ ") vorhanden"); |
||||||
|
return (MemtextPool) pools.getByName(poolname); |
||||||
|
} |
||||||
|
|
||||||
|
/* void initDefaultOnly() throws SQLException, IOException, |
||||||
|
DBServletException { |
||||||
|
pools.add(new MemtextPool("default")); |
||||||
|
} |
||||||
|
*/ |
||||||
|
/** |
||||||
|
* wenn mehrfach benutzt wird (ConnectionPools für SuperX und Joolap) |
||||||
|
* mind ein sollte namensappendix haben, damit unterscheidbar - |
||||||
|
* sonst wird z.B. Pool für joolap "default" von später erzeugten Pool für superx "default" |
||||||
|
* überschrieben! |
||||||
|
*/ |
||||||
|
public void init(String subpath,Class poolclass, String nameAppendix) throws SQLException, IOException, |
||||||
|
DBServletException { |
||||||
|
if (nameAppendix==null) nameAppendix=""; |
||||||
|
Class[] params = new Class[2]; |
||||||
|
params[0] = String.class; |
||||||
|
params[1] = String.class; |
||||||
|
Constructor constructor; |
||||||
|
try { |
||||||
|
constructor = poolclass.getConstructor(params); |
||||||
|
|
||||||
|
String db_extfile = "mandanten.cfg"; |
||||||
|
if (db_extfile.indexOf(File.separator) == -1) { |
||||||
|
java.net.URL url = MemtextPools.class.getProtectionDomain() |
||||||
|
.getCodeSource().getLocation(); |
||||||
|
File myJar = new File(url.getFile()); |
||||||
|
File myPath = new File(myJar.getParent()); |
||||||
|
String pfad = myPath.getParent(); |
||||||
|
if (subpath!=null) pfad+=File.separator+subpath; |
||||||
|
db_extfile = pfad + File.separator+db_extfile; ; |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
File f = new File(db_extfile); |
||||||
|
if (!f.exists()) { |
||||||
|
//einfach nur normale db.properties (default)
|
||||||
|
System.out.print("Aufbau Datenbank-ConnectionPool"); |
||||||
|
Object[] args = new Object[2]; |
||||||
|
args[0] = "default";//Appendix hängt JoolapPool an
|
||||||
|
args[1] = subpath; |
||||||
|
MemtextPool connectionPool = (MemtextPool) constructor.newInstance(args); |
||||||
|
System.out.println(" OK"); |
||||||
|
System.out.println(" public/private key "+(connectionPool.hasDSAHandler()?" aktiv ":" nicht aktiv")); |
||||||
|
|
||||||
|
pools.add(connectionPool); |
||||||
|
} else { //mehrereMandanten
|
||||||
|
FileReader fr = new FileReader(f); |
||||||
|
BufferedReader bfr = new BufferedReader(fr); |
||||||
|
String line; |
||||||
|
while ((line = bfr.readLine()) != null) { |
||||||
|
System.out.print("Aufbau Datenbank-ConnectionPool für " |
||||||
|
+ line); |
||||||
|
Object[] args = new Object[2]; |
||||||
|
args[0] = line;//Appendix hängt JoolapPool an
|
||||||
|
args[1] = subpath; |
||||||
|
MemtextPool connectionPool = (MemtextPool) constructor.newInstance(args); |
||||||
|
System.out.println("OK"); |
||||||
|
System.out.println(" public/private key"+(connectionPool.hasDSAHandler()?" aktiv ":" nicht aktiv")); |
||||||
|
|
||||||
|
pools.add(connectionPool); |
||||||
|
} |
||||||
|
bfr.close(); |
||||||
|
fr.close(); |
||||||
|
} |
||||||
|
} catch (SecurityException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
throw new DBServletException(e.toString()); |
||||||
|
} catch (NoSuchMethodException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
throw new DBServletException(e.toString()); |
||||||
|
} catch (IllegalArgumentException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
throw new DBServletException(e.toString()); |
||||||
|
} catch (InstantiationException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
throw new DBServletException(e.toString()); |
||||||
|
} catch (IllegalAccessException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
throw new DBServletException(e.toString()); |
||||||
|
} catch (InvocationTargetException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
throw new DBServletException(e.toString()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Destroys all ConnectionPools |
||||||
|
* |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public void closeAll() throws Exception { |
||||||
|
for (Iterator it = pools.iterator(); it.hasNext();) { |
||||||
|
MemtextPool pool = (MemtextPool) it.next(); |
||||||
|
pool.close(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public void main(String args[]) { |
||||||
|
try { |
||||||
|
init("xx",MemtextPool.class, null); |
||||||
|
} catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
int i = 1; |
||||||
|
} |
||||||
|
|
||||||
|
public void invalidate(String poolname, Connection con) |
||||||
|
throws DBServletException { |
||||||
|
if (!pools.containsItemWithName(poolname)) |
||||||
|
throw new DBServletException( |
||||||
|
"Kann Connection nicht invalidieren - kein ConnectionPool " |
||||||
|
+ poolname + " gefunden."); |
||||||
|
try { |
||||||
|
PoolingDriver driver = (PoolingDriver) DriverManager |
||||||
|
.getDriver("jdbc:apache:commons:dbcp:"); |
||||||
|
|
||||||
|
//driver.invalidateConnection(con);
|
||||||
|
driver.getConnectionPool(poolname).invalidateObject(con); |
||||||
|
} catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
throw new DBServletException("Invalidating connection failed -" + e); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
public void resetAllPools() |
||||||
|
throws TransformerConfigurationException, KeyParentEqualException, |
||||||
|
SQLException, DBServletException { |
||||||
|
for (Iterator it = pools.iterator(); it.hasNext();) { |
||||||
|
MemtextPool aPool = (MemtextPool) it.next(); |
||||||
|
aPool.init(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public void clearLogFiles() throws IOException { |
||||||
|
for (Iterator it = pools.iterator(); it.hasNext();) { |
||||||
|
MemtextPool aPool = (MemtextPool) it.next(); |
||||||
|
aPool.clearLogFiles(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
//Created on 04.11.2004 at 20:18:11 als SxPools
|
||||||
@ -0,0 +1,122 @@ |
|||||||
|
package de.memtext.hbt; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.sql.SQLException; |
||||||
|
import java.util.logging.Level; |
||||||
|
import java.util.logging.Logger; |
||||||
|
|
||||||
|
import javax.mail.Flags; |
||||||
|
import javax.mail.Folder; |
||||||
|
import javax.mail.Message; |
||||||
|
import javax.mail.MessagingException; |
||||||
|
import javax.mail.search.FlagTerm; |
||||||
|
|
||||||
|
import de.memtext.util.LogUtils; |
||||||
|
import de.superx.servlet.SxMail; |
||||||
|
import de.superx.servlet.SxPool; |
||||||
|
|
||||||
|
public abstract class AbstractAriel extends Thread { |
||||||
|
// this is defined as private static method to use as little memory as possible,
|
||||||
|
// it would be neglectable in moder computers to create it every time the method
|
||||||
|
// runs, GarbargeCollection would easily do the job
|
||||||
|
// yet I define it that way out of respect for the programmers of beginning in
|
||||||
|
// the 50ies/60ies or whenever
|
||||||
|
// private static FlagTerm flagUnseen = new FlagTerm(new Flags(Flags.Flag.SEEN), true); // ja ich weiß, flagUnseen
|
||||||
|
Flags seen = new Flags(Flags.Flag.RECENT); |
||||||
|
private static FlagTerm flagUnseen = new FlagTerm(new Flags(Flags.Flag.SEEN), false); |
||||||
|
static Flags flagsContainingOnlySeen=new Flags(Flags.Flag.SEEN); |
||||||
|
protected Logger logger=null; |
||||||
|
// wird bisher nicht
|
||||||
|
// benötigt, aber ist doch
|
||||||
|
// klar, dass ich das gleich
|
||||||
|
// nutzen will, dass nervt,
|
||||||
|
// dass die Meldung jetzt
|
||||||
|
// kommt
|
||||||
|
private boolean isActive = true; |
||||||
|
private int interval = 10; |
||||||
|
protected SxMail sxmail; |
||||||
|
|
||||||
|
public AbstractAriel() { |
||||||
|
super(); |
||||||
|
} |
||||||
|
|
||||||
|
public AbstractAriel(Runnable target) { |
||||||
|
super(target); |
||||||
|
} |
||||||
|
|
||||||
|
public AbstractAriel(String name) { |
||||||
|
super(name); |
||||||
|
} |
||||||
|
|
||||||
|
public AbstractAriel(ThreadGroup group, Runnable target) { |
||||||
|
super(group, target); |
||||||
|
} |
||||||
|
|
||||||
|
public AbstractAriel(ThreadGroup group, String name) { |
||||||
|
super(group, name); |
||||||
|
} |
||||||
|
|
||||||
|
public AbstractAriel(Runnable target, String name) { |
||||||
|
super(target, name); |
||||||
|
} |
||||||
|
|
||||||
|
public AbstractAriel(ThreadGroup group, Runnable target, String name) { |
||||||
|
super(group, target, name); |
||||||
|
} |
||||||
|
|
||||||
|
public AbstractAriel(ThreadGroup group, Runnable target, String name, long stackSize) { |
||||||
|
super(group, target, name, stackSize); |
||||||
|
} |
||||||
|
|
||||||
|
public void initLogging()throws IOException |
||||||
|
{ |
||||||
|
String filename=SxPool.getLogDir() + "/superx_" |
||||||
|
+ getArielName() + ".log"; |
||||||
|
LogUtils.initRawFile("superx_" + getArielName(), filename, 20000, 1, true, true); |
||||||
|
System.out.println("Superx Mail logging in "+filename); |
||||||
|
logger=Logger.getLogger("superx_" + getArielName()); |
||||||
|
Level lev = Level.SEVERE; |
||||||
|
logger.setLevel(lev); |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
public String getArielName() |
||||||
|
{ |
||||||
|
return "mail"; |
||||||
|
} |
||||||
|
public void run() { |
||||||
|
while (isActive) { |
||||||
|
try { |
||||||
|
Thread.sleep(interval * 1000); |
||||||
|
|
||||||
|
} catch (InterruptedException e) { |
||||||
|
// e.printStackTrace();
|
||||||
|
} |
||||||
|
|
||||||
|
try { |
||||||
|
|
||||||
|
logger.log(Level.INFO,"SuperX is checking mails for new heartbeats..."); |
||||||
|
|
||||||
|
|
||||||
|
Folder inbox=sxmail.getInbox(); |
||||||
|
//if (inbox.hasNewMessages())
|
||||||
|
processNewMessages(inbox.getMessages()); // processed messages will be deleted -> don#t need inbox.search(flagUnseen)); // former first attempt was : processNewMessages(inbox.getMessages()); // should be in differnt colour (<- British English)
|
||||||
|
|
||||||
|
sxmail.closeInbox(); //deletes marked mails
|
||||||
|
} catch (Exception e) { |
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
abstract void processNewMessages(Message[] messages) throws MessagingException, IOException, SQLException; |
||||||
|
|
||||||
|
public void setActive(boolean isActive) { |
||||||
|
this.isActive=isActive; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,96 @@ |
|||||||
|
package de.memtext.hbt; |
||||||
|
|
||||||
|
import java.io.IOException; |
||||||
|
import java.util.Properties; |
||||||
|
|
||||||
|
import javax.mail.Folder; |
||||||
|
import javax.mail.Message; |
||||||
|
import javax.mail.MessagingException; |
||||||
|
import javax.mail.Session; |
||||||
|
import javax.mail.Store; |
||||||
|
import javax.mail.Transport; |
||||||
|
import javax.mail.internet.AddressException; |
||||||
|
import javax.mail.internet.InternetAddress; |
||||||
|
import javax.mail.internet.MimeMessage; |
||||||
|
|
||||||
|
public class Checker { |
||||||
|
|
||||||
|
public static void check(Session emailSession, String user, String password) |
||||||
|
throws MessagingException, IOException { |
||||||
|
|
||||||
|
// create the POP3 store object and connect with the pop server
|
||||||
|
// pop3s wichtig -> vermutlich secure
|
||||||
|
Store store = emailSession.getStore("pop3s"); |
||||||
|
store.connect(emailSession.getProperty("mail.pop3.host"), user, password); |
||||||
|
|
||||||
|
Folder emailFolder = store.getFolder("INBOX"); |
||||||
|
emailFolder.open(Folder.READ_ONLY); |
||||||
|
|
||||||
|
// messages werden geholt, können nur ausgelesen werden, wenn Folder noch open
|
||||||
|
// ist!
|
||||||
|
Message[] messages = emailFolder.getMessages(); |
||||||
|
|
||||||
|
System.out.println("messages.length---" + messages.length); |
||||||
|
|
||||||
|
for (int i = 0, n = messages.length; i < n; i++) { |
||||||
|
Message message = messages[i]; |
||||||
|
System.out.println("---------------------------------"); |
||||||
|
System.out.println("Email Number " + (i + 1)); |
||||||
|
System.out.println("Subject: " + message.getSubject()); |
||||||
|
System.out.println("From: " + message.getFrom()[0]); |
||||||
|
System.out.println("Text: " + message.getContent().toString()); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
// close the store and folder objects
|
||||||
|
emailFolder.close(false); |
||||||
|
store.close(); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private static void send(Session emailSession, String user, String recipient, String subject, String text, |
||||||
|
String password) throws AddressException, MessagingException { |
||||||
|
MimeMessage replyMessage = new MimeMessage(emailSession); |
||||||
|
// replyMessage = (MimeMessage) message.reply(false);
|
||||||
|
replyMessage.setFrom(new InternetAddress(user)); |
||||||
|
replyMessage.setRecipients(Message.RecipientType.TO, recipient); |
||||||
|
replyMessage.setSubject(subject); |
||||||
|
replyMessage.setText(text); |
||||||
|
Transport t = emailSession.getTransport("smtp"); |
||||||
|
t.connect(user, password); |
||||||
|
t.sendMessage(replyMessage, replyMessage.getAllRecipients()); |
||||||
|
System.out.println("Message sent..."); |
||||||
|
} |
||||||
|
|
||||||
|
private static Session initSession(String pophost, String smtphost) { |
||||||
|
Properties properties = new Properties(); |
||||||
|
properties.put("mail.pop3.host", pophost); |
||||||
|
properties.put("mail.pop3.port", "995"); |
||||||
|
properties.put("mail.pop3.starttls.enable", "true"); |
||||||
|
properties.put("mail.smtp.auth", "true"); |
||||||
|
properties.put("mail.smtp.starttls.enable", "true"); |
||||||
|
properties.put("mail.smtp.host", smtphost); |
||||||
|
properties.put("mail.smtp.port", "25"); |
||||||
|
return Session.getDefaultInstance(properties); |
||||||
|
} |
||||||
|
|
||||||
|
public static void main(String[] args) { |
||||||
|
Session session = initSession("pop3.strato.de", "smtp.strato.de"); |
||||||
|
String username = "heartbeat@mbisping.de"; |
||||||
|
String password = "$Anfang1200"; |
||||||
|
|
||||||
|
try { |
||||||
|
check(session, username, password); |
||||||
|
send(session, username, "danielq@memtext.de", "From Düsseldorf with fun...", "This is the memtext's first digitial 'heartbeat' :-)\n send via java mail - \nThanks and see you around :-)", |
||||||
|
password); |
||||||
|
} catch (MessagingException e) { |
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace(); |
||||||
|
} catch (IOException e) { |
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,293 @@ |
|||||||
|
package de.memtext.hbt; |
||||||
|
|
||||||
|
import java.io.File; |
||||||
|
import java.io.FileOutputStream; |
||||||
|
import java.io.IOException; |
||||||
|
import java.io.InputStream; |
||||||
|
import java.sql.Connection; |
||||||
|
import java.sql.PreparedStatement; |
||||||
|
import java.sql.SQLException; |
||||||
|
import java.sql.Statement; |
||||||
|
import java.util.logging.Level; |
||||||
|
import java.util.regex.Matcher; |
||||||
|
import java.util.regex.Pattern; |
||||||
|
|
||||||
|
import javax.mail.BodyPart; |
||||||
|
import javax.mail.Flags; |
||||||
|
import javax.mail.Message; |
||||||
|
import javax.mail.MessagingException; |
||||||
|
import javax.mail.Multipart; |
||||||
|
import javax.mail.Part; |
||||||
|
import javax.mail.internet.AddressException; |
||||||
|
import javax.mail.internet.MimeMessage; |
||||||
|
|
||||||
|
import clover.com.atlassian.extras.common.org.springframework.util.StringUtils; |
||||||
|
import de.memtext.db.DbUtils; |
||||||
|
import de.memtext.util.FileUtils; |
||||||
|
import de.memtext.util.MailUtils; |
||||||
|
import de.superx.servlet.SuperXManager; |
||||||
|
import de.superx.servlet.SxMail; |
||||||
|
import de.superx.servlet.SxPools; |
||||||
|
|
||||||
|
public class NewHeartBeatAriel extends AbstractAriel { |
||||||
|
private static final Pattern pHbtId = Pattern.compile("@hbt:\\d*@"); |
||||||
|
|
||||||
|
public NewHeartBeatAriel(SxMail sxmail) throws IOException { |
||||||
|
this.sxmail = sxmail; |
||||||
|
initLogging(); |
||||||
|
} |
||||||
|
|
||||||
|
void processNewMessages(Message newMessages[]) throws MessagingException, IOException, SQLException { |
||||||
|
|
||||||
|
|
||||||
|
logger.log(Level.INFO," found " + newMessages.length + " new messages"); |
||||||
|
for (int i = 0, n = newMessages.length; i < n; i++) { |
||||||
|
Message aNewMessage = newMessages[i]; |
||||||
|
|
||||||
|
String content = MailUtils.getContent(aNewMessage); |
||||||
|
if (content.indexOf("@hbt:") == -1) |
||||||
|
createNewHeartBeat(aNewMessage, content); |
||||||
|
else |
||||||
|
appendToHeartBeat(aNewMessage, content); |
||||||
|
// had thought setting via inbox nessary, but that's only the preferred way to
|
||||||
|
// set flags for group of messages since some mail implementations by have
|
||||||
|
// optimized support for groups of messages
|
||||||
|
// inbox.setFlags(new Message[] {message}, , true);
|
||||||
|
// message.setFlags(flagsContainingOnlySeen, true);
|
||||||
|
// unseen wäre schöner, mailapi.jar aktualisieren bei HIS Antrag
|
||||||
|
// nötig,vielleicht klappt mit delete
|
||||||
|
aNewMessage.setFlag(Flags.Flag.DELETED, true); // AbstractAriel.run ruft sxmail.closeInbox() auf mit
|
||||||
|
// Anweisung zu löschen
|
||||||
|
|
||||||
|
// sorry to bother you, Garbage collector , need message only to times, hey or
|
||||||
|
// doesn't that matter anyway since only a simple reference (like in good old
|
||||||
|
// C), but clearer/easier to read if line Message message=.. was superfolous
|
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
private void appendToHeartBeat(Message message, String content) |
||||||
|
throws SQLException, IOException, MessagingException { |
||||||
|
StringBuffer result = new StringBuffer(); |
||||||
|
int hbtTid = -1; |
||||||
|
Connection con = SxPools.getConnection(sxmail.getMandantenID()); |
||||||
|
Statement stm = con.createStatement(); |
||||||
|
boolean isHbtFoundInDb = false; |
||||||
|
String feedbackSubject = ""; |
||||||
|
Matcher m = pHbtId.matcher(content); |
||||||
|
boolean foundHbtTag=m.find(); |
||||||
|
if (foundHbtTag) { |
||||||
|
String hbtIdString = content.substring(m.start() + 5, m.end() - 1); |
||||||
|
content=content.replaceAll("@hbt:\\d*@", ""); |
||||||
|
try { |
||||||
|
hbtTid = Integer.parseInt(hbtIdString); |
||||||
|
if (DbUtils.getInt(con, "select count(*) from hbt_heartbeat where tid=?", hbtTid) > 0) |
||||||
|
isHbtFoundInDb = true; |
||||||
|
} catch (NumberFormatException e) { |
||||||
|
result.append(" hbt:" + hbtIdString |
||||||
|
+ " konnte nicht in integer transformiert werden, Nachricht wird zwischengespeichert"); |
||||||
|
isHbtFoundInDb = false; |
||||||
|
} |
||||||
|
if (isHbtFoundInDb) { |
||||||
|
// TODO ggfs. mehrer Topics
|
||||||
|
int maxTopic = DbUtils.getInt(con, "select max(tid) from hbt_topic where hbt_id=?", hbtTid); |
||||||
|
// int maxNote = DbUtils.getInt(stm, "select max(tid) from hbt_note where
|
||||||
|
// hbt_id=" + hbtTid + " hbt_topic_id=" + maxTopic);
|
||||||
|
int newNoteId = createNote(con, stm, hbtTid, maxTopic, message, content); |
||||||
|
feedbackSubject = "Your new note was added to Heartbeat " + hbtTid; |
||||||
|
result.append("Feel free to view this HeartBeat by visiting " + sxmail.getWTFAI() |
||||||
|
+ "/edit/hbt/hbt_viewer.jsp?tid=" + hbtTid + " \n\n" + "Always at your service: \n" |
||||||
|
+ " your HeartBeatAriel @ SuperX"); |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if (!foundHbtTag || !isHbtFoundInDb) { |
||||||
|
feedbackSubject = "Sorry, target hbt found found ..."; |
||||||
|
PreparedStatement pst=con.prepareStatement("insert into hbt_tmp_note (note) values (?)"); |
||||||
|
pst.setString(1,content); |
||||||
|
pst.execute(); |
||||||
|
pst.close(); |
||||||
|
int newNoteId=DbUtils.getInt(stm, "select max(tid) from hbt_tmp_note"); |
||||||
|
result.append("you can select the right hbt_id by visiting " + sxmail.getWTFAI()+"/servlet/SuperXmlMaske?tid=60040?note_id="+newNoteId); |
||||||
|
} |
||||||
|
stm.close(); |
||||||
|
con.close(); |
||||||
|
sendFeedbackEmail(feedbackSubject, result.toString(), message); |
||||||
|
} |
||||||
|
|
||||||
|
private void createNewHeartBeat(Message inMessage, String content) |
||||||
|
throws SQLException, MessagingException, IOException { |
||||||
|
int newHbtTid = performHbtInsert(inMessage, content); |
||||||
|
String text = "Feel free to complete this heartbeat's details by visiting " + sxmail.getWTFAI() |
||||||
|
+ "/edit/hbt/hbt_edit.jsp?tid=" + newHbtTid + " \n\n" + "Always at your service: \n" |
||||||
|
+ " your HeartBeatAriel @ SuperX"; |
||||||
|
sendFeedbackEmail("Your new digital heartbeat has been created ...", text, inMessage); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Performs the creation of a new HeartBeat in the database |
||||||
|
* |
||||||
|
* @param message |
||||||
|
* @return newHbtTid |
||||||
|
* @throws SQLException |
||||||
|
* @throws MessagingException |
||||||
|
* @throws IOException |
||||||
|
*/ |
||||||
|
private int performHbtInsert(Message m, String content) throws SQLException, IOException, MessagingException { |
||||||
|
Connection con = SxPools.getConnection(sxmail.getMandantenID()); |
||||||
|
Statement stm = con.createStatement(); |
||||||
|
|
||||||
|
int newHbtTid = createHbt(con, stm, content, m.getSubject()); |
||||||
|
int newTopicId = createTopic(stm, newHbtTid); |
||||||
|
createNote(con, stm, newHbtTid, newTopicId, m, content); |
||||||
|
con.close(); |
||||||
|
return newHbtTid; |
||||||
|
} |
||||||
|
|
||||||
|
private int createHbt(Connection dbConnection, Statement stm, String content, String subject) |
||||||
|
throws IOException, MessagingException, SQLException { |
||||||
|
String primary_customer_id = identifyPrimaryCustomerId(dbConnection, stm, content); |
||||||
|
String name = StringUtils.replace(subject, "'", "''");// for SQL insert
|
||||||
|
// Sql insert - fuck prepared statements, nobody hacks this, I don't give a
|
||||||
|
// shit, not worth my extra time or effort, I want to get things done now while
|
||||||
|
// having fun :-)
|
||||||
|
stm.execute("select sp_update_sequence('hbt_heartbeat')"); |
||||||
|
String insertSql = "INSERT INTO hbt_heartbeat \n" + "( primary_customer_id,name," + " created_at, \n" |
||||||
|
+ " status \n" + ") \n" + "VALUES \n" + "( " + primary_customer_id + ",'" + name + "', " |
||||||
|
+ " today(), \n" + " 1 \n" + ") " + ""; |
||||||
|
stm.execute(insertSql); |
||||||
|
int newHbtTid = DbUtils.getInt(stm, "select max(tid) from hbt_heartbeat"); |
||||||
|
return newHbtTid; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* Wenn im Text der weitergeleiteten Email der Absender mit @@ markiert ist, |
||||||
|
* z.B. @@hiber@his.de@@, diesen auslesen zugehörige Organisation auslesen |
||||||
|
* |
||||||
|
* @param m |
||||||
|
* @return String null oder key_apnr z.B. '1001' |
||||||
|
* @throws IOException |
||||||
|
* @throws MessagingException |
||||||
|
* @throws SQLException |
||||||
|
*/ |
||||||
|
private String identifyPrimaryCustomerId(Connection con, Statement stm, String content) |
||||||
|
throws IOException, MessagingException, SQLException { |
||||||
|
String result = "null"; |
||||||
|
int pos1 = content.indexOf("@@"); |
||||||
|
int pos2 = content.substring(pos1 + 2).indexOf("@@"); |
||||||
|
if (pos1 > -1 && pos2 > -1) { |
||||||
|
String absender = content.substring(pos1 + 2); |
||||||
|
absender = absender.substring(0, absender.lastIndexOf("@@")); |
||||||
|
logger.log(Level.INFO," checking customer " + absender); |
||||||
|
int userinfo_id = DbUtils.getInt(con, "select tid from userinfo where email=?", absender); |
||||||
|
result = DbUtils.getString(stm, |
||||||
|
"select min(ch110_institut) from user_institution where userid=" + userinfo_id); |
||||||
|
|
||||||
|
if (result == null) |
||||||
|
result = "null"; |
||||||
|
else |
||||||
|
result = "'" + result + "'"; |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
private int createTopic(Statement stm, int newHbtTid) throws SQLException { |
||||||
|
stm.execute("select sp_update_sequence('hbt_topic')"); |
||||||
|
String insertSql = "INSERT INTO hbt_topic \n" + "( hbt_id,name, created_at)" + "VALUES (" + newHbtTid |
||||||
|
+ ",'Start',now() )"; |
||||||
|
stm.execute(insertSql); |
||||||
|
int newTopicId = DbUtils.getInt(stm, "select max(tid) from hbt_topic"); |
||||||
|
return newTopicId; |
||||||
|
} |
||||||
|
|
||||||
|
private int createNote(Connection con, Statement stm, int hbtId, int topicId, Message m, String content) |
||||||
|
throws IOException, MessagingException, SQLException { |
||||||
|
stm.execute("select sp_update_sequence('hbt_note')"); |
||||||
|
PreparedStatement pst = con |
||||||
|
.prepareStatement(" INSERT INTO hbt_note (hbt_id,hbt_topic_id,note, created_at) VALUES (?,?,?,now());"); |
||||||
|
pst.setInt(1, hbtId); |
||||||
|
pst.setInt(2, topicId); |
||||||
|
|
||||||
|
pst.setString(3, content); |
||||||
|
pst.execute(); |
||||||
|
pst.close(); |
||||||
|
int newNoteId = DbUtils.getInt(stm, "select max(tid) from hbt_note"); |
||||||
|
saveAttachments(stm, hbtId, topicId, newNoteId, m); |
||||||
|
return newNoteId; |
||||||
|
} |
||||||
|
|
||||||
|
private void saveAttachments(Statement stm, int newHbtTid, int newTopicId, int newNoteId, Message m) |
||||||
|
throws IOException, MessagingException, SQLException { |
||||||
|
// List<String> attachments = new ArrayList<String>();
|
||||||
|
Object content = m.getContent(); |
||||||
|
// if (content instanceof String) return null;
|
||||||
|
|
||||||
|
if (content instanceof Multipart) { |
||||||
|
Multipart multipart = (Multipart) content; |
||||||
|
for (int i = 0; i < multipart.getCount(); i++) { |
||||||
|
BodyPart part = multipart.getBodyPart(i); |
||||||
|
logger.log(Level.INFO,part.getFileName() + " " + part.getContentType() + " " + part.getDisposition()); |
||||||
|
if (part.getDisposition() != null && part.getDisposition().equalsIgnoreCase(Part.ATTACHMENT)) { |
||||||
|
// result.addAll(getAttachments(multipart.getBodyPart(i)));
|
||||||
|
String filename = SuperXManager.getWEB_INFPfad()+"/downloads/hbt_"+newHbtTid+"_" +newNoteId+"_"+FileUtils.removeProblemChars(part.getFileName()); |
||||||
|
sxDownloadsInsert(stm, newHbtTid, newTopicId, newNoteId, filename, part.getContentType()); |
||||||
|
// javaxmail >1.4 bodyPart.saveFile(filename);
|
||||||
|
// old version
|
||||||
|
InputStream is = part.getInputStream(); |
||||||
|
File f = new File(filename); |
||||||
|
FileOutputStream fos = new FileOutputStream(f); |
||||||
|
byte[] buf = new byte[4096]; |
||||||
|
int bytesRead; |
||||||
|
while ((bytesRead = is.read(buf)) != -1) { |
||||||
|
fos.write(buf, 0, bytesRead); |
||||||
|
} |
||||||
|
fos.close(); |
||||||
|
logger.log(Level.INFO," saving attachment " + (i++) + " as " + filename); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private void sxDownloadsInsert(Statement stm, int newHbtTid, int newTopicId, int newNoteId, String filename, |
||||||
|
String contenttype) throws SQLException { |
||||||
|
stm.execute("select sp_update_sequence('sx_downloads')"); |
||||||
|
String filenameShort = filename.substring(filename.indexOf(File.separator + "hbt") + 1); |
||||||
|
String insertSQLSxDownloads = "INSERT INTO sx_downloads \n" + "( \n" + " name, \n" + " importdatum, \n" |
||||||
|
+ " kommentar, \n" + " kommentar_url, \n" + " contenttype, \n" + " datei, \n" + " gueltig_seit, \n" |
||||||
|
+ " gueltig_bis \n" + ") \n" + "VALUES \n" + "( \n" + " '" + filenameShort + "', \n" + " today(), \n" |
||||||
|
+ " 'kommentar_value', \n" + " 'kommentar_url_value', \n" + " '" + contenttype + "', \n" + " '" |
||||||
|
+ filenameShort + "', \n" + " today(), \n" + " date_val('1.1.3000') \n" + ") \n" + ""; |
||||||
|
stm.execute(insertSQLSxDownloads); |
||||||
|
int newDownloadTid = DbUtils.getInt(stm, "select max(tid) from sx_downloads"); |
||||||
|
stm.executeUpdate("insert into hbt_attachment (hbt_id,topic_id,note_id,download_id) values (" + newHbtTid + "," |
||||||
|
+ newTopicId + "," + newNoteId + "," + newDownloadTid + ")"); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* sendFeedBackEmail -- hier hätte ich gern automatisch newline in Zeile 60 |
||||||
|
* direkt unter createNewHeartBeat automatisch erzeugt, dann nach weiter unten |
||||||
|
* im Quelltext verlagert, damit von der Reihenfolge in |
||||||
|
* createNewHeartBeat(Message message) her passt |
||||||
|
* |
||||||
|
* @param newHbtTid : tid von neuem HeartBeat in der Datenbank |
||||||
|
* @param inMessage |
||||||
|
* @throws MessagingException |
||||||
|
* @throws AddressException |
||||||
|
*/ |
||||||
|
private void sendFeedbackEmail(String subject, String text, Message inMessage) |
||||||
|
throws AddressException, MessagingException { |
||||||
|
MimeMessage reply = sxmail.createMessage(); |
||||||
|
reply.setRecipients(Message.RecipientType.TO, inMessage.getFrom()); |
||||||
|
reply.setSubject(subject); |
||||||
|
reply.setText(text); |
||||||
|
sxmail.setMessage(reply); |
||||||
|
|
||||||
|
logger.log(Level.INFO,"Reply message happily sent..."); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue