Browse Source

Polishing

pull/928/merge
Juergen Hoeller 10 years ago
parent
commit
e78425103e
  1. 7
      spring-web/src/main/java/org/springframework/http/client/OkHttpClientHttpRequest.java
  2. 30
      spring-web/src/main/java/org/springframework/http/client/support/ProxyFactoryBean.java

7
spring-web/src/main/java/org/springframework/http/client/OkHttpClientHttpRequest.java

@ -46,8 +46,7 @@ import org.springframework.util.concurrent.SettableListenableFuture;
* @author Arjen Poutsma * @author Arjen Poutsma
* @since 4.2 * @since 4.2
*/ */
class OkHttpClientHttpRequest extends AbstractBufferingAsyncClientHttpRequest class OkHttpClientHttpRequest extends AbstractBufferingAsyncClientHttpRequest implements ClientHttpRequest {
implements ClientHttpRequest {
private final OkHttpClient client; private final OkHttpClient client;
@ -74,8 +73,8 @@ class OkHttpClientHttpRequest extends AbstractBufferingAsyncClientHttpRequest
} }
@Override @Override
protected ListenableFuture<ClientHttpResponse> executeInternal(HttpHeaders headers, protected ListenableFuture<ClientHttpResponse> executeInternal(HttpHeaders headers, byte[] content)
byte[] content) throws IOException { throws IOException {
MediaType contentType = getContentType(headers); MediaType contentType = getContentType(headers);
RequestBody body = (content.length > 0 ? RequestBody.create(contentType, content) : null); RequestBody body = (content.length > 0 ? RequestBody.create(contentType, content) : null);

30
spring-web/src/main/java/org/springframework/http/client/support/ProxyFactoryBean.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2015 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -42,41 +42,46 @@ public class ProxyFactoryBean implements FactoryBean<Proxy>, InitializingBean {
private Proxy proxy; private Proxy proxy;
/** /**
* Sets the proxy type. Defaults to {@link java.net.Proxy.Type#HTTP}. * Set the proxy type.
* <p>Defaults to {@link java.net.Proxy.Type#HTTP}.
*/ */
public void setType(Proxy.Type type) { public void setType(Proxy.Type type) {
this.type = type; this.type = type;
} }
/** /**
* Sets the proxy host name. * Set the proxy host name.
*/ */
public void setHostname(String hostname) { public void setHostname(String hostname) {
this.hostname = hostname; this.hostname = hostname;
} }
/** /**
* Sets the proxy port. * Set the proxy port.
*/ */
public void setPort(int port) { public void setPort(int port) {
this.port = port; this.port = port;
} }
@Override @Override
public void afterPropertiesSet() throws IllegalArgumentException { public void afterPropertiesSet() throws IllegalArgumentException {
Assert.notNull(type, "'type' must not be null"); Assert.notNull(this.type, "'type' must not be null");
Assert.hasLength(hostname, "'hostname' must not be empty"); Assert.hasLength(this.hostname, "'hostname' must not be empty");
Assert.isTrue(port >= 0 && port <= 65535, "'port' out of range: " + port); if (this.port < 0 || this.port > 65535) {
throw new IllegalArgumentException("'port' value out of range: " + this.port);
SocketAddress socketAddress = new InetSocketAddress(hostname, port); }
this.proxy = new Proxy(type, socketAddress);
SocketAddress socketAddress = new InetSocketAddress(this.hostname, this.port);
this.proxy = new Proxy(this.type, socketAddress);
} }
@Override @Override
public Proxy getObject() { public Proxy getObject() {
return proxy; return this.proxy;
} }
@Override @Override
@ -88,4 +93,5 @@ public class ProxyFactoryBean implements FactoryBean<Proxy>, InitializingBean {
public boolean isSingleton() { public boolean isSingleton() {
return true; return true;
} }
} }

Loading…
Cancel
Save