You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@jakarta.apache.org by se...@apache.org on 2010/11/30 01:11:43 UTC

svn commit: r1040353 - in /jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler: HTTPAbstractImpl.java HTTPHC3Impl.java HTTPHC4Impl.java HTTPJavaImpl.java

Author: sebb
Date: Tue Nov 30 00:11:42 2010
New Revision: 1040353

URL: http://svn.apache.org/viewvc?rev=1040353&view=rev
Log:
Add HTTP implementations for use by HTTPSamplerProxy

Added:
    jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java   (with props)
    jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC3Impl.java
      - copied, changed from r1038781, jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java
    jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java   (with props)
    jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPJavaImpl.java
      - copied, changed from r1021539, jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java

Added: jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java?rev=1040353&view=auto
==============================================================================
--- jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java (added)
+++ jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java Tue Nov 30 00:11:42 2010
@@ -0,0 +1,170 @@
+/*
+ * 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.sampler;
+
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.apache.jmeter.config.Arguments;
+import org.apache.jmeter.protocol.http.control.AuthManager;
+import org.apache.jmeter.protocol.http.control.CacheManager;
+import org.apache.jmeter.protocol.http.control.CookieManager;
+import org.apache.jmeter.protocol.http.control.HeaderManager;
+import org.apache.jmeter.protocol.http.util.HTTPConstantsInterface;
+import org.apache.jmeter.protocol.http.util.HTTPFileArg;
+import org.apache.jmeter.samplers.Interruptible;
+import org.apache.jmeter.samplers.SampleResult;
+
+/**
+ * Base class for HTTP implementations used by the HTTPSamplerProxy sampler.
+ */
+public abstract class HTTPAbstractImpl implements Interruptible, HTTPConstantsInterface {
+
+    protected final HTTPSamplerBase testElement;
+
+    protected HTTPAbstractImpl(HTTPSamplerBase testElement){
+        this.testElement = testElement;
+    }
+
+    protected abstract HTTPSampleResult sample(URL url, String method, boolean areFollowingRedirect, int frameDepth);
+
+    // Allows HTTPSamplerProxy to call threadFinished; subclasses can override if necessary
+    protected void threadFinished() {
+    }
+
+    // Provide access to HTTPSamplerBase methods
+    
+    protected HeaderManager getHeaderManager() {
+        return testElement.getHeaderManager();
+    }
+
+    protected HTTPFileArg[] getHTTPFiles() {
+        return testElement.getHTTPFiles();
+    }
+
+    protected AuthManager getAuthManager() {
+        return testElement.getAuthManager();
+    }
+
+    protected Arguments getArguments() {
+        return testElement.getArguments();
+    }
+
+    protected CookieManager getCookieManager() {
+        return testElement.getCookieManager();
+    }
+
+    protected HTTPSampleResult errorResult(IOException iex, HTTPSampleResult res) {
+        return testElement.errorResult(iex, res);
+    }
+
+    protected byte[] readResponse(SampleResult res, BufferedInputStream in,
+            int contentLength) throws IOException {
+        return testElement.readResponse(res, in, contentLength);
+    }
+
+    protected CacheManager getCacheManager() {
+        return testElement.getCacheManager();
+    }
+
+    protected boolean getUseKeepAlive() {
+        return testElement.getUseKeepAlive();
+    }
+
+    protected int getResponseTimeout() {
+        return testElement.getResponseTimeout();
+    }
+
+    protected int getConnectTimeout() {
+        return testElement.getConnectTimeout();
+    }
+
+    protected boolean getAutoRedirects() {
+        return testElement.getAutoRedirects();
+    }
+
+    protected int getProxyPortInt() {
+        return testElement.getProxyPortInt();
+    }
+
+    protected String getProxyHost() {
+        return testElement.getProxyHost();
+    }
+
+    protected HTTPSampleResult resultProcessing(boolean areFollowingRedirect,
+            int frameDepth, HTTPSampleResult res) {
+        return testElement.resultProcessing(areFollowingRedirect, frameDepth, res);
+    }
+
+    protected boolean isSuccessCode(int errorLevel) {
+        return testElement.isSuccessCode(errorLevel);
+    }
+
+    protected void setUseKeepAlive(boolean b) {
+        testElement.setUseKeepAlive(b);
+    }
+
+    protected boolean isMonitor() {
+        return testElement.isMonitor();
+    }
+    protected boolean getSendParameterValuesAsPostBody() {
+        return testElement.getSendParameterValuesAsPostBody();
+    }
+
+    protected boolean getSendFileAsPostBody() {
+        return testElement.getSendFileAsPostBody();
+    }
+
+    protected boolean hasArguments() {
+        return testElement.hasArguments();
+    }
+
+    protected String getContentEncoding() {
+        return testElement.getContentEncoding();
+    }
+
+    protected boolean getUseMultipartForPost() {
+        return testElement.getUseMultipartForPost();
+    }
+
+    protected String getProxyPass() {
+        return testElement.getProxyPass();
+    }
+
+    protected String getProxyUser() {
+        return testElement.getProxyUser();
+    }
+
+    protected String getIpSource() {
+        return testElement.getIpSource();
+    }
+
+    protected HTTPSampleResult errorResult(IllegalArgumentException e,
+            HTTPSampleResult res) {
+        return testElement.errorResult(e, res);
+    }
+
+    protected byte[] readResponse(HTTPSampleResult res, InputStream instream,
+            int responseContentLength) throws IOException {
+        return testElement.readResponse(res, instream, responseContentLength);
+    }
+
+}

Propchange: jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPAbstractImpl.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC3Impl.java (from r1038781, jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java)
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC3Impl.java?p2=jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC3Impl.java&p1=jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java&r1=1038781&r2=1040353&rev=1040353&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler2.java (original)
+++ jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC3Impl.java Tue Nov 30 00:11:42 2010
@@ -77,7 +77,6 @@ import org.apache.jmeter.protocol.http.u
 import org.apache.jmeter.protocol.http.util.HTTPFileArg;
 import org.apache.jmeter.protocol.http.util.LoopbackHttpClientSocketFactory;
 import org.apache.jmeter.protocol.http.util.SlowHttpClientSocketFactory;
-import org.apache.jmeter.samplers.Interruptible;
 import org.apache.jmeter.testelement.property.CollectionProperty;
 import org.apache.jmeter.testelement.property.PropertyIterator;
 import org.apache.jmeter.util.JMeterUtils;
@@ -91,7 +90,7 @@ import org.apache.log.Logger;
  * HTTP requests, including cookies and authentication.
  *
  */
-public class HTTPSampler2 extends HTTPSamplerBase implements Interruptible {
+public class HTTPHC3Impl extends HTTPAbstractImpl {
 
     private static final Logger log = LoggingManager.getLoggerForClass();
 
@@ -122,6 +121,8 @@ public class HTTPSampler2 extends HTTPSa
     private static final String PROXY_DOMAIN =
         JMeterUtils.getPropDefault("http.proxyDomain",""); // $NON-NLS-1$ $NON-NLS-2$
 
+    public static final String IP_SOURCE = "HTTPSampler.ipSource"; // $NON-NLS-1$ // TODO not here
+
     static final InetAddress localAddress;
 
     private static final String localHost;
@@ -130,7 +131,12 @@ public class HTTPSampler2 extends HTTPSa
      * Connection is re-used within the thread if possible
      */
     static final ThreadLocal<Map<HostConfiguration, HttpClient>> httpClients =
-        new ThreadLocal<Map<HostConfiguration, HttpClient>>();
+        new ThreadLocal<Map<HostConfiguration, HttpClient>>(){
+            @Override
+            protected Map<HostConfiguration, HttpClient> initialValue() {
+                return new HashMap<HostConfiguration, HttpClient>();
+            }
+        };
 
     private static final Set<String> nonProxyHostFull   = new HashSet<String>();// www.apache.org
     private static final List<String> nonProxyHostSuffix = new ArrayList<String>();// .apache.org
@@ -243,12 +249,8 @@ public class HTTPSampler2 extends HTTPSa
         }
     }
 
-    /**
-     * Constructor for the HTTPSampler2 object.
-     *
-     * Consider using HTTPSamplerFactory.newInstance() instead
-     */
-    public HTTPSampler2() {
+    protected HTTPHC3Impl(HTTPSamplerBase base) {
+        super(base);
     }
 
     /*
@@ -1129,14 +1131,6 @@ public class HTTPSampler2 extends HTTPSa
 
 
     @Override
-    public void threadStarted() {
-        log.debug("Thread Started");
-
-        // Does not need to be synchronised, as all access is from same thread
-        httpClients.set ( new HashMap<HostConfiguration, HttpClient>() );
-    }
-
-    @Override
     public void threadFinished() {
         log.debug("Thread Finished");
 
@@ -1170,4 +1164,5 @@ public class HTTPSampler2 extends HTTPSa
         }
         return client != null;
     }
+
 }

Added: jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java?rev=1040353&view=auto
==============================================================================
--- jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java (added)
+++ jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java Tue Nov 30 00:11:42 2010
@@ -0,0 +1,43 @@
+/*
+ * 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.sampler;
+
+import java.net.URL;
+
+import org.apache.commons.lang.NotImplementedException;
+
+public class HTTPHC4Impl extends HTTPAbstractImpl {
+
+    protected HTTPHC4Impl(HTTPSamplerBase testElement) {
+        super(testElement);
+    }
+
+    public boolean interrupt() {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    @Override
+    protected HTTPSampleResult sample(URL url, String method,
+            boolean areFollowingRedirect, int frameDepth) {
+        // TODO Auto-generated method stub
+        throw new NotImplementedException();
+    }
+
+}

Propchange: jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPJavaImpl.java (from r1021539, jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java)
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPJavaImpl.java?p2=jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPJavaImpl.java&p1=jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java&r1=1021539&r2=1040353&rev=1040353&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java (original)
+++ jakarta/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPJavaImpl.java Tue Nov 30 00:11:42 2010
@@ -40,8 +40,8 @@ import org.apache.jmeter.protocol.http.c
 import org.apache.jmeter.protocol.http.control.CookieManager;
 import org.apache.jmeter.protocol.http.control.Header;
 import org.apache.jmeter.protocol.http.control.HeaderManager;
+import org.apache.jmeter.protocol.http.util.HTTPConstantsInterface;
 
-import org.apache.jmeter.samplers.Interruptible;
 import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.testelement.property.CollectionProperty;
 import org.apache.jmeter.testelement.property.PropertyIterator;
@@ -58,7 +58,7 @@ import org.apache.log.Logger;
  * HTTP requests, including cookies and authentication.
  *
  */
-public class HTTPSampler extends HTTPSamplerBase implements Interruptible {
+public class HTTPJavaImpl extends HTTPAbstractImpl {
     private static final boolean OBEY_CONTENT_LENGTH =
         JMeterUtils.getPropDefault("httpsampler.obey_contentlength", false); // $NON-NLS-1$
 
@@ -82,12 +82,8 @@ public class HTTPSampler extends HTTPSam
 
     private volatile HttpURLConnection savedConn;
 
-    /**
-     * Constructor for the HTTPSampler object.
-     *
-     * Consider using HTTPSamplerFactory.newInstance() instead
-     */
-    public HTTPSampler() {
+    protected HTTPJavaImpl(HTTPSamplerBase base) {
+        super(base);
     }
 
     /**
@@ -100,12 +96,12 @@ public class HTTPSampler extends HTTPSam
      */
     protected void setPostHeaders(URLConnection conn) throws IOException {
         postOrPutWriter = new PostWriter();
-        postOrPutWriter.setHeaders(conn, this);
+        postOrPutWriter.setHeaders(conn, testElement);
     }
 
     private void setPutHeaders(URLConnection conn) throws IOException {
         postOrPutWriter = new PutWriter();
-        postOrPutWriter.setHeaders(conn, this);
+        postOrPutWriter.setHeaders(conn, testElement);
     }
 
     /**
@@ -119,11 +115,11 @@ public class HTTPSampler extends HTTPSam
      *                if an I/O exception occurs
      */
     protected String sendPostData(URLConnection connection) throws IOException {
-        return postOrPutWriter.sendPostData(connection, this);
+        return postOrPutWriter.sendPostData(connection, testElement);
     }
 
     private String sendPutData(URLConnection connection) throws IOException {
-        return postOrPutWriter.sendPostData(connection, this);
+        return postOrPutWriter.sendPostData(connection, testElement);
     }
 
     /**
@@ -182,7 +178,7 @@ public class HTTPSampler extends HTTPSam
             conn.setReadTimeout(rto);
         }
 
-        if (PROTOCOL_HTTPS.equalsIgnoreCase(u.getProtocol())) {
+        if (HTTPConstantsInterface.PROTOCOL_HTTPS.equalsIgnoreCase(u.getProtocol())) {
             try {
                 if (null != sslmgr){
                     sslmgr.setContext(conn); // N.B. must be done after opening connection
@@ -492,7 +488,7 @@ public class HTTPSampler extends HTTPSam
                         savedConn = null; // we don't want interrupt to try disconnection again
                         conn.disconnect();
                     }
-                    this.setUseKeepAlive(false);
+                    setUseKeepAlive(false);
                     continue; // try again
                 } catch (IOException e) {
                     log.debug("Connection failed, giving up");
@@ -522,6 +518,7 @@ public class HTTPSampler extends HTTPSam
 
             res.setResponseData(responseData);
 
+            @SuppressWarnings("null") // Cannot be null here
             int errorLevel = conn.getResponseCode();
             String respMsg = conn.getResponseMessage();
             String hdr=conn.getHeaderField(0);



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@jakarta.apache.org
For additional commands, e-mail: notifications-help@jakarta.apache.org