Example usage for org.springframework.http MediaType APPLICATION_XML

List of usage examples for org.springframework.http MediaType APPLICATION_XML

Introduction

In this page you can find the example usage for org.springframework.http MediaType APPLICATION_XML.

Prototype

MediaType APPLICATION_XML

To view the source code for org.springframework.http MediaType APPLICATION_XML.

Click Source Link

Document

Public constant media type for application/xml .

Usage

From source file:com.orange.ngsi.server.NgsiBaseControllerTest.java

@Test
public void checkSubscribeContextImplementedInXml() throws Exception {
    mockMvc.perform(post("/i/subscribeContext")
            .content(xmlmapper.writeValueAsString(Util.createSubscribeContextTemperature()))
            .contentType(MediaType.APPLICATION_XML).header("Host", "localhost")
            .accept(MediaType.APPLICATION_XML)).andExpect(status().isOk());
}

From source file:edu.mayo.qdm.webapp.rest.controller.TranslatorController.java

/**
 * Gets the xml.//from  w  ww .j  a va  2 s  . c o m
 *
 * @param executionId the execution id
 * @return the xml
 * @throws Exception the exception
 */
@RequestMapping(value = "executor/execution/{executionId}/xml", method = RequestMethod.GET)
public ResponseEntity<String> getOutputXml(@PathVariable String executionId) throws Exception {
    File xml = fileSystemResolver.getFiles(executionId).getOuptutResultXml();

    String xmlString = FileUtils.readFileToString(xml, "UTF-8");

    final HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_XML);

    return new ResponseEntity<String>(xmlString, headers, HttpStatus.OK);
}

From source file:se.skltp.cooperation.web.rest.v1.controller.ConnectionPointControllerTest.java

@Test
public void getAllXmlUrl_shouldReturnAll() throws Exception {

    when(connectionPointServiceMock.findAll(any(ConnectionPointCriteria.class)))
            .thenReturn(Arrays.asList(cp1, cp2));
    when(mapperMock.map(cp1, ConnectionPointDTO.class)).thenReturn(dto1);
    when(mapperMock.map(cp2, ConnectionPointDTO.class)).thenReturn(dto2);

    mockMvc.perform(get("/api/v1/connectionPoints.xml").accept(MediaType.APPLICATION_XML))
            .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_XML))
            .andExpect(xpath("/connectionPoints/connectionPoint[1]/id").string(is(dto1.getId().toString())))
            .andExpect(xpath("/connectionPoints/connectionPoint[1]/platform").string(is(dto1.getPlatform())))
            .andExpect(//from w  w  w  . j ava 2 s  .co m
                    xpath("/connectionPoints/connectionPoint[1]/environment").string(is(dto1.getEnvironment())))
            .andExpect(xpath("/connectionPoints/connectionPoint[1]/snapshotTime")
                    .string(is(isoDateFormatter.print(dto1.getSnapshotTime().getTime()))))
            .andExpect(xpath("/connectionPoints/connectionPoint[2]/id").string(is(dto2.getId().toString())))
            .andExpect(xpath("/connectionPoints/connectionPoint[2]/platform").string(is(dto2.getPlatform())))
            .andExpect(
                    xpath("/connectionPoints/connectionPoint[2]/environment").string(is(dto2.getEnvironment())))
            .andExpect(xpath("/connectionPoints/connectionPoint[2]/snapshotTime")
                    .string(is(isoDateFormatter.print(dto2.getSnapshotTime().getTime()))));

    verify(connectionPointServiceMock, times(1)).findAll(any(ConnectionPointCriteria.class));
    verifyNoMoreInteractions(connectionPointServiceMock);

}

From source file:se.skltp.cooperation.web.rest.v1.controller.CooperationControllerTest.java

@Test
public void testGetAllAsXml_shouldReturnAll() throws Exception {

    when(cooperationServiceMock.findAll(any(CooperationCriteria.class))).thenReturn(Arrays.asList(c1, c2));
    when(mapperMock.map(c1, CooperationDTO.class)).thenReturn(dto1);
    when(mapperMock.map(c2, CooperationDTO.class)).thenReturn(dto2);

    mockMvc.perform(get("/api/v1/cooperations").accept(MediaType.APPLICATION_XML)).andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_XML))
            .andExpect(xpath("/cooperations/cooperation[1]/id").string(is(dto1.getId().toString())))
            .andExpect(xpath("/cooperations/cooperation[2]/id").string(is(dto2.getId().toString())));

    verify(cooperationServiceMock, times(1)).findAll(any(CooperationCriteria.class));
    verifyNoMoreInteractions(cooperationServiceMock);

}

From source file:org.ow2.proactive.workflow_catalog.rest.service.WorkflowRevisionService.java

public ResponseEntity<?> getWorkflow(Long bucketId, Long workflowId, Optional<Long> revisionId,
        Optional<String> alt) {
    findBucket(bucketId);/*from ww  w . ja  v a  2s  .c o  m*/
    findWorkflow(workflowId);

    WorkflowRevision workflowRevision = getWorkflowRevision(bucketId, workflowId, revisionId);

    if (alt.isPresent()) {
        String altValue = alt.get();

        if (!altValue.equalsIgnoreCase(SUPPORTED_ALT_VALUE)) {
            throw new UnsupportedMediaTypeException("Unsupported media type '" + altValue + "' (only '"
                    + SUPPORTED_ALT_VALUE + "' is allowed)");
        }

        byte[] bytes = workflowRevision.getXmlPayload();

        return ResponseEntity.ok().contentLength(bytes.length).contentType(MediaType.APPLICATION_XML)
                .body(new InputStreamResource(new ByteArrayInputStream(bytes)));
    }

    WorkflowMetadata workflowMetadata = new WorkflowMetadata(workflowRevision);

    workflowMetadata.add(createLink(bucketId, workflowId, workflowRevision));

    return ResponseEntity.ok(workflowMetadata);
}

From source file:edu.mayo.qdm.webapp.rest.controller.TranslatorController.java

@RequestMapping(value = "executor/execution/{executionId}/input", method = RequestMethod.GET)
public ResponseEntity<String> getInputputXml(@PathVariable String executionId) throws Exception {
    File xml = fileSystemResolver.getFiles(executionId).getInputQdmXml();

    String xmlString = FileUtils.readFileToString(xml, "UTF-8");

    final HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_XML);

    return new ResponseEntity<String>(xmlString, headers, HttpStatus.OK);
}

From source file:com.orange.ngsi.server.NgsiRestBaseControllerTest.java

@Test
public void xmlSyntaxErrorHandling() throws Exception {

    mockMvc.perform(/*from   w w  w  .j  a v a2 s .c  o m*/
            post("/rest/ni/contextEntities/test").content("bad xml").contentType(MediaType.APPLICATION_XML)
                    .header("Host", "localhost").accept(MediaType.APPLICATION_XML))
            .andExpect(status().isOk())
            .andExpect(MockMvcResultMatchers.xpath("statusCode/code").string(CodeEnum.CODE_400.getLabel()))
            .andExpect(MockMvcResultMatchers.xpath("statusCode/reasonPhrase")
                    .string(CodeEnum.CODE_400.getShortPhrase()))
            .andExpect(MockMvcResultMatchers.xpath("statusCode/details")
                    .string(CodeEnum.CODE_400.getLongPhrase()));
}

From source file:com.orange.ngsi.server.NgsiBaseControllerTest.java

@Test
public void checkUpdateContextSubscriptionImplementedInXml() throws Exception {
    mockMvc.perform(post("/i/updateContextSubscription")
            .content(xmlmapper.writeValueAsString(Util.createUpdateContextSubscriptionTemperature()))
            .contentType(MediaType.APPLICATION_XML).header("Host", "localhost")
            .accept(MediaType.APPLICATION_XML)).andExpect(status().isOk());
}

From source file:se.skltp.cooperation.web.rest.v1.controller.ServiceConsumerControllerTest.java

@Test
public void get_shouldReturnOneAsXml() throws Exception {

    when(serviceConsumerServiceMock.find(c1.getId())).thenReturn(c1);
    when(mapperMock.map(c1, ServiceConsumerDTO.class)).thenReturn(dto1);

    mockMvc.perform(get("/api/v1/serviceConsumers/{id}", c1.getId()).accept(MediaType.APPLICATION_XML))
            .andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_XML))
            .andExpect(xpath("/serviceConsumer/id").string(is(dto1.getId().toString())))
            .andExpect(xpath("/serviceConsumer/description").string(is(dto1.getDescription())))
            .andExpect(xpath("/serviceConsumer/hsaId").string(is(dto1.getHsaId())));

}

From source file:edu.mayo.qdm.webapp.rest.controller.TranslatorController.java

@RequestMapping(value = "executor/execution/{executionId}/xslt/eMeasure.xsl", method = RequestMethod.GET)
public ResponseEntity<String> getMeasureXslt(@PathVariable String executionId) throws Exception {
    File xml = fileSystemResolver.getFiles(executionId).getInputQdmXml();

    String xmlString = IOUtils.toString(new ClassPathResource("/eMeasure.xsl").getInputStream(), "UTF-8");

    final HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_XML);

    return new ResponseEntity<String>(xmlString, headers, HttpStatus.OK);
}