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
| import java.io.IOException;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.methods.PostMethod;
import org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor;
import org.springframework.remoting.httpinvoker.HttpInvokerClientConfiguration;
public class Titi extends CommonsHttpInvokerRequestExecutor {
private final ThreadLocal<String> threadLocal = new ThreadLocal<String>();
// private Object threadLocalLock = new Object();
@Override
protected PostMethod createPostMethod(
final HttpInvokerClientConfiguration config) throws IOException {
final String ppauth = threadLocal.get();
if (ppauth == null) {
throw new RuntimeException(
"No authentification cookie found for this query!");
}
final PostMethod post = super.createPostMethod(config);
post.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
post.setRequestHeader(new Header("Cookie", "ppauth=" + ppauth));
return post;
}
public void setPPAuthCookie(final String cookie) {
threadLocal.set(cookie);
}
} |