Try with the below code...
CustomeBasicAuthHttpClientFactory Customfact =
new CustomeBasicAuthHttpClientFactory(username, password);
client.getConfiguration().setHttpClientFactory(Customfact);
import java.util.ArrayList;
import javax.net.ssl.SSLContext;
import org.apache.http.*;
import org.apache.olingo.client.core.http.DefaultHttpClientFactory;
import org.apache.olingo.commons.api.http.HttpMethod;
public class CustomeBasicAuthHttpClientFactory extends DefaultHttpClientFactory {
private final String username;
private final String password;
public CustomeBasicAuthHttpClientFactory(String username, String password) {
this.username = username;
this.password = password;
}
public DefaultHttpClient create(HttpMethod method, URI uri) {
Logger.logMessage(LogLevel.LEVEL_DEBUG, ODATAstepAdaptor.ODATA_CLIENT_LOG_MODULE, "In side:create(HttpMethod method, URI uri)");
DefaultHttpClient client=null;
String[] tlsProtocols=null;
String[] cipherSuites=null;
try {
String filepath=System.getProperty("com.xxx.xxxx.home");
Logger.logMessage(LogLevel.LEVEL_DEBUG, ODATAstepAdaptor.ODATA_CLIENT_LOG_MODULE, "FilePath=>"+filepath+"/java/conf/tlsProtocols.dat");
BufferedReader in = new BufferedReader(new FileReader(filepath+"/java/conf/tlsProtocols.dat"));
String str=null;
ArrayList<String> lines = new ArrayList<String>();
while((str = in.readLine()) != null){
lines.add(str);
}
in.close();
tlsProtocols = lines.toArray(new String[lines.size()]);
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, null, null);
//SSLSocketFactory sf = new SSLSocketFactory(sslContext);
SSLSocketFactory sf = new CustomizedSSLSocketFactory(sslContext,null,tlsProtocols,cipherSuites);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", sf, 443));
ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
client=new DefaultHttpClient(ccm, params);
client.getCredentialsProvider().setCredentials(new AuthScope(uri.getHost(), uri.getPort()), new UsernamePasswordCredentials(this.username, this.password));
} catch (Exception e) {
Logger.logMessage(LogLevel.LEVEL_ERROR, ODATAstepAdaptor.ODATA_CLIENT_LOG_MODULE,e.getMessage());
}
return client;
}
}