Search in sources :

Example 86 with MediaType

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());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) MediaType(javax.ws.rs.core.MediaType) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Annotation(java.lang.annotation.Annotation)

Example 87 with MediaType

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\""));
}
Also used : MediaType(javax.ws.rs.core.MediaType) Record(org.orcid.jaxb.model.record_v2.Record) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 88 with MediaType

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"));
}
Also used : MediaType(javax.ws.rs.core.MediaType) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 89 with MediaType

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);
    }
}
Also used : MediaType(javax.ws.rs.core.MediaType) Type(java.lang.reflect.Type)

Example 90 with MediaType

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();
}
Also used : MediaType(javax.ws.rs.core.MediaType)

Aggregations

MediaType (javax.ws.rs.core.MediaType)477 Test (org.junit.Test)184 Path (javax.ws.rs.Path)44 Produces (javax.ws.rs.Produces)44 ByteArrayInputStream (java.io.ByteArrayInputStream)42 WebApplicationException (javax.ws.rs.WebApplicationException)41 IOException (java.io.IOException)40 Response (javax.ws.rs.core.Response)40 InputStream (java.io.InputStream)38 ArrayList (java.util.ArrayList)31 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)31 Type (java.lang.reflect.Type)30 Consumes (javax.ws.rs.Consumes)27 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)27 GET (javax.ws.rs.GET)25 OutputStream (java.io.OutputStream)23 Annotation (java.lang.annotation.Annotation)23 HashSet (java.util.HashSet)22 Locale (java.util.Locale)22 HashMap (java.util.HashMap)21