Skip to content

Commit

Permalink
Merge pull request #151 from cvedel/0.4.0.0
Browse files Browse the repository at this point in the history
avoid being challenged for each request
  • Loading branch information
Yaguang Wang committed Jan 26, 2014
2 parents 75cd126 + 9536e12 commit 261869f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
7 changes: 6 additions & 1 deletion dev/cosbench-cdmi-base/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,25 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: com.intel.cosbench.api.auth,
com.intel.cosbench.api.context,
com.intel.cosbench.api.storage,
com.intel.cosbench.client.cdmi.util,
com.intel.cosbench.client.http,
com.intel.cosbench.config,
com.intel.cosbench.log,
com.intel.cosbench.client.cdmi.util,
org.apache.commons.codec;version="[1.3.0,2.0.0)",
org.apache.commons.codec.binary;version="1.3.0",
org.apache.commons.codec.net;version="[1.3.0,2.0.0)",
org.apache.commons.io.input;version="[1.3.0,2.0.0)",
org.apache.commons.lang.math;version="2.5.0",
org.apache.http;version="[4.1.4,5.0.0)",
org.apache.http.auth.params;version="[4.1.3,5.0.0)",
org.apache.http.client;version="[4.1.3,5.0.0)",
org.apache.http.client.methods;version="[4.1.3,5.0.0)",
org.apache.http.client.params;version="[4.1.3,5.0.0)",
org.apache.http.client.protocol;version="[4.1.3,5.0.0)",
org.apache.http.conn;version="[4.1.3,5.0.0)",
org.apache.http.entity;version="[4.1.4,5.0.0)",
org.apache.http.impl.client;version="[4.1.3,5.0.0)",
org.apache.http.message;version="[4.1.4,5.0.0)",
org.apache.http.params;version="[4.1.4,5.0.0)",
org.apache.http.protocol;version="[4.1.4,5.0.0)",
org.apache.http.util;version="[4.1.4,5.0.0)"
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package com.intel.cosbench.client.cdmi.base;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Map;
import java.io.*;
import java.util.*;

import org.apache.http.Header;
import org.apache.http.client.HttpClient;
import org.apache.http.auth.params.AuthPNames;
import org.apache.http.client.*;
import org.apache.http.client.params.AuthPolicy;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.message.BasicHeader;
import org.apache.http.protocol.*;


public abstract class BaseCdmiClient {
protected boolean raise_delete_errors = false;
protected HttpClient client;
protected HttpClient client;
protected HttpContext httpContext;
protected String uri;
protected ArrayList<Header> custom_headers = new ArrayList<Header> ();
//
Expand All @@ -21,7 +25,12 @@ public abstract class BaseCdmiClient {
// }

public void init(HttpClient httpClient, String uri, Map<String, String> headerKV, boolean flag) {
this.client = httpClient;
this.client = httpClient;
this.httpContext = new BasicHttpContext();
httpContext.setAttribute(AuthPNames.TARGET_AUTH_PREF, Arrays.asList(new String[] {AuthPolicy.BASIC, AuthPolicy.DIGEST}));

final AuthCache authCache = new BasicAuthCache();
httpContext.setAttribute(ClientContext.AUTH_CACHE, authCache);
this.uri = uri;
this.raise_delete_errors = flag;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void createContainer(String container) throws IOException,

method.setEntity(new StringEntity("{}"));

response = client.execute(method);
response = client.execute(method, httpContext);
int statusCode = response.getStatusLine().getStatusCode();

if (statusCode == SC_CREATED || statusCode == SC_ACCEPTED) {
Expand All @@ -96,7 +96,7 @@ public void deleteContainer(String container) throws IOException,
method.setHeader("X-CDMI-Specification-Version", cdmi_ver);
setCustomHeaders(method);

response = client.execute(method);
response = client.execute(method, httpContext);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == SC_NO_CONTENT)
return;
Expand Down Expand Up @@ -128,7 +128,7 @@ public InputStream getObjectAsStream(String container, String object)
method.setHeader("X-CDMI-Specification-Version", cdmi_ver);
setCustomHeaders(method);

response = client.execute(method);
response = client.execute(method, httpContext);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == SC_OK)
return response.getEntity().getContent();
Expand Down Expand Up @@ -193,7 +193,7 @@ public void storeStreamedObject(String container, String object,

method.setEntity(entity);

response = client.execute(method);
response = client.execute(method, httpContext);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_CREATED) {
return;
Expand Down Expand Up @@ -224,7 +224,7 @@ public void deleteObject(String container, String object)
method.setHeader("X-CDMI-Specification-Version", cdmi_ver);
setCustomHeaders(method);

response = client.execute(method);
response = client.execute(method, httpContext);

int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == SC_NO_CONTENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void createContainer(String container) throws IOException,

setCustomHeaders(method);

response = client.execute(method);
response = client.execute(method, httpContext);
int statusCode = response.getStatusLine().getStatusCode();

if (statusCode == SC_CREATED || statusCode == SC_ACCEPTED) {
Expand All @@ -77,7 +77,7 @@ public void deleteContainer(String container) throws IOException,

setCustomHeaders(method);

response = client.execute(method);
response = client.execute(method, httpContext);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == SC_NO_CONTENT)
return;
Expand Down Expand Up @@ -107,7 +107,7 @@ public InputStream getObjectAsStream(String container, String object)

setCustomHeaders(method);

response = client.execute(method);
response = client.execute(method, httpContext);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == SC_OK)
return response.getEntity().getContent();
Expand Down Expand Up @@ -168,7 +168,7 @@ public void storeStreamedObject(String container, String object,

method.setEntity(entity);

response = client.execute(method);
response = client.execute(method, httpContext);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_CREATED) {
return;
Expand Down Expand Up @@ -198,7 +198,7 @@ public void deleteObject(String container, String object)

setCustomHeaders(method);

response = client.execute(method);
response = client.execute(method, httpContext);

int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == SC_NO_CONTENT)
Expand Down

0 comments on commit 261869f

Please sign in to comment.