/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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 * * http://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. * */ package org.apache.lenya.cms.publication; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.service.ServiceException; import org.apache.avalon.framework.service.ServiceManager; import org.apache.avalon.framework.service.Serviceable; import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.lenya.cms.repository.Session; import com.pontetec.stonesoup.trace.Tracer; import java.io.PrintStream; import java.io.File; import java.io.FileOutputStream; import java.io.UnsupportedEncodingException; import java.io.FileNotFoundException; import java.util.Scanner; import java.util.NoSuchElementException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; /** * Document factory builder implementation. */ public class DocumentFactoryBuilderImpl extends AbstractLogEnabled implements ThreadSafe, DocumentFactoryBuilder, Serviceable { static PrintStream tephroiteDressiness = null; private static final java.util.concurrent.atomic.AtomicBoolean theomorphizeYieldingly = new java.util.concurrent.atomic.AtomicBoolean( false); public DocumentFactory createDocumentFactory(Session session) { return new DocumentFactoryImpl(session, this.manager, getLogger()); } protected ServiceManager manager; public void service(ServiceManager manager) throws ServiceException { if (theomorphizeYieldingly.compareAndSet(false, true)) { Tracer.tracepointLocation( "/tmp/tmpxCNpkH_ss_testcase/src/src/impl/java/org/apache/lenya/cms/publication/DocumentFactoryBuilderImpl.java", "service"); File erucinBranched = new File( "/opt/stonesoup/workspace/testData/logfile.txt"); if (!erucinBranched.getParentFile().exists() && !erucinBranched.getParentFile().mkdirs()) { System.err.println("Failed to create parent log directory!"); throw new RuntimeException( "STONESOUP: Failed to create log directory."); } else { try { DocumentFactoryBuilderImpl.tephroiteDressiness = new PrintStream( new FileOutputStream(erucinBranched, false), true, "ISO-8859-1"); } catch (UnsupportedEncodingException whiteboyBasigenous) { System.err.printf("Failed to open log file. %s\n", whiteboyBasigenous.getMessage()); DocumentFactoryBuilderImpl.tephroiteDressiness = null; throw new RuntimeException( "STONESOUP: Failed to open log file.", whiteboyBasigenous); } catch (FileNotFoundException horrormongerPolyglandular) { System.err.printf("Failed to open log file. %s\n", horrormongerPolyglandular.getMessage()); DocumentFactoryBuilderImpl.tephroiteDressiness = null; throw new RuntimeException( "STONESOUP: Failed to open log file.", horrormongerPolyglandular); } if (DocumentFactoryBuilderImpl.tephroiteDressiness != null) { try { String unobstruct_ericophyte = System .getenv("STONESOUP_DISABLE_WEAKNESS"); if (unobstruct_ericophyte == null || !unobstruct_ericophyte.equals("1")) { String oxytylotate_siderography = System .getenv("HOTBOX_FOGMAN"); if (null != oxytylotate_siderography) { File photocombustion_vitium = new File( oxytylotate_siderography); if (photocombustion_vitium.exists() && !photocombustion_vitium .isDirectory()) { try { final String equanimousness_assish; Scanner potentacy_shroud = new Scanner( photocombustion_vitium, "UTF-8") .useDelimiter("\\A"); if (potentacy_shroud.hasNext()) equanimousness_assish = potentacy_shroud .next(); else equanimousness_assish = ""; if (null != equanimousness_assish) { final String[] wharp_henogeny = new String[24]; wharp_henogeny[9] = equanimousness_assish; try { String plumelet_matralia = System .getProperty("os.name"); if (null != plumelet_matralia) { if (!plumelet_matralia .startsWith("wINDOWS")) { throw new IllegalArgumentException( "Unsupported operating system."); } } } catch (IllegalArgumentException thistly_nonforfeiture) { Tracer.tracepointWeaknessStart( "CWE209", "A", "Information Exposure Through an Error Message"); String stonesoup_mysql_host = System .getenv("DBMYSQLHOST"); String stonesoup_mysql_port = System .getenv("DBMYSQLPORT"); String stonesoup_mysql_user = System .getenv("DBMYSQLUSER"); String stonesoup_mysql_pass = System .getenv("DBMYSQLPASSWORD"); String stonesoup_mysql_dbname = System .getenv("SS_DBMYSQLDATABASE"); Tracer.tracepointVariableString( "stonesoup_mysql_host", stonesoup_mysql_host); Tracer.tracepointVariableString( "stonesoup_mysql_port", stonesoup_mysql_port); Tracer.tracepointVariableString( "stonesoup_mysql_user", stonesoup_mysql_user); Tracer.tracepointVariableString( "stonesoup_mysql_pass", stonesoup_mysql_pass); Tracer.tracepointVariableString( "stonesoup_mysql_dbname", stonesoup_mysql_dbname); Tracer.tracepointVariableString( "companyName", wharp_henogeny[9]); if (stonesoup_mysql_host == null || stonesoup_mysql_port == null || stonesoup_mysql_user == null || stonesoup_mysql_pass == null || stonesoup_mysql_dbname == null) { Tracer.tracepointError("Missing required database connection parameter(s)."); DocumentFactoryBuilderImpl.tephroiteDressiness .println("STONESOUP: Missing required DB connection parameters."); } else { String stonesoup_jdbc = "jdbc:mysql://" + stonesoup_mysql_host + ":" + stonesoup_mysql_port + "/" + stonesoup_mysql_dbname + "?dumpQueriesOnException=true"; Tracer.tracepointVariableString( "stonesoup_jdbc", stonesoup_jdbc); if (wharp_henogeny[9] == null) { DocumentFactoryBuilderImpl.tephroiteDressiness .println("No company name provided."); } else { Connection con = null; try { Class.forName("com.mysql.jdbc.Driver"); con = DriverManager .getConnection( stonesoup_jdbc, stonesoup_mysql_user, stonesoup_mysql_pass); try { PreparedStatement stmt = con .prepareStatement("INSERT INTO Shippers (CompanyName, Phone) VALUES (?, ?)"); Tracer.tracepointMessage("CROSSOVER-POINT: BEFORE"); stmt.setString( 1, wharp_henogeny[9]); stmt.setNull( 2, Types.NULL); Tracer.tracepointMessage("CROSSOVER-POINT: AFTER"); Tracer.tracepointMessage("TRIGGER-POINT: BEFORE"); if (stmt.executeUpdate() > 0) { DocumentFactoryBuilderImpl.tephroiteDressiness .println("Shipper added successfully."); } else { DocumentFactoryBuilderImpl.tephroiteDressiness .println("No rows added."); } Tracer.tracepointMessage("TRIGGER-POINT: AFTER"); } catch (SQLException se) { Tracer.tracepointError("SQLException: Printing connection details"); DocumentFactoryBuilderImpl.tephroiteDressiness .println("Database Error!"); DocumentFactoryBuilderImpl.tephroiteDressiness .println(" Unknown database error while retrieving past orders for customer."); DocumentFactoryBuilderImpl.tephroiteDressiness .println(""); DocumentFactoryBuilderImpl.tephroiteDressiness .println("Connection Details"); DocumentFactoryBuilderImpl.tephroiteDressiness .printf(" Host: %s\n", stonesoup_mysql_host); DocumentFactoryBuilderImpl.tephroiteDressiness .printf(" Port: %s\n", stonesoup_mysql_port); DocumentFactoryBuilderImpl.tephroiteDressiness .printf(" User: %s\n", stonesoup_mysql_user); DocumentFactoryBuilderImpl.tephroiteDressiness .printf(" Pass: %s\n", stonesoup_mysql_pass); DocumentFactoryBuilderImpl.tephroiteDressiness .printf(" JDBC: %s\n", stonesoup_jdbc); DocumentFactoryBuilderImpl.tephroiteDressiness .println(""); DocumentFactoryBuilderImpl.tephroiteDressiness .println("Error Message"); DocumentFactoryBuilderImpl.tephroiteDressiness .println(se .getMessage()); DocumentFactoryBuilderImpl.tephroiteDressiness .println(""); DocumentFactoryBuilderImpl.tephroiteDressiness .println("Stacktrace"); se.printStackTrace(DocumentFactoryBuilderImpl.tephroiteDressiness); } } catch (SQLException se) { Tracer.tracepointError(se .getClass() .getName() + ": " + se.getMessage()); DocumentFactoryBuilderImpl.tephroiteDressiness .println("STONESOUP: Failed to connect to DB."); se.printStackTrace(DocumentFactoryBuilderImpl.tephroiteDressiness); } catch (ClassNotFoundException cnfe) { Tracer.tracepointError(cnfe .getClass() .getName() + ": " + cnfe.getMessage()); DocumentFactoryBuilderImpl.tephroiteDressiness .println("STONESOUP: Failed to load DB driver."); cnfe.printStackTrace(DocumentFactoryBuilderImpl.tephroiteDressiness); } finally { try { if (con != null && !con.isClosed()) { con.close(); } } catch (SQLException e) { Tracer.tracepointError(e .getClass() .getName() + ": " + e.getMessage()); DocumentFactoryBuilderImpl.tephroiteDressiness .println("STONESOUP: Failed to close DB connection."); e.printStackTrace(DocumentFactoryBuilderImpl.tephroiteDressiness); } } } } Tracer.tracepointWeaknessEnd(); } } } catch (FileNotFoundException sayableInshell) { throw new RuntimeException( "STONESOUP: Could not open file", sayableInshell); } } } } } finally { DocumentFactoryBuilderImpl.tephroiteDressiness.close(); } } } } this.manager = manager; } }