Search in sources :

Example 46 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project trex-stateless-gui by cisco-system-traffic-generator.

the class RPCMethods method acquireServerPort.

/**
     *
     * @param portID the port ID
     * @param force if force is set to true then the port will be acquired even
     * though it is owned by other
     * @return connectionHandler in case of success
     * @throws PortAcquireException
     */
public String acquireServerPort(int portID, boolean force) throws PortAcquireException {
    LOG.trace("Acquiring port [" + portID + "]");
    LogsController.getInstance().appendText(LogType.INFO, "Acquiring port [" + portID + "]");
    AcquireParams acquireParams = new AcquireParams();
    acquireParams.setPortId(portID);
    acquireParams.setForce(force);
    acquireParams.setUser(serverConnectionManager.getClientName());
    acquireParams.setSessionId(Util.getRandomID());
    ObjectMapper mapper = new ObjectMapper();
    try {
        String response = serverConnectionManager.sendRPCRequest(Constants.ACQUIRE_METHOD, acquireParams);
        response = Util.removeFirstBrackets(response);
        RPCResponse rpcResult = mapper.readValue(response, RPCResponse.class);
        String handler = mapper.readValue(rpcResult.getResult(), String.class);
        connectionHandler.put(portID, handler);
        serverConnectionManager.propagatePortHandler(portID, handler);
        return handler;
    } catch (JsonProcessingException | UnsupportedEncodingException | InvalidRPCResponseException | IncorrectRPCMethodException | NullPointerException ex) {
        throw new PortAcquireException(ex.getMessage());
    } catch (IOException ex) {
        throw new PortAcquireException(ex.getMessage());
    }
}
Also used : PortAcquireException(com.exalttech.trex.remote.exceptions.PortAcquireException) RPCResponse(com.cisco.trex.stateless.model.RPCResponse) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) IncorrectRPCMethodException(com.exalttech.trex.remote.exceptions.IncorrectRPCMethodException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) InvalidRPCResponseException(com.exalttech.trex.remote.exceptions.InvalidRPCResponseException)

Example 47 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project trex-stateless-gui by cisco-system-traffic-generator.

the class RPCMethods method updateTraffic.

/**
     *
     * @param portID
     * @param force
     * @param type
     * @param multiplierValue
     * @return multiplier value from the server
     * @throws com.exalttech.trex.remote.exceptions.TrafficException
     */
public double updateTraffic(int portID, boolean force, String type, double multiplierValue) throws TrafficException {
    LOG.trace("Updating Traffic on port(s) [" + portID + "], setting to " + multiplierValue + " pps");
    LogsController.getInstance().appendText(LogType.INFO, "Updating Traffic on port(s) [" + portID + "], setting to " + multiplierValue + " pps");
    Multiplier trafficMultiplier = new Multiplier(type, multiplierValue);
    String handler = (String) connectionHandler.get(portID);
    TrafficParams trafficParams = new TrafficParams(force, handler, trafficMultiplier, portID);
    try {
        String updateTrafficResponse = serverConnectionManager.sendRPCRequest(Constants.UPDATE_TRAFFIC_METHOD, trafficParams);
        return getMultiplierValue(updateTrafficResponse);
    } catch (JsonProcessingException | UnsupportedEncodingException | InvalidRPCResponseException | IncorrectRPCMethodException | NullPointerException ex) {
        throw new TrafficException(ex.toString());
    }
}
Also used : Multiplier(com.exalttech.trex.remote.models.multiplier.Multiplier) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IncorrectRPCMethodException(com.exalttech.trex.remote.exceptions.IncorrectRPCMethodException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) InvalidRPCResponseException(com.exalttech.trex.remote.exceptions.InvalidRPCResponseException) TrafficException(com.exalttech.trex.remote.exceptions.TrafficException)

Example 48 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project dal by ctripcorp.

the class DatabaseResource method getOneDB.

@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("getOneDB")
public Status getOneDB(@Context HttpServletRequest request, @FormParam("allinonename") String allinonename) {
    String userNo = RequestUtil.getUserNo(request);
    Status status = Status.OK;
    DalGroupDBDao allDbDao = SpringBeanGetter.getDaoOfDalGroupDB();
    DalGroupDB groupDb = allDbDao.getGroupDBByDbName(allinonename);
    LoginUser user = SpringBeanGetter.getDaoOfLoginUser().getUserByNo(userNo);
    if (!validatePermision(user.getId(), groupDb.getDal_group_id())) {
        status = Status.ERROR;
        status.setInfo("你没有当前DataBase的操作权限.");
        return status;
    }
    try {
        if (DatabaseType.MySQL.getValue().equals(groupDb.getDb_providerName())) {
            groupDb.setDb_providerName(DatabaseType.MySQL.toString());
        } else if (DatabaseType.SQLServer.getValue().equals(groupDb.getDb_providerName())) {
            groupDb.setDb_providerName(DatabaseType.SQLServer.toString());
        } else {
            groupDb.setDb_providerName("no");
        }
        status.setInfo(mapper.writeValueAsString(groupDb));
    } catch (JsonProcessingException e) {
        status = Status.ERROR;
        status.setInfo(e.getMessage());
        return status;
    }
    return Status.OK;
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status) DalGroupDBDao(com.ctrip.platform.dal.daogen.dao.DalGroupDBDao) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 49 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project dal by ctripcorp.

the class GenTaskBySqlBuilderResource method getMockValue.

@POST
@Path("getMockValue")
public Status getMockValue(@FormParam("db_name") String set_name, @FormParam("table_name") String table_name, @FormParam("crud_type") String crud_type, @FormParam("fields") String fields, @FormParam("condition") String condition, @FormParam("pagination") boolean pagination) throws Exception {
    Status status = Status.OK;
    int[] sqlTypes = getSqlTypes(set_name, table_name, crud_type, fields, condition);
    Object[] values = SQLValidation.mockStringValues(sqlTypes);
    try {
        status.setInfo(mapper.writeValueAsString(values));
    } catch (JsonProcessingException e) {
        status = Status.ERROR;
        status.setInfo("获取mock value异常.");
    }
    return status;
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 50 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project dropbox-sdk-java by dropbox.

the class DbxRawClientV2 method rpcStyle.

public <ArgT, ResT, ErrT> ResT rpcStyle(final String host, final String path, final ArgT arg, final boolean noAuth, final StoneSerializer<ArgT> argSerializer, final StoneSerializer<ResT> responseSerializer, final StoneSerializer<ErrT> errorSerializer) throws DbxWrappedException, DbxException {
    final byte[] body = writeAsBytes(argSerializer, arg);
    final List<HttpRequestor.Header> headers = new ArrayList<HttpRequestor.Header>();
    if (!noAuth) {
        addAuthHeaders(headers);
    }
    if (!this.host.getNotify().equals(host)) {
        // TODO(krieb): fix this ugliness
        addUserLocaleHeader(headers, requestConfig);
    }
    headers.add(new HttpRequestor.Header("Content-Type", "application/json; charset=utf-8"));
    return executeRetriable(requestConfig.getMaxRetries(), new RetriableExecution<ResT>() {

        private String userIdAnon;

        @Override
        public ResT execute() throws DbxWrappedException, DbxException {
            HttpRequestor.Response response = DbxRequestUtil.startPostRaw(requestConfig, USER_AGENT_ID, host, path, body, headers);
            try {
                switch(response.getStatusCode()) {
                    case 200:
                        return responseSerializer.deserialize(response.getBody());
                    case 409:
                        throw DbxWrappedException.fromResponse(errorSerializer, response, userIdAnon);
                    default:
                        throw DbxRequestUtil.unexpectedStatus(response, userIdAnon);
                }
            } catch (JsonProcessingException ex) {
                String requestId = DbxRequestUtil.getRequestId(response);
                throw new BadResponseException(requestId, "Bad JSON: " + ex.getMessage(), ex);
            } catch (IOException ex) {
                throw new NetworkIOException(ex);
            }
        }

        private RetriableExecution<ResT> init(String userId) {
            this.userIdAnon = userId;
            return this;
        }
    }.init(this.userId));
}
Also used : HttpRequestor(com.dropbox.core.http.HttpRequestor) BadResponseException(com.dropbox.core.BadResponseException) ArrayList(java.util.ArrayList) NetworkIOException(com.dropbox.core.NetworkIOException) IOException(java.io.IOException) NetworkIOException(com.dropbox.core.NetworkIOException) DbxRequestUtil.addUserLocaleHeader(com.dropbox.core.DbxRequestUtil.addUserLocaleHeader) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)117 IOException (java.io.IOException)28 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)26 ArrayList (java.util.ArrayList)14 HashMap (java.util.HashMap)11 Test (org.junit.Test)11 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 InputStream (java.io.InputStream)7 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 ErrorResponseBody (com.nike.riposte.server.error.handler.ErrorResponseBody)6 HttpProcessingState (com.nike.riposte.server.http.HttpProcessingState)6 OutputStreamWriter (java.io.OutputStreamWriter)6 Map (java.util.Map)6 Status (com.ctrip.platform.dal.daogen.domain.Status)5 TaskDTO (com.linkedin.thirdeye.datalayer.dto.TaskDTO)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 List (java.util.List)4 IncorrectRPCMethodException (com.exalttech.trex.remote.exceptions.IncorrectRPCMethodException)3 InvalidRPCResponseException (com.exalttech.trex.remote.exceptions.InvalidRPCResponseException)3