Update AAF Version 1.0.0
[aaf/cadi.git] / core / src / main / java / org / onap / aaf / cadi / BufferedCadiWrap.java
1 /*******************************************************************************\r
2  * ============LICENSE_START====================================================\r
3  * * org.onap.aaf\r
4  * * ===========================================================================\r
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * * ===========================================================================\r
7  * * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * * you may not use this file except in compliance with the License.\r
9  * * You may obtain a copy of the License at\r
10  * * \r
11  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * * \r
13  *  * Unless required by applicable law or agreed to in writing, software\r
14  * * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * * See the License for the specific language governing permissions and\r
17  * * limitations under the License.\r
18  * * ============LICENSE_END====================================================\r
19  * *\r
20  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
21  * *\r
22  ******************************************************************************/\r
23 package org.onap.aaf.cadi;\r
24 \r
25 import java.io.BufferedReader;\r
26 import java.io.IOException;\r
27 import java.io.InputStreamReader;\r
28 \r
29 import javax.servlet.http.HttpServletRequest;\r
30 \r
31 /**\r
32  * BufferedCadiWrap exists to additionally wrap the InputStream with a BufferedInputStream to engage the\r
33  * "mark()/release()" API of InputStream.\r
34  * \r
35  * This is a requirement for Re-Reading Content for brain-dead Middleware such as SOAP WS-Security.\r
36  * \r
37  * Framework needs to set the TafResp and Lur (typically) later in the \r
38  * \r
39  *\r
40  */\r
41 public class BufferedCadiWrap extends CadiWrap {\r
42         private BufferedServletInputStream sis;\r
43         \r
44         public BufferedCadiWrap(HttpServletRequest request) {\r
45                 super(request, null, null); // will need to set TafResp and Lur separately\r
46                 sis = null;\r
47         }\r
48 \r
49 \r
50         // @Override\r
51         public BufferedServletInputStream getInputStream() throws IOException {\r
52 //              System.out.println("getInputStream() from Buffered CadiWrap... sis = " + sis);\r
53 //              try {\r
54 //                      throw new Exception("OK, here's where we are...");\r
55 //              } catch (Exception e) {\r
56 //                      e.printStackTrace();\r
57 //              }\r
58                 if(sis==null) {\r
59                         sis = new BufferedServletInputStream(super.getInputStream());\r
60 //              } else {\r
61 //                      try {\r
62 //                      System.out.println("sis has " + sis.buffered() + " buffered bytes, and reports " + sis.available() + " available");\r
63 //                      } catch (Exception e) {\r
64 //                              e.printStackTrace();\r
65 //                      }\r
66                 }\r
67                 return sis;\r
68         }\r
69 \r
70         // @Override\r
71         public BufferedReader getReader() throws IOException {\r
72 //              System.out.println("getReader() from Buffered CadiWrap... sis = " + sis);\r
73 //              try {\r
74 //                      throw new Exception("OK, here's where we are...");\r
75 //              } catch (Exception e) {\r
76 //                      e.printStackTrace();\r
77 //              }\r
78                 return new BufferedReader(new InputStreamReader(getInputStream()));\r
79         }\r
80 }\r