Example usage for org.springframework.http HttpMethod POST

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

Introduction

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

Prototype

HttpMethod POST

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

Click Source Link

Usage

From source file:com.cloudera.nav.sdk.client.NavApiCient.java

/**
 * Constructs relation API call from query, and cursorMark.Returns a batch of
 * results that satisfy the query, starting from the cursorMark.
 * Called in next() of IncrementalExtractIterator()
 *
 * @param metadataQuery Solr query string, cursormark and limit
 * @return ResultsBatch set of results that satisfy query and next cursor
 *//*from www .  j a va  2s .c  o m*/
public ResultsBatch<Map<String, Object>> getRelationBatch(MetadataQuery metadataQuery) {
    String fullUrlPost = pagingUrl("relations");
    return sendRequest(fullUrlPost, HttpMethod.POST, RelationResultsBatch.class, metadataQuery);
}

From source file:com.logsniffer.event.publisher.http.HttpPublisherTest.java

@Test
public void testPost() throws PublishException {
    stubFor(post(urlEqualTo("/eventId/12345")).withRequestBody(equalTo("eventbody"))
            .willReturn(aResponse().withStatus(HttpStatus.NO_CONTENT.value())
                    .withHeader("Content-Type", "text/xml").withBody("<response>Some content</response>")));
    publisher.setMethod(HttpMethod.POST);
    publisher.setUrl("http://localhost:" + port + "/eventId/12345");
    publisher.setBody("eventbody");
    Event event = new Event();
    event.setId("123");
    publisher.publish(event);/*  w  ww . jav a2s. c om*/
}

From source file:com.appglu.impl.AnalyticsTemplateTest.java

@Test
public void uploadSessions() throws ParseException {
    mockServer.expect(requestTo("http://localhost/appglu/v1/analytics")).andExpect(method(HttpMethod.POST))
            .andExpect(header("Content-Type", jsonMediaType.toString()))
            .andExpect(content().string(compactedJson("data/analytics_sessions")))
            .andRespond(withStatus(HttpStatus.CREATED).body("").headers(responseHeaders));

    List<AnalyticsSession> sessions = new ArrayList<AnalyticsSession>();
    sessions.add(session());//from  ww w .  ja va 2 s.  co  m
    sessions.add(session());
    analyticsOperations.uploadSessions(sessions);

    mockServer.verify();
}

From source file:fragment.web.AbstractManageResourceControllerTest.java

@Test
public void testRouting() throws Exception {
    logger.debug("Testing routing....");
    DispatcherTestServlet servlet = this.getServletInstance();
    Class<? extends AbstractManageResourceController> controllerClass = controller.getClass();
    Method expected = locateMethod(controllerClass, "getSSOCmdString", new Class[] { Tenant.class, String.class,
            String.class, ModelMap.class, HttpServletRequest.class, HttpServletResponse.class });
    Method handler = servlet//from w  w w.j a va 2 s .  c  o  m
            .recognize(getRequestTemplate(HttpMethod.POST, "/manage_resource/get_sso_cmd_string"));
    Assert.assertEquals(expected, handler);

    expected = locateMethod(controllerClass, "getResourceViews",
            new Class[] { Tenant.class, String.class, String.class, ModelMap.class, HttpServletRequest.class });
    handler = servlet.recognize(getRequestTemplate(HttpMethod.GET, "/manage_resource/get_resource_views"));
    Assert.assertEquals(expected, handler);
}

From source file:io.syndesis.runtime.credential.CredentialITCase.java

@Test
public void shouldApplyOAuthPropertiesToNewlyCreatedConnections() {
    final OAuth2CredentialFlowState flowState = new OAuth2CredentialFlowState.Builder()
            .providerId("test-provider").key("key").accessGrant(new AccessGrant("token")).build();

    final HttpHeaders cookies = persistAsCookie(flowState);

    final Connection newConnection = new Connection.Builder().name("Test connection").build();
    final ResponseEntity<Connection> connectionResponse = http(HttpMethod.POST, "/api/v1/connections",
            newConnection, Connection.class, tokenRule.validToken(), cookies, HttpStatus.OK);

    assertThat(connectionResponse.hasBody()).as("Should contain created connection").isTrue();

    final Connection createdConnection = connectionResponse.getBody();
    assertThat(createdConnection.isDerived()).isTrue();
    assertThat(createdConnection.getConfiguredProperties()).containsOnly(entry("accessToken", "token"),
            entry("clientId", "appId"), entry("clientSecret", "appSecret"));
}

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

/**
 * Executes a POST on a url./*from ww  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> unifiedPost(final Class<T> clazz, final P parm, final String url,
        final String dn) {
    return unifiedX(HttpMethod.POST, clazz, parm, url, dn, null);
}

From source file:org.appverse.web.framework.backend.test.util.frontfacade.mvc.tests.predefined.BasicAuthEndPointsDisabledPredefinedTests.java

@Test
public void simpleAuthenticationServiceTest() throws Exception {
    int port = context.getEmbeddedServletContainer().getPort();

    CredentialsVO credentialsVO = new CredentialsVO();
    credentialsVO.setUsername(getUsername());
    credentialsVO.setPassword(getPassword());
    HttpEntity<CredentialsVO> entity = new HttpEntity<CredentialsVO>(credentialsVO);

    ResponseEntity<AuthorizationData> responseEntity = restTemplate.exchange(
            "http://localhost:" + port + baseApiPath + simpleAuthenticationEndpointPath, HttpMethod.POST,
            entity, AuthorizationData.class);
    // When an enpoint is disabled, "405 - METHOD NOT ALLOWED" is returned
    assertEquals(HttpStatus.METHOD_NOT_ALLOWED, responseEntity.getStatusCode());
}

From source file:com.appglu.impl.SyncTemplateTest.java

@Test(expected = AppGluRestClientException.class)
public void changesForTablesUsingCallback_TableNameAfterChanges() {
    mockServer.expect(requestTo("http://localhost/appglu/v1/sync/changes")).andExpect(method(HttpMethod.POST))
            .andExpect(header("Content-Type", jsonMediaType.toString()))
            .andExpect(content().string(compactedJson("data/sync_changes_for_tables_request")))
            .andRespond(withStatus(HttpStatus.OK)
                    .body(compactedJson("data/sync_parser_table_name_after_changes")).headers(responseHeaders));

    MemoryTableChangesCallback callback = new MemoryTableChangesCallback();

    TableVersion loggedTable = new TableVersion("logged_table");
    TableVersion otherTable = new TableVersion("other_table", 1);

    this.syncOperations.changesForTables(callback, loggedTable, otherTable);
}

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 {/* w  w  w .j  a  v  a  2 s.  c  o  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:com.sitewhere.rest.service.SiteWhereClient.java

@Override
public Site createSite(SiteCreateRequest request) throws SiteWhereException {
    Map<String, String> vars = new HashMap<String, String>();
    return sendRest(getBaseUrl() + "sites", HttpMethod.POST, request, Site.class, vars);
}