use of javax.ws.rs.core.MediaType in project cxf by apache.
the class AtomPojoProviderTest method doTestReadEntry.
private void doTestReadEntry(AtomPojoProvider provider) throws Exception {
provider.setFormattedOutput(true);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
MediaType mt = MediaType.valueOf("application/atom+xml;type=entry");
provider.writeTo(new Book("a"), Book.class, Book.class, new Annotation[] {}, mt, null, bos);
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
@SuppressWarnings({ "unchecked", "rawtypes" }) Book book = (Book) provider.readFrom((Class) Book.class, Book.class, new Annotation[] {}, mt, null, bis);
assertEquals("a", book.getName());
}
use of javax.ws.rs.core.MediaType in project ORCID-Source by ORCID.
the class RDFWriterTest method missingCreditName.
@Test
public void missingCreditName() throws Exception {
ByteArrayOutputStream entityStream = new ByteArrayOutputStream(1024);
Record fakeBio = fakeBio();
// empty creditName
fakeBio.getPerson().getName().setCreditName(null);
// fakeBio.getOrcidProfile().getOrcidBio().getPersonalDetails().setCreditName(null);
rdfWriter.writeTo(fakeBio, Record.class, null, null, new MediaType("text", "turtle"), null, entityStream);
String str = entityStream.toString("utf-8");
System.out.println(str);
// Should NOT include a foaf:name
assertFalse(str.contains("foaf:name"));
// but do include a concatenation as a label
assertTrue(str.contains("rdfs:label"));
assertTrue(str.contains("\"John Doe\""));
// And family/given
assertTrue(str.contains("foaf:familyName"));
assertTrue(str.contains("\"Doe\""));
assertTrue(str.contains("foaf:givenName"));
assertTrue(str.contains("\"John\""));
}
use of javax.ws.rs.core.MediaType in project ORCID-Source by ORCID.
the class RDFWriterTest method writeNtriples.
@Test
public void writeNtriples() throws Exception {
ByteArrayOutputStream entityStream = new ByteArrayOutputStream(1024);
rdfWriter.writeTo(fakeBio(), Record.class, null, null, new MediaType("application", "n-triples"), null, entityStream);
String str = entityStream.toString("utf-8");
System.out.println(str);
assertTrue(str.contains("<http://orcid.example.com/000-1337>"));
assertTrue(str.contains("<http://xmlns.com/foaf/0.1/account>"));
assertTrue(str.contains(EXAMPLE_RDF_URI));
assertTrue(str.contains("<http://xmlns.com/foaf/0.1/Person>"));
assertTrue(str.contains("<http://xmlns.com/foaf/0.1/familyName>"));
assertTrue(str.contains("\"Doe\""));
assertTrue(str.contains("<http://xmlns.com/foaf/0.1/givenName>"));
assertTrue(str.contains("\"John\""));
// and the credit name, which here includes initial F
assertTrue(str.contains("<http://xmlns.com/foaf/0.1/name>"));
assertTrue(str.contains("\"John F Doe\""));
// ontology details should NOT be included
assertFalse(str.contains("subClassOf"));
// provenance
assertTrue(str.contains("<http://purl.org/pav/lastUpdateOn>"));
assertTrue(str.contains("1980-12-31T23:29:29.999Z"));
// location
assertTrue(str.contains("<http://www.geonames.org/ontology#countryCode>"));
assertTrue(str.contains("GB"));
}
use of javax.ws.rs.core.MediaType in project appengine-angular-guestbook-java by googlearchive.
the class GsonMessageBodyHandler method writeTo.
@Override
public void writeTo(Object object, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
try (OutputStreamWriter writer = new OutputStreamWriter(entityStream, UTF_8)) {
Type jsonType;
if (type.equals(genericType)) {
jsonType = type;
} else {
jsonType = genericType;
}
getGson().toJson(object, jsonType, writer);
}
}
use of javax.ws.rs.core.MediaType in project entando-core by entando.
the class LocalStorageManagerInterface method getApiResourceURLWithParams.
public String getApiResourceURLWithParams(Properties properties, BasicFileAttributeView fileAttributeView, String path, boolean isProtected) throws Throwable {
String langCode = properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER);
MediaType mediaType = (MediaType) properties.get(SystemConstants.API_PRODUCES_MEDIA_TYPE_PARAMETER);
String applicationBaseUrl = properties.getProperty(SystemConstants.API_APPLICATION_BASE_URL_PARAMETER);
String url = this.getApiResourceUrl(fileAttributeView, applicationBaseUrl, langCode, mediaType);
StringBuilder stringBuilder = new StringBuilder(url);
String fullPath = this.buildResourcePath(fileAttributeView, path);
if (StringUtils.isNotBlank(fullPath))
fullPath = URLDecoder.decode(fullPath, CharEncoding.UTF_8);
stringBuilder.append("?").append(PARAM_PATH).append("=").append(fullPath);
stringBuilder.append("&").append(PARAM_IS_PROTECTED).append("=").append(isProtected);
return stringBuilder.toString();
}
Aggregations