Fixed some deprecation and varargs cast warnings; removed deprecated mock classes
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1512339 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0fb27248f5
commit
bace78ebb4
|
@ -76,8 +76,10 @@ public class ConnectTimeoutException extends InterruptedIOException {
|
||||||
final InetAddress... remoteAddresses) {
|
final InetAddress... remoteAddresses) {
|
||||||
super("Connect to " +
|
super("Connect to " +
|
||||||
(host != null ? host.toHostString() : "remote host") +
|
(host != null ? host.toHostString() : "remote host") +
|
||||||
(remoteAddresses != null ? " " + Arrays.asList(remoteAddresses) : "")
|
(remoteAddresses != null && remoteAddresses.length > 0 ?
|
||||||
+ ((cause != null && cause.getMessage() != null) ? " failed: " + cause.getMessage() : " timed out"));
|
" " + Arrays.asList(remoteAddresses) : "") +
|
||||||
|
((cause != null && cause.getMessage() != null) ?
|
||||||
|
" failed: " + cause.getMessage() : " timed out"));
|
||||||
this.host = host;
|
this.host = host;
|
||||||
initCause(cause);
|
initCause(cause);
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,8 +67,10 @@ public class HttpHostConnectException extends ConnectException {
|
||||||
final InetAddress... remoteAddresses) {
|
final InetAddress... remoteAddresses) {
|
||||||
super("Connect to " +
|
super("Connect to " +
|
||||||
(host != null ? host.toHostString() : "remote host") +
|
(host != null ? host.toHostString() : "remote host") +
|
||||||
(remoteAddresses != null ? " " + Arrays.asList(remoteAddresses) : "")
|
(remoteAddresses != null && remoteAddresses .length > 0 ?
|
||||||
+ ((cause != null && cause.getMessage() != null) ? " failed: " + cause.getMessage() : " refused"));
|
" " + Arrays.asList(remoteAddresses) : "") +
|
||||||
|
((cause != null && cause.getMessage() != null) ?
|
||||||
|
" failed: " + cause.getMessage() : " refused"));
|
||||||
this.host = host;
|
this.host = host;
|
||||||
initCause(cause);
|
initCause(cause);
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,7 @@ public class ServiceUnavailableRetryExec implements ClientExecChain {
|
||||||
if (this.retryStrategy.retryRequest(response, c, context)) {
|
if (this.retryStrategy.retryRequest(response, c, context)) {
|
||||||
response.close();
|
response.close();
|
||||||
final long nextInterval = this.retryStrategy.getRetryInterval();
|
final long nextInterval = this.retryStrategy.getRetryInterval();
|
||||||
|
if (nextInterval > 0) {
|
||||||
try {
|
try {
|
||||||
this.log.trace("Wait for " + nextInterval);
|
this.log.trace("Wait for " + nextInterval);
|
||||||
Thread.sleep(nextInterval);
|
Thread.sleep(nextInterval);
|
||||||
|
@ -85,15 +86,13 @@ public class ServiceUnavailableRetryExec implements ClientExecChain {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
throw new InterruptedIOException();
|
throw new InterruptedIOException();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
} catch (final RuntimeException ex) {
|
} catch (final RuntimeException ex) {
|
||||||
response.close();
|
response.close();
|
||||||
throw ex;
|
throw ex;
|
||||||
} catch (final IOException ex) {
|
|
||||||
response.close();
|
|
||||||
throw ex;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,14 +54,14 @@ public class TestExceptions {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConnectTimeoutExceptionFromNullCause() {
|
public void testConnectTimeoutExceptionFromNullCause() {
|
||||||
final ConnectTimeoutException ctx = new ConnectTimeoutException(null, null, null);
|
final ConnectTimeoutException ctx = new ConnectTimeoutException(null, null);
|
||||||
Assert.assertEquals("Connect to remote host timed out", ctx.getMessage());
|
Assert.assertEquals("Connect to remote host timed out", ctx.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConnectTimeoutExceptionFromCause() {
|
public void testConnectTimeoutExceptionFromCause() {
|
||||||
final IOException cause = new IOException("something awful");
|
final IOException cause = new IOException("something awful");
|
||||||
final ConnectTimeoutException ctx = new ConnectTimeoutException(cause, null, null);
|
final ConnectTimeoutException ctx = new ConnectTimeoutException(cause, null);
|
||||||
Assert.assertEquals("Connect to remote host failed: something awful", ctx.getMessage());
|
Assert.assertEquals("Connect to remote host failed: something awful", ctx.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ public class TestExceptions {
|
||||||
public void testConnectTimeoutExceptionFromCauseAndHost() {
|
public void testConnectTimeoutExceptionFromCauseAndHost() {
|
||||||
final HttpHost target = new HttpHost("localhost");
|
final HttpHost target = new HttpHost("localhost");
|
||||||
final IOException cause = new IOException();
|
final IOException cause = new IOException();
|
||||||
final ConnectTimeoutException ctx = new ConnectTimeoutException(cause, target, null);
|
final ConnectTimeoutException ctx = new ConnectTimeoutException(cause, target);
|
||||||
Assert.assertEquals("Connect to localhost timed out", ctx.getMessage());
|
Assert.assertEquals("Connect to localhost timed out", ctx.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,14 +84,15 @@ public class TestExceptions {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHttpHostConnectExceptionFromNullCause() {
|
public void testHttpHostConnectExceptionFromNullCause() {
|
||||||
final HttpHostConnectException ctx = new HttpHostConnectException(null, null, null);
|
final HttpHostConnectException ctx = new HttpHostConnectException(null, null,
|
||||||
|
(InetAddress [])null);
|
||||||
Assert.assertEquals("Connect to remote host refused", ctx.getMessage());
|
Assert.assertEquals("Connect to remote host refused", ctx.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHttpHostConnectExceptionFromCause() {
|
public void testHttpHostConnectExceptionFromCause() {
|
||||||
final IOException cause = new IOException("something awful");
|
final IOException cause = new IOException("something awful");
|
||||||
final HttpHostConnectException ctx = new HttpHostConnectException(cause, null, null);
|
final HttpHostConnectException ctx = new HttpHostConnectException(cause, null);
|
||||||
Assert.assertEquals("Connect to remote host failed: something awful", ctx.getMessage());
|
Assert.assertEquals("Connect to remote host failed: something awful", ctx.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +100,7 @@ public class TestExceptions {
|
||||||
public void testHttpHostConnectExceptionFromCauseAndHost() {
|
public void testHttpHostConnectExceptionFromCauseAndHost() {
|
||||||
final HttpHost target = new HttpHost("localhost");
|
final HttpHost target = new HttpHost("localhost");
|
||||||
final IOException cause = new IOException();
|
final IOException cause = new IOException();
|
||||||
final HttpHostConnectException ctx = new HttpHostConnectException(cause, target, null);
|
final HttpHostConnectException ctx = new HttpHostConnectException(cause, target);
|
||||||
Assert.assertEquals("Connect to localhost refused", ctx.getMessage());
|
Assert.assertEquals("Connect to localhost refused", ctx.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,150 +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.
|
|
||||||
* ====================================================================
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many
|
|
||||||
* individuals on behalf of the Apache Software Foundation. For more
|
|
||||||
* information on the Apache Software Foundation, please see
|
|
||||||
* <http://www.apache.org/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.apache.http.cookie;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import org.apache.http.impl.cookie.BrowserCompatSpecFactory;
|
|
||||||
import org.apache.http.impl.cookie.NetscapeDraftSpecFactory;
|
|
||||||
import org.apache.http.impl.cookie.RFC2109SpecFactory;
|
|
||||||
import org.apache.http.params.BasicHttpParams;
|
|
||||||
import org.apache.http.params.HttpParams;
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test cases for {@link CookieSpecRegistry}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class TestCookiePolicy {
|
|
||||||
|
|
||||||
private static final String BROWSER_COMPATIBILITY = "BROWSER_COMPATIBILITY";
|
|
||||||
private static final String NETSCAPE = "NETSCAPE";
|
|
||||||
private static final String RFC_2109 = "RFC_2109";
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRegisterUnregisterCookieSpecFactory() {
|
|
||||||
final CookieSpecRegistry registry = new CookieSpecRegistry();
|
|
||||||
List<String> names = registry.getSpecNames();
|
|
||||||
Assert.assertNotNull(names);
|
|
||||||
Assert.assertEquals(0, names.size());
|
|
||||||
|
|
||||||
registry.register(BROWSER_COMPATIBILITY,
|
|
||||||
new BrowserCompatSpecFactory());
|
|
||||||
registry.register(NETSCAPE,
|
|
||||||
new NetscapeDraftSpecFactory());
|
|
||||||
registry.register(RFC_2109,
|
|
||||||
new RFC2109SpecFactory());
|
|
||||||
registry.register(RFC_2109,
|
|
||||||
new RFC2109SpecFactory());
|
|
||||||
registry.register(NETSCAPE,
|
|
||||||
new NetscapeDraftSpecFactory());
|
|
||||||
|
|
||||||
names = registry.getSpecNames();
|
|
||||||
Assert.assertNotNull(names);
|
|
||||||
Assert.assertEquals(3, names.size());
|
|
||||||
final HashSet<String> m = new HashSet<String>(names);
|
|
||||||
Assert.assertTrue(m.contains(BROWSER_COMPATIBILITY.toLowerCase(Locale.ENGLISH)));
|
|
||||||
Assert.assertTrue(m.contains(NETSCAPE.toLowerCase(Locale.ENGLISH)));
|
|
||||||
Assert.assertTrue(m.contains(RFC_2109.toLowerCase(Locale.ENGLISH)));
|
|
||||||
|
|
||||||
registry.unregister(NETSCAPE);
|
|
||||||
registry.unregister(NETSCAPE);
|
|
||||||
registry.unregister(RFC_2109);
|
|
||||||
registry.unregister(BROWSER_COMPATIBILITY);
|
|
||||||
registry.unregister("whatever");
|
|
||||||
|
|
||||||
names = registry.getSpecNames();
|
|
||||||
Assert.assertNotNull(names);
|
|
||||||
Assert.assertEquals(0, names.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetNewCookieSpec() {
|
|
||||||
final CookieSpecRegistry registry = new CookieSpecRegistry();
|
|
||||||
registry.register(BROWSER_COMPATIBILITY,
|
|
||||||
new BrowserCompatSpecFactory());
|
|
||||||
registry.register(NETSCAPE,
|
|
||||||
new NetscapeDraftSpecFactory());
|
|
||||||
registry.register(RFC_2109,
|
|
||||||
new RFC2109SpecFactory());
|
|
||||||
|
|
||||||
Assert.assertNotNull(registry.getCookieSpec(NETSCAPE));
|
|
||||||
Assert.assertNotNull(registry.getCookieSpec(RFC_2109));
|
|
||||||
Assert.assertNotNull(registry.getCookieSpec(BROWSER_COMPATIBILITY));
|
|
||||||
try {
|
|
||||||
registry.getCookieSpec("whatever");
|
|
||||||
Assert.fail("IllegalStateException should have been thrown");
|
|
||||||
} catch (final IllegalStateException ex) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
final HttpParams params = new BasicHttpParams();
|
|
||||||
Assert.assertNotNull(registry.getCookieSpec(NETSCAPE, params));
|
|
||||||
Assert.assertNotNull(registry.getCookieSpec(RFC_2109, params));
|
|
||||||
Assert.assertNotNull(registry.getCookieSpec(BROWSER_COMPATIBILITY, params));
|
|
||||||
try {
|
|
||||||
registry.getCookieSpec("whatever", params);
|
|
||||||
Assert.fail("IllegalStateException should have been thrown");
|
|
||||||
} catch (final IllegalStateException ex) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testInvalidInput() {
|
|
||||||
final CookieSpecRegistry registry = new CookieSpecRegistry();
|
|
||||||
try {
|
|
||||||
registry.register(null, null);
|
|
||||||
Assert.fail("IllegalArgumentException should have been thrown");
|
|
||||||
} catch (final IllegalArgumentException ex) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
registry.register("whatever", null);
|
|
||||||
Assert.fail("IllegalArgumentException should have been thrown");
|
|
||||||
} catch (final IllegalArgumentException ex) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
registry.unregister(null);
|
|
||||||
Assert.fail("IllegalArgumentException should have been thrown");
|
|
||||||
} catch (final IllegalArgumentException ex) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
registry.getCookieSpec((String)null);
|
|
||||||
Assert.fail("IllegalArgumentException should have been thrown");
|
|
||||||
} catch (final IllegalArgumentException ex) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -43,6 +43,7 @@ public class TestRFC2617Scheme {
|
||||||
|
|
||||||
static class TestAuthScheme extends RFC2617Scheme {
|
static class TestAuthScheme extends RFC2617Scheme {
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public Header authenticate(
|
public Header authenticate(
|
||||||
final Credentials credentials,
|
final Credentials credentials,
|
||||||
final HttpRequest request) throws AuthenticationException {
|
final HttpRequest request) throws AuthenticationException {
|
||||||
|
|
|
@ -1,62 +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.
|
|
||||||
* ====================================================================
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many
|
|
||||||
* individuals on behalf of the Apache Software Foundation. For more
|
|
||||||
* information on the Apache Software Foundation, please see
|
|
||||||
* <http://www.apache.org/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.apache.http.mockup;
|
|
||||||
|
|
||||||
import java.net.Socket;
|
|
||||||
|
|
||||||
import org.apache.http.conn.scheme.SchemeLayeredSocketFactory;
|
|
||||||
import org.apache.http.params.HttpParams;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link org.apache.http.conn.scheme.LayeredSchemeSocketFactory} mockup implementation.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class SecureSocketFactoryMockup extends SocketFactoryMockup
|
|
||||||
implements SchemeLayeredSocketFactory {
|
|
||||||
|
|
||||||
/* A default instance of this mockup. */
|
|
||||||
public final static SchemeLayeredSocketFactory INSTANCE = new SecureSocketFactoryMockup("INSTANCE");
|
|
||||||
|
|
||||||
public SecureSocketFactoryMockup(final String name) {
|
|
||||||
super(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
// don't implement equals and hashcode, all instances are different!
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "SecureSocketFactoryMockup." + mockup_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Socket createLayeredSocket(final Socket socket, final String host, final int port,
|
|
||||||
final HttpParams params) {
|
|
||||||
throw new UnsupportedOperationException("I'm a mockup!");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,79 +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.
|
|
||||||
* ====================================================================
|
|
||||||
*
|
|
||||||
* This software consists of voluntary contributions made by many
|
|
||||||
* individuals on behalf of the Apache Software Foundation. For more
|
|
||||||
* information on the Apache Software Foundation, please see
|
|
||||||
* <http://www.apache.org/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.apache.http.mockup;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
|
|
||||||
import org.apache.http.conn.ConnectTimeoutException;
|
|
||||||
import org.apache.http.conn.scheme.SchemeSocketFactory;
|
|
||||||
import org.apache.http.params.HttpParams;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link SchemeSocketFactory} mockup implementation.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public class SocketFactoryMockup implements SchemeSocketFactory {
|
|
||||||
|
|
||||||
/* A default instance of this mockup. */
|
|
||||||
public final static SchemeSocketFactory INSTANCE = new SocketFactoryMockup("INSTANCE");
|
|
||||||
|
|
||||||
/** The name of this mockup socket factory. */
|
|
||||||
protected final String mockup_name;
|
|
||||||
|
|
||||||
public SocketFactoryMockup(final String name) {
|
|
||||||
mockup_name = (name != null) ? name : String.valueOf(hashCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
// don't implement equals and hashcode, all instances are different!
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "SocketFactoryMockup." + mockup_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Socket createSocket(final HttpParams params) {
|
|
||||||
throw new UnsupportedOperationException("I'm a mockup!");
|
|
||||||
}
|
|
||||||
|
|
||||||
public Socket connectSocket(
|
|
||||||
final Socket sock,
|
|
||||||
final InetSocketAddress remoteAddress,
|
|
||||||
final InetSocketAddress localAddress,
|
|
||||||
final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
|
|
||||||
throw new UnsupportedOperationException("I'm a mockup!");
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSecure(final Socket sock) {
|
|
||||||
// no way that the argument is from *this* factory...
|
|
||||||
throw new UnsupportedOperationException("I'm a mockup!");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue