use of org.apache.http.params.BasicHttpParams in project stanbol by apache.
the class RestfulLangidentEngine method activate.
/**
* Activate and read the properties. Configures and initialises a POSTagger for each language configured in
* CONFIG_LANGUAGES.
*
* @param ce the {@link org.osgi.service.component.ComponentContext}
*/
@Activate
protected void activate(ComponentContext ce) throws ConfigurationException, IOException {
super.activate(ce);
log.info("activate {} '{}'", getClass().getSimpleName(), getName());
@SuppressWarnings("unchecked") Dictionary<String, Object> properties = ce.getProperties();
Object value = properties.get(ANALYSIS_SERVICE_URL);
if (value == null) {
throw new ConfigurationException(ANALYSIS_SERVICE_URL, "The RESTful Language Identification Service URL is missing in the provided configuration!");
} else {
try {
serviceUrl = new URI(value.toString());
log.info(" ... service: {}", serviceUrl);
} catch (URISyntaxException e) {
throw new ConfigurationException(ANALYSIS_SERVICE_URL, "The parsed RESTful Language Identification Service URL '" + value + "'is not a valid URL!", e);
}
}
String usr;
String pwd;
value = properties.get(ANALYSIS_SERVICE_USER);
if (value != null && !value.toString().isEmpty()) {
usr = value.toString();
value = properties.get(ANALYSIS_SERVICE_PWD);
pwd = value == null ? null : value.toString();
} else {
// no user set
usr = null;
pwd = null;
}
// init the http client
httpParams = new BasicHttpParams();
httpParams.setParameter(CoreProtocolPNames.USER_AGENT, "Apache Stanbol RESTful Language Identification Engine");
httpParams.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, true);
httpParams.setIntParameter(ClientPNames.MAX_REDIRECTS, 3);
httpParams.setBooleanParameter(CoreConnectionPNames.SO_KEEPALIVE, true);
connectionManager = new PoolingClientConnectionManager();
connectionManager.setMaxTotal(20);
connectionManager.setDefaultMaxPerRoute(20);
httpClient = new DefaultHttpClient(connectionManager, httpParams);
if (usr != null) {
log.info(" ... setting user to {}", usr);
httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(usr, pwd));
// And add request interceptor to have preemptive authentication
httpClient.addRequestInterceptor(new PreemptiveAuthInterceptor(), 0);
}
}
use of org.apache.http.params.BasicHttpParams in project stanbol by apache.
the class RestfulNlpAnalysisEngine method activate.
/**
* Activate and read the properties. Configures and initialises a POSTagger for each language configured in
* CONFIG_LANGUAGES.
*
* @param ce the {@link org.osgi.service.component.ComponentContext}
*/
@Activate
protected void activate(ComponentContext ce) throws ConfigurationException, IOException {
super.activate(ce);
log.info("activate {} '{}'", getClass().getSimpleName(), getName());
config = ce.getProperties();
Object value = config.get(ANALYSIS_SERVICE_URL);
if (value == null) {
throw new ConfigurationException(ANALYSIS_SERVICE_URL, "The RESTful Analysis Service URL is missing in the provided configuration!");
} else {
try {
analysisServiceUrl = new URI(value.toString());
log.info(" ... service: {}", analysisServiceUrl);
} catch (URISyntaxException e) {
throw new ConfigurationException(ANALYSIS_SERVICE_URL, "The parsed RESTful Analysis Service URL '" + value + "'is not a valid URL!", e);
}
}
String usr;
String pwd;
value = config.get(ANALYSIS_SERVICE_USER);
if (value != null && !value.toString().isEmpty()) {
usr = value.toString();
value = config.get(ANALYSIS_SERVICE_PWD);
pwd = value == null ? null : value.toString();
} else {
// no user set
usr = null;
pwd = null;
}
// init the http client
httpParams = new BasicHttpParams();
httpParams.setParameter(CoreProtocolPNames.USER_AGENT, "Apache Stanbol RESTful NLP Analysis Engine");
httpParams.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, true);
httpParams.setIntParameter(ClientPNames.MAX_REDIRECTS, 3);
httpParams.setBooleanParameter(CoreConnectionPNames.SO_KEEPALIVE, true);
connectionManager = new PoolingClientConnectionManager();
connectionManager.setMaxTotal(20);
connectionManager.setDefaultMaxPerRoute(20);
// NOTE: The list of supported languages is the combination of the
// languages enabled by the configuration (#languageConfig) and the
// languages supported by the RESTful NLP Analysis Service
// (#supportedLanguages)
// init the language configuration with the engine configuration
languageConfig.setConfiguration(config);
httpClient = new DefaultHttpClient(connectionManager, httpParams);
if (usr != null) {
log.info(" ... setting user to {}", usr);
httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(usr, pwd));
// And add request interceptor to have preemptive authentication
httpClient.addRequestInterceptor(new PreemptiveAuthInterceptor(), 0);
}
// STANBOL-1389: deactivated initialization during activation as this can create
// issues in cases where Stanbol and the NLP service do run in the same
// servlet container.
// initRESTfulNlpAnalysisService();
value = config.get(WRITE_TEXT_ANNOTATIONS_STATE);
if (value instanceof Boolean) {
this.writeTextAnnotations = ((Boolean) value).booleanValue();
} else if (value != null) {
this.writeTextAnnotations = Boolean.parseBoolean(value.toString());
} else {
this.writeTextAnnotations = DEFAULT_WRITE_TEXT_ANNOTATION_STATE;
}
}
use of org.apache.http.params.BasicHttpParams in project ABPlayer by winkstu.
the class HttpUtil method httpGetHost.
public static String httpGetHost(String url) {
HttpGet httpget = new HttpGet(url);
String strResult = "";
BasicHttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, 5000);
HttpConnectionParams.setSoTimeout(httpParams, 5000);
HttpClient httpclient;
try {
httpclient = new DefaultHttpClient(httpParams);
HttpResponse response = httpclient.execute(httpget);
System.out.println(response.getStatusLine().getStatusCode());
if (response.getStatusLine().getStatusCode() == 200) {
strResult = EntityUtils.toString(response.getEntity(), HTTP.UTF_8);
}
} catch (ConnectException e) {
e.printStackTrace();
System.out.println("hosterror");
} catch (ClientProtocolException e) {
System.out.println("Client");
e.printStackTrace();
} catch (IOException e) {
System.out.println("IO");
e.printStackTrace();
}
return strResult;
}
use of org.apache.http.params.BasicHttpParams in project ABPlayer by winkstu.
the class HttpUtil method HttpGetBmpInputStream.
public static InputStream HttpGetBmpInputStream(String url) {
HttpGet httpget = new HttpGet(url);
BasicHttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, 10000);
HttpConnectionParams.setSoTimeout(httpParams, 10000);
InputStream is = null;
try {
HttpClient httpclient = new DefaultHttpClient(httpParams);
HttpResponse response = httpclient.execute(httpget);
is = response.getEntity().getContent();
} catch (Exception e) {
e.printStackTrace();
}
return is;
}
use of org.apache.http.params.BasicHttpParams in project ABPlayer by winkstu.
the class HttpUtil method httpGet.
public static String httpGet(String url) {
System.out.println("httpGet" + url);
HttpGet httpget = new HttpGet(url);
String strResult = null;
BasicHttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, 10000);
HttpConnectionParams.setSoTimeout(httpParams, 10000);
HttpClient httpclient;
try {
httpclient = new DefaultHttpClient(httpParams);
httpget.setHeader("Cookie", cookieName + "=" + cookieValue);
HttpResponse response = httpclient.execute(httpget);
System.out.println(response.getStatusLine().getStatusCode());
if (response.getStatusLine().getStatusCode() == 200) {
strResult = EntityUtils.toString(response.getEntity(), HTTP.UTF_8);
// System.out.println(strResult);
System.out.println("getFinish");
}
} catch (ConnectException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
System.out.println("Client");
e.printStackTrace();
} catch (IOException e) {
System.out.println("IO");
e.printStackTrace();
}
return strResult;
}
Aggregations