当前位置: 首页>>代码示例>>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;未经允许,请勿转载。