Search in sources :

Example 31 with GenericEntity

use of javax.ws.rs.core.GenericEntity in project hadoop by apache.

the class AHSWebServices method getContainerLogMeta.

private Response getContainerLogMeta(ApplicationId appId, String appOwner, final String nodeId, final String containerIdStr, boolean emptyLocalContainerLogMeta) {
    try {
        List<ContainerLogMeta> containerLogMeta = LogToolUtils.getContainerLogMetaFromRemoteFS(conf, appId, containerIdStr, nodeId, appOwner);
        if (containerLogMeta.isEmpty()) {
            throw new NotFoundException("Can not get log meta for container: " + containerIdStr);
        }
        List<ContainerLogsInfo> containersLogsInfo = new ArrayList<>();
        for (ContainerLogMeta meta : containerLogMeta) {
            ContainerLogsInfo logInfo = new ContainerLogsInfo(meta, ContainerLogAggregationType.AGGREGATED);
            containersLogsInfo.add(logInfo);
        }
        if (emptyLocalContainerLogMeta) {
            ContainerLogMeta emptyMeta = new ContainerLogMeta(containerIdStr, "N/A");
            ContainerLogsInfo empty = new ContainerLogsInfo(emptyMeta, ContainerLogAggregationType.LOCAL);
            containersLogsInfo.add(empty);
        }
        GenericEntity<List<ContainerLogsInfo>> meta = new GenericEntity<List<ContainerLogsInfo>>(containersLogsInfo) {
        };
        ResponseBuilder response = Response.ok(meta);
        // Sending the X-Content-Type-Options response header with the value
        // nosniff will prevent Internet Explorer from MIME-sniffing a response
        // away from the declared content-type.
        response.header("X-Content-Type-Options", "nosniff");
        return response.build();
    } catch (Exception ex) {
        throw new WebApplicationException(ex);
    }
}
Also used : ContainerLogsInfo(org.apache.hadoop.yarn.server.webapp.dao.ContainerLogsInfo) WebApplicationException(javax.ws.rs.WebApplicationException) GenericEntity(javax.ws.rs.core.GenericEntity) ContainerLogMeta(org.apache.hadoop.yarn.logaggregation.ContainerLogMeta) ArrayList(java.util.ArrayList) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) List(java.util.List) ArrayList(java.util.ArrayList) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) WebApplicationException(javax.ws.rs.WebApplicationException) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException) ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException)

Example 32 with GenericEntity

use of javax.ws.rs.core.GenericEntity in project exhibitor by soabase.

the class UIResource method getAdditionalTabSpecs.

@Path("tabs")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getAdditionalTabSpecs() {
    final AtomicInteger index = new AtomicInteger(0);
    List<UITabSpec> names = Lists.transform(tabs, new Function<UITab, UITabSpec>() {

        @Override
        public UITabSpec apply(UITab tab) {
            String base = tab.contentIsHtml() ? HTML_UI_TAB_BASE_URL : TEXT_UI_TAB_BASE_URL;
            return new UITabSpec(tab.getName(), base + index.getAndIncrement(), tab.contentIsHtml(), tab.getUITabType());
        }
    });
    // move out of Google's TransformingRandomAccessList
    names = Lists.newArrayList(names);
    GenericEntity<List<UITabSpec>> entity = new GenericEntity<List<UITabSpec>>(names) {
    };
    return Response.ok(entity).build();
}
Also used : UITabSpec(com.netflix.exhibitor.core.entities.UITabSpec) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GenericEntity(javax.ws.rs.core.GenericEntity) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 33 with GenericEntity

use of javax.ws.rs.core.GenericEntity in project exhibitor by soabase.

the class ClusterResource method getClusterStatus.

@Path("status")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getClusterStatus() throws Exception {
    InstanceConfig config = context.getExhibitor().getConfigManager().getConfig();
    ServerList serverList = new ServerList(config.getString(StringConfigs.SERVERS_SPEC));
    ClusterStatusTask task = new ClusterStatusTask(context.getExhibitor(), serverList.getSpecs());
    List<ServerStatus> statuses = context.getExhibitor().getForkJoinPool().invoke(task);
    GenericEntity<List<ServerStatus>> entity = new GenericEntity<List<ServerStatus>>(statuses) {
    };
    return Response.ok(entity).build();
}
Also used : InstanceConfig(com.netflix.exhibitor.core.config.InstanceConfig) GenericEntity(javax.ws.rs.core.GenericEntity) ServerStatus(com.netflix.exhibitor.core.entities.ServerStatus) ServerList(com.netflix.exhibitor.core.state.ServerList) ServerList(com.netflix.exhibitor.core.state.ServerList) List(java.util.List) ClusterStatusTask(com.netflix.exhibitor.core.automanage.ClusterStatusTask) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 34 with GenericEntity

use of javax.ws.rs.core.GenericEntity in project cxf by apache.

the class ResponseImplTest method testGetEntityUnwrapped.

@Test
public void testGetEntityUnwrapped() {
    final Book book = new Book();
    Response r = Response.ok().entity(new GenericEntity<Book>(book) {
    }).build();
    assertSame(book, r.getEntity());
}
Also used : Response(javax.ws.rs.core.Response) Book(org.apache.cxf.jaxrs.resources.Book) GenericEntity(javax.ws.rs.core.GenericEntity) Test(org.junit.Test)

Example 35 with GenericEntity

use of javax.ws.rs.core.GenericEntity in project cxf by apache.

the class JAXRS20ClientServerBookTest method testJAXBElementBookCollection.

@Test
public void testJAXBElementBookCollection() throws Exception {
    String address = "http://localhost:" + PORT + "/bookstore/jaxbelementxmlrootcollections";
    Client client = ClientBuilder.newClient();
    WebTarget target = client.target(address);
    Book b1 = new Book("CXF in Action", 123L);
    Book b2 = new Book("CXF Rocks", 124L);
    List<JAXBElement<Book>> books = new ArrayList<JAXBElement<Book>>();
    books.add(new JAXBElement<Book>(new QName("bookRootElement"), Book.class, b1));
    books.add(new JAXBElement<Book>(new QName("bookRootElement"), Book.class, b2));
    GenericEntity<List<JAXBElement<Book>>> collectionEntity = new GenericEntity<List<JAXBElement<Book>>>(books) {
    };
    GenericType<List<JAXBElement<Book>>> genericResponseType = new GenericType<List<JAXBElement<Book>>>() {
    };
    List<JAXBElement<Book>> books2 = target.request().accept("application/xml").post(Entity.entity(collectionEntity, "application/xml"), genericResponseType);
    assertNotNull(books2);
    assertNotSame(books, books2);
    assertEquals(2, books2.size());
    Book b11 = books.get(0).getValue();
    assertEquals(123L, b11.getId());
    assertEquals("CXF in Action", b11.getName());
    Book b22 = books.get(1).getValue();
    assertEquals(124L, b22.getId());
    assertEquals("CXF Rocks", b22.getName());
}
Also used : GenericType(javax.ws.rs.core.GenericType) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) JAXBElement(javax.xml.bind.JAXBElement) GenericEntity(javax.ws.rs.core.GenericEntity) List(java.util.List) ArrayList(java.util.ArrayList) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Aggregations

GenericEntity (javax.ws.rs.core.GenericEntity)35 List (java.util.List)15 GenericType (javax.ws.rs.core.GenericType)15 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)14 WebTarget (javax.ws.rs.client.WebTarget)14 Collection (java.util.Collection)10 Produces (javax.ws.rs.Produces)9 Response (javax.ws.rs.core.Response)9 GET (javax.ws.rs.GET)7 Path (javax.ws.rs.Path)7 LinkedList (java.util.LinkedList)6 JAXBElement (javax.xml.bind.JAXBElement)5 IOException (java.io.IOException)4 Annotation (java.lang.annotation.Annotation)4 Comparator (java.util.Comparator)4 HashSet (java.util.HashSet)4 Queue (java.util.Queue)4 Set (java.util.Set)4 Stack (java.util.Stack)4