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());
}
}
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());
}
}
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;
}
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;
}
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));
}
Aggregations