[OLINGO-242] Implementation provided

This commit is contained in:
Francesco Chicchiriccò 2014-04-09 17:34:26 +02:00
parent 9f96234e69
commit 6019385e61
5 changed files with 58 additions and 9 deletions

View File

@ -99,6 +99,12 @@
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>

View File

@ -22,7 +22,6 @@ import java.net.URI;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.olingo.client.api.http.HttpMethod;
@ -43,8 +42,8 @@ public class BasicAuthHttpClientFactory extends DefaultHttpClientFactory {
}
@Override
public HttpClient createHttpClient(final HttpMethod method, final URI uri) {
final DefaultHttpClient httpclient = (DefaultHttpClient) super.createHttpClient(method, uri);
public DefaultHttpClient createHttpClient(final HttpMethod method, final URI uri) {
final DefaultHttpClient httpclient = super.createHttpClient(method, uri);
httpclient.getCredentialsProvider().setCredentials(
new AuthScope(uri.getHost(), uri.getPort()),

View File

@ -18,13 +18,18 @@
*/
package org.apache.olingo.client.core.http;
import java.io.InputStream;
import java.io.Serializable;
import java.net.URI;
import java.util.Properties;
import org.apache.commons.io.IOUtils;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.CoreProtocolPNames;
import org.apache.olingo.client.api.http.HttpClientFactory;
import org.apache.olingo.client.api.http.HttpMethod;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Default implementation returning HttpClients with default parameters.
@ -33,8 +38,31 @@ public class DefaultHttpClientFactory implements HttpClientFactory, Serializable
private static final long serialVersionUID = -2461355444507227332L;
private static final Logger LOG = LoggerFactory.getLogger(DefaultHttpClientFactory.class);
private static final String USER_AGENT;
static {
final StringBuilder userAgent = new StringBuilder("Apache-Olingo");
final InputStream input = DefaultHttpClientFactory.class.getResourceAsStream("/client.properties");
try {
final Properties prop = new Properties();
prop.load(input);
userAgent.append('/').append(prop.getProperty("version"));
} catch (Exception e) {
LOG.warn("Could not get Apache Olingo version", e);
} finally {
IOUtils.closeQuietly(input);
}
USER_AGENT = userAgent.toString();
}
@Override
public HttpClient createHttpClient(final HttpMethod method, final URI uri) {
return new DefaultHttpClient();
public DefaultHttpClient createHttpClient(final HttpMethod method, final URI uri) {
final DefaultHttpClient client = new DefaultHttpClient();
client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT);
return client;
}
}

View File

@ -23,7 +23,6 @@ import java.net.URI;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.NTCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.olingo.client.api.http.HttpMethod;
@ -59,8 +58,8 @@ public class NTLMAuthHttpClientFactory extends DefaultHttpClientFactory {
}
@Override
public HttpClient createHttpClient(final HttpMethod method, final URI uri) {
final DefaultHttpClient httpclient = (DefaultHttpClient) super.createHttpClient(method, uri);
public DefaultHttpClient createHttpClient(final HttpMethod method, final URI uri) {
final DefaultHttpClient httpclient = super.createHttpClient(method, uri);
final CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY,

View File

@ -0,0 +1,17 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
version=${project.version}