Search in sources :

Example 6 with TypeReference

use of org.codehaus.jackson.type.TypeReference in project android-app by eoecn.

the class BlogsDao method getMore.

public BlogsMoreResponse getMore(String more_url) {
    BlogsMoreResponse response;
    try {
        String result = RequestCacheUtil.getRequestContent(mActivity, more_url + Utility.getScreenParams(mActivity), Constants.WebSourceType.Json, Constants.DBContentType.Content_list, true);
        response = mObjectMapper.readValue(result, new TypeReference<BlogsMoreResponse>() {
        });
        return response;
    } catch (JsonParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JsonMappingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}
Also used : JsonMappingException(org.codehaus.jackson.map.JsonMappingException) BlogsMoreResponse(cn.eoe.app.entity.BlogsMoreResponse) TypeReference(org.codehaus.jackson.type.TypeReference) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException)

Example 7 with TypeReference

use of org.codehaus.jackson.type.TypeReference in project pinot by linkedin.

the class GenerateDataCommand method buildCardinalityRangeMaps.

private void buildCardinalityRangeMaps(String file, HashMap<String, Integer> cardinality, HashMap<String, IntRange> range) throws JsonParseException, JsonMappingException, IOException {
    List<SchemaAnnotation> saList;
    if (file == null) {
        // Nothing to do here.
        return;
    }
    ObjectMapper objectMapper = new ObjectMapper();
    saList = objectMapper.readValue(new File(file), new TypeReference<List<SchemaAnnotation>>() {
    });
    for (SchemaAnnotation sa : saList) {
        String column = sa.getColumn();
        if (sa.isRange()) {
            range.put(column, new IntRange(sa.getRangeStart(), sa.getRangeEnd()));
        } else {
            cardinality.put(column, sa.getCardinality());
        }
    }
}
Also used : IntRange(org.apache.commons.lang.math.IntRange) TypeReference(org.codehaus.jackson.type.TypeReference) SchemaAnnotation(com.linkedin.pinot.tools.data.generator.SchemaAnnotation) File(java.io.File) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 8 with TypeReference

use of org.codehaus.jackson.type.TypeReference in project databus by linkedin.

the class TestRelayCommandsLocal method testRegisterV4CommandLessThanHappyPaths.

@Test
public void testRegisterV4CommandLessThanHappyPaths() throws Exception {
    LOG.debug("\n\nstarting testRegisterV4CommandLessThanHappyPaths()\n");
    // protocolVersion < 2
    HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/register?sources=4002&" + DatabusHttpHeaders.PROTOCOL_VERSION_PARAM + "=1");
    SimpleTestHttpClient httpClient = SimpleTestHttpClient.createLocal(TimeoutPolicy.ALL_TIMEOUTS);
    SimpleHttpResponseHandler respHandler = httpClient.sendRequest(_serverAddress, httpRequest);
    assertTrue("failed to get a response", respHandler.awaitResponseUninterruptedly(1, TimeUnit.SECONDS));
    HttpResponse respObj = respHandler.getResponse();
    assertNotNull("/register failed to return expected error", respObj.getHeader(DatabusHttpHeaders.DATABUS_ERROR_CLASS_HEADER));
    LOG.debug("DATABUS_ERROR_CLASS_HEADER = " + respObj.getHeader(DatabusHttpHeaders.DATABUS_ERROR_CLASS_HEADER));
    // protocolVersion > 4
    httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/register?sources=4002&" + DatabusHttpHeaders.PROTOCOL_VERSION_PARAM + "=5");
    respHandler = httpClient.sendRequest(_serverAddress, httpRequest);
    assertTrue("failed to get a response", respHandler.awaitResponseUninterruptedly(1, TimeUnit.SECONDS));
    respObj = respHandler.getResponse();
    assertNotNull("/register failed to return expected error", respObj.getHeader(DatabusHttpHeaders.DATABUS_ERROR_CLASS_HEADER));
    LOG.debug("DATABUS_ERROR_CLASS_HEADER = " + respObj.getHeader(DatabusHttpHeaders.DATABUS_ERROR_CLASS_HEADER));
    // protocolVersion == 2:  this is a happy path, but explicitly specifying the version is
    // unusual in this case (default = version 2 or 3, which are identical for /register), so
    // check for expected response
    httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/register?sources=4002&" + DatabusHttpHeaders.PROTOCOL_VERSION_PARAM + "=2");
    respHandler = httpClient.sendRequest(_serverAddress, httpRequest);
    assertTrue("failed to get a response", respHandler.awaitResponseUninterruptedly(1, TimeUnit.SECONDS));
    respObj = respHandler.getResponse();
    assertNull("/register v2 returned unexpected error: " + respObj.getHeader(DatabusHttpHeaders.DATABUS_ERROR_CLASS_HEADER), respObj.getHeader(DatabusHttpHeaders.DATABUS_ERROR_CLASS_HEADER));
    LOG.debug("DATABUS_ERROR_CLASS_HEADER = " + respObj.getHeader(DatabusHttpHeaders.DATABUS_ERROR_CLASS_HEADER));
    String registerResponseProtocolVersionStr = respObj.getHeader(DatabusHttpHeaders.DBUS_CLIENT_RELAY_PROTOCOL_VERSION_HDR);
    assertNotNull("/register protocol-version response header not present", registerResponseProtocolVersionStr);
    assertEquals("client-relay protocol response version mismatch", "2", registerResponseProtocolVersionStr);
    byte[] respBytes = respHandler.getReceivedBytes();
    if (LOG.isDebugEnabled()) {
        LOG.debug("/register response: " + new String(respBytes));
    }
    ByteArrayInputStream in = new ByteArrayInputStream(respBytes);
    ObjectMapper objMapper = new ObjectMapper();
    List<RegisterResponseEntry> sourceSchemasList = null;
    try {
        sourceSchemasList = objMapper.readValue(in, new TypeReference<List<RegisterResponseEntry>>() {
        });
    } catch (JsonMappingException jmex) {
        Assert.fail("ObjectMapper failed unexpectedly");
    }
    assertNotNull("missing source schemas in response", sourceSchemasList);
    assertEquals("expected one source schema", 1, sourceSchemasList.size());
    RegisterResponseEntry rre = sourceSchemasList.get(0);
    assertEquals("unexpected source id", 4002, rre.getId());
    Schema resSchema = Schema.parse(rre.getSchema());
    assertEquals("unexpected source-schema name for source id 4002", "test4.source2_v1", resSchema.getFullName());
    // protocolVersion == 3:  as with v2 above; just do a quick sanity check
    httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/register?sources=4002&" + DatabusHttpHeaders.PROTOCOL_VERSION_PARAM + "=3");
    respHandler = httpClient.sendRequest(_serverAddress, httpRequest);
    assertTrue("failed to get a response", respHandler.awaitResponseUninterruptedly(1, TimeUnit.SECONDS));
    respObj = respHandler.getResponse();
    assertNull("/register v3 returned unexpected error: " + respObj.getHeader(DatabusHttpHeaders.DATABUS_ERROR_CLASS_HEADER), respObj.getHeader(DatabusHttpHeaders.DATABUS_ERROR_CLASS_HEADER));
    LOG.debug("DATABUS_ERROR_CLASS_HEADER = " + respObj.getHeader(DatabusHttpHeaders.DATABUS_ERROR_CLASS_HEADER));
    registerResponseProtocolVersionStr = respObj.getHeader(DatabusHttpHeaders.DBUS_CLIENT_RELAY_PROTOCOL_VERSION_HDR);
    assertNotNull("/register protocol-version response header not present", registerResponseProtocolVersionStr);
    assertEquals("client-relay protocol response version mismatch", "3", registerResponseProtocolVersionStr);
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) SimpleHttpResponseHandler(com.linkedin.databus.core.test.netty.SimpleHttpResponseHandler) Schema(org.apache.avro.Schema) VersionedSchema(com.linkedin.databus2.schemas.VersionedSchema) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) RegisterResponseEntry(com.linkedin.databus2.core.container.request.RegisterResponseEntry) SimpleTestHttpClient(com.linkedin.databus.core.test.netty.SimpleTestHttpClient) TypeReference(org.codehaus.jackson.type.TypeReference) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.testng.annotations.Test)

Example 9 with TypeReference

use of org.codehaus.jackson.type.TypeReference in project exhibitor by soabase.

the class ExplorerResource method getAnalyze.

@GET
@Path("analyze")
@Produces("application/json")
public Response getAnalyze(@QueryParam("request") String json) throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    TypeReference<List<PathAnalysisRequest>> ref = new TypeReference<List<PathAnalysisRequest>>() {
    };
    List<PathAnalysisRequest> paths = mapper.getJsonFactory().createJsonParser(json).readValueAs(ref);
    return analyze(paths);
}
Also used : IdList(com.netflix.exhibitor.core.entities.IdList) List(java.util.List) TypeReference(org.codehaus.jackson.type.TypeReference) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) PathAnalysisRequest(com.netflix.exhibitor.core.entities.PathAnalysisRequest)

Example 10 with TypeReference

use of org.codehaus.jackson.type.TypeReference in project predix-machine-template-adapter-edison by PredixDev.

the class IntelBoardSubscriptionMachineAdapter method activate.

/*
	 * ############################################### # OSGi service lifecycle
	 * management # ###############################################
	 */
/**
	 * OSGi component lifecycle activation method
	 * 
	 * @param ctx
	 *            component context
	 * @throws IOException
	 *             on fail to load/set configuration properties
	 */
@Activate
public void activate(ComponentContext ctx) throws IOException {
    //$NON-NLS-1$
    _logger.info("Starting sample " + ctx.getBundleContext().getBundle().getSymbolicName());
    ObjectMapper mapper = new ObjectMapper();
    File configFile = new File(MACHINE_HOME + File.separator + this.config.getNodeConfigFile());
    this.configNodes = mapper.readValue(configFile, new TypeReference<List<JsonDataNode>>() {
    });
    createNodes(this.configNodes);
    this.adapterInfo = new MachineAdapterInfo(this.config.getAdapterName(), IntelBoardSubscriptionMachineAdapter.SERVICE_PID, this.config.getAdapterDescription(), ctx.getBundleContext().getBundle().getVersion().toString());
    List<String> subs = Arrays.asList(parseDataSubscriptions());
    // Start data subscription and sign up for data updates.
    for (String sub : subs) {
        WorkshopDataSubscription dataSubscription = new WorkshopDataSubscription(this, sub, this.config.getUpdateInterval(), new ArrayList<PDataNode>(this.dataNodes.values()), spillway);
        this.dataSubscriptions.put(dataSubscription.getId(), dataSubscription);
        // Using internal listener, but these subscriptions can be used with
        // Spillway listener also
        dataSubscription.addDataSubscriptionListener(this.dataUpdateHandler);
        new Thread(dataSubscription).start();
    }
}
Also used : PDataNode(com.ge.dspmicro.machinegateway.types.PDataNode) JsonDataNode(com.ge.predix.solsvc.workshop.config.JsonDataNode) WorkshopDataSubscription(com.ge.predix.solsvc.workshop.types.WorkshopDataSubscription) TypeReference(org.codehaus.jackson.type.TypeReference) MachineAdapterInfo(com.ge.dspmicro.machinegateway.api.adapter.MachineAdapterInfo) File(java.io.File) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Activate(aQute.bnd.annotation.component.Activate)

Aggregations

TypeReference (org.codehaus.jackson.type.TypeReference)28 IOException (java.io.IOException)16 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)10 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)10 JsonParseException (org.codehaus.jackson.JsonParseException)9 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 InputStreamReader (java.io.InputStreamReader)4 HashMap (java.util.HashMap)4 HttpResponse (org.apache.http.HttpResponse)4 ClientProtocolException (org.apache.http.client.ClientProtocolException)4 HttpClient (org.apache.http.client.HttpClient)4 HttpGet (org.apache.http.client.methods.HttpGet)3 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)3 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)3 File (java.io.File)2 List (java.util.List)2 Test (org.junit.Test)2 Activate (aQute.bnd.annotation.component.Activate)1 BlogSearchJson (cn.eoe.app.entity.BlogSearchJson)1