Example usage for org.springframework.http HttpMethod GET

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

Introduction

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

Prototype

HttpMethod GET

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

Click Source Link

Usage

From source file:fi.helsinki.opintoni.server.OodiServer.java

public void expectStudentEventsRequest(String studentNumber) {
    server.expect(requestTo(eventsUrl(studentNumber))).andExpect(method(HttpMethod.GET)).andRespond(
            withSuccess(SampleDataFiles.toText("oodi/studentevents.json"), MediaType.APPLICATION_JSON));
}

From source file:org.openbaton.nse.beans.connectivitymanageragent.ConnectivityManagerRequestor.java

public Host getHost() {
    String url = configuration.getBaseUrl() + "/hosts";
    HttpHeaders headers = new HttpHeaders();
    HttpEntity<String> getEntity = new HttpEntity<>(headers);
    logger.debug("REQUESTING HOSTS to " + url);
    ResponseEntity<String> hosts = template.exchange(url, HttpMethod.GET, getEntity, String.class);

    logger.debug("hosts " + hosts.getBody());

    if (!hosts.getStatusCode().is2xxSuccessful()) {
        return null;
    } else {/*w w w.  j  av  a2s .co  m*/
        return mapper.fromJson(hosts.getBody(), Host.class);
    }
}

From source file:net.eusashead.hateoas.response.impl.OptionsResponseBuilderImplTest.java

@Test
public void testAllHeaders() throws Exception {
    Entity entity = new Entity("foo");
    ResponseEntity<Entity> response = builder.entity(entity).allow(HttpMethod.GET, HttpMethod.PUT).build();
    Assert.assertNotNull(response);/*from   w  ww. ja  va  2 s  . co m*/
    Assert.assertEquals(HttpStatus.OK, response.getStatusCode());
    Assert.assertEquals(entity, response.getBody());
    Assert.assertNotNull(response.getHeaders().getAllow());
    Set<HttpMethod> allow = new HashSet<HttpMethod>();
    allow.addAll(Arrays.asList(HttpMethod.GET, HttpMethod.PUT));
    Assert.assertEquals(allow, response.getHeaders().getAllow());
}

From source file:org.openbaton.nfvo.security.authentication.ResourceServer.java

@Override
public void configure(HttpSecurity http) throws Exception {
    http.headers().frameOptions().disable();

    boolean enabled = Boolean.parseBoolean(enabledSt);

    // API calls/*from  w ww .  j av  a  2 s  .  c  o  m*/
    if (true) {
        log.info("Security is enabled");
        http.authorizeRequests().regexMatchers(HttpMethod.POST, "/api/v1/").access("#oauth2.hasScope('write')")
                .and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER).and()
                .exceptionHandling();

        http.authorizeRequests().antMatchers(HttpMethod.POST, "/api/**").access("#oauth2.hasScope('write')")
                .and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER).and()
                .exceptionHandling();
        http.authorizeRequests().regexMatchers(HttpMethod.GET, "/api/v1/vnf-packages/*/download-with-link")
                .permitAll();
    } else {
        log.warn("Security is not enabled!");
        http.authorizeRequests().anyRequest().permitAll();
    }
}

From source file:org.starfishrespect.myconsumption.android.tasks.SensorValuesUpdater.java

public void refreshDB() {

    AsyncTask<Void, List, Void> task = new AsyncTask<Void, List, Void>() {
        @Override/*from   www . j  a  v a  2  s  . co m*/
        protected Void doInBackground(Void... params) {
            DatabaseHelper db = SingleInstance.getDatabaseHelper();
            RestTemplate template = new RestTemplate();
            HttpHeaders httpHeaders = CryptoUtils.createHeadersCurrentUser();
            ResponseEntity<List> responseEnt;
            template.getMessageConverters().add(new MappingJacksonHttpMessageConverter());

            try {
                SensorValuesDao valuesDao = new SensorValuesDao(db);
                for (SensorData sensor : db.getSensorDao().queryForAll()) {
                    int startTime = (int) (sensor.getLastLocalValue().getTime() / 1000);
                    String url = String.format(SingleInstance.getServerUrl() + "sensors/%s/data?start=%d",
                            sensor.getSensorId(), startTime);
                    Log.d(TAG, url);
                    responseEnt = template.exchange(url, HttpMethod.GET, new HttpEntity<>(httpHeaders),
                            List.class);
                    List<List<Integer>> sensorData = responseEnt.getBody();
                    List<SensorValue> values = new ArrayList<>();
                    long last = 0;
                    long first = Long.MAX_VALUE;
                    for (List<Integer> value : sensorData) {
                        values.add(new SensorValue(value.get(0), value.get(1)));
                        if (value.get(0) > last) {
                            last = value.get(0);
                        }
                        if (value.get(0) < first) {
                            first = value.get(0);
                        }
                    }
                    valuesDao.insertSensorValues(sensor.getSensorId(), values);
                    sensor.setLastLocalValue(new Date(last * 1000));
                    long formerFirst = sensor.getFirstLocalValue().getTime() / 1000;
                    if (formerFirst > first || formerFirst == 0) {
                        sensor.setFirstLocalValue(new Date(first * 1000));
                    }
                    db.getSensorDao().update(sensor);
                    Log.d(TAG, "Inserted values to " + last);
                }
            } catch (SQLException e) {
                Log.e(TAG, "Error:" + e.toString());
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            if (updateFinishedCallback != null) {
                updateFinishedCallback.onUpdateFinished();
            }
        }
    };

    task.execute();
}

From source file:at.ac.univie.isc.asio.security.HttpMethodRestrictionFilterTest.java

@Test
public void should_ignore_request_without_authentication() throws Exception {
    request.setMethod(HttpMethod.GET.name());
    subject.doFilter(request, response, chain);
    assertThat(getAuthentication(), nullValue());
}

From source file:fi.helsinki.opintoni.server.UnisportServer.java

public void expectAuthorizationFailWith404() {
    server.expect(//from  ww  w . ja  v a 2s .c om
            requestTo(unisportBaseUrl + "/api/v1/en/ext/opintoni/authorization?eppn=opettaja@helsinki.fi"))
            .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.NOT_FOUND));
}

From source file:org.zalando.github.spring.MembersTemplateTest.java

@Test
public void listPublicMembers() throws Exception {
    mockServer.expect(requestTo("https://api.github.com/orgs/zalando-stups/public_members?per_page=25"))
            .andExpect(method(HttpMethod.GET))
            // .andExpect(header("Authorization", "Bearer ACCESS_TOKEN"))
            .andRespond(withSuccess(new ClassPathResource("listMembers.json", getClass()),
                    MediaType.APPLICATION_JSON));

    List<User> issueList = membersTemplate.listPublicMembers("zalando-stups");

    Assertions.assertThat(issueList).isNotNull();
    Assertions.assertThat(issueList.size()).isEqualTo(1);
}

From source file:edu.infsci2560.LoginIT.java

@Test
public void testLoginPageValid() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.TEXT_HTML));

    ResponseEntity<String> entity = this.restTemplate.exchange("/login", HttpMethod.GET,
            new HttpEntity<>(headers), String.class);
    assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
    PageHtmlValidator.validatePage(entity.getBody());
}

From source file:net.eusashead.hateoas.response.argumentresolver.AsyncEntityController.java

@RequestMapping(method = RequestMethod.OPTIONS)
public Callable<ResponseEntity<Entity>> options(final OptionsResponseBuilder<Entity> builder) {

    return new Callable<ResponseEntity<Entity>>() {

        @Override/*www  .j  a v  a  2 s.  c o m*/
        public ResponseEntity<Entity> call() throws Exception {
            return builder.allow(HttpMethod.GET, HttpMethod.HEAD).entity(new Entity("foo")).build();
        }
    };
}