本文整理汇总了Java中com.sun.jersey.api.client.filter.HTTPBasicAuthFilter类的典型用法代码示例。如果您正苦于以下问题:Java HTTPBasicAuthFilter类的具体用法?Java HTTPBasicAuthFilter怎么用?Java HTTPBasicAuthFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HTTPBasicAuthFilter类属于com.sun.jersey.api.client.filter包,在下文中一共展示了HTTPBasicAuthFilter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: jirasend
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; //导入依赖的package包/类
/**
* Sends an Activity to SCMActivity Plugin's REST api
* @param activity ScmActivity object corresponding to commit found in push payload
* @throws ScmSyncException on post failure
*/
private void jirasend(ScmActivity activity) throws ScmSyncException {
// Setup Client
Client client = Client.create();
WebResource webResource = client.resource(jiraRestUrl);
client.addFilter(new HTTPBasicAuthFilter(jiraUser, jiraPassword));
// Post to SCMActivity
ClientResponse clientResponse = webResource.type("application/json").post(ClientResponse.class, activity.toJson());
String result = clientResponse.getStatus() + " " + clientResponse.getEntity(String.class);
logger.debug("Jira Send: \n\t" + activity.toString() + "\n\tResponse: " + result );
if (clientResponse.getStatus() == 201 ) {
logger.info("OK " + activity.getChangeId());
} else {
throw new ScmSyncException("Jira Rejected Activity because " + result + " " + activity.toString());
}
}
示例2: getClientResponse
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; //导入依赖的package包/类
private ClientResponse getClientResponse(Object st, String path) {
String masterServer = "http://tinytank.lefrantguillaume.com/api/server/";
ClientConfig clientConfig = new DefaultClientConfig();
clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
Client client = Client.create(clientConfig);
client.addFilter(new HTTPBasicAuthFilter("T0N1jjOQIDmA4cJnmiT6zHvExjoSLRnbqEJ6h2zWKXLtJ9N8ygVHvkP7Sy4kqrv", "lMhIq0tVVwIvPKSBg8p8YbPg0zcvihBPJW6hsEGUiS6byKjoZcymXQs5urequUo"));
WebResource webResource = client.resource(masterServer + path);
System.out.println("sending to data server : " + st);
ClientResponse response = webResource
.accept("application/json")
.type("application/json")
.post(ClientResponse.class, st);
if (response.getStatus() != 200) {
throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
}
System.out.println("response from data server : " + response);
return response;
}
示例3: addJob
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; //导入依赖的package包/类
public int addJob(MsJob job, String username, String password) {
Client client = Client.create();
HTTPBasicAuthFilter authFilter = new HTTPBasicAuthFilter(username, password);
client.addFilter(authFilter);
WebResource webRes = client.resource(BASE_URI);
// String data = "{\"projectId\":\"24\", \"dataDirectory\":\"test\", \"pipeline\":\"MACCOSS\", \"date\":\"2010-03-29\"}";
ClientResponse response = webRes.path("add").type("application/xml").accept("text/plain").post(ClientResponse.class, job);
Status status = response.getClientResponseStatus();
if(status == Status.OK) {
String jobId = response.getEntity(String.class);
System.out.println(jobId);
int idx = jobId.lastIndexOf("ID: ");
return Integer.parseInt(jobId.substring(idx+4).trim());
}
else {
System.err.println(status.getStatusCode()+": "+status.getReasonPhrase());
System.err.println(response.getEntity(String.class));
return 0;
}
}
示例4: delete
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; //导入依赖的package包/类
public void delete(int jobId, String username, String password) {
Client client = Client.create();
HTTPBasicAuthFilter authFilter = new HTTPBasicAuthFilter(username, password);
client.addFilter(authFilter);
WebResource webRes = client.resource(BASE_URI);
ClientResponse response = webRes.path("delete/"+String.valueOf(jobId)).delete(ClientResponse.class);
Status status = response.getClientResponseStatus();
if(status == Status.OK) {
String resp = response.getEntity(String.class);
System.out.println(resp);
}
else {
System.err.println(status.getStatusCode()+": "+status.getReasonPhrase());
System.err.println(response.getEntity(String.class));
}
}
示例5: sendComplexMessage
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; //导入依赖的package包/类
private ClientResponse sendComplexMessage(String recipient) {
Client client = Client.create();
client.addFilter(new HTTPBasicAuthFilter("api", MAILGUN_API_KEY));
WebResource webResource = client.resource("https://api.mailgun.net/v3/" + MAILGUN_DOMAIN_NAME
+ "/messages");
FormDataMultiPart formData = new FormDataMultiPart();
formData.field("from", "Mailgun User <[email protected]" + MAILGUN_DOMAIN_NAME + ">");
formData.field("to", recipient);
formData.field("subject", "Complex Mailgun Example");
formData.field("html", "<html>HTML <strong>content</strong></html>");
ClassLoader classLoader = getClass().getClassLoader();
File txtFile = new File(classLoader.getResource("example-attachment.txt").getFile());
formData.bodyPart(new FileDataBodyPart("attachment", txtFile, MediaType.TEXT_PLAIN_TYPE));
return webResource.type(MediaType.MULTIPART_FORM_DATA_TYPE)
.post(ClientResponse.class, formData);
}
示例6: sendComplexMessage
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; //导入依赖的package包/类
private ClientResponse sendComplexMessage(String recipient) {
Client client = Client.create();
client.addFilter(new HTTPBasicAuthFilter("api", MAILGUN_API_KEY));
FormDataMultiPart formData = new FormDataMultiPart();
formData.field("from", "Mailgun User <[email protected]" + MAILGUN_DOMAIN_NAME + ">");
formData.field("to", recipient);
formData.field("subject", "Complex Mailgun Example");
formData.field("html", "<html>HTML <strong>content</strong></html>");
ClassLoader classLoader = getClass().getClassLoader();
File txtFile = new File(classLoader.getResource("example-attachment.txt").getFile());
formData.bodyPart(new FileDataBodyPart("attachment", txtFile, MediaType.TEXT_PLAIN_TYPE));
WebResource webResource = client.resource(
"https://api.mailgun.net/v3/" + MAILGUN_DOMAIN_NAME + "/messages");
return webResource.type(MediaType.MULTIPART_FORM_DATA_TYPE)
.post(ClientResponse.class, formData);
}
示例7: sendComplexMessage
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; //导入依赖的package包/类
@SuppressWarnings("VariableDeclarationUsageDistance")
private ClientResponse sendComplexMessage(String recipient) {
Client client = Client.create();
client.addFilter(new HTTPBasicAuthFilter("api", MAILGUN_API_KEY));
WebResource webResource =
client.resource("https://api.mailgun.net/v3/" + MAILGUN_DOMAIN_NAME + "/messages");
FormDataMultiPart formData = new FormDataMultiPart();
formData.field("from", "Mailgun User <[email protected]" + MAILGUN_DOMAIN_NAME + ">");
formData.field("to", recipient);
formData.field("subject", "Complex Mailgun Example");
formData.field("html", "<html>HTML <strong>content</strong></html>");
ClassLoader classLoader = getClass().getClassLoader();
File txtFile = new File(classLoader.getResource("example-attachment.txt").getFile());
formData.bodyPart(new FileDataBodyPart("attachment", txtFile, MediaType.TEXT_PLAIN_TYPE));
return webResource
.type(MediaType.MULTIPART_FORM_DATA_TYPE)
.post(ClientResponse.class, formData);
}
示例8: getEwayWebResource
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; //导入依赖的package包/类
/**
* Fetches and configures a Web Resource to connect to eWAY
*
* @return A WebResource
*/
private WebResource getEwayWebResource() {
ClientConfig clientConfig = new DefaultClientConfig();
clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
Client client = Client.create(clientConfig);
client.addFilter(new HTTPBasicAuthFilter(APIKey, password));
if (this.debug) {
client.addFilter(new LoggingFilter(System.out));
}
// Set additional headers
RapidClientFilter rapidFilter = new RapidClientFilter();
rapidFilter.setVersion(apiVersion);
client.addFilter(rapidFilter);
WebResource resource = client.resource(webUrl);
return resource;
}
示例9: AbstractClient
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; //导入依赖的package包/类
/**
* @param apiKey your Asana API key
* @param connectionTimeout the connection timeout in MILLISECONDS
* @param readTimeout the read timeout in MILLISECONDS
*/
public AbstractClient(String apiKey, int connectionTimeout, int readTimeout){
this.apiKey = apiKey;
ClientConfig config = new DefaultClientConfig();
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, true);
mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
JacksonJsonProvider provider = new JacksonJsonProvider(mapper);
config.getSingletons().add(provider);
//config.getClasses().add(JacksonJsonProvider.class);
Client client = Client.create(config);
client.addFilter(new HTTPBasicAuthFilter(apiKey, ""));
client.setConnectTimeout(connectionTimeout);
client.setReadTimeout(readTimeout);
service = client.resource(UriBuilder.fromUri(BASE_URL).build());
}
示例10: CPEClientSession
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; //导入依赖的package包/类
public CPEClientSession (CpeActions cpeActions, String username, String passwd, String authtype) {
this.cpeActions = cpeActions;
this.authtype = authtype;
this.username = username;
this.passwd = passwd;
String urlstr = ((ConfParameter)this.cpeActions.confdb.confs.get(this.cpeActions.confdb.props.getProperty("MgmtServer_URL"))).value; //"http://192.168.1.50:8085/ws?wsdl";
System.out.println("ACS MGMT URL -------> " + urlstr);
service = ResourceAPI.getInstance().getResourceAPI(urlstr);
if (username != null && passwd != null) {
if (authtype.equalsIgnoreCase("digest")) {
service.addFilter(new HTTPDigestAuthFilter(username, passwd));
} else {
service.addFilter(new HTTPBasicAuthFilter(username, passwd));
}
//System.out.println("==========================> " + username + " " + passwd);
}
//System.out.println(" 2nd time ==============> " + username + " " + passwd);
}
示例11: getClient
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; //导入依赖的package包/类
/**
* Returns jersey client to make any call to webservice
* @return
*/
private Client getClient(boolean is_multipart) {
if(m_client == null) {
if(is_multipart) {
ClientConfig config = new DefaultClientConfig();
config.getClasses().add(MultiPartWriter.class);
m_client = Client.create(config);
} else {
m_client = new Client();
}
if(!isTokenbasedAuth) {
final HTTPBasicAuthFilter authFilter = new HTTPBasicAuthFilter(x_username, x_password);
m_client.addFilter(authFilter);
m_client.addFilter(new LoggingFilter());
} else {
//TODO for token based authentication
}
}
return m_client;
}
示例12: authenticateLoginCredentials
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; //导入依赖的package包/类
/**
* Use REST API to authenticate provided credentials
*
* @throws Exception
*/
private void authenticateLoginCredentials() throws Exception {
if ( client == null ) {
ClientConfig clientConfig = new DefaultClientConfig();
clientConfig.getFeatures().put( JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE );
client = Client.create( clientConfig );
client.addFilter( new HTTPBasicAuthFilter( username, password ) );
}
WebResource resource = client.resource( url + AUTHENTICATION + AdministerSecurityAction.NAME );
String response = resource.get( String.class );
if ( !response.equals( "true" ) ) {
throw new Exception( Messages.getInstance().getString( "REPOSITORY_CLEANUP_UTIL.ERROR_0012.ACCESS_DENIED" ) );
}
}
示例13: getClientBuilder
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; //导入依赖的package包/类
/**
* Gets a client web resource builder for the base XOS REST API
* with an optional additional URI.
*
* @param uri URI suffix to append to base URI
* @return web resource builder
*/
public WebResource.Builder getClientBuilder(String uri) {
Client client = Client.create();
client.addFilter(new HTTPBasicAuthFilter(AUTH_USER, AUTH_PASS));
WebResource resource = client.resource(baseUrl() + uri);
log.info("XOS REST CALL>> {}", resource);
return resource.accept(UTF_8).type(UTF_8);
}
示例14: setConf
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; //导入依赖的package包/类
@Override
public void setConf(Configuration conf) {
super.setConf(conf);
if (conf == null) {
// Configured gets passed null before real conf. Why? I don't know.
return;
}
serverHostname = conf.get(REST_API_CLUSTER_MANAGER_HOSTNAME, DEFAULT_SERVER_HOSTNAME);
serverUsername = conf.get(REST_API_CLUSTER_MANAGER_USERNAME, DEFAULT_SERVER_USERNAME);
serverPassword = conf.get(REST_API_CLUSTER_MANAGER_PASSWORD, DEFAULT_SERVER_PASSWORD);
clusterName = conf.get(REST_API_CLUSTER_MANAGER_CLUSTER_NAME, DEFAULT_CLUSTER_NAME);
// Add filter to Client instance to enable server authentication.
client.addFilter(new HTTPBasicAuthFilter(serverUsername, serverPassword));
}
示例15: handleCredentials
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; //导入依赖的package包/类
private HTTPBasicAuthFilter handleCredentials(MaterialDefinition definition) {
HTTPBasicAuthFilter credentials = null;
//
// if (definition.getUsername() != null && definition.getPassword() != null) {
// String username = materialSpecificDetails.get("username").toString();
// String password = super.securityService.decrypt(materialSpecificDetails.get("password").toString());
//
// credentials = new HTTPBasicAuthFilter(username, password);
// }
return credentials;
}