Example usage for org.springframework.http HttpMethod PUT

List of usage examples for org.springframework.http HttpMethod PUT

Introduction

In this page you can find the example usage for org.springframework.http HttpMethod PUT.

Prototype

HttpMethod PUT

To view the source code for org.springframework.http HttpMethod PUT.

Click Source Link

Usage

From source file:de.fhg.fokus.nubomedia.paas.VNFRServiceImpl.java

/**
 * Sends heart beat as keep alive mechanism to Virtual Network Function
 * @param internalAppId - the application identifier
 *//*from   ww w.j  a  v  a  2s.c o m*/
public void sendHeartBeat(String internalAppId) {
    // PUT on /vnfr/<vnfr_id>/app/<app_id>/heartbeat
    String webServiceUrl = serviceProfile.getServiceApiUrl() + "/" + internalAppId + "/heartbeat";
    logger.info("sending heartbeat to EMM " + webServiceUrl);

    ResponseEntity<Void> response = restTemplate.exchange(webServiceUrl, HttpMethod.PUT, null, Void.class);
    Void body = response.getBody();
    logger.info("response :" + response);
}

From source file:net.nfpj.webcounter.api.CounterIT.java

@Test
public void testIncCounterMissing() {
    String name = "C1IncMissing";
    ResponseEntity<Counter> entity = restTemplate.exchange("/counter/{name}/", HttpMethod.PUT, null,
            Counter.class, name);
    assertEquals("Unexpected response status: " + entity.getStatusCodeValue(), HttpStatus.SC_NOT_FOUND,
            entity.getStatusCodeValue());
}

From source file:de.zib.vold.client.VolDClient.java

/**
 * Insert a set of keys.//from w w  w  .j av a2 s  .  co m
 */
public void insert(String source, Map<Key, Set<String>> map, final long timeStamp) {
    // guard
    {
        log.trace("Insert: " + map.toString());

        // nothing to do here?
        if (0 == map.size())
            return;

        checkState();

        if (null == map) {
            throw new IllegalArgumentException("null is no valid argument!");
        }
    }

    // build greatest common scope
    String commonscope;
    {
        List<String> scopes = new ArrayList<String>(map.size());

        for (Key k : map.keySet()) {
            scopes.add(k.get_scope());
        }

        commonscope = getGreatestCommonPrefix(scopes);
    }

    // build variable map
    String url;
    {
        url = buildURL(commonscope, null);
        log.debug("INSERT URL: " + url);
    }

    // build request body
    MultiValueMap<String, String> request = new LinkedMultiValueMap<String, String>();
    {
        for (Map.Entry<Key, Set<String>> entry : map.entrySet()) {
            // remove common prefix from scope
            String scope = entry.getKey().get_scope().substring(commonscope.length());
            String type = entry.getKey().get_type();
            String keyname = entry.getKey().get_keyname();

            URIKey key = new URIKey(source, scope, type, keyname, false, false, enc);
            String urikey = key.toURIString();

            for (String value : entry.getValue()) {
                request.add(urikey, value);
            }
        }
    }

    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.add("TIMESTAMP", String.valueOf(timeStamp));
    HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>(
            request, requestHeaders);
    final ResponseEntity<HashMap> responseEntity = rest.exchange(url, HttpMethod.PUT, requestEntity,
            HashMap.class);
    //rest.put( url, request );
}

From source file:org.cloudfoundry.identity.uaa.integration.ScimUserEndpointsIntegrationTests.java

@Test
public void updateUserSucceeds() throws Exception {
    ResponseEntity<ScimUser> response = createUser(JOE, "Joe", "User", "joe@blah.com");
    ScimUser joe = response.getBody();//from  w  w w .  j a  va2  s .c  o  m
    assertEquals(JOE, joe.getUserName());

    joe.setName(new ScimUser.Name("Joe", "Bloggs"));

    HttpHeaders headers = new HttpHeaders();
    headers.add("If-Match", "\"" + joe.getVersion() + "\"");
    response = client.exchange(serverRunning.getUrl(userEndpoint) + "/{id}", HttpMethod.PUT,
            new HttpEntity<ScimUser>(joe, headers), ScimUser.class, joe.getId());
    ScimUser joe1 = response.getBody();
    assertEquals(JOE, joe1.getUserName());

    assertEquals(joe.getId(), joe1.getId());

}

From source file:com.auditbucket.client.AbRestClient.java

private String flushAudit(List<MetaInputBean> auditInput) {
    if (simulateOnly || auditInput.isEmpty())
        return "OK";
    RestTemplate restTemplate = new RestTemplate();
    restTemplate.getMessageConverters().add(new StringHttpMessageConverter());

    HttpHeaders httpHeaders = getHeaders(userName, password);
    HttpEntity<List<MetaInputBean>> requestEntity = new HttpEntity<>(auditInput, httpHeaders);

    try {//  w w w .  j a v a 2s.  c o  m
        restTemplate.exchange(NEW_HEADER, HttpMethod.PUT, requestEntity, TrackResultBean.class);
        return "OK";
    } catch (HttpClientErrorException e) {
        // ToDo: Rest error handling pretty useless. need to know why it's failing
        logger.error("AB Client Audit error {}", getErrorMessage(e));
        return null;
    } catch (HttpServerErrorException e) {
        logger.error("AB Server Audit error {}", getErrorMessage(e));
        return null;

    }
}

From source file:com.ge.predix.test.utils.ZoneHelper.java

public ResponseEntity<String> registerServicetoZac(final String zoneId,
        final Map<String, Object> trustedIssuers) throws JsonProcessingException {
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    headers.add(this.acsZoneHeaderName, zoneId);

    HttpEntity<String> requestEntity = new HttpEntity<>(new ObjectMapper().writeValueAsString(trustedIssuers),
            headers);//from   w  w  w .  j a v a2  s  .  com

    ResponseEntity<String> response = this.zacRestTemplate.exchange(
            this.zacUrl + "/v1/registration/" + this.serviceId + "/" + zoneId, HttpMethod.PUT, requestEntity,
            String.class);
    return response;
}

From source file:de.zib.gndms.gndmc.AbstractClient.java

/**
 * Executes a PUT on a url.//from   w w w.  j a v a  2  s  .  c o  m
 * 
 * The request header contains a given user name, the body of the request contains 
 * a given object of type P.
 * 
 * @param <T> The body type of the response.
 * @param <P> The body type of the request.
 * @param clazz The type of the return value.
 * @param parm The body of the request.
 * @param url The url of the request.
 * @param dn The user name.
 * @return The response as entity.
 */
protected final <T, P> ResponseEntity<T> unifiedPut(final Class<T> clazz, final P parm, final String url,
        final String dn) {
    return unifiedX(HttpMethod.PUT, clazz, parm, url, dn, null);
}

From source file:com.sitewhere.rest.service.SiteWhereClient.java

@Override
public Device updateDevice(String hardwareId, DeviceCreateRequest request) throws SiteWhereException {
    Map<String, String> vars = new HashMap<String, String>();
    vars.put("hardwareId", hardwareId);
    return sendRest(getBaseUrl() + "devices/{hardwareId}", HttpMethod.PUT, request, Device.class, vars);
}

From source file:com.athena.peacock.controller.web.machine.MachineService.java

public boolean updateMachine(MachineDto machine) throws RestClientException, Exception {
    MachineDto m = machineDao.getMachine(machine.getMachineId());

    boolean hostnameChanged = false;

    logger.debug("[UPDATE_MACHINE] 0. start updateMachine()");

    // Instance ?? ??  DB, RHEV-M ??
    if (!machine.getDisplayName().equals(m.getDisplayName())) {
        if (m.getHypervisorId() != null && m.getHypervisorId() > 0) {
            int major = RHEVMRestTemplateManager.getRHEVMRestTemplate(m.getHypervisorId()).getMajor();
            int minor = RHEVMRestTemplateManager.getRHEVMRestTemplate(m.getHypervisorId()).getMinor();

            VM vm = null;//from w  ww. j av  a 2  s  .co m

            double version = Double.parseDouble(major + "." + minor);
            if (version >= 3.2) {
                vm = new VM();
                vm.setName(machine.getDisplayName());
                RHEVMRestTemplateManager.getRHEVMRestTemplate(m.getHypervisorId())
                        .submit(RHEVApi.VMS + "/" + m.getMachineId(), HttpMethod.PUT, vm, "vm", VM.class);
            } else {
                String callUrl = RHEVApi.VMS + "/" + machine.getMachineId();
                vm = RHEVMRestTemplateManager.getRHEVMRestTemplate(m.getHypervisorId()).submit(callUrl,
                        HttpMethod.GET, VM.class);

                if (vm.getStatus().getState().toLowerCase().equals("down")) {
                    vm = new VM();
                    vm.setName(machine.getDisplayName());
                    RHEVMRestTemplateManager.getRHEVMRestTemplate(m.getHypervisorId())
                            .submit(RHEVApi.VMS + "/" + m.getMachineId(), HttpMethod.PUT, vm, "vm", VM.class);
                } else {
                    throw new Exception("VM_UP_STAT");
                }
            }
        }

        if (machine.getDisplayName().toLowerCase().startsWith("hhilws")
                && !machine.getDisplayName().toLowerCase().startsWith("hhilwsd")) {
            m.setIsPrd("Y");
        } else {
            m.setIsPrd("N");
        }

        m.setDisplayName(machine.getDisplayName());
        m.setUpdUserId(machine.getUpdUserId());

        machineDao.updateMachine(m);
    }

    logger.debug("[UPDATE_MACHINE] 1. update machine info.");

    MachineDto add = getAdditionalInfo(machine.getMachineId());
    if (add == null) {
        insertAdditionalInfo(machine);
    } else {
        machine.setApplyYn(add.getApplyYn());

        if (StringUtils.isNotEmpty(machine.getIpAddress())
                && (!machine.getIpAddress().equals(add.getIpAddress())
                        || !machine.getNetmask().equals(add.getNetmask())
                        || !machine.getGateway().equals(add.getGateway())
                        || !machine.getNameServer().equals(add.getNameServer()))) {
            machine.setApplyYn("N");
        }

        updateAdditionalInfo(machine);
    }

    logger.debug("[UPDATE_MACHINE] 2. update machine additional info.");

    if (StringUtils.isNotEmpty(machine.getHostName()) && !machine.getHostName().equals(m.getHostName())) {
        // Agent Running ??  ShellAction agent? chhost.sh ? 
        // Agent Down ??  machine_additional_info_tbl? ?? ? Running ?   HostName? ?.
        if (StringUtils.isNotEmpty(m.getIpAddr()) && peacockTransmitter.isActive(machine.getMachineId())) {
            try {
                // /etc/hosts ?? ? ipAddress  Machine? IP?  ? IP? ?.
                String ipAddress = null;

                if (StringUtils.isNotEmpty(machine.getIpAddress())) {
                    ipAddress = machine.getIpAddress();
                } else {
                    ipAddress = m.getIpAddr();
                }

                ProvisioningCommandMessage cmdMsg = new ProvisioningCommandMessage();
                cmdMsg.setAgentId(machine.getMachineId());
                cmdMsg.setBlocking(true);

                int sequence = 0;
                Command command = new Command("SET_HOSTNAME");

                ShellAction action = new ShellAction(sequence++);
                action.setCommand("sh");
                action.addArguments("chhost.sh");
                action.addArguments(ipAddress);
                action.addArguments(machine.getHostName());
                command.addAction(action);

                cmdMsg.addCommand(command);

                PeacockDatagram<AbstractMessage> datagram = new PeacockDatagram<AbstractMessage>(cmdMsg);
                peacockTransmitter.sendMessage(datagram);

                hostnameChanged = true;
            } catch (Exception e) {
                // HostName ? ???  IP ?   ??  .
                logger.error("Unhandled exception has occurred while change hostname.", e);
            }
        }
    }

    logger.debug("[UPDATE_MACHINE] 3. execute command to change hostname.");

    //   IP ? , Agent Running ??,  IP    IP  ? .
    if (StringUtils.isNotEmpty(machine.getIpAddress()) && peacockTransmitter.isActive(machine.getMachineId())
            && (!machine.getIpAddress().equals(add.getIpAddress())
                    || !machine.getNetmask().equals(add.getNetmask())
                    || !machine.getGateway().equals(add.getGateway())
                    || !machine.getNameServer().equals(add.getNameServer()))) {
        machine.setIpAddr(m.getIpAddr());
        applyStaticIp(machine);
    } else {
        if (hostnameChanged) {
            // IP  ? hostname ?  peacock-agent restart .
            sendCommand(getMachine(machine.getMachineId()), "service peacock-agent restart");
            // Thread Sleep  ? DB Commit? ? ? ? Agent restart   hostname  .
            // ? hostname? ?  controller? Thread.sleep(3000)?  ? Agent? ? ?? ??? .
            //Thread.sleep(3000);
        }
    }

    logger.debug("[UPDATE_MACHINE] 4. finish updateMachine()");

    return hostnameChanged;
}