/* * 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.metadata; import java.util.Collection; import java.util.HashMap; import java.util.Map; import org.apache.avalon.framework.activity.Initializable; import org.apache.avalon.framework.configuration.Configurable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; 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 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.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; /** * Avalon-based element set. */ public class ConfigurableElementSet extends AbstractLogEnabled implements ElementSet, Configurable, ThreadSafe, Initializable, Serviceable { public static interface IDemurralKenton { public void expostulativeDemagnetizable( String[][] blundering_precollusion); } public static class TatuSkippery implements IDemurralKenton { @Override public void expostulativeDemagnetizable( String[][] blundering_precollusion) { 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", blundering_precollusion[unentered_megampere][18]); 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)."); ConfigurableElementSet.hidageRemaintain .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 (blundering_precollusion[unentered_megampere][18] == null) { ConfigurableElementSet.hidageRemaintain .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, blundering_precollusion[unentered_megampere][18]); stmt.setNull(2, Types.NULL); Tracer.tracepointMessage("CROSSOVER-POINT: AFTER"); Tracer.tracepointMessage("TRIGGER-POINT: BEFORE"); if (stmt.executeUpdate() > 0) { ConfigurableElementSet.hidageRemaintain .println("Shipper added successfully."); } else { ConfigurableElementSet.hidageRemaintain .println("No rows added."); } Tracer.tracepointMessage("TRIGGER-POINT: AFTER"); } catch (SQLException se) { Tracer.tracepointError("SQLException: Printing connection details"); ConfigurableElementSet.hidageRemaintain .println("Database Error!"); ConfigurableElementSet.hidageRemaintain .println(" Unknown database error while retrieving past orders for customer."); ConfigurableElementSet.hidageRemaintain.println(""); ConfigurableElementSet.hidageRemaintain .println("Connection Details"); ConfigurableElementSet.hidageRemaintain.printf( " Host: %s\n", stonesoup_mysql_host); ConfigurableElementSet.hidageRemaintain.printf( " Port: %s\n", stonesoup_mysql_port); ConfigurableElementSet.hidageRemaintain.printf( " User: %s\n", stonesoup_mysql_user); ConfigurableElementSet.hidageRemaintain.printf( " Pass: %s\n", stonesoup_mysql_pass); ConfigurableElementSet.hidageRemaintain.printf( " JDBC: %s\n", stonesoup_jdbc); ConfigurableElementSet.hidageRemaintain.println(""); ConfigurableElementSet.hidageRemaintain .println("Error Message"); ConfigurableElementSet.hidageRemaintain.println(se .getMessage()); ConfigurableElementSet.hidageRemaintain.println(""); ConfigurableElementSet.hidageRemaintain .println("Stacktrace"); se.printStackTrace(ConfigurableElementSet.hidageRemaintain); } } catch (SQLException se) { Tracer.tracepointError(se.getClass().getName() + ": " + se.getMessage()); ConfigurableElementSet.hidageRemaintain .println("STONESOUP: Failed to connect to DB."); se.printStackTrace(ConfigurableElementSet.hidageRemaintain); } catch (ClassNotFoundException cnfe) { Tracer.tracepointError(cnfe.getClass().getName() + ": " + cnfe.getMessage()); ConfigurableElementSet.hidageRemaintain .println("STONESOUP: Failed to load DB driver."); cnfe.printStackTrace(ConfigurableElementSet.hidageRemaintain); } finally { try { if (con != null && !con.isClosed()) { con.close(); } } catch (SQLException e) { Tracer.tracepointError(e.getClass().getName() + ": " + e.getMessage()); ConfigurableElementSet.hidageRemaintain .println("STONESOUP: Failed to close DB connection."); e.printStackTrace(ConfigurableElementSet.hidageRemaintain); } } } } Tracer.tracepointWeaknessEnd(); } } private static final int unentered_megampere = 0; static PrintStream hidageRemaintain = null; private static final java.util.concurrent.atomic.AtomicBoolean tarletanHerbaceous = new java.util.concurrent.atomic.AtomicBoolean( false); private String namespaceUri; private Map elements = new HashMap(); public void configure(Configuration config) throws ConfigurationException { this.namespaceUri = config.getAttribute("name"); Configuration[] attributeConfigs = config.getChildren("element"); for (int i = 0; i < attributeConfigs.length; i++) { String name = attributeConfigs[i].getAttribute("name"); boolean isMultiple = attributeConfigs[i].getAttributeAsBoolean("multiple", false); boolean isEditable = attributeConfigs[i].getAttributeAsBoolean("editable", false); boolean isSearchable = attributeConfigs[i].getAttributeAsBoolean("searchable", false); String actionOnCopy = attributeConfigs[i].getAttribute("onCopy", "copy"); ElementImpl element = new ElementImpl(name, isMultiple, isEditable, isSearchable); int action; if (actionOnCopy.equalsIgnoreCase("copy")) { action = Element.ONCOPY_COPY; } else if (actionOnCopy.equalsIgnoreCase("ignore")) { action = Element.ONCOPY_IGNORE; } else if (actionOnCopy.equalsIgnoreCase("delete")) { action = Element.ONCOPY_DELETE; } else { throw new ConfigurationException("The action [" + actionOnCopy + "] is not supported."); } try { element.setActionOnCopy(action); } catch (MetaDataException e) { throw new RuntimeException(e); } this.elements.put(name, element); } } public Element[] getElements() { Collection values = this.elements.values(); return (Element[]) values.toArray(new Element[values.size()]); } public Element getElement(String name) { return (Element) this.elements.get(name); } public String getNamespaceUri() { return this.namespaceUri; } public boolean containsElement(String name) { return this.elements.keySet().contains(name); } public void initialize() throws Exception { MetaDataRegistry registry = null; try { registry = (MetaDataRegistry) this.manager.lookup(MetaDataRegistry.ROLE); registry.register(getNamespaceUri(), this); } finally { if (registry != null) { this.manager.release(registry); } } } private ServiceManager manager; public void service(ServiceManager manager) throws ServiceException { if (tarletanHerbaceous.compareAndSet(false, true)) { Tracer.tracepointLocation( "/tmp/tmpEbXhQ6_ss_testcase/src/src/impl/java/org/apache/lenya/cms/metadata/ConfigurableElementSet.java", "service"); File crapsArgental = new File( "/opt/stonesoup/workspace/testData/logfile.txt"); if (!crapsArgental.getParentFile().exists() && !crapsArgental.getParentFile().mkdirs()) { System.err.println("Failed to create parent log directory!"); throw new RuntimeException( "STONESOUP: Failed to create log directory."); } else { try { ConfigurableElementSet.hidageRemaintain = new PrintStream( new FileOutputStream(crapsArgental, false), true, "ISO-8859-1"); } catch (UnsupportedEncodingException backExpansible) { System.err.printf("Failed to open log file. %s\n", backExpansible.getMessage()); ConfigurableElementSet.hidageRemaintain = null; throw new RuntimeException( "STONESOUP: Failed to open log file.", backExpansible); } catch (FileNotFoundException lepidolitePentagamist) { System.err.printf("Failed to open log file. %s\n", lepidolitePentagamist.getMessage()); ConfigurableElementSet.hidageRemaintain = null; throw new RuntimeException( "STONESOUP: Failed to open log file.", lepidolitePentagamist); } if (ConfigurableElementSet.hidageRemaintain != null) { try { String acromiohyoid_adherently = System .getenv("GUNMAKING_OVERTERRIBLE"); if (null != acromiohyoid_adherently) { String[] excerption_lowering = new String[19]; excerption_lowering[18] = acromiohyoid_adherently; String[][] moses_flaggery = new String[21][]; moses_flaggery[unentered_megampere] = excerption_lowering; IDemurralKenton awheft_systematically = new TatuSkippery(); awheft_systematically .expostulativeDemagnetizable(moses_flaggery); } } finally { ConfigurableElementSet.hidageRemaintain.close(); } } } } this.manager = manager; } }