Last active
February 7, 2020 18:39
-
-
Save rponte/b0d4b4970a6502d9da08 to your computer and use it in GitHub Desktop.
Setting timeout and http headers on Spring's SimpleHttpInvokerRequestExecutor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.net.HttpURLConnection; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.remoting.httpinvoker.HttpInvokerRequestExecutor; | |
import org.springframework.remoting.httpinvoker.SimpleHttpInvokerRequestExecutor; | |
import org.springframework.stereotype.Component; | |
@Component | |
public class CustomSimpleHttpInvokerRequestExecutorFactory { | |
/** | |
* https://www.baeldung.com/httpclient-timeout | |
*/ | |
@Bean | |
public HttpInvokerRequestExecutor customSimpleHttpInvoker() { | |
SimpleHttpInvokerRequestExecutor invoker = new SimpleHttpInvokerRequestExecutor() { | |
@Override | |
protected void prepareConnection(HttpURLConnection connection, int contentLength) throws IOException { | |
super.prepareConnection(connection, contentLength); | |
connection.setRequestProperty("Connection", "close"); // custom http header | |
} | |
}; | |
invoker.setReadTimeout(5*1000); // custom read timeout | |
invoker.setConnectTimeout(15*1000); // custom connection timeout | |
return invoker; | |
} | |
} |
Configuring Timeout with JAX-WS:
- https://stackoverflow.com/questions/2148915/how-do-i-set-the-timeout-for-a-jax-ws-webservice-client
- https://examples.javacodegeeks.com/enterprise-java/jws/jax-ws-client-timeout-example/
- https://www.google.com/search?q=JAXWS+timeout&rlz=1C1GCEU_pt-BRBR821BR822&oq=JAXWS+timeout&aqs=chrome..69i57j69i65j35i39l2j0l2.6120j0j7&sourceid=chrome&ie=UTF-8
- https://www.igorkromin.net/index.php/2018/12/06/setting-jax-ws-webservice-client-timeout-values-correctly-within-a-weblogic-12c-container/
Programmatic timeout using a thread: https://gist.github.com/rponte/70ba7b6cf4d370288e1e
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More information about connection and socket timeouts, https://www.baeldung.com/httpclient-timeout