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:be.solidx.hot.utils.AbstractHttpDataDeserializer.java

@Override
public Object processRequestData(byte[] data, String contentType) {
    MediaType ct = MediaType.parseMediaType(contentType);

    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Content-type: " + contentType);

    Charset charset = ct.getCharSet() == null ? Charset.forName("UTF-8") : ct.getCharSet();

    // Subtypes arre used because of possible encoding definitions
    if (ct.getSubtype().equals(MediaType.APPLICATION_OCTET_STREAM.getSubtype())) {
        return data;
    } else if (ct.getSubtype().equals(MediaType.APPLICATION_JSON.getSubtype())) {
        try {/*from   www  .j a  va  2s.  c o  m*/
            return fromJSON(data);
        } catch (IOException e) {
            throw new RuntimeException(e.getMessage(), e.getCause());
        }
    } else if (ct.getSubtype().equals(MediaType.APPLICATION_XML.getSubtype())) {
        try {
            return toXML(data, ct.getCharSet() == null ? Charset.forName("UTF-8") : ct.getCharSet());
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e.getCause());
        }
    } else if (ct.getSubtype().equals(MediaType.APPLICATION_FORM_URLENCODED.getSubtype())) {
        String decoded;
        try {
            decoded = URLDecoder.decode(new String(data, charset), charset.toString());
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage(), e.getCause());
        }
        return fromFormUrlEncoded(decoded);
    } else {
        return new String(data, ct.getCharSet() == null ? Charset.forName("UTF-8") : ct.getCharSet());
    }
}

From source file:org.projecthdata.ehr.viewer.service.PatientSyncService.java

private void doSyncPatientInfo() {
    this.editor = prefs.edit();
    editor.putString(Constants.PREF_PATIENT_INFO_SYNC_STATE, SyncState.WORKING.toString()).commit();

    try {/*from  www .j a v  a 2  s .c o  m*/
        Dao<RootEntry, Integer> rootDao = hDataOrmManager.getDatabaseHelper().getRootEntryDao();
        Dao<SectionDocMetadata, Integer> sectionDao = hDataOrmManager.getDatabaseHelper()
                .getSectionDocMetadataDao();

        // find the first entry that has the right schema and contains xml documents
        RootEntry entry = rootDao.queryForFirst(
                rootDao.queryBuilder().where().eq(RootEntry.COLUMN_NAME_EXTENSION, Constants.EXTENSION_PATIENT)
                        .and().eq(RootEntry.COLUMN_NAME_CONTENT_TYPE, MediaType.APPLICATION_XML).prepare());

        //find the metadata for the first xml document in the section owned by the previous found root entry
        SectionDocMetadata metadata = sectionDao
                .queryForFirst(sectionDao.queryBuilder().where().eq("rootEntry_id", entry.get_id()).and()
                        .eq("contentType", MediaType.APPLICATION_XML).prepare());

        // grab that document and parse out the patient info
        Connection<HData> connection = connectionRepository.getPrimaryConnection(HData.class);

        RestTemplate restTemplate = connection.getApi().getRootOperations().getRestTemplate();

        Patient patientInfo = restTemplate.getForObject(metadata.getLink(), Patient.class);

        save(patientInfo);

        //get the url for their photo
        entry = rootDao.queryForFirst(
                rootDao.queryBuilder().where().eq(RootEntry.COLUMN_NAME_EXTENSION, Constants.EXTENSION_PNG)
                        .and().eq(RootEntry.COLUMN_NAME_CONTENT_TYPE, MediaType.IMAGE_PNG).prepare());
        if (entry != null) {
            metadata = sectionDao.queryForFirst(sectionDao.queryBuilder().where()
                    .eq("rootEntry_id", entry.get_id()).and().eq("contentType", MediaType.IMAGE_PNG).prepare());

            this.editor.putString(Constants.PREF_PATIENT_PHOTO_URL, metadata.getLink());
        }
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    this.editor.putString(Constants.PREF_PATIENT_INFO_SYNC_STATE, SyncState.READY.toString());
    //committing all of the changes 
    this.editor.commit();
}

From source file:lcn.samples.petclinic.web.VisitsViewTest.java

@Test
public void getVisitsXml() throws Exception {
    ResultActions actions = this.mockMvc.perform(get("/vets.xml").accept(MediaType.APPLICATION_XML));
    actions.andDo(print()); // action is logged into the console
    actions.andExpect(status().isOk());/*from   w  w  w .j  a v  a  2 s  . c om*/
    actions.andExpect(content().contentType("application/xml"));
    actions.andExpect(xpath("/vets/vetList[id=1]/firstName").string(containsString("James")));

}

From source file:org.kepennar.android.client.rest.HttpPostJsonXmlActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.setContentView(R.layout.http_post_json_xml_activity_layout);

    // Initiate the JSON POST request when the JSON button is clicked
    final Button buttonJson = (Button) findViewById(R.id.button_post_json);
    buttonJson.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            new PostMessageTask().execute(MediaType.APPLICATION_JSON);
        }/*from w  w  w. j  a va2 s .  co m*/
    });

    // Initiate the XML POST request when the XML button is clicked
    final Button buttonXml = (Button) findViewById(R.id.button_post_xml);
    buttonXml.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            new PostMessageTask().execute(MediaType.APPLICATION_XML);
        }
    });
}

From source file:com.orange.ngsi.client.NgsiClientTest.java

@Test
public void getRequestHeadersWithNullUrl() {
    HttpHeaders httpHeaders = ngsiClient.getRequestHeaders(null);

    assertEquals(MediaType.APPLICATION_XML, httpHeaders.getContentType());
    assertTrue(httpHeaders.getAccept().contains(MediaType.APPLICATION_XML));
}

From source file:example.xmlbeam.XmlBeamHttpMessageConverter.java

@Override
public List<MediaType> getSupportedMediaTypes() {
    return Collections.singletonList(MediaType.APPLICATION_XML);
}

From source file:org.kepennar.android.client.rest.HttpGetParametersActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.setContentView(R.layout.http_get_parameters_activity_layout);

    // Initiate the request for JSON data when the JSON button is pushed
    final Button buttonJson = (Button) findViewById(R.id.button_json);
    buttonJson.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            new DownloadStateTask().execute(MediaType.APPLICATION_JSON);
        }//from   w w  w .  j a  v a 2 s.c om
    });

    // Initiate the request for XML data when the XML button is pushed
    final Button buttonXml = (Button) findViewById(R.id.button_xml);
    buttonXml.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            new DownloadStateTask().execute(MediaType.APPLICATION_XML);
        }
    });
}

From source file:com.compomics.colims.core.service.impl.UniProtServiceImpl.java

@Override
public Map<String, String> getUniProtByAccession(String accession) throws RestClientException, IOException {
    Map<String, String> uniProt = new HashMap<>();

    try {/*w  w w. j  a  v a  2  s.c  o m*/
        // Set XML content type explicitly to force response in XML (If not spring gets response in JSON)
        HttpHeaders headers = new HttpHeaders();
        headers.setAccept(Arrays.asList(MediaType.APPLICATION_XML));
        HttpEntity<String> entity = new HttpEntity<>("parameters", headers);

        ResponseEntity<String> response = restTemplate.exchange(UNIPROT_BASE_URL + "/" + accession + ".xml",
                HttpMethod.GET, entity, String.class);
        String responseBody = response.getBody();

        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        InputSource is = new InputSource(new StringReader(responseBody));

        Document document = (Document) builder.parse(is);
        document.getDocumentElement().normalize();
        NodeList recommendedName = document.getElementsByTagName("recommendedName");

        Node node = recommendedName.item(0);
        Element element = (Element) node;
        if (element.getElementsByTagName("fullName").item(0).getTextContent() != null
                && !element.getElementsByTagName("fullName").item(0).getTextContent().equals("")) {
            uniProt.put("description", element.getElementsByTagName("fullName").item(0).getTextContent());
        }

        NodeList organism = document.getElementsByTagName("organism");
        node = organism.item(0);
        element = (Element) node;
        if (element.getElementsByTagName("name").item(0).getTextContent() != null
                && !element.getElementsByTagName("name").item(0).getTextContent().equals("")) {
            uniProt.put("species", element.getElementsByTagName("name").item(0).getTextContent());
        }

        NodeList dbReference = document.getElementsByTagName("dbReference");
        node = dbReference.item(0);
        element = (Element) node;
        if (element.getAttribute("id") != null && !element.getAttribute("id").equals("")) {
            uniProt.put("taxid", element.getAttribute("id"));
        }

    } catch (HttpClientErrorException ex) {
        LOGGER.error(ex.getMessage(), ex);
        //ignore the exception if the namespace doesn't correspond to an ontology
        if (!ex.getStatusCode().equals(HttpStatus.NOT_FOUND)) {
            throw ex;
        }
    } catch (ParserConfigurationException | SAXException ex) {
        java.util.logging.Logger.getLogger(UniProtServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
    }

    return uniProt;
}

From source file:biz.c24.io.spring.http.C24HttpMessageConverterUnitTests.java

@Test
public void readsXmlCorrectly() throws IOException {

    when(inputMessage.getBody()).thenReturn(new ByteArrayInputStream(TestConstants.SAMPLE_XML.getBytes()));
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_XML);
    when(inputMessage.getHeaders()).thenReturn(headers);

    CustomerLocal result = (CustomerLocal) converter.read(CustomerLocal.class, inputMessage);
    assertThat(result, is(notNullValue()));
    assertThat(result.getFirstname(), is("Firstname"));
}

From source file:com.applechip.android.showcase.rest.HttpGetParametersActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.http_get_parameters_activity_layout);

    // Initiate the request for JSON data when the JSON button is pushed
    final Button buttonJson = (Button) findViewById(R.id.button_json);
    buttonJson.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            new DownloadStateTask().execute(MediaType.APPLICATION_JSON);
        }/*from w w  w.  j a v  a2 s  .  co  m*/
    });

    // Initiate the request for XML data when the XML button is pushed
    final Button buttonXml = (Button) findViewById(R.id.button_xml);
    buttonXml.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            new DownloadStateTask().execute(MediaType.APPLICATION_XML);
        }
    });
}