本文整理匯總了Java中com.sun.jersey.api.client.filter.LoggingFilter類的典型用法代碼示例。如果您正苦於以下問題:Java LoggingFilter類的具體用法?Java LoggingFilter怎麽用?Java LoggingFilter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
LoggingFilter類屬於com.sun.jersey.api.client.filter包,在下文中一共展示了LoggingFilter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getResource
import com.sun.jersey.api.client.filter.LoggingFilter; //導入依賴的package包/類
@Override
public WebResource getResource() {
WebResource webResource = null;
ClientConfig config = new DefaultClientConfig();
config.getClasses().add(GsonJerseyProvider.class);
Client client = Client.create(config);
OAuthParameters oaParams = new OAuthParameters().signatureMethod("HMAC-SHA1").consumerKey(consumerKey)
.token(accessToken).version("1.0");
OAuthSecrets oaSecrets = new OAuthSecrets().consumerSecret(consumerSecret).tokenSecret(accessTokenSecret);
OAuthClientFilter oAuthFilter = new OAuthClientFilter(client.getProviders(), oaParams, oaSecrets);
client.addFilter(oAuthFilter);
if (this.sandbox) {
webResource = client.resource(Constants.SANDBOX_BASE_API_URL);
} else if (null!= this.domain){
webResource = client.resource(this.domain);
}
else{
webResource = client.resource(Constants.BASE_API_URL);
}
if (this.trace) {
webResource.addFilter(new LoggingFilter());
}
return webResource;
}
示例2: rebuildHttpClient
import com.sun.jersey.api.client.filter.LoggingFilter; //導入依賴的package包/類
/**
* Build the Client used to make HTTP requests with the latest settings,
* i.e. objectMapper and debugging.
* TODO: better to use the Builder Pattern?
*/
public ApiClient rebuildHttpClient() {
// Add the JSON serialization support to Jersey
JacksonJsonProvider jsonProvider = new JacksonJsonProvider(objectMapper);
DefaultClientConfig conf = new DefaultClientConfig();
conf.getSingletons().add(jsonProvider);
Client client = Client.create(conf);
if (debugging) {
client.addFilter(new LoggingFilter());
}
//to solve the issue of GET:metadata/:guid with accepted encodeing is 'gzip'
//in the past, when clients use gzip header, actually it doesn't trigger a gzip encoding... So everything is fine
//After the release, the content is return in gzip, while the sdk doesn't handle it correctly
client.addFilter(new GZIPContentEncodingFilter(false));
this.httpClient = client;
return this;
}
示例3: getEwayWebResource
import com.sun.jersey.api.client.filter.LoggingFilter; //導入依賴的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;
}
示例4: getClient
import com.sun.jersey.api.client.filter.LoggingFilter; //導入依賴的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;
}
示例5: login
import com.sun.jersey.api.client.filter.LoggingFilter; //導入依賴的package包/類
/**
* Logs in into the NEst service and captures session information
*
* @throws ConnectionException if the credentials are incorrect
* @throws IOException if the response date cannot be parsed
*/
@Start
public void login() throws ConnectionException, IOException
{
httpClient.addFilter(new LoggingFilter());
MultivaluedMap<String, String> map = new MultivaluedMapImpl();
map.putSingle("username", getUsername());
map.putSingle("password", getPassword());
WebResource webResource = httpClient.resource("https://home.nest.com/user/login");
ClientResponse response = webResource.type("application/x-www-form-urlencoded")
.post(ClientResponse.class, map);
if (response.getStatus()> 399)
{
throw new ConnectionException(ConnectionExceptionCode.INCORRECT_CREDENTIALS, "unauthorized user", response.toString());
}
String res = response.getEntity(String.class);
System.out.println("Login: " + res);
login = mapper.readValue(res, Login.class);
baseUri = login.getUrls().getTransportUrl();
getMetaData();
}
示例6: RestClient
import com.sun.jersey.api.client.filter.LoggingFilter; //導入依賴的package包/類
public RestClient (URI baseURI)
{
ObjectMapper mapper = Jackson.newObjectMapper ()
.registerModule (new SupernodeModule ());
Validator validator = Validation.buildDefaultValidatorFactory ().getValidator ();
ClientConfig cc = new DefaultClientConfig (JsonProcessingExceptionMapper.class);
cc.getProperties ().put (ClientConfig.PROPERTY_CONNECT_TIMEOUT, 5000);
cc.getProperties ().put (ClientConfig.PROPERTY_READ_TIMEOUT, 5000);
cc.getSingletons ().add (new JacksonMessageBodyProvider (mapper, validator));
Client client = Client.create (cc);
client.addFilter (new LoggingFilter ());
this.client = client;
this.baseURI = baseURI;
}
示例7: testGetNewApplication
import com.sun.jersey.api.client.filter.LoggingFilter; //導入依賴的package包/類
@Test
public void testGetNewApplication() throws Exception {
client().addFilter(new LoggingFilter(System.out));
rm.start();
String mediaTypes[] =
{ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML };
for (String acceptMedia : mediaTypes) {
testGetNewApplication(acceptMedia);
}
rm.stop();
}
示例8: testGetAppQueue
import com.sun.jersey.api.client.filter.LoggingFilter; //導入依賴的package包/類
@Test
public void testGetAppQueue() throws Exception {
client().addFilter(new LoggingFilter(System.out));
boolean isCapacityScheduler =
rm.getResourceScheduler() instanceof CapacityScheduler;
rm.start();
MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
String[] contentTypes =
{ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML };
for (String contentType : contentTypes) {
RMApp app = rm.submitApp(CONTAINER_MB, "", webserviceUserName);
amNodeManager.nodeHeartbeat(true);
ClientResponse response =
this
.constructWebResource("apps", app.getApplicationId().toString(),
"queue").accept(contentType).get(ClientResponse.class);
assertEquals(Status.OK, response.getClientResponseStatus());
String expectedQueue = "default";
if(!isCapacityScheduler) {
expectedQueue = "root." + webserviceUserName;
}
if (contentType.equals(MediaType.APPLICATION_JSON)) {
verifyAppQueueJson(response, expectedQueue);
} else {
verifyAppQueueXML(response, expectedQueue);
}
}
rm.stop();
}
示例9: testCreateDelegationToken
import com.sun.jersey.api.client.filter.LoggingFilter; //導入依賴的package包/類
@Test
public void testCreateDelegationToken() throws Exception {
rm.start();
this.client().addFilter(new LoggingFilter(System.out));
final String renewer = "test-renewer";
String jsonBody = "{ \"renewer\" : \"" + renewer + "\" }";
String xmlBody =
"<delegation-token><renewer>" + renewer
+ "</renewer></delegation-token>";
String[] mediaTypes =
{ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML };
Map<String, String> bodyMap = new HashMap<String, String>();
bodyMap.put(MediaType.APPLICATION_JSON, jsonBody);
bodyMap.put(MediaType.APPLICATION_XML, xmlBody);
for (final String mediaType : mediaTypes) {
final String body = bodyMap.get(mediaType);
for (final String contentType : mediaTypes) {
if (isKerberosAuth == true) {
verifyKerberosAuthCreate(mediaType, contentType, body, renewer);
} else {
verifySimpleAuthCreate(mediaType, contentType, body);
}
}
}
rm.stop();
return;
}
示例10: testNodeHelper
import com.sun.jersey.api.client.filter.LoggingFilter; //導入依賴的package包/類
public void testNodeHelper(String path, String media) throws JSONException,
Exception {
WebResource r = resource();
Application app = new MockApp(1);
nmContext.getApplications().put(app.getAppId(), app);
addAppContainers(app);
Application app2 = new MockApp(2);
nmContext.getApplications().put(app2.getAppId(), app2);
addAppContainers(app2);
client().addFilter(new LoggingFilter());
ClientResponse response = r.path("ws").path("v1").path("node").path(path)
.accept(media).get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
JSONObject json = response.getEntity(JSONObject.class);
JSONObject info = json.getJSONObject("containers");
assertEquals("incorrect number of elements", 1, info.length());
JSONArray conInfo = info.getJSONArray("container");
assertEquals("incorrect number of elements", 4, conInfo.length());
for (int i = 0; i < conInfo.length(); i++) {
verifyNodeContainerInfo(
conInfo.getJSONObject(i),
nmContext.getContainers().get(
ConverterUtils.toContainerId(conInfo.getJSONObject(i).getString(
"id"))));
}
}
示例11: testNodeSingleContainerXML
import com.sun.jersey.api.client.filter.LoggingFilter; //導入依賴的package包/類
@Test
public void testNodeSingleContainerXML() throws JSONException, Exception {
WebResource r = resource();
Application app = new MockApp(1);
nmContext.getApplications().put(app.getAppId(), app);
HashMap<String, String> hash = addAppContainers(app);
Application app2 = new MockApp(2);
nmContext.getApplications().put(app2.getAppId(), app2);
addAppContainers(app2);
client().addFilter(new LoggingFilter(System.out));
for (String id : hash.keySet()) {
ClientResponse response = r.path("ws").path("v1").path("node")
.path("containers").path(id).accept(MediaType.APPLICATION_XML)
.get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_XML_TYPE, response.getType());
String xml = response.getEntity(String.class);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xml));
Document dom = db.parse(is);
NodeList nodes = dom.getElementsByTagName("container");
assertEquals("incorrect number of elements", 1, nodes.getLength());
verifyContainersInfoXML(nodes,
nmContext.getContainers().get(ConverterUtils.toContainerId(id)));
}
}
示例12: rebuildHttpClient
import com.sun.jersey.api.client.filter.LoggingFilter; //導入依賴的package包/類
/**
* Build the Client used to make HTTP requests with the latest settings,
* i.e. objectMapper and debugging.
*/
public ApiClient rebuildHttpClient() {
// Add the JSON serialization support to Jersey
JacksonJsonProvider jsonProvider = new JacksonJsonProvider(objectMapper);
DefaultClientConfig conf = new DefaultClientConfig();
conf.getSingletons().add(jsonProvider);
Client client = Client.create(conf);
if (debugging) {
client.addFilter(new LoggingFilter());
}
this.httpClient = client;
return this;
}
示例13: getClient
import com.sun.jersey.api.client.filter.LoggingFilter; //導入依賴的package包/類
/**
* Get an existing client or create a new client to handle HTTP request.
*/
private Client getClient() {
if(!hostMap.containsKey(basePath)) {
Client client = Client.create();
if (debugging)
client.addFilter(new LoggingFilter());
hostMap.put(basePath, client);
}
return hostMap.get(basePath);
}
示例14: main
import com.sun.jersey.api.client.filter.LoggingFilter; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
TwitterAdsClient.setTrace(true);
TwitterAdsClient.setSandbox(false);
String domain = "https://ads-api.twitter.com";
TwitterAdsClient.setDomain(domain);
WebResource webResource = Resource.getResource();
webResource.addFilter(new LoggingFilter());
String resourcePath = "/0/accounts/" + ACCOUNT_ID + "/promoted_tweets";
MultivaluedMap<String, String> params = new MultivaluedMapImpl();
params.add("with_deleted", "true");
List<PromotedTweet> promotedTweets = webResource
.queryParams(params)
.path(resourcePath)
.accept(MediaType.APPLICATION_JSON_TYPE)
.get(new GenericType<List<PromotedTweet>>() {});
for (PromotedTweet promotedTweet : promotedTweets) {
//System.out.println(promotedTweet.toString());
Long tweetIdL = Long.parseLong(promotedTweet.getTweet_id());
System.out.println(tweetIdL);
Tweet.destroy(tweetIdL);
}
}
示例15: getClient
import com.sun.jersey.api.client.filter.LoggingFilter; //導入依賴的package包/類
/**
* Get an existing client or create a new client to handle HTTP request.
*/
private Client getClient(String baseUrl) {
if (!hostMap.containsKey(baseUrl)) {
Client client = Client.create();
if (debugging)
client.addFilter(new LoggingFilter());
hostMap.put(baseUrl,
client);
}
return hostMap.get(baseUrl);
}