當前位置: 首頁>>代碼示例>>Java>>正文


Java WebClient類代碼示例

本文整理匯總了Java中org.apache.cxf.jaxrs.client.WebClient的典型用法代碼示例。如果您正苦於以下問題:Java WebClient類的具體用法?Java WebClient怎麽用?Java WebClient使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


WebClient類屬於org.apache.cxf.jaxrs.client包,在下文中一共展示了WebClient類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: readGroupMembers

import org.apache.cxf.jaxrs.client.WebClient; //導入依賴的package包/類
private GroupMembership readGroupMembers(String groupKey, GroupMembership parent) throws ResourceNotFoundException {
    String path = MessageFormat.format("groups/{0}/members", new Object[]{groupKey});

    WebClient webClient = WebClient.fromClient(directoryApiClient, true).path(path);
    ClientAccessToken accessToken = tokenCache.get();
    webClient.authorization(accessToken);
    GroupMembership result;
    try {
        if (parent != null && parent.getNextPageToken() != null) {
            result = webClient.query("pageToken", parent.getNextPageToken()).get(GroupMembership.class);
            result.getMembers().addAll(parent.getMembers());
        } else {
            result = webClient.get(GroupMembership.class);
        }
        return result.getNextPageToken() != null ? readGroupMembers(groupKey, result) : result;
    } catch (NotFoundException e) {
        throw new ResourceNotFoundException("Group " + groupKey + " not found.", e);
    }
}
 
開發者ID:hlavki,項目名稱:g-suite-identity-sync,代碼行數:20,代碼來源:GSuiteDirectoryServiceImpl.java

示例2: getAccessToken

import org.apache.cxf.jaxrs.client.WebClient; //導入依賴的package包/類
private ClientAccessToken getAccessToken() {
    JwsHeaders headers = new JwsHeaders(JoseType.JWT, SignatureAlgorithm.RS256);
    JwtClaims claims = new JwtClaims();
    claims.setIssuer(config.getServiceAccountClientId());
    claims.setAudience("https://accounts.google.com/o/oauth2/token");
    claims.setSubject(config.getServiceAccountSubject());

    long issuedAt = OAuthUtils.getIssuedAt();
    long tokenTimeout = config.getServiceAccountTokenLifetime();
    claims.setIssuedAt(issuedAt);
    claims.setExpiryTime(issuedAt + tokenTimeout);
    claims.setProperty("scope", "https://www.googleapis.com/auth/admin.directory.group.readonly https://www.googleapis.com/auth/admin.directory.user");

    JwtToken token = new JwtToken(headers, claims);
    JwsJwtCompactProducer p = new JwsJwtCompactProducer(token);
    String base64UrlAssertion = p.signWith(privateKey);

    JwtBearerGrant grant = new JwtBearerGrant(base64UrlAssertion);

    WebClient accessTokenService = WebClient.create("https://accounts.google.com/o/oauth2/token",
            Arrays.asList(new OAuthJSONProvider(), new AccessTokenGrantWriter()));

    accessTokenService.type(MediaType.APPLICATION_FORM_URLENCODED).accept(MediaType.APPLICATION_JSON);

    return accessTokenService.post(grant, ClientAccessToken.class);
}
 
開發者ID:hlavki,項目名稱:g-suite-identity-sync,代碼行數:27,代碼來源:GSuiteDirectoryServiceImpl.java

示例3: sendRequest

import org.apache.cxf.jaxrs.client.WebClient; //導入依賴的package包/類
public <T> T sendRequest (Function <WebClient, T> request) {
	int retries = 0;
	do {
		try {
			WebClient webClientCopy = WebClient.fromClient(webClient);
			T response = request.apply(webClientCopy);
			webClientCopy.close();
			return response;
		}
		catch (NotAuthorizedException e) {
			if (retries < 5) {
				retries ++;
				authClient.refreshAuthenticationContext();
			}
			else throw e;
		}
	} 
	while (retries < 5);
	
	return null;
}
 
開發者ID:ser316asu,項目名稱:Reinickendorf_SER316,代碼行數:22,代碼來源:ApiClient.java

示例4: doPost

import org.apache.cxf.jaxrs.client.WebClient; //導入依賴的package包/類
String doPost(String api, Prameters prams) {
    WebClient wc = WebClient.create(api);
    Form form = new Form();
    form.param(ACCESS_TOKEN, access_token());
    String[] keys = prams.keys;
    for(int i = 0 ; i < keys.length ; i ++){
        form.param(keys[i], prams.value(i).toString());
    }
    Response resp = wc.form(form);
    String result = "";
    try {
        result = IOUtils.toString((InputStream) resp.getEntity());
    } catch (IOException e) {
        throw new ParseResultException(e);
    }
    handleResponse(resp, wc);
    return result;
}
 
開發者ID:kylinsoong,項目名稱:weibo4j,代碼行數:19,代碼來源:Weibo.java

示例5: doPostOauth2

import org.apache.cxf.jaxrs.client.WebClient; //導入依賴的package包/類
String doPostOauth2(String api, Prameters prams) {
    WebClient wc = WebClient.create(api);
    Form form = new Form();
    String[] keys = prams.keys;
    for(int i = 0 ; i < keys.length ; i ++){
        form.param(keys[i], prams.value(i).toString());
    }
    Response resp = wc.form(form);
    String result = "";
    try {
        result = IOUtils.toString((InputStream) resp.getEntity());
    } catch (IOException e) {
        throw new ParseResultException(e);
    }
    handleResponse(resp, wc);
    return result;
}
 
開發者ID:kylinsoong,項目名稱:weibo4j,代碼行數:18,代碼來源:Weibo.java

示例6: test504checkGeneratedValue

import org.apache.cxf.jaxrs.client.WebClient; //導入依賴的package包/類
@Test
public void test504checkGeneratedValue() throws Exception {
	final String TEST_NAME = "test503generateValueExecute";
	displayTestTile(this, TEST_NAME);

	WebClient client = prepareClient();
	client.path("/users/" + USER_DARTHADDER_OID );
	
	getDummyAuditService().clear();

	TestUtil.displayWhen(TEST_NAME);
	Response response = client.get();

	TestUtil.displayThen(TEST_NAME);
	displayResponse(response);

	assertEquals("Expected 200 but got " + response.getStatus(), 200, response.getStatus());
	
	UserType user = response.readEntity(UserType.class);
	assertNotNull("EmployeeNumber must not be null", user.getEmployeeNumber());
}
 
開發者ID:Pardus-Engerek,項目名稱:engerek,代碼行數:22,代碼來源:TestAbstractRestService.java

示例7: getPeerInfo

import org.apache.cxf.jaxrs.client.WebClient; //導入依賴的package包/類
@Override
public PeerInfo getPeerInfo( final String destinationHost ) throws PeerException
{

    WebClient client = null;
    Response response;

    try
    {
        client = restUtil.getTrustedWebClient( buildUrl( destinationHost, "info" ), provider );
        client.type( MediaType.APPLICATION_JSON );
        client.accept( MediaType.APPLICATION_JSON );

        response = client.get();
    }
    catch ( Exception e )
    {
        throw new PeerException( String.format( "Can not connect to '%s'.", destinationHost ) );
    }
    finally
    {
        WebClientBuilder.close( client );
    }

    return WebClientBuilder.checkResponse( response, PeerInfo.class );
}
 
開發者ID:subutai-io,項目名稱:base,代碼行數:27,代碼來源:RegistrationClientImpl.java

示例8: addPeerEnvironmentPubKey

import org.apache.cxf.jaxrs.client.WebClient; //導入依賴的package包/類
public void addPeerEnvironmentPubKey( final String keyId, final String pubKeyRing ) throws PeerException
{
    WebClient client = null;
    Response response;
    try
    {
        remotePeer.checkRelation();
        String path = String.format( "/pek/add/%s", keyId );

        client = WebClientBuilder.buildPeerWebClient( peerInfo, path, provider, 3000, 15000, 1 );
        client.type( MediaType.APPLICATION_JSON );
        client.accept( MediaType.APPLICATION_JSON );
        response = client.post( pubKeyRing );
    }
    catch ( Exception e )
    {
        LOG.error( e.getMessage(), e );
        throw new PeerException( String.format( "Error adding PEK: %s", e.getMessage() ) );
    }
    finally
    {
        WebClientBuilder.close( client );
    }

    WebClientBuilder.checkResponse( response );
}
 
開發者ID:subutai-io,項目名稱:base,代碼行數:27,代碼來源:PeerWebClient.java

示例9: getRoleManagementService

import org.apache.cxf.jaxrs.client.WebClient; //導入依賴的package包/類
protected RoleManagementService getRoleManagementService( String authzHeader )
{
    RoleManagementService service =
        JAXRSClientFactory.create( "http://localhost:" + port + "/" + getRestServicesPath() + "/redbackServices/",
                                   RoleManagementService.class,
                                   Collections.singletonList( new JacksonJaxbJsonProvider() ) );

    // for debuging purpose
    WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 3000000L );

    if ( authzHeader != null )
    {
        WebClient.client( service ).header( "Authorization", authzHeader );
    }
    return service;
}
 
開發者ID:ruikom,項目名稱:apache-archiva,代碼行數:17,代碼來源:AbstractDownloadTest.java

示例10: notifyAgent

import org.apache.cxf.jaxrs.client.WebClient; //導入依賴的package包/類
void notifyAgent( ResourceHostInfo resourceHostInfo )
{
    WebClient webClient = null;
    javax.ws.rs.core.Response response = null;

    try
    {
        webClient = getWebClient( resourceHostInfo );

        response = webClient.form( new Form() );

        if ( response.getStatus() == javax.ws.rs.core.Response.Status.OK.getStatusCode()
                || response.getStatus() == javax.ws.rs.core.Response.Status.ACCEPTED.getStatusCode() )
        {
            hostRegistry.updateResourceHostEntryTimestamp( resourceHostInfo.getId() );
        }
    }
    finally
    {
        RestUtil.close( response, webClient );
    }
}
 
開發者ID:subutai-io,項目名稱:base,代碼行數:23,代碼來源:CommandProcessor.java

示例11: setupClientQueryAndHeaders

import org.apache.cxf.jaxrs.client.WebClient; //導入依賴的package包/類
@SuppressWarnings("unchecked")
protected void setupClientQueryAndHeaders(WebClient client, Exchange exchange) throws Exception {
    Message inMessage = exchange.getIn();
    CxfRsEndpoint cxfRsEndpoint = (CxfRsEndpoint) getEndpoint();
    // check if there is a query map in the message header
    Map<String, String> maps = inMessage.getHeader(CxfConstants.CAMEL_CXF_RS_QUERY_MAP, Map.class);
    if (maps == null) {
        // Get the map from HTTP_QUERY header
        String queryString = inMessage.getHeader(Exchange.HTTP_QUERY, String.class);
        if (queryString != null) {
            maps = getQueryParametersFromQueryString(queryString,
                                                     IOHelper.getCharsetName(exchange));
        }
    }
    if (maps == null) {
        maps = cxfRsEndpoint.getParameters();
    }
    if (maps != null) {
        for (Map.Entry<String, String> entry : maps.entrySet()) {
            client.query(entry.getKey(), entry.getValue());
        }
    }
    
    setupClientHeaders(client, exchange);
    
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:27,代碼來源:CxfRsProducer.java

示例12: checkRemoteConnectivityFail

import org.apache.cxf.jaxrs.client.WebClient; //導入依賴的package包/類
@Test
public void checkRemoteConnectivityFail()
    throws Exception
{

    RemoteRepositoriesService service = getRemoteRepositoriesService();

    WebClient.client( service ).header( "Authorization", authorizationHeader );

    try
    {

        RemoteRepository repo = getRemoteRepository();

        repo.setUrl( "http://localhost:8956" );

        service.addRemoteRepository( repo );

        assertThat( service.checkRemoteConnectivity( repo.getId() ) ).isFalse();
    }
    finally
    {
        service.deleteRemoteRepository( "id-new" );

    }
}
 
開發者ID:ruikom,項目名稱:apache-archiva,代碼行數:27,代碼來源:RemoteRepositoryConnectivityCheckTest.java

示例13: getSearchService

import org.apache.cxf.jaxrs.client.WebClient; //導入依賴的package包/類
protected SearchService getSearchService( String authzHeader )
{
    // START SNIPPET: cxf-searchservice-creation        
    SearchService service =
        JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/",
                                   SearchService.class,
                                   Collections.singletonList( new JacksonJaxbJsonProvider() ) );
    // to add authentification
    if ( authzHeader != null )
    {
        WebClient.client( service ).header( "Authorization", authzHeader );
    }
    // to configure read timeout
    WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 100000000 );
    // if you want to use json as exchange format xml is supported too
    WebClient.client( service ).accept( MediaType.APPLICATION_JSON_TYPE );
    WebClient.client( service ).type( MediaType.APPLICATION_JSON_TYPE );
    return service;
    // END SNIPPET: cxf-searchservice-creation

}
 
開發者ID:ruikom,項目名稱:apache-archiva,代碼行數:22,代碼來源:AbstractArchivaRestTest.java

示例14: getCommonServices

import org.apache.cxf.jaxrs.client.WebClient; //導入依賴的package包/類
protected CommonServices getCommonServices( String authzHeader )
{
    CommonServices service =
        JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/",
                                   CommonServices.class,
                                   Collections.singletonList( new JacksonJaxbJsonProvider() ) );

    if ( authzHeader != null )
    {
        WebClient.client( service ).header( "Authorization", authzHeader );
    }
    WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 100000000 );
    WebClient.client( service ).accept( MediaType.APPLICATION_JSON_TYPE );
    WebClient.client( service ).type( MediaType.APPLICATION_JSON_TYPE );
    return service;
}
 
開發者ID:ruikom,項目名稱:apache-archiva,代碼行數:17,代碼來源:AbstractArchivaRestTest.java

示例15: readArtifactContentText

import org.apache.cxf.jaxrs.client.WebClient; //導入依賴的package包/類
@Test
public void readArtifactContentText()
    throws Exception
{
    BrowseService browseService = getBrowseService( authorizationHeader, true );

    WebClient.client( browseService ).accept( MediaType.TEXT_PLAIN );

    String text =
        browseService.getArtifactContentText( "commons-logging", "commons-logging", "1.1", "sources", null,
                                              "org/apache/commons/logging/LogSource.java",
                                              TEST_REPO_ID ).getContent();

    log.debug( "text: {}", text );

    assertThat( text ).contains( "package org.apache.commons.logging;" ).contains( "public class LogSource {" );
}
 
開發者ID:ruikom,項目名稱:apache-archiva,代碼行數:18,代碼來源:BrowseServiceTest.java


注:本文中的org.apache.cxf.jaxrs.client.WebClient類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。