Example usage for org.springframework.http HttpEntity getBody

List of usage examples for org.springframework.http HttpEntity getBody

Introduction

In this page you can find the example usage for org.springframework.http HttpEntity getBody.

Prototype

@Nullable
public T getBody() 

Source Link

Document

Returns the body of this entity.

Usage

From source file:org.bozzo.ipplan.web.SubnetController.java

@RequestMapping(value = "/{subnetId}", method = RequestMethod.GET, produces = { MediaType.TEXT_HTML_VALUE })
@ApiIgnore//from ww w  .ja  v  a2  s  .  c o m
public ModelAndView getSubnetView(@PathVariable @NotNull Integer infraId, @PathVariable Long subnetId,
        @RequestParam(required = false) RequestMode mode) {
    HttpEntity<SubnetResource> subnet = this.getSubnet(infraId, subnetId, mode);
    ModelAndView view = new ModelAndView("subnet");
    view.addObject("id", subnetId);
    view.addObject("object", subnet.getBody());
    return view;
}

From source file:com.onedrive.api.internal.MultipartRelatedHttpMessageConverter.java

@SuppressWarnings("unchecked")
private void writePart(String name, HttpEntity<?> partEntity, OutputStream os) throws IOException {
    Object partBody = partEntity.getBody();
    Class<?> partType = partBody.getClass();
    HttpHeaders partHeaders = partEntity.getHeaders();
    MediaType partContentType = partHeaders.getContentType();
    for (HttpMessageConverter<?> messageConverter : this.partConverters) {
        if (messageConverter.canWrite(partType, partContentType)) {
            HttpOutputMessage multipartMessage = new MultipartHttpOutputMessage(os);
            StringBuilder builder = new StringBuilder("<").append(name).append('>');
            multipartMessage.getHeaders().set("Content-ID", builder.toString());
            if (!partHeaders.isEmpty()) {
                multipartMessage.getHeaders().putAll(partHeaders);
            }/*from ww  w . j  av a 2s  . c  o m*/
            ((HttpMessageConverter<Object>) messageConverter).write(partBody, partContentType,
                    multipartMessage);
            return;
        }
    }
    throw new HttpMessageNotWritableException("Could not write request: no suitable HttpMessageConverter "
            + "found for request type [" + partType.getName() + "]");
}

From source file:org.bozzo.ipplan.web.SubnetController.java

@RequestMapping(method = RequestMethod.GET, produces = { MediaType.TEXT_HTML_VALUE })
@ApiIgnore//w w w. ja  v  a 2 s  . c  o  m
public ModelAndView getSubnetsView(@RequestParam(required = false) String ip,
        @RequestParam(required = false) Long size, @PathVariable @NotNull Integer infraId, Pageable pageable,
        PagedResourcesAssembler<Subnet> pagedAssembler) {
    HttpEntity<PagedResources<SubnetResource>> subnets = this.getSubnets(ip, size, infraId, pageable,
            pagedAssembler);
    ModelAndView view = new ModelAndView("subnets");
    view.addObject("pages", subnets.getBody());
    return view;
}

From source file:org.energyos.espi.thirdparty.web.custodian.AdministratorController.java

@RequestMapping(value = Routes.ROOT_SERVICE_STATUS, method = RequestMethod.GET)
public String showServiceStatus(ModelMap model) {

    ApplicationInformation applicationInformation = resourceService.findById(1L, ApplicationInformation.class);
    String statusUri = applicationInformation.getAuthorizationServerAuthorizationEndpoint()
            + "/ReadServiceStatus";
    // not sure this will work w/o the right seed information
    ////www.jav a 2s. c om
    Authorization authorization = resourceService.findByResourceUri(statusUri, Authorization.class);
    RetailCustomer retailCustomer = authorization.getRetailCustomer();

    String accessToken = authorization.getAccessToken();
    String serviceStatus = "OK";

    try {

        HttpHeaders requestHeaders = new HttpHeaders();
        requestHeaders.set("Authorization", "Bearer " + accessToken);
        @SuppressWarnings({ "unchecked", "rawtypes" })
        HttpEntity<?> requestEntity = new HttpEntity(requestHeaders);

        // get the subscription
        HttpEntity<String> httpResult = restTemplate.exchange(statusUri, HttpMethod.GET, requestEntity,
                String.class);

        // import it into the repository
        ByteArrayInputStream bs = new ByteArrayInputStream(httpResult.getBody().toString().getBytes());

        importService.importData(bs, retailCustomer.getId());

        List<EntryType> entries = importService.getEntries();

        // TODO: Use-Case 1 registration - service status

    } catch (Exception e) {
        // nothing there, so log the fact and move on. It will
        // get imported later.
        e.printStackTrace();
    }
    model.put("serviceStatus", serviceStatus);

    return "/custodian/datacustodian/showservicestatus";
}

From source file:org.jasig.portlet.degreeprogress.dao.xml.HttpDegreeProgressDaoImpl.java

@Override
public DegreeProgressReport getProgressReport(PortletRequest request) {
    Map<String, String> params = createParameters(request, urlParams);
    if (log.isDebugEnabled()) {
        log.debug("Invoking uri '" + degreeProgressUrlFormat + "' with the following parameters:  "
                + params.toString());//from   w  w w. j  a  v  a  2  s.c  o m
    }

    HttpEntity<?> requestEntity = getRequestEntity(request);
    HttpEntity<DegreeProgressReport> response = restTemplate.exchange(degreeProgressUrlFormat, HttpMethod.GET,
            requestEntity, DegreeProgressReport.class, params);

    DegreeProgressReport report = response.getBody();
    for (DegreeRequirementSection section : report.getDegreeRequirementSections()) {
        for (JAXBElement<? extends GeneralRequirementType> requirement : section.getGeneralRequirements()) {
            GeneralRequirementType req = requirement.getValue();
            if (req instanceof GpaRequirement) {
                section.setRequiredGpa(((GpaRequirement) req).getRequiredGpa());
            }
        }
        for (CourseRequirement req : section.getCourseRequirements()) {
            for (Course course : req.getCourses()) {
                StudentCourseRegistration registration = new StudentCourseRegistration();
                registration.setCredits(course.getCredits());
                registration.setSource(course.getSource());
                registration.setSemester(course.getSemester());
                registration.setCourse(course);
                Grade grade = new Grade();
                grade.setCode(course.getGrade().getCode());
                registration.setGrade(grade);
                req.getRegistrations().add(registration);
            }
        }
        report.addSection(section);
    }
    return report;
}

From source file:com.formkiq.core.api.FormRestController.java

/**
 * Process Form Events.// w  w w.j a  va  2  s  . c  o  m
 * @param request {@link HttpServletRequest}
 * @param type {@link String}
 * @param event {@link String}
 * @param entity {@link HttpEntity}
 * @return {@link FormJSON}
 * @throws IOException IOException
 */
@RequestMapping(value = API_ROOT + "/event/{type}/{event}", method = POST)
public FormJSON events(final HttpServletRequest request,
        final @PathVariable(name = "type", required = true) String type,
        final @PathVariable(name = "event", required = true) String event, final HttpEntity<byte[]> entity)
        throws IOException {

    FormJSON form = this.jsonService.readValue(entity.getBody(), FormJSON.class);

    return this.workflowService.handleFormEvents(form, type);
}

From source file:org.ngrinder.perftest.controller.PerfTestControllerTest.java

@Test
public void testSearchTag() {
    HttpEntity<String> rtn = controller.searchTag(getAdminUser(), "");
    assertThat(rtn.getBody(), notNullValue());
    rtn = controller.searchTag(getAdminUser(), "test");
    assertThat(rtn.getBody(), notNullValue());
}

From source file:org.ngrinder.perftest.controller.PerfTestControllerTest.java

@Test
public void testUpdateStatus() {
    String testName = "test1";
    PerfTest test = createPerfTest(testName, Status.TESTING, new Date());
    String testName2 = "test1";
    PerfTest test2 = createPerfTest(testName2, Status.START_AGENTS, new Date());

    String ids = test.getId() + "," + test2.getId();
    HttpEntity<String> rtnJson = controller.getStatuses(getTestUser(), ids);
    assertThat(rtnJson.getBody(), notNullValue());
}

From source file:org.darwinathome.server.controller.HubController.java

@RequestMapping(Hub.SET_GENOME_SERVICE)
@ResponseBody/*  w  w w.j  av  a  2s  .  c  om*/
public String setGenome(@PathVariable("session") String session, HttpEntity<byte[]> entity) {
    log.info(Hub.SET_GENOME_SERVICE + " " + session);
    try {
        DataInputStream dis = new DataInputStream(new ByteArrayInputStream(entity.getBody()));
        Genome genome = Genome.read(dis, worldHistory.getNoise());
        worldHistory.setGenome(getEmail(session), genome);
        return Hub.SUCCESS;
    } catch (IOException e) {
        log.warn("Unable to read genome", e);
        return Hub.FAILURE + Failure.MARSHALLING;
    } catch (NoSessionException e) {
        return Hub.FAILURE + Failure.SESSION;
    }
}

From source file:org.appverse.web.framework.backend.test.util.frontfacade.xs.xss.tests.predefined.XssFilterPredefinedTests.java

@Test
public void testXssFilterInUrlPath() throws Exception {
    HttpHeaders headers = new HttpHeaders();
    headers.set("testSafeHeader", "safeHeader");
    HttpEntity<String> entity = new HttpEntity<String>(headers);

    int port = context.getEmbeddedServletContainer().getPort();
    HttpEntity<String> response = restTemplate.exchange(
            "http://localhost:" + port + "/test/safeurlpath/document.cookie", HttpMethod.GET, entity,
            String.class);
    // Assert that: Safe header is kept, Safe url path is kept, Risky URK path is skipped
    assertThat(response.getBody(), equalTo("|safeHeader|safeurlpath|document|"));
}