下面列出了怎么用org.apache.http.protocol.BasicHttpContext的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public boolean deleteFromStore(APIIdentifier apiId, APIStore store) throws APIManagementException {
boolean deleted = false;
if (store.getEndpoint() == null || store.getUsername() == null || store.getPassword() == null) {
String msg = "External APIStore endpoint URL or credentials are not defined.Cannot proceed with publishing API to the APIStore - " + store.getDisplayName();
throw new APIManagementException(msg);
} else {
CookieStore cookieStore = new BasicCookieStore();
HttpContext httpContext = new BasicHttpContext();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
boolean authenticated = authenticateAPIM(store,httpContext);
if (authenticated) {
deleted = deleteWSO2Store(apiId, store.getUsername(), store.getEndpoint(), httpContext,store.getDisplayName());
logoutFromExternalStore(store, httpContext);
}
return deleted;
}
}
StatefullRestTemplate(HttpContext httpContext) {
super();
HttpClient httpClient = HttpClientBuilder.create().build();
this.httpContext = httpContext == null ? new BasicHttpContext() : httpContext;
StatefullHttpComponentsClientHttpRequestFactory statefullHttpComponentsClientHttpRequestFactory
= new StatefullHttpComponentsClientHttpRequestFactory(httpClient, httpContext);
super.setRequestFactory(statefullHttpComponentsClientHttpRequestFactory);
List<HttpMessageConverter<?>> converters = this.getMessageConverters();
for (HttpMessageConverter<?> converter : converters) {
if (converter instanceof MappingJackson2HttpMessageConverter) {
List<MediaType> mediaTypes = converter.getSupportedMediaTypes();
List<MediaType> newMediaTypes = new ArrayList<>(mediaTypes);
newMediaTypes.add(MediaType.TEXT_HTML);
((MappingJackson2HttpMessageConverter) converter).setSupportedMediaTypes(newMediaTypes);
}
}
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
NULogger.getLogger().info("Getting startup cookies & link from DropBox.com");
responseString = NUHttpClientUtils.getData("https://www.dropbox.com/login", httpContext);
doc = Jsoup.parse(responseString);
cont = doc.select("form").first().select("input[name=cont]").attr("value");
signup_data = doc.select("form").first().select("input[name=signup_data]").attr("value");
signup_tag = doc.select("form").first().select("input[name=signup_data]").attr("value");
recaptcha_resp = doc.select("form").first().select("input[name=recaptcha_response_field]").attr("value");
recaptcha_key = doc.select("form").first().select("input[name=recaptcha_public_key]").attr("value");
db_t_val = doc.select("input[name=t]").attr("value");
}
@Override
public void login() {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
try {
initialize();
loginZShare();
} catch(NUException ex){
ex.printError();
resetLogin();
accountUIShow().setVisible(true);
} catch (Exception e) {
NULogger.getLogger().log(Level.SEVERE, "Error in ZShare.net Login: {0}", e);
resetLogin();
showWarningMessage( Translation.T().loginerror(), HOSTNAME);
accountUIShow().setVisible(true);
}
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
NULogger.getLogger().info("** JheBerg.net ** => Initiating plugin, please wait ...");
responseString = NUHttpClientUtils.getData("http://www.jheberg.net/", httpContext);
doc = Jsoup.parse(responseString);
csrfmiddlewaretoken = doc.select("form").first().select("input[name=csrfmiddlewaretoken]").attr("value");
if (!csrfmiddlewaretoken.isEmpty()){
NULogger.getLogger().info("** JheBerg.net ** => Login token found successfully, proceeding ...");
} else {
NULogger.getLogger().info("** JheBerg.net ** => Error! Unable to find the login token!");
}
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
//NULogger.getLogger().info("Getting startup cookies & link from FileHoot.com");
//responseString = NUHttpClientUtils.getData("http://filehoot.com", httpContext);
}
private void initialize() throws Exception {
RemoveCryptographyRestrictions.removeCryptographyRestrictions();
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
NULogger.getLogger().info("Getting startup cookies & link from SendSpace.com");
responseString = NUHttpClientUtils.getData("https://www.sendspace.com/", httpContext);
doc = Jsoup.parse(responseString);
target = doc.select("form").eq(1).select("input[name=target]").attr("value");
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
//NULogger.getLogger().info("Getting startup cookies & link from Asfile.com");
//responseString = NUHttpClientUtils.getData("http://asfile.com", httpContext);
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
NULogger.getLogger().info("Getting startup cookies & link from UploadHero.co");
responseString = NUHttpClientUtils.getData("http://uploadhero.co/connection", httpContext);
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
//NULogger.getLogger().info("Getting startup cookies & link from IndiShare.com");
//responseString = NUHttpClientUtils.getData("http://www.indishare.com/", httpContext);
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
//NULogger.getLogger().info("Getting startup cookies & link from MediaFire.com");
//responseString = NUHttpClientUtils.getData("MediaFire.com", httpContext);
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
//NULogger.getLogger().info("Getting startup cookies & link from Go4Up.com");
//responseString = NUHttpClientUtils.getData("", httpContext);
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
NULogger.getLogger().info("Getting startup cookies & link from UltraMegaBit.com");
responseString = NUHttpClientUtils.getData("https://ultramegabit.com/login", httpContext);
csrf_token = Jsoup.parse(responseString).select("input[name=csrf_token]").val();
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
//NULogger.getLogger().info("Getting startup cookies & link from LunaticFiles.com");
//responseString = NUHttpClientUtils.getData("LunaticFiles.com", httpContext);
}
@Override
protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) {
final AuthCache authCache = new BasicAuthCache();
final BasicScheme basicAuth = new BasicScheme();
authCache.put(host, basicAuth);
final BasicHttpContext localcontext = new BasicHttpContext();
localcontext.setAttribute(HttpClientContext.AUTH_CACHE, authCache);
return localcontext;
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
//NULogger.getLogger().info("Getting startup cookies & link from UpaFile.com");
//responseString = NUHttpClientUtils.getData("http://upafile.com", httpContext);
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
//NULogger.getLogger().info("Getting startup cookies & link from SpeedVideo.net");
//responseString = NUHttpClientUtils.getData("http://speedvideo.net/", httpContext);
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
NULogger.getLogger().info("Getting startup cookies & link from UsersFiles.com");
responseString = NUHttpClientUtils.getData("https://usersfiles.com/", httpContext);
doc = Jsoup.parse(responseString);
rand = doc.select("form[name=FL]").select("input[name=rand]").attr("value");
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
//NULogger.getLogger().info("Getting startup cookies & link from GriftHost.com");
//responseString = NUHttpClientUtils.getData("http://grifthost.com", httpContext);
}
@Bean
public RestTemplate restTemplate() {
CookieStore cookieStore = new BasicCookieStore();
HttpContext httpContext = new BasicHttpContext();
httpContext.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore);
httpContext.setAttribute(HttpClientContext.REQUEST_CONFIG, RequestConfig.custom().setRedirectsEnabled(false).build());
return new StatefullRestTemplate(httpContext);
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
//NULogger.getLogger().info("Getting startup cookies & link from ArabLoads.com");
//responseString = NUHttpClientUtils.getData("http://arabloads.com", httpContext);
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
//NULogger.getLogger().info("Getting startup cookies & link from TeraFile.co");
//responseString = NUHttpClientUtils.getData("http://terafile.co", httpContext);
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
NULogger.getLogger().info("Getting startup cookies & link from UploadAble.ch");
responseString = NUHttpClientUtils.getData("https://www.uploadable.ch/login.php", httpContext);
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
//NULogger.getLogger().info("Getting startup cookies & link from NovaFile.com");
//responseString = NUHttpClientUtils.getData("http://novafile.com", httpContext);
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
//NULogger.getLogger().info("Getting startup cookies & link from IguanaShare.com");
//responseString = NUHttpClientUtils.getData("", httpContext);
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
//NULogger.getLogger().info("Getting startup cookies & link from PutStream.com");
//responseString = NUHttpClientUtils.getData("", httpContext);
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
//NULogger.getLogger().info("Getting startup cookies & link from RainUpload.net");
//responseString = NUHttpClientUtils.getData("http://rainupload.net", httpContext);
}
@Override
public Client create(final RestClientConfiguration configuration) {
checkNotNull(configuration);
try (TcclBlock tccl = TcclBlock.begin(ResteasyClientBuilder.class)) {
HttpContext httpContext = new BasicHttpContext();
if (configuration.getUseTrustStore()) {
httpContext.setAttribute(SSLContextSelector.USE_TRUST_STORE, true);
}
HttpClient client;
if (configuration.getHttpClient() != null) {
client = checkNotNull(configuration.getHttpClient().get());
}
else {
client = httpClient.get();
}
ClientHttpEngine httpEngine = new ApacheHttpClient4Engine(client, httpContext);
ResteasyClientBuilder builder = new ResteasyClientBuilder().httpEngine(httpEngine);
if (configuration.getCustomizer() != null) {
configuration.getCustomizer().apply(builder);
}
return builder.build();
}
}
private HttpResponse login(BonitaCredentials credentials) throws IOException {
BasicHttpContext httpContext = new BasicHttpContext();
BasicCookieStore cookieStore = new BasicCookieStore();
httpContext.setAttribute("http.cookie-store", cookieStore);
List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
urlParameters.add(new BasicNameValuePair("username", credentials.username));
urlParameters.add(new BasicNameValuePair("password", credentials.password));
urlParameters.add(new BasicNameValuePair("redirect", "false"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(urlParameters, "utf-8");
HttpPost postRequest = new HttpPost(credentials.loginServletURI);
postRequest.setEntity(entity);
return getProxyClient().execute(postRequest, httpContext);
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
//NULogger.getLogger().info("Getting startup cookies & link from YaVideo.tv");
//responseString = NUHttpClientUtils.getData("", httpContext);
}