Java Code Examples for org.apache.cxf.jaxrs.client.WebClient#put()

The following examples show how to use org.apache.cxf.jaxrs.client.WebClient#put() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PeerWebClient.java    From peer-os with Apache License 2.0 6 votes vote down vote up
public void joinOrUpdateP2PSwarm( final P2PConfig config ) throws PeerException
{
    WebClient client = null;
    Response response;
    try
    {
        remotePeer.checkRelation();
        String path = "/p2ptunnel";

        client = WebClientBuilder.buildPeerWebClient( peerInfo, path, provider );

        client.type( MediaType.APPLICATION_JSON );
        response = client.put( config );
    }
    catch ( Exception e )
    {
        LOG.error( e.getMessage(), e );
        throw new PeerException( String.format( "Error joining/updating P2P swarm: %s", e.getMessage() ) );
    }
    finally
    {
        WebClientBuilder.close( client );
    }

    WebClientBuilder.checkResponse( response );
}
 
Example 2
Source File: EnvironmentWebClient.java    From peer-os with Apache License 2.0 6 votes vote down vote up
public void rollbackContainerSnapshot( final ContainerId containerId, final String partition, final String label,
                                       final boolean force ) throws PeerException
{
    WebClient client = null;
    Response response;
    try
    {
        remotePeer.checkRelation();
        String path = String.format( "/%s/container/%s/snapshots/partition/%s/label/%s/%b",
                containerId.getEnvironmentId().getId(), containerId.getId(), partition, label, force );
        client = WebClientBuilder.buildEnvironmentWebClient( peerInfo, path, provider );

        response = client.put( null );
    }
    catch ( Exception e )
    {
        LOG.error( e.getMessage(), e );
        throw new PeerException( "Error rolling back container snapshot:" + e.getMessage() );
    }
    finally
    {
        WebClientBuilder.close( client );
    }

    WebClientBuilder.checkResponse( response );
}
 
Example 3
Source File: PeerWebClient.java    From peer-os with Apache License 2.0 5 votes vote down vote up
public void updateEnvironmentPubKey( PublicKeyContainer publicKeyContainer ) throws PeerException
{
    WebClient client = null;
    Response response;
    try
    {
        remotePeer.checkRelation();
        String path = "/pek";

        client = WebClientBuilder.buildPeerWebClient( peerInfo, path, provider );

        client.type( MediaType.APPLICATION_JSON );
        client.accept( MediaType.APPLICATION_JSON );
        response = client.put( publicKeyContainer );
    }
    catch ( Exception e )
    {
        LOG.error( e.getMessage(), e );
        throw new PeerException( String.format( "Error updating peer environment key: %s", e.getMessage() ) );
    }
    finally
    {
        WebClientBuilder.close( client );
    }

    WebClientBuilder.checkResponse( response );
}
 
Example 4
Source File: EnvironmentWebClient.java    From peer-os with Apache License 2.0 5 votes vote down vote up
public SshKeys generateSshKeysForEnvironment( final EnvironmentId environmentId,
                                              final SshEncryptionType sshKeyType ) throws PeerException
{
    WebClient client = null;
    Response response;
    try
    {
        String path = String.format( "/%s/containers/sshkeys/%s", environmentId.getId(), sshKeyType );

        client = WebClientBuilder.buildEnvironmentWebClient( peerInfo, path, provider );

        client.accept( MediaType.APPLICATION_JSON );

        response = client.put( null );
    }
    catch ( Exception e )
    {
        LOG.error( e.getMessage(), e );
        throw new PeerException( "Error generating ssh keys in environment: " + e.getMessage() );
    }
    finally
    {
        WebClientBuilder.close( client );
    }

    return WebClientBuilder.checkResponse( response, SshKeys.class );
}
 
Example 5
Source File: EnvironmentWebClient.java    From peer-os with Apache License 2.0 5 votes vote down vote up
public void removeHostnamesFromEtcHosts( final EnvironmentId environmentId, final HostAddresses hostAddresses )
        throws PeerException
{
    WebClient client = null;
    Response response;
    try
    {
        String path = String.format( "/%s/containers/etchosts", environmentId.getId() );

        client = WebClientBuilder.buildEnvironmentWebClient( peerInfo, path, provider );

        client.type( MediaType.APPLICATION_JSON );

        response = client.put( hostAddresses );
    }
    catch ( Exception e )
    {
        LOG.error( e.getMessage(), e );
        throw new PeerException( "Error removing hostnames : " + e.getMessage() );
    }
    finally
    {
        WebClientBuilder.close( client );
    }

    WebClientBuilder.checkResponse( response );
}
 
Example 6
Source File: JAXRSClientServerProxySpringBookTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testPutName() throws Exception {
    String endpointAddress = "http://localhost:" + PORT + "/test/v1/names/1";
    WebClient wc = WebClient.create(endpointAddress);
    wc.type("application/json").accept("application/json");
    String id = wc.put(null, String.class);
    assertEquals("1", id);
}
 
Example 7
Source File: JAXRSClientServerBookTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testEmptyPut() throws Exception {
    WebClient wc =
        WebClient.create("http://localhost:"
                         + PORT + "/bookstore/emptyput");
    Response response = wc.type("application/json").put(null);
    assertEquals(204, response.getStatus());
    assertNull(response.getMetadata().getFirst("Content-Type"));

    response = wc.put("");
    assertEquals(204, response.getStatus());
    assertNull(response.getMetadata().getFirst("Content-Type"));
}
 
Example 8
Source File: Client.java    From cxf with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    String keyStoreLoc = "src/main/config/clientKeystore.jks";

    KeyStore keyStore = KeyStore.getInstance("JKS");
    keyStore.load(new FileInputStream(keyStoreLoc), "cspass".toCharArray());

    SSLContext sslcontext = SSLContexts.custom()
            .loadTrustMaterial(keyStore, null)
            .loadKeyMaterial(keyStore, "ckpass".toCharArray())
            .useProtocol("TLSv1.2")
            .build();

    /*
     * Send HTTP GET request to query customer info using portable HttpClient
     * object from Apache HttpComponents
     */
    SSLConnectionSocketFactory sf = new SSLConnectionSocketFactory(sslcontext);

    System.out.println("Sending HTTPS GET request to query customer info");
    CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sf).build();
    HttpGet httpget = new HttpGet(BASE_SERVICE_URL + "/123");
    BasicHeader bh = new BasicHeader("Accept", "text/xml");
    httpget.addHeader(bh);
    CloseableHttpResponse response = httpclient.execute(httpget);
    HttpEntity entity = response.getEntity();
    entity.writeTo(System.out);
    response.close();
    httpclient.close();

    /*
     *  Send HTTP PUT request to update customer info, using CXF WebClient method
     *  Note: if need to use basic authentication, use the WebClient.create(baseAddress,
     *  username,password,configFile) variant, where configFile can be null if you're
     *  not using certificates.
     */
    System.out.println("\n\nSending HTTPS PUT to update customer name");
    WebClient wc = WebClient.create(BASE_SERVICE_URL, CLIENT_CONFIG_FILE);
    Customer customer = new Customer();
    customer.setId(123);
    customer.setName("Mary");
    Response resp = wc.put(customer);

    /*
     *  Send HTTP POST request to add customer, using JAXRSClientProxy
     *  Note: if need to use basic authentication, use the JAXRSClientFactory.create(baseAddress,
     *  username,password,configFile) variant, where configFile can be null if you're
     *  not using certificates.
     */
    System.out.println("\n\nSending HTTPS POST request to add customer");
    CustomerService proxy = JAXRSClientFactory.create(BASE_SERVICE_URL, CustomerService.class,
          CLIENT_CONFIG_FILE);
    customer = new Customer();
    customer.setName("Jack");
    resp = wc.post(customer);

    System.out.println("\n");
    System.exit(0);
}