Package: jakarta-jmeter / 2.13-4

05_ignore-jodd.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
Description: Disable the JoddExtractor since jodd isn't in Debian yet
Author: Emmanuel Bourg <ebourg@apache.org>
Forwarded: not-needed
--- a/src/components/org/apache/jmeter/extractor/HtmlExtractor.java
+++ b/src/components/org/apache/jmeter/extractor/HtmlExtractor.java
@@ -48,7 +48,7 @@
      * @return Array containing the names of the possible extractors.
      */
     public static String[] getImplementations(){
-        return new String[]{EXTRACTOR_JSOUP,EXTRACTOR_JODD};
+        return new String[]{EXTRACTOR_JSOUP};
     }
 
     public static final String DEFAULT_EXTRACTOR = ""; // $NON-NLS-1$
@@ -217,8 +217,8 @@
         boolean useDefaultExtractor = DEFAULT_EXTRACTOR.equals(impl);
         if (useDefaultExtractor || EXTRACTOR_JSOUP.equals(impl)) {
             return new JSoupExtractor();
-        } else if (EXTRACTOR_JODD.equals(impl)) {
-            return new JoddExtractor();
+        //} else if (EXTRACTOR_JODD.equals(impl)) {
+        //    return new JoddExtractor();
         } else {
             throw new IllegalArgumentException("Extractor implementation:"+ impl+" is unknown");
         }
--- a/src/components/org/apache/jmeter/extractor/JoddExtractor.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * 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.jmeter.extractor;
-
-import java.util.List;
-
-import jodd.lagarto.dom.LagartoDOMBuilder;
-import jodd.lagarto.dom.Node;
-import jodd.lagarto.dom.NodeSelector;
-import jodd.log.LoggerFactory;
-import jodd.log.impl.Slf4jLoggerFactory;
-
-import org.apache.jmeter.threads.JMeterContextService;
-import org.apache.jorphan.util.JOrphanUtils;
-
-/**
- * Jodd-Lagerto based CSS/JQuery extractor
- * see http://jodd.org/doc/csselly/
- * @since 2.9
- */
-public class JoddExtractor implements Extractor {
-
-    /**
-     * 
-     */
-    private static final long serialVersionUID = -7235814605293262972L;
-
-    private static final String CACHE_KEY_PREFIX = JoddExtractor.class.getName()+"_PARSED_BODY";
-    
-    static {
-        LoggerFactory.setLoggerFactory(new Slf4jLoggerFactory());
-    }
-
-    /**
-     * 
-     */
-    public JoddExtractor() {
-        super();
-    }
-
-    /**
-     * @see org.apache.jmeter.extractor.Extractor#extract(String, String, int, String, List, int, String)
-     */
-    @Override
-    public int extract(String expression, String attribute, int matchNumber,
-            String inputString, List<String> result, int found,
-            String cacheKey) {
-        NodeSelector nodeSelector = null;
-        if (cacheKey != null) {
-            nodeSelector = (NodeSelector) 
-                    JMeterContextService.getContext().getSamplerContext().get(CACHE_KEY_PREFIX+cacheKey);
-            if(nodeSelector==null) {
-                LagartoDOMBuilder domBuilder = new LagartoDOMBuilder();
-                jodd.lagarto.dom.Document doc = domBuilder.parse(inputString);
-                nodeSelector = new NodeSelector(doc);
-                JMeterContextService.getContext().getSamplerContext().put(CACHE_KEY_PREFIX+cacheKey, nodeSelector);
-            }
-        } else {
-            LagartoDOMBuilder domBuilder = new LagartoDOMBuilder();
-            jodd.lagarto.dom.Document doc = domBuilder.parse(inputString);
-            nodeSelector = new NodeSelector(doc);
-        }
-        List<Node> elements = nodeSelector.select(expression);
-        int size = elements.size();
-        for (int i = 0; i < size; i++) {
-            Node element = elements.get(i);
-            if (matchNumber <=0 || found != matchNumber) {
-                result.add(extractValue(attribute, element));
-                found++;
-            } else {
-                break;
-            }
-        }
-        
-        return found;
-    }
-    
-    
-    private String extractValue(String attribute, Node element) {
-        if (!JOrphanUtils.isBlank(attribute)) {
-            return element.getAttribute(attribute);
-        } else {
-            return element.getTextContent().trim();
-        }
-    }
-}
--- a/src/protocol/http/org/apache/jmeter/protocol/http/parser/LagartoBasedHtmlParser.java
+++ /dev/null
@@ -1,242 +0,0 @@
-/*
- * 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.jmeter.protocol.http.parser;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.Stack;
-
-import jodd.lagarto.EmptyTagVisitor;
-import jodd.lagarto.LagartoException;
-import jodd.lagarto.LagartoParser;
-import jodd.lagarto.LagartoParserConfig;
-import jodd.lagarto.Tag;
-import jodd.lagarto.TagType;
-import jodd.lagarto.TagUtil;
-import jodd.lagarto.dom.HtmlCCommentExpressionMatcher;
-import jodd.log.LoggerFactory;
-import jodd.log.impl.Slf4jLoggerFactory;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.jmeter.protocol.http.util.ConversionUtils;
-import org.apache.jorphan.logging.LoggingManager;
-import org.apache.log.Logger;
-
-/**
- * Parser based on Lagarto
- * @since 2.10
- */
-public class LagartoBasedHtmlParser extends HTMLParser {
-    private static final Logger log = LoggingManager.getLoggerForClass();
-    static {
-        LoggerFactory.setLoggerFactory(new Slf4jLoggerFactory());
-    }
-
-    /*
-     * A dummy class to pass the pointer of URL.
-     */
-    private static class URLPointer {
-        private URLPointer(URL newUrl) {
-            url = newUrl;
-        }
-        private URL url;
-    }
-    
-    private static final class JMeterTagVisitor extends EmptyTagVisitor {
-        private HtmlCCommentExpressionMatcher htmlCCommentExpressionMatcher;
-        private URLCollection urls;
-        private URLPointer baseUrl;
-        private Float ieVersion;
-        private Stack<Boolean> enabled = new Stack<Boolean>();
-
-        /**
-         * @param baseUrl base url to add possibly missing information to urls found in <code>urls</code>
-         * @param urls collection of urls to consider
-         * @param ieVersion version number of IE to emulate
-         */
-        public JMeterTagVisitor(final URLPointer baseUrl, URLCollection urls, Float ieVersion) {
-            this.urls = urls;
-            this.baseUrl = baseUrl;
-            this.ieVersion = ieVersion;
-        }
-
-        private final void extractAttribute(Tag tag, String attributeName) {
-            CharSequence url = tag.getAttributeValue(attributeName);
-            if (!StringUtils.isEmpty(url)) {
-                urls.addURL(url.toString(), baseUrl.url);
-            }
-        }
-        /*
-         * (non-Javadoc)
-         * 
-         * @see jodd.lagarto.EmptyTagVisitor#script(jodd.lagarto.Tag,
-         * java.lang.CharSequence)
-         */
-        @Override
-        public void script(Tag tag, CharSequence body) {
-            if (!enabled.peek().booleanValue()) {
-                return;
-            }
-            extractAttribute(tag, ATT_SRC);
-        }
-
-        /*
-         * (non-Javadoc)
-         * 
-         * @see jodd.lagarto.EmptyTagVisitor#tag(jodd.lagarto.Tag)
-         */
-        @Override
-        public void tag(Tag tag) {
-            if (!enabled.peek().booleanValue()) {
-                return;
-            }
-            TagType tagType = tag.getType();
-            switch (tagType) {
-            case START:
-            case SELF_CLOSING:
-                if (tag.nameEquals(TAG_BODY)) {
-                    extractAttribute(tag, ATT_BACKGROUND);
-                } else if (tag.nameEquals(TAG_BASE)) {
-                    CharSequence baseref = tag.getAttributeValue(ATT_HREF);
-                    try {
-                        if (!StringUtils.isEmpty(baseref))// Bugzilla 30713
-                        {
-                            baseUrl.url = ConversionUtils.makeRelativeURL(baseUrl.url, baseref.toString());
-                        }
-                    } catch (MalformedURLException e1) {
-                        throw new RuntimeException(e1);
-                    }
-                } else if (tag.nameEquals(TAG_IMAGE)) {
-                    extractAttribute(tag, ATT_SRC);
-                } else if (tag.nameEquals(TAG_APPLET)) {
-                    extractAttribute(tag, ATT_CODE);
-                } else if (tag.nameEquals(TAG_OBJECT)) {
-                    extractAttribute(tag, ATT_CODEBASE);                
-                    extractAttribute(tag, ATT_DATA);                 
-                } else if (tag.nameEquals(TAG_INPUT)) {
-                    // we check the input tag type for image
-                    CharSequence type = tag.getAttributeValue(ATT_TYPE);
-                    if (type != null && TagUtil.equalsIgnoreCase(ATT_IS_IMAGE, type)) {
-                        // then we need to download the binary
-                        extractAttribute(tag, ATT_SRC);
-                    }
-                } else if (tag.nameEquals(TAG_SCRIPT)) {
-                    extractAttribute(tag, ATT_SRC);
-                    // Bug 51750
-                } else if (tag.nameEquals(TAG_FRAME) || tag.nameEquals(TAG_IFRAME)) {
-                    extractAttribute(tag, ATT_SRC);
-                } else if (tag.nameEquals(TAG_EMBED)) {
-                    extractAttribute(tag, ATT_SRC);
-                } else if (tag.nameEquals(TAG_BGSOUND)){
-                    extractAttribute(tag, ATT_SRC);
-                } else if (tag.nameEquals(TAG_LINK)) {
-                    CharSequence relAttribute = tag.getAttributeValue(ATT_REL);
-                    // Putting the string first means it works even if the attribute is null
-                    if (relAttribute != null && TagUtil.equalsIgnoreCase(STYLESHEET,relAttribute)) {
-                        extractAttribute(tag, ATT_HREF);
-                    }
-                } else {
-                    extractAttribute(tag, ATT_BACKGROUND);
-                }
-    
-    
-                // Now look for URLs in the STYLE attribute
-                CharSequence styleTagStr = tag.getAttributeValue(ATT_STYLE);
-                if(!StringUtils.isEmpty(styleTagStr)) {
-                    HtmlParsingUtils.extractStyleURLs(baseUrl.url, urls, styleTagStr.toString());
-                }
-                break;
-            case END:
-                break;
-            }
-        }
-
-        /* (non-Javadoc)
-         * @see jodd.lagarto.EmptyTagVisitor#condComment(java.lang.CharSequence, boolean, boolean, boolean)
-         */
-        @Override
-        public void condComment(CharSequence expression, boolean isStartingTag,
-                boolean isHidden, boolean isHiddenEndTag) {
-            // See http://css-tricks.com/how-to-create-an-ie-only-stylesheet/
-            if(!isStartingTag) {
-                enabled.pop();
-            } else {
-                if (htmlCCommentExpressionMatcher == null) {
-                    htmlCCommentExpressionMatcher = new HtmlCCommentExpressionMatcher();
-                }
-                String expressionString = expression.toString().trim();
-                enabled.push(Boolean.valueOf(htmlCCommentExpressionMatcher.match(ieVersion.floatValue(),
-                        expressionString)));                
-            }
-        }
-
-        /* (non-Javadoc)
-         * @see jodd.lagarto.EmptyTagVisitor#start()
-         */
-        @Override
-        public void start() {
-            super.start();
-            enabled.clear();
-            enabled.push(Boolean.TRUE);
-        }
-    }
-
-    @Override
-    public Iterator<URL> getEmbeddedResourceURLs(String userAgent, byte[] html, URL baseUrl,
-            URLCollection coll, String encoding) throws HTMLParseException {
-        try {
-            Float ieVersion = extractIEVersion(userAgent);
-            
-            String contents = new String(html,encoding); 
-            // As per Jodd javadocs, emitStrings should be false for visitor for better performances
-            LagartoParser lagartoParser = new LagartoParser(contents, false);
-            LagartoParserConfig<LagartoParserConfig<?>> config = new LagartoParserConfig<LagartoParserConfig<?>>();
-            config.setCaseSensitive(false);
-            // Conditional comments only apply for IE < 10
-            config.setEnableConditionalComments(isEnableConditionalComments(ieVersion));
-            
-            lagartoParser.setConfig(config);
-            JMeterTagVisitor tagVisitor = new JMeterTagVisitor(new URLPointer(baseUrl), coll, ieVersion);
-            lagartoParser.parse(tagVisitor);
-            return coll.iterator();
-        } catch (LagartoException e) {
-            // TODO is it the best way ? https://issues.apache.org/bugzilla/show_bug.cgi?id=55634
-            if(log.isDebugEnabled()) {
-                log.debug("Error extracting embedded resource URLs from:'"+baseUrl+"', probably not text content, message:"+e.getMessage());
-            }
-            return Collections.<URL>emptyList().iterator();
-        } catch (Exception e) {
-            throw new HTMLParseException(e);
-        }
-    }
-
-    
-
-
-
-    /* (non-Javadoc)
-     * @see org.apache.jmeter.protocol.http.parser.HTMLParser#isReusable()
-     */
-    @Override
-    protected boolean isReusable() {
-        return true;
-    }
-}