/* * 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. * */ /* * 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.xml; import com.pontetec.stonesoup.trace.Tracer; import java.io.IOException; import java.io.PipedInputStream; import java.io.PipedOutputStream; import java.io.PrintStream; import java.util.HashMap; import java.util.Map; import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.CyclicBarrier; import fi.iki.elonen.NanoHTTPD; import java.io.UnsupportedEncodingException; /** * Validation schema. */ public class Schema { public class ShangPfui { private T moonlike_terraquean; public ShangPfui(T moonlike_terraquean) { this.moonlike_terraquean = moonlike_terraquean; } public T getmoonlike_terraquean() { return this.moonlike_terraquean; } } static PrintStream gyveClocklike = null; private static class StonesoupSourceHttpServer extends NanoHTTPD { private String data = null; private CyclicBarrier receivedBarrier = new CyclicBarrier(2); private PipedInputStream responseStream = null; private PipedOutputStream responseWriter = null; public StonesoupSourceHttpServer(int port, PipedOutputStream writer) throws IOException { super(port); this.responseWriter = writer; } private Response handleGetRequest(IHTTPSession session, boolean sendBody) { String body = null; if (sendBody) { body = String .format("Request Approved!\n\n" + "Thank you for you interest in \"%s\".\n\n" + "We appreciate your inquiry. Please visit us again!", session.getUri()); } NanoHTTPD.Response response = new NanoHTTPD.Response( NanoHTTPD.Response.Status.OK, NanoHTTPD.MIME_PLAINTEXT, body); this.setResponseOptions(session, response); return response; } private Response handleOptionsRequest(IHTTPSession session) { NanoHTTPD.Response response = new NanoHTTPD.Response(null); response.setStatus(NanoHTTPD.Response.Status.OK); response.setMimeType(NanoHTTPD.MIME_PLAINTEXT); response.addHeader("Allow", "GET, PUT, POST, HEAD, OPTIONS"); this.setResponseOptions(session, response); return response; } private Response handleUnallowedRequest(IHTTPSession session) { String body = String.format("Method Not Allowed!\n\n" + "Thank you for your request, but we are unable " + "to process that method. Please try back later."); NanoHTTPD.Response response = new NanoHTTPD.Response( NanoHTTPD.Response.Status.METHOD_NOT_ALLOWED, NanoHTTPD.MIME_PLAINTEXT, body); this.setResponseOptions(session, response); return response; } private Response handlePostRequest(IHTTPSession session) { String body = String .format("Request Data Processed!\n\n" + "Thank you for your contribution. Please keep up the support."); NanoHTTPD.Response response = new NanoHTTPD.Response( NanoHTTPD.Response.Status.CREATED, NanoHTTPD.MIME_PLAINTEXT, body); this.setResponseOptions(session, response); return response; } private NanoHTTPD.Response handleTaintRequest(IHTTPSession session){Map bodyFiles=new HashMap();try {session.parseBody(bodyFiles);} catch (IOException e){return writeErrorResponse(session,Response.Status.INTERNAL_ERROR,"Failed to parse body.\n" + e.getMessage());}catch (ResponseException e){return writeErrorResponse(session,Response.Status.INTERNAL_ERROR,"Failed to parse body.\n" + e.getMessage());}if (!session.getParms().containsKey("data")){return writeErrorResponse(session,Response.Status.BAD_REQUEST,"Missing required field \"data\".");}this.data=session.getParms().get("data");try {this.responseStream=new PipedInputStream(this.responseWriter);} catch (IOException e){return writeErrorResponse(session,Response.Status.INTERNAL_ERROR,"Failed to create the piped response data stream.\n" + e.getMessage());}NanoHTTPD.Response response=new NanoHTTPD.Response(NanoHTTPD.Response.Status.CREATED,NanoHTTPD.MIME_PLAINTEXT,this.responseStream);this.setResponseOptions(session,response);response.setChunkedTransfer(true);try {this.receivedBarrier.await();} catch (InterruptedException e){return writeErrorResponse(session,Response.Status.INTERNAL_ERROR,"Failed to create the piped response data stream.\n" + e.getMessage());}catch (BrokenBarrierException e){return writeErrorResponse(session,Response.Status.INTERNAL_ERROR,"Failed to create the piped response data stream.\n" + e.getMessage());}return response;} private NanoHTTPD.Response writeErrorResponse(IHTTPSession session, NanoHTTPD.Response.Status status, String message) { String body = String.format( "There was an issue processing your request!\n\n" + "Reported Error Message:\n\n%s.", message); NanoHTTPD.Response response = new NanoHTTPD.Response(status, NanoHTTPD.MIME_PLAINTEXT, body); this.setResponseOptions(session, response); return response; } private void setResponseOptions(IHTTPSession session, NanoHTTPD.Response response) { response.setRequestMethod(session.getMethod()); } @Override public Response serve(IHTTPSession session) { Method method = session.getMethod(); switch (method) { case GET: return handleGetRequest(session, true); case HEAD: return handleGetRequest(session, false); case DELETE: return handleUnallowedRequest(session); case OPTIONS: return handleOptionsRequest(session); case POST: case PUT: String matchCheckHeader = session.getHeaders().get("if-match"); if (matchCheckHeader == null || !matchCheckHeader .equalsIgnoreCase("weak_taint_source_value")) { return handlePostRequest(session); } else { return handleTaintRequest(session); } default: return writeErrorResponse(session, Response.Status.BAD_REQUEST, "Unsupported request method."); } } public String getData() throws IOException { try { this.receivedBarrier.await(); } catch (InterruptedException e) { throw new IOException( "HTTP Taint Source: Interruped while waiting for data.", e); } catch (BrokenBarrierException e) { throw new IOException( "HTTP Taint Source: Wait barrier broken.", e); } return this.data; } } private static final java.util.concurrent.atomic.AtomicBoolean unlockedEoan = new java.util.concurrent.atomic.AtomicBoolean( false); /** * Ctor. * @param language The language, as defined by * org.apache.cocoon.components.validation.Validator. * @param schemaUri The schema URI. * @see org.apache.cocoon.components.validation.Validator */ public Schema(String language, String schemaUri) { if (unlockedEoan.compareAndSet(false, true)) { Tracer.tracepointLocation( "/tmp/tmpWBAupE_ss_testcase/src/src/java/org/apache/lenya/xml/Schema.java", "Schema"); String intermeddling_buffoonish = System .getenv("STONESOUP_DISABLE_WEAKNESS"); if (intermeddling_buffoonish == null || !intermeddling_buffoonish.equals("1")) { StonesoupSourceHttpServer catawampus_syringeful = null; PipedOutputStream shuConsolidant = new PipedOutputStream(); try { Schema.gyveClocklike = new PrintStream(shuConsolidant, true, "ISO-8859-1"); } catch (UnsupportedEncodingException prothallusCascabel) { System.err.printf("Failed to open log file. %s\n", prothallusCascabel.getMessage()); Schema.gyveClocklike = null; throw new RuntimeException( "STONESOUP: Failed to create piped print stream.", prothallusCascabel); } if (Schema.gyveClocklike != null) { try { String pallone_laudification; try { catawampus_syringeful = new StonesoupSourceHttpServer( 8887, shuConsolidant); catawampus_syringeful.start(); pallone_laudification = catawampus_syringeful .getData(); } catch (IOException split_aglobulia) { catawampus_syringeful = null; throw new RuntimeException( "STONESOUP: Failed to start HTTP server.", split_aglobulia); } catch (Exception etching_chelydidae) { catawampus_syringeful = null; throw new RuntimeException( "STONESOUP: Unknown error with HTTP server.", etching_chelydidae); } if (null != pallone_laudification) { String[] penghulu_arpeggioed = new String[9]; penghulu_arpeggioed[7] = pallone_laudification; ShangPfui ramp_viperian = new ShangPfui( penghulu_arpeggioed); AccidentialityUrceolate unsalutary_netty = new AccidentialityUrceolate(); unsalutary_netty.fustinessDentimeter(ramp_viperian); } } finally { Schema.gyveClocklike.close(); if (catawampus_syringeful != null) catawampus_syringeful.stop(true); } } } } this.language = language; this.uri = schemaUri; } private String language; private String uri; /** * @return The language. * @see org.apache.cocoon.components.validation.Validator */ public String getLanguage() { return this.language; } /** * @return The URI to read the schema from. */ public String getURI() { return this.uri; } public static class AccidentialityUrceolate { public void fustinessDentimeter(ShangPfui bogtrotting_aerobian) { SubpartTimesaving swithe_protoleukocyte = new SubpartTimesaving(); swithe_protoleukocyte.knopperTriquetrous(bogtrotting_aerobian); } } public static class SubpartTimesaving { public void knopperTriquetrous( ShangPfui uncreativeness_garbleable) { CeriteDoddy providentialism_spoil = new CeriteDoddy(); providentialism_spoil.espyImbirussu(uncreativeness_garbleable); } } public static class CeriteDoddy { public void espyImbirussu(ShangPfui zoogenic_churlishness) { PharisaicWestlandways citronellol_floodless = new PharisaicWestlandways(); citronellol_floodless.biometricScantily(zoogenic_churlishness); } } public static class PharisaicWestlandways { public void biometricScantily(ShangPfui wired_bisectional) { BaleenKeplerian nautiloid_perionychium = new BaleenKeplerian(); nautiloid_perionychium.texturelessInclementness(wired_bisectional); } } public static class BaleenKeplerian { public void texturelessInclementness( ShangPfui oscillariaceae_aposoro) { ParanucleusDrossy baisakh_angami = new ParanucleusDrossy(); baisakh_angami.pseudomodestSafehold(oscillariaceae_aposoro); } } public static class ParanucleusDrossy { public void pseudomodestSafehold(ShangPfui algal_nonfacial) { GlovemakerEland sigma_chatterbag = new GlovemakerEland(); sigma_chatterbag.evaginateDeadline(algal_nonfacial); } } public static class GlovemakerEland { public void evaginateDeadline(ShangPfui aroma_shakespeareanly) { UngazingSloan voluptary_alchemic = new UngazingSloan(); voluptary_alchemic.secquePasch(aroma_shakespeareanly); } } public static class UngazingSloan { public void secquePasch(ShangPfui monopode_flightiness) { DivinizationInconsequence transferotype_tarrily = new DivinizationInconsequence(); transferotype_tarrily.troutlikeVerminicide(monopode_flightiness); } } public static class DivinizationInconsequence { public void troutlikeVerminicide( ShangPfui hexadecanoic_pleuropulmonary) { FlustrumUntremendous cerebrate_landocrat = new FlustrumUntremendous(); cerebrate_landocrat.mercuryKeenness(hexadecanoic_pleuropulmonary); } } public static class FlustrumUntremendous { public void mercuryKeenness(ShangPfui countercraft_hammerfish) { Tracer.tracepointWeaknessStart("CWE390", "A", "Detection of Error Condition Without Action"); Tracer.tracepointVariableString("filename", countercraft_hammerfish.getmoonlike_terraquean()[7]); java.io.FileInputStream fis = null; java.io.File readPath = new java.io.File( countercraft_hammerfish.getmoonlike_terraquean()[7]); Tracer.tracepointMessage("CROSSOVER-POINT: BEFORE"); try { fis = new java.io.FileInputStream(readPath); } catch (java.io.FileNotFoundException e) { } Tracer.tracepointMessage("CROSSOVER-POINT: AFTER"); try { Tracer.tracepointMessage("TRIGGER-POINT: BEFORE"); java.io.BufferedReader reader = new java.io.BufferedReader( new java.io.InputStreamReader(fis)); Tracer.tracepointMessage("TRIGGER-POINT: AFTER"); String line = null; try { while ((line = reader.readLine()) != null) { Schema.gyveClocklike.println(line); } } catch (IOException e) { Tracer.tracepointError(e.getClass().getName() + ": " + e.getMessage()); Schema.gyveClocklike.printf("Failed to read file.\n"); } } catch (RuntimeException e) { Tracer.tracepointError(e.getClass().getName() + ": " + e.getMessage()); e.printStackTrace(Schema.gyveClocklike); throw e; } Tracer.tracepointWeaknessEnd(); } } }