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:io.github.microcks.util.test.HttpTestRunner.java

/**
 * Build the HttpMethod corresponding to string. Default to POST
 * if unknown or unrecognized./*from  w  w  w  .  j a  v  a2  s .  c  om*/
 */
@Override
public HttpMethod buildMethod(String method) {
    if (method != null) {
        if ("GET".equals(method.toUpperCase().trim())) {
            return HttpMethod.GET;
        } else if ("PUT".equals(method.toUpperCase().trim())) {
            return HttpMethod.PUT;
        } else if ("DELETE".equals(method.toUpperCase().trim())) {
            return HttpMethod.DELETE;
        }
    }
    return HttpMethod.POST;
}

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

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

    joe.setUserName(JOE + "new");

    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 + "new", joe1.getUserName());

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

}

From source file:access.test.PiazzaEnvironmentTests.java

@Test
public void testResourceCreationServerError() {
    Mockito.when(this.restTemplate.exchange(Mockito.endsWith("/workspaces/piazza.json"),
            Mockito.eq(HttpMethod.GET), Mockito.any(), Mockito.eq(String.class)))
            .thenThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND));
    Mockito.when(this.restTemplate.exchange(Mockito.endsWith("/workspaces"), Mockito.eq(HttpMethod.POST),
            Mockito.any(), Mockito.eq(String.class)))
            .thenReturn(new ResponseEntity<>("{\"result\": \"all good\"}", HttpStatus.OK))
            .thenThrow(new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR))
            .thenThrow(new RuntimeException());
    Mockito.when(this.restTemplate.exchange(Mockito.endsWith("/workspaces/piazza.xml"),
            Mockito.eq(HttpMethod.PUT), Mockito.any(), Mockito.eq(String.class)))
            .thenThrow(new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR));

    Mockito.when(this.restTemplate.exchange(Mockito.endsWith("/datastores/piazza.json"),
            Mockito.eq(HttpMethod.GET), Mockito.any(), Mockito.eq(String.class)))
            .thenThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND));
    Mockito.when(this.restTemplate.exchange(Mockito.endsWith("/datastores"), Mockito.eq(HttpMethod.POST),
            Mockito.any(), Mockito.eq(String.class)))
            .thenThrow(new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR))
            .thenThrow(new RuntimeException());

    this.piazzaEnvironment.initializeEnvironment();
    this.piazzaEnvironment.initializeEnvironment();
    this.piazzaEnvironment.initializeEnvironment();
}

From source file:fragment.web.AccessDecisionTest.java

@Test
public void testUserUrls() {
    Object[][] valid = { { HttpMethod.GET, "/portal/portal/" }, { HttpMethod.GET, "/portal/portal/home" },
            { HttpMethod.GET, "/portal/portal/profile" }, { HttpMethod.GET, "/portal/portal/profile/edit" },
            { HttpMethod.POST, "/portal/portal/profile" },
            { HttpMethod.POST, "/portal/portal/acceptCookies" } };

    Object[][] invalid = { { HttpMethod.GET, "/portal/portal/users/1" },
            { HttpMethod.PUT, "/portal/portal/users/1" }, { HttpMethod.GET, "/portal/portal/users" },
            { HttpMethod.GET, "/portal/portal/users/new" }, { HttpMethod.POST, "/portal/portal/users" },
            { HttpMethod.GET, "/portal/portal/tenants" }, { HttpMethod.POST, "/portal/portal/tenants" },
            { HttpMethod.GET, "/portal/portal/tenants/new" },
            { HttpMethod.GET, "/portal/portal/tenants/1/edit" },
            { HttpMethod.PUT, "/portal/portal/tenants/1" } };

    User user = createTestUserInTenant(getDefaultTenant());
    Authentication auth = createAuthenticationToken(user);
    verify(auth, valid, invalid);/* www .j  ava 2 s.  c  o m*/
}

From source file:io.syndesis.runtime.BaseITCase.java

protected <T> ResponseEntity<T> put(String url, Object body, Class<T> responseClass, String token,
        HttpStatus expectedStatus) {//from w  ww.j a  v a 2s  . c o  m
    return http(HttpMethod.PUT, url, body, responseClass, token, new HttpHeaders(), expectedStatus);
}

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

/**
 * Executes a PUT on a url.//from w  ww  . j  av a 2  s.c  om
 * 
 * The request header contains a given user name and workflow id, 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.
 * @param wid The workflow id.
 * @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, final String wid) {
    return unifiedX(HttpMethod.PUT, clazz, parm, url, dn, wid);
}

From source file:org.zalando.boot.etcd.EtcdClientTest.java

@Test
public void compareAndSwapWithPrevExist() throws EtcdException {
    server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample?prevExist=false"))
            .andExpect(MockRestRequestMatchers.method(HttpMethod.PUT))
            .andExpect(MockRestRequestMatchers.content().contentType(MediaType.APPLICATION_FORM_URLENCODED))
            .andExpect(MockRestRequestMatchers.content().string("value=Hello+world")).andRespond(
                    MockRestResponseCreators.withSuccess(new ClassPathResource("EtcdClientTest_delete.json"),
                            MediaType.APPLICATION_JSON));

    EtcdResponse response = client.compareAndSwap("sample", "Hello world", false);
    Assert.assertNotNull("response", response);

    server.verify();/*from w w  w . j  a va 2 s . c o  m*/
}

From source file:io.gravitee.management.security.config.basic.BasicSecurityConfigurerAdapter.java

@Override
protected void configure(HttpSecurity http) throws Exception {
    final String jwtSecret = environment.getProperty("jwt.secret");
    if (jwtSecret == null || jwtSecret.isEmpty()) {
        throw new IllegalStateException("JWT secret is mandatory");
    }/*from   www  .j a  v a  2 s . co m*/

    http.httpBasic().realmName("Gravitee.io Management API").and().sessionManagement()
            .sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().authorizeRequests()
            .antMatchers(HttpMethod.OPTIONS, "**").permitAll().antMatchers(HttpMethod.GET, "/user/**")
            .permitAll()
            // API requests
            .antMatchers(HttpMethod.GET, "/apis/**").permitAll().antMatchers(HttpMethod.POST, "/apis/**")
            .hasAnyAuthority("ADMIN", "API_PUBLISHER").antMatchers(HttpMethod.PUT, "/apis/**")
            .hasAnyAuthority("ADMIN", "API_PUBLISHER").antMatchers(HttpMethod.DELETE, "/apis/**")
            .hasAnyAuthority("ADMIN", "API_PUBLISHER")
            // Application requests
            .antMatchers(HttpMethod.POST, "/applications/**").hasAnyAuthority("ADMIN", "API_CONSUMER")
            .antMatchers(HttpMethod.PUT, "/applications/**").hasAnyAuthority("ADMIN", "API_CONSUMER")
            .antMatchers(HttpMethod.DELETE, "/applications/**").hasAnyAuthority("ADMIN", "API_CONSUMER")
            // Instance requests
            .antMatchers(HttpMethod.GET, "/instances/**").hasAuthority("ADMIN").anyRequest().authenticated()
            .and().csrf().disable().addFilterAfter(corsFilter(), AbstractPreAuthenticatedProcessingFilter.class)
            .addFilterBefore(new JWTAuthenticationFilter(jwtCookieGenerator, jwtSecret),
                    BasicAuthenticationFilter.class)
            .addFilterAfter(
                    new AuthenticationSuccessFilter(jwtCookieGenerator, jwtSecret,
                            environment.getProperty("jwt.issuer", DEFAULT_JWT_ISSUER), environment
                                    .getProperty("jwt.expire-after", Integer.class, DEFAULT_JWT_EXPIRE_AFTER)),
                    BasicAuthenticationFilter.class);
}

From source file:com.cloud.baremetal.networkservice.Force10BaremetalSwitchBackend.java

@Override
public void prepareVlan(BaremetalVlanStruct struct) {
    String link = buildLink(struct.getSwitchIp(),
            String.format("/api/running/ftos/interface/vlan/%s", struct.getVlan()));
    HttpHeaders headers = createBasicAuthenticationHeader(struct);
    HttpEntity<String> request = new HttpEntity<>(headers);
    ResponseEntity rsp = rest.exchange(link, HttpMethod.GET, request, String.class);
    logger.debug(String.format("http get: %s", link));

    if (rsp.getStatusCode() == HttpStatus.NOT_FOUND) {
        PortInfo port = new PortInfo(struct);
        XmlObject xml = new XmlObject("vlan")
                .putElement("vlan-id", new XmlObject("vlan-id").setText(String.valueOf(struct.getVlan())))
                .putElement("untagged",
                        new XmlObject("untagged").putElement(port.interfaceType,
                                new XmlObject(port.interfaceType).putElement("name",
                                        new XmlObject("name").setText(port.port))))
                .putElement("shutdown", new XmlObject("shutdown").setText("false"));
        request = new HttpEntity<>(xml.dump(), headers);
        link = buildLink(struct.getSwitchIp(), String.format("/api/running/ftos/interface/"));
        logger.debug(String.format("http get: %s, body: %s", link, request));
        rsp = rest.exchange(link, HttpMethod.POST, request, String.class);
        if (!successHttpStatusCode.contains(rsp.getStatusCode())) {
            throw new CloudRuntimeException(String.format(
                    "unable to create vlan[%s] on force10 switch[ip:%s]. HTTP status code:%s, body dump:%s",
                    struct.getVlan(), struct.getSwitchIp(), rsp.getStatusCode(), rsp.getBody()));
        } else {/*from   ww w  .  ja v  a 2 s  .co m*/
            logger.debug(String.format(
                    "successfully programmed vlan[%s] on Force10[ip:%s, port:%s]. http response[status code:%s, body:%s]",
                    struct.getVlan(), struct.getSwitchIp(), struct.getPort(), rsp.getStatusCode(),
                    rsp.getBody()));
        }
    } else if (successHttpStatusCode.contains(rsp.getStatusCode())) {
        PortInfo port = new PortInfo(struct);
        XmlObject xml = XmlObjectParser.parseFromString((String) rsp.getBody());
        List<XmlObject> ports = xml.getAsList("untagged.tengigabitethernet");
        ports.addAll(xml.<XmlObject>getAsList("untagged.gigabitethernet"));
        ports.addAll(xml.<XmlObject>getAsList("untagged.fortyGigE"));
        for (XmlObject pxml : ports) {
            XmlObject name = pxml.get("name");
            if (port.port.equals(name.getText())) {
                logger.debug(String.format("port[%s] has joined in vlan[%s], no need to program again",
                        struct.getPort(), struct.getVlan()));
                return;
            }
        }

        xml.removeElement("mtu");
        xml.setText(null);
        XmlObject tag = xml.get("untagged");
        if (tag == null) {
            tag = new XmlObject("untagged");
            xml.putElement("untagged", tag);
        }

        tag.putElement(port.interfaceType,
                new XmlObject(port.interfaceType).putElement("name", new XmlObject("name").setText(port.port)));
        request = new HttpEntity<>(xml.dump(), headers);
        link = buildLink(struct.getSwitchIp(),
                String.format("/api/running/ftos/interface/vlan/%s", struct.getVlan()));
        logger.debug(String.format("http get: %s, body: %s", link, request));
        rsp = rest.exchange(link, HttpMethod.PUT, request, String.class);
        if (!successHttpStatusCode.contains(rsp.getStatusCode())) {
            throw new CloudRuntimeException(String.format(
                    "failed to program vlan[%s] for port[%s] on force10[ip:%s]. http status:%s, body dump:%s",
                    struct.getVlan(), struct.getPort(), struct.getSwitchIp(), rsp.getStatusCode(),
                    rsp.getBody()));
        } else {
            logger.debug(String.format(
                    "successfully join port[%s] into vlan[%s] on Force10[ip:%s]. http response[status code:%s, body:%s]",
                    struct.getPort(), struct.getVlan(), struct.getSwitchIp(), rsp.getStatusCode(),
                    rsp.getBody()));
        }
    } else {
        throw new CloudRuntimeException(
                String.format("force10[ip:%s] returns unexpected error[%s] when http getting %s, body dump:%s",
                        struct.getSwitchIp(), rsp.getStatusCode(), link, rsp.getBody()));
    }
}

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

@Test
@OAuth2ContextConfiguration(resource = OAuth2ContextConfiguration.Implicit.class, initialize = false)
public void testUserChangesOthersPasswordFails() throws Exception {

    MultiValueMap<String, String> parameters = new LinkedMultiValueMap<String, String>();
    parameters.set("source", "credentials");
    parameters.set("username", joe.getUserName());
    parameters.set("password", "password");
    context.getAccessTokenRequest().putAll(parameters);

    PasswordChangeRequest change = new PasswordChangeRequest();
    change.setPassword("newpassword");

    HttpHeaders headers = new HttpHeaders();
    ResponseEntity<Void> result = client.exchange(serverRunning.getUrl(userEndpoint) + "/{id}/password",
            HttpMethod.PUT, new HttpEntity<PasswordChangeRequest>(change, headers), null, bob.getId());
    assertEquals(HttpStatus.FORBIDDEN, result.getStatusCode());

}