本文整理汇总了Java中org.ektorp.http.StdHttpClient类的典型用法代码示例。如果您正苦于以下问题:Java StdHttpClient类的具体用法?Java StdHttpClient怎么用?Java StdHttpClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StdHttpClient类属于org.ektorp.http包,在下文中一共展示了StdHttpClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: beforeClass
import org.ektorp.http.StdHttpClient; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() throws MalformedURLException {
HttpClient httpClient = new StdHttpClient.Builder()
.url("http://192.168.99.100:5984/")
.username("mapUser")
.password("myCouchDBSecret")
.build();
dbi = new StdCouchDbInstance(httpClient);
CouchDbConnector dbc = dbi.createConnector(CouchInjector.DB_NAME, false);
repo = new MapRepository();
repo.db = dbc;
repo.postConstruct();
debugWriter = repo.sites.mapper.writerWithDefaultPrettyPrinter();
}
示例2: initConnection
import org.ektorp.http.StdHttpClient; //导入依赖的package包/类
private CouchDbConnector initConnection(String dbName, String userName, String password, String host, int port, boolean enableSSL, int timeout)
{
Builder builder = new StdHttpClient.Builder()
.host(host)
.port(port)
.connectionTimeout(timeout)
.socketTimeout(timeout)
.enableSSL(enableSSL);
if(userName != null && !userName.isEmpty() && password != null && !password.isEmpty())
builder.username(userName).password(password);
dbInstance = new StdCouchDbInstance(builder.build());
if (!dbInstance.checkIfDbExists(dbName))
dbInstance.createDatabase(dbName);
CouchDbConnector couchDB = dbInstance.createConnector(dbName, true);
return couchDB;
}
示例3: connect
import org.ektorp.http.StdHttpClient; //导入依赖的package包/类
@Override
public void connect() throws IOException
{
StdHttpClient.Builder builder = new StdHttpClient.Builder();
if (dbUrl != null) {
try {
builder.url(dbUrl);
} catch (MalformedURLException e) {
throw new IllegalArgumentException(e.getMessage());
}
}
if (userName != null) {
builder.username(userName);
}
if (password != null) {
builder.password(password);
}
HttpClient httpClient = builder.build();
couchInstance = new StdCouchDbInstance(httpClient);
dbConnector = couchInstance.createConnector(dbName, false);
}
示例4: before
import org.ektorp.http.StdHttpClient; //导入依赖的package包/类
@Before
public void before() throws Exception {
loadConfiguration();
if (isConfigured()) {
final int timeout = 8 * 1000; // 8 seconds should be more than
// enough
httpClient = new StdHttpClient.Builder().socketTimeout(timeout).host(getHostname()).build();
// set up a simple database
couchDbInstance = new StdCouchDbInstance(httpClient);
final String databaseName = getDatabaseName();
if (couchDbInstance.getAllDatabases().contains(databaseName)) {
throw new IllegalStateException("Couch DB instance already has a database called " + databaseName);
}
connector = couchDbInstance.createConnector(databaseName, true);
final String[] columnNames = new String[] { "name", "gender", "age" };
final ColumnType[] columnTypes = new ColumnType[] { ColumnType.STRING, ColumnType.CHAR,
ColumnType.INTEGER };
predefinedTableDef = new SimpleTableDef(databaseName, columnNames, columnTypes);
}
}
示例5: beforeClass
import org.ektorp.http.StdHttpClient; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() throws MalformedURLException {
roomOwner = "testOwner";
HttpClient httpClient = new StdHttpClient.Builder()
.url("http://127.0.0.1:5984/")
.build();
dbi = new StdCouchDbInstance(httpClient);
CouchDbConnector dbc = dbi.createConnector(CouchInjector.DB_NAME, false);
repo = new MapRepository();
repo.db = dbc;
repo.postConstruct();
debugWriter = repo.sites.mapper.writerWithDefaultPrettyPrinter();
swapRoomsAccessPolicy = new AccessCertainResourcesPolicy(Collections.singleton(SiteSwapPermission.class));
}
示例6: initConnection
import org.ektorp.http.StdHttpClient; //导入依赖的package包/类
private CouchDbConnector initConnection() throws MalformedURLException, ProxyInitilizedFailedException {
String username = ConfigManager.get("couchdbUsername");
String password = ConfigManager.get("couchdbPassword");
String host = ConfigManager.get("couchdbHost");
int port = ConfigManager.getInt("couchdbPort");
int timeout = ConfigManager.getInt("couchdbTimeout");
boolean enableSSL = ConfigManager.getBoolean("couchdbEnableSSL", false);
String dbName = ConfigManager.get("couchdbDBName");
Builder builder = new StdHttpClient.Builder();
builder = builder
.host(host)
.port(port)
.connectionTimeout(timeout)
.enableSSL(enableSSL);
if (username != null && !username.isEmpty() && password != null && !password.isEmpty() ) {
builder = builder.username(username).password(password);
}
CouchDbInstance dbInstance = new StdCouchDbInstance(builder.build());
if (!dbInstance.checkIfDbExists(dbName))
dbInstance.createDatabase(dbName);
CouchDbConnector couchDB = dbInstance.createConnector(dbName, true);
return couchDB;
}
示例7: setup
import org.ektorp.http.StdHttpClient; //导入依赖的package包/类
static void setup()
{
StdHttpClient.Builder builder = new StdHttpClient.Builder();
HttpClient httpClient = builder.build();
StdCouchDbInstance instance = new StdCouchDbInstance(httpClient);
DbPath dbPath = new DbPath(TEST_DB);
if (instance.checkIfDbExists((dbPath))) {
instance.deleteDatabase(dbPath.getPath());
}
connector = instance.createConnector(TEST_DB, true);
}
示例8: teardown
import org.ektorp.http.StdHttpClient; //导入依赖的package包/类
static void teardown()
{
StdHttpClient.Builder builder = new StdHttpClient.Builder();
HttpClient httpClient = builder.build();
StdCouchDbInstance instance = new StdCouchDbInstance(httpClient);
DbPath dbPath = new DbPath(TEST_DB);
if (instance.checkIfDbExists((dbPath))) {
instance.deleteDatabase(dbPath.getPath());
}
}
示例9: init
import org.ektorp.http.StdHttpClient; //导入依赖的package包/类
/**
* Inits the.
*/
@PostConstruct
public void init() {
LOGGER.trace("Initializing version: " + WifKeys.WIF_KEY_VERSION);
// TODO do it more elegant,enable the rewriting of reviews, only for
// development
System.setProperty("org.ektorp.support.AutoUpdateViewOnChange", "true");
repoURL = couchDBConfig.getRepoURL();
wifDB = couchDBConfig.getWifDB();
loginRequired = couchDBConfig.isLoginRequired();
LOGGER.info("Using CouchDB URL {}, with What If database: {} ", repoURL,
wifDB);
try {
if (loginRequired) {
LOGGER.info("using the login name {} ", couchDBConfig.getLogin());
httpClient = new StdHttpClient.Builder().url(repoURL)
.username(couchDBConfig.getLogin())
.password(couchDBConfig.getPassword()).build();
} else {
LOGGER.info("authentication not required, not using credentials");
httpClient = new StdHttpClient.Builder().url(repoURL).build();
}
} catch (MalformedURLException e) {
LOGGER.error(
"MalformedURLException: Using CouchDB URL {} , with What If database: {} "
+ repoURL, wifDB);
}
CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
// TODO There should be one for each repository
db = new StdCouchDbConnector(wifDB, dbInstance);
}
示例10: getDB
import org.ektorp.http.StdHttpClient; //导入依赖的package包/类
public UpdateableDataContext getDB(String user, String password) throws Exception {
HttpClient httpClient = new StdHttpClient.Builder().host(getHostname()).password(password).username(user).maxConnections(4).build();
StdCouchDbInstance couchDbInstance = new StdCouchDbInstance(httpClient);
UpdateableDataContext dataContext = new CouchDbDataContext(couchDbInstance);
return dataContext;
}
示例11: create
import org.ektorp.http.StdHttpClient; //导入依赖的package包/类
@Override
public CouchDbInstance create(CloudantServiceInfo serviceInfo,
ServiceConnectorConfig serviceConnectorConfig) {
HttpClient httpClient;
try {
httpClient = new StdHttpClient.Builder()
.url(serviceInfo.getUrl())
.build();
return new StdCouchDbInstance(httpClient);
} catch (MalformedURLException e) {
LOG.logp(Level.WARNING, CloudantInstanceCreator.class.getName(), "create", "Error parsing URL", e);
return null;
}
}
示例12: init
import org.ektorp.http.StdHttpClient; //导入依赖的package包/类
@PostConstruct
private void init() {
HttpClient httpClient;
httpClient = new StdHttpClient.Builder()
.host("127.0.0.1")
.port(5984)
.username("admin")
.password("password")
.build();
CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
couchDBConnector = dbInstance.createConnector("relax-dms", false);
restTemplate = new RestTemplate(httpClient);
}
示例13: configure
import org.ektorp.http.StdHttpClient; //导入依赖的package包/类
@Override
protected void configure() {
try {
CouchDbInstance couchDbInstance = new StdCouchDbInstance(new StdHttpClient.Builder()
.url(couchDbConfig.getUrl())
.username(couchDbConfig.getAdmin().getUsername())
.password(couchDbConfig.getAdmin().getPassword())
.maxConnections(couchDbConfig.getMaxConnections())
.build());
DbConnectorFactory connectorFactory = new DbConnectorFactory(couchDbInstance, couchDbConfig.getDbPrefix());
CouchDbConnector dataSourceConnector = connectorFactory.createConnector(OdsRegistrationRepository.DATABASE_NAME, true);
bind(CouchDbConnector.class).annotatedWith(Names.named(OdsRegistrationRepository.DATABASE_NAME)).toInstance(dataSourceConnector);
CouchDbConnector clientConnector = connectorFactory.createConnector(ClientRepository.DATABASE_NAME, true);
bind(CouchDbConnector.class).annotatedWith(Names.named(ClientRepository.DATABASE_NAME)).toInstance(clientConnector);
CouchDbConnector eplAdapterConnector = connectorFactory.createConnector(EplAdapterRepository.DATABASE_NAME, true);
bind(CouchDbConnector.class).annotatedWith(Names.named(EplAdapterRepository.DATABASE_NAME)).toInstance(eplAdapterConnector);
CouchDbConnector userConnector = connectorFactory.createConnector(UserRepository.DATABASE_NAME, true);
bind(CouchDbConnector.class).annotatedWith(Names.named(UserRepository.DATABASE_NAME)).toInstance(userConnector);
} catch (MalformedURLException mue) {
throw new RuntimeException(mue);
}
}
示例14: createConnector
import org.ektorp.http.StdHttpClient; //导入依赖的package包/类
public CouchDbConnector createConnector(String couchUrl, String dbName,
int maxConnections, String username, String password) {
HttpClient httpClient;
try {
StdHttpClient.Builder builder = new StdHttpClient.Builder().url(
couchUrl).maxConnections(maxConnections);
if (username != null) {
builder.username(username);
}
if (password != null) {
builder.password(password);
}
httpClient = builder.build();
} catch (MalformedURLException e) {
throw new IllegalStateException(e);
}
CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
StdCouchDbConnector connector = new StdCouchDbConnector(dbName,
dbInstance) {
final StreamingJsonSerializer customSerializer = new StreamingJsonSerializer(
mapper);
@Override
protected String serializeToJson(Object o) {
return customSerializer.toJson(o);
}
};
return connector;
}
示例15: beforeClass
import org.ektorp.http.StdHttpClient; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() throws MalformedURLException {
httpClient = new StdHttpClient.Builder().url(SERVER_URL).build();
repository = new CouchDbStatementRepository(
new CouchDbConnectorFactory().createConnector(SERVER_URL,
DB_ID, 20), new QueryResolver());
}