javax.naming.SizeLimitExceededException源码实例Demo

类javax.naming.SizeLimitExceededException源码实例Demo

下面列出了javax.naming.SizeLimitExceededException 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: we-cmdb   文件: UIFileManagementController.java
@RolesAllowed({ MENU_ADMIN_CMDB_MODEL_MANAGEMENT })
@PostMapping("/files/upload")
@ResponseBody
public Object uploadFile(@RequestParam(value = "file", required = false) MultipartFile file) throws SizeLimitExceededException {
    if (file.getSize() > applicationProperties.getMaxFileSize().toBytes()) {
        String errorMessage = String.format("Upload file failed due to file size (%s bytes) exceeded limitation (%s KB).", file.getSize(), applicationProperties.getMaxFileSize().toKilobytes());
        log.warn(errorMessage);
        throw new CmdbException(errorMessage);
    }

    try {
        String contentType = file.getContentType();
        return imageService.upload(file.getName(), contentType, file.getBytes());
    } catch (IOException e) {
        String msg = String.format("Failed to upload image file. (fileName:%s)", file.getName());
        log.warn(msg, e);
        throw new CmdbException(msg);
    }
}
 
源代码2 项目: minecraft-world-downloader   文件: DataProvider.java
/**
 * Provides the object with all the bytes from the packet, allowing them to be read into the correct data types
 * easily. This method will also decompress the packet, as this is the first time we have the full packet
 * available, which is what we need for valid decompression.
 * @param size the packet size
 * @return the data parser for the decompressed packet
 */
public DataTypeProvider withSize(int size) throws SizeLimitExceededException {
    byte[] compressed = reader.readByteArray(size);

    byte[] fullPacket;
    if (compressionManager.isCompressionEnabled()) {
        final int[] compressionPos = {0};
        int uncompressedSize = DataReader.readVarInt(
            () -> compressionPos[0] < compressed.length,
            () -> compressed[compressionPos[0]++]
        );

        // packets over this size will crash the game client, so it may help to reject them here
        if (uncompressedSize > MAX_SIZE) {
            throw new SizeLimitExceededException("WARNING: discarding packet over maximum size (size: " + uncompressedSize + ")");
        }

        fullPacket = compressionManager.decompressPacket(compressed, compressionPos[0], uncompressedSize);
    } else {
        fullPacket = compressed;
    }

    return DataTypeProvider.ofPacket(fullPacket);
}
 
/**
 * Build the given packet, will generate a type provider to parse the contents of the packages to real values. Will
 * determine if the packet is to be forwarded using its return value.
 * @param size the size of the packet to build
 * @return true if the packet should be forwarded, otherwise false.
 */
public final boolean build(int size) {
    DataTypeProvider typeProvider;
    try {
        typeProvider = reader.withSize(size);
    } catch (SizeLimitExceededException ex) {
        System.out.println(ex.getMessage());
        return false;
    }

    int packetID = typeProvider.readVarInt();

    String packetType = protocol.get(packetID, isClientBound());
    PacketOperator operator = getOperators().getOrDefault(packetType, null);
    if (operator == null) {
        return true;
    }

    return operator.apply(typeProvider);
}
 
源代码4 项目: trex-stateless-gui   文件: RPCMethods.java
/**
 *
 * @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 (InvalidRPCResponseException | IncorrectRPCMethodException | NullPointerException | IOException | SizeLimitExceededException ex) {
        throw new PortAcquireException(ex.getMessage());
    }

}
 
源代码5 项目: trex-stateless-gui   文件: RPCMethods.java
/**
 *
 * @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 | SizeLimitExceededException ex) {
        throw new TrafficException(ex.toString());
    }

}
 
源代码6 项目: trex-stateless-gui   文件: RPCMethods.java
/**
 *
 * @param portID
 * @param force
 * @param type
 * @param multiplierValue
 * @param duration
 * @return multiplier value from the server
 * @throws com.exalttech.trex.remote.exceptions.TrafficException
 */
public double startTraffic(int portID, boolean force, String type, double multiplierValue, double duration) throws TrafficException {
    LogsController.getInstance().appendText(LogType.INFO, "Starting Traffic on Port " + portID);
    String handler = (String) connectionHandler.get(portID);
    Multiplier trafficMultiplier = new Multiplier(type, multiplierValue);
    TrafficParams trafficParams = new TrafficParams(force, handler, trafficMultiplier, portID);
    trafficParams.setDuration(duration);
    try {
        String updateTrafficResponse = serverConnectionManager.sendRPCRequest(Constants.START_TRAFFIC_METHOD, trafficParams);
        LOG.trace("Start Traffic response:" + updateTrafficResponse);
        return getMultiplierValue(updateTrafficResponse);

    } catch (JsonProcessingException | UnsupportedEncodingException | InvalidRPCResponseException | IncorrectRPCMethodException | NullPointerException | SizeLimitExceededException ex) {
        throw new TrafficException(ex.toString());
    }
}
 
源代码7 项目: trex-stateless-gui   文件: ConnectionManager.java
String sendAddStreamRequest(Profile[] profilesList) throws JsonProcessingException, UnsupportedEncodingException, IncorrectRPCMethodException, InvalidRPCResponseException, SizeLimitExceededException {
    List<String> addStreamCommandList = new ArrayList<>();
    ObjectMapper mapper = new ObjectMapper();
    RPCRequest rpcRequest = new RPCRequest();
    String jsonRequestString;
    for (Profile aProfilesList : profilesList) {

        rpcRequest.setId(Util.getRandomID(Constants.RPC_REQUEST_ID_LENGTH));
        rpcRequest.setMethod(Constants.ADD_STREAM_METHOD);
        rpcRequest.setParams(aProfilesList);

        jsonRequestString = mapper.writeValueAsString(rpcRequest);
        jsonRequestString = Util.tuneJSONParams(jsonRequestString, aProfilesList, apiH);
        addStreamCommandList.add(jsonRequestString);

    }

    List<List<String>> streamGroups = packMultipleRequestsIntoGroups(addStreamCommandList);

    StringBuilder response = new StringBuilder();
    for (List<String> group : streamGroups) {
        response.append(sendStreamGroup(group)).append("\n");
    }
    return response.toString();
}
 
源代码8 项目: trex-stateless-gui   文件: ConnectionManager.java
public String sendPortStatusRequest(List<Port> portList) throws JsonProcessingException, UnsupportedEncodingException, IncorrectRPCMethodException, InvalidRPCResponseException, SizeLimitExceededException {
    List<String> addStreamCommandList = new ArrayList<>();
    ObjectMapper mapper = new ObjectMapper();
    RPCRequest rpcRequest = new RPCRequest();
    String jsonRequestString;
    for (Port port : portList) {
        rpcRequest.setId(Util.getRandomID(Constants.RPC_REQUEST_ID_LENGTH));
        rpcRequest.setMethod(Constants.PORT_STATUS_METHOD);
        rpcRequest.setParams(new GetPortStatusParams(port.getIndex(), false));
        jsonRequestString = mapper.writeValueAsString(rpcRequest);
        jsonRequestString = Util.tuneJSONParams(jsonRequestString, port.getPortParam(), apiH);
        addStreamCommandList.add(jsonRequestString);

    }
    String requestCommand = Util.toPrettyFormat(addStreamCommandList.toString());
    LOG.info("Send port status request \n " + requestCommand);
    byte[] serverResponse = getServerRPCResponse(addStreamCommandList.toString());

    return handleResponse(serverResponse, false);
}
 
源代码9 项目: trex-stateless-gui   文件: ConnectionManager.java
public String sendPortXStatsNamesRequest(Port port) throws JsonProcessingException, UnsupportedEncodingException, IncorrectRPCMethodException, InvalidRPCResponseException, SizeLimitExceededException {
    List<String> addStreamCommandList = new ArrayList<>();
    ObjectMapper mapper = new ObjectMapper();
    RPCRequest rpcRequest = new RPCRequest();
    String jsonRequestString;

    rpcRequest.setId(Util.getRandomID(Constants.RPC_REQUEST_ID_LENGTH));
    rpcRequest.setMethod(Constants.PORT_XSTATS_NAMES_METHOD);
    rpcRequest.setParams(port.getPortParam());

    jsonRequestString = mapper.writeValueAsString(rpcRequest);
    jsonRequestString = Util.tuneJSONParams(jsonRequestString, port.getPortParam(), apiH);
    addStreamCommandList.add(jsonRequestString);

    String requestCommand = Util.toPrettyFormat(addStreamCommandList.toString());
    LOG.info("Send port xstats_names request \n " + requestCommand);

    byte[] serverResponse = getServerRPCResponse(addStreamCommandList.toString());

    return handleResponse(serverResponse, false);
}
 
源代码10 项目: trex-stateless-gui   文件: ConnectionManager.java
public String sendPortXStatsValuesRequest(Port port) throws JsonProcessingException, UnsupportedEncodingException, IncorrectRPCMethodException, InvalidRPCResponseException, SizeLimitExceededException {
    List<String> addStreamCommandList = new ArrayList<>();
    ObjectMapper mapper = new ObjectMapper();
    RPCRequest rpcRequest = new RPCRequest();
    String jsonRequestString;

    rpcRequest.setId(Util.getRandomID(Constants.RPC_REQUEST_ID_LENGTH));
    rpcRequest.setMethod(Constants.PORT_XSTATS_VALUES_METHOD);
    rpcRequest.setParams(port.getPortParam());

    jsonRequestString = mapper.writeValueAsString(rpcRequest);
    jsonRequestString = Util.tuneJSONParams(jsonRequestString, port.getPortParam(), apiH);
    addStreamCommandList.add(jsonRequestString);

    String requestCommand = Util.toPrettyFormat(addStreamCommandList.toString());
    LOG.info("Send port xstats_values request \n " + requestCommand);

    byte[] serverResponse = getServerRPCResponse(addStreamCommandList.toString());

    return handleResponse(serverResponse, false);
}
 
源代码11 项目: trex-stateless-gui   文件: RPCMethods.java
private boolean buildCommonRPCRequest(int portID, String handler, String method) {
    CommonParams params = new CommonParams(portID, handler);
    try {
        serverConnectionManager.sendRPCRequest(method, params);
        return true;
    } catch (JsonProcessingException | UnsupportedEncodingException | InvalidRPCResponseException | IncorrectRPCMethodException | SizeLimitExceededException ex) {
        return false;
    }

}
 
源代码12 项目: trex-stateless-gui   文件: RPCMethods.java
/**
 *
 * @return true if the ping was successful false otherwise
 */
public Boolean pingRPCServer() {
    LOG.trace("Pinging RPC Server");
    try {
        serverConnectionManager.sendRPCRequest(Constants.PING_METHOD, new PingParams());
        LOG.trace("Ping OK");
        return true;
    } catch (JsonProcessingException | UnsupportedEncodingException | InvalidRPCResponseException | IncorrectRPCMethodException | NullPointerException | SizeLimitExceededException ex) {
        LOG.error("Failed to ping RPC Server", ex);
        return false;
    }

}
 
源代码13 项目: trex-stateless-gui   文件: ConnectionManager.java
String sendRPCRequest(String method, Params params) throws JsonProcessingException, UnsupportedEncodingException, InvalidRPCResponseException, IncorrectRPCMethodException, SizeLimitExceededException {
    RPCRequest rpcRequest = new RPCRequest();
    ObjectMapper mapper = new ObjectMapper();
    rpcRequest.setId(Util.getRandomID(Constants.RPC_REQUEST_ID_LENGTH));
    rpcRequest.setMethod(method);
    if (params != null) {
        rpcRequest.setParams(params);
    }
    String jsonRequestString = mapper.writeValueAsString(rpcRequest);
    jsonRequestString = Util.tuneJSONParams(jsonRequestString, params, apiH);
    LOG.trace("Sending request \n" + Util.toPrettyFormat(jsonRequestString));
    logProperty.setValue("Sending request " + Util.toPrettyFormat(jsonRequestString));
    byte[] serverResponse = getServerRPCResponse(jsonRequestString);
    return handleResponse(serverResponse, true);
}
 
源代码14 项目: trex-stateless-gui   文件: ConnectionManager.java
private String sendStreamGroup(List<String> addStreamCommandList) throws SizeLimitExceededException, UnsupportedEncodingException, IncorrectRPCMethodException, InvalidRPCResponseException {
    String requestCommand = Util.toPrettyFormat(addStreamCommandList.toString());
    LOG.info(requestCommand);
    logProperty.setValue("Sending request " + requestCommand);
    byte[] serverResponse = getServerRPCResponse(addStreamCommandList.toString());
    return handleResponse(serverResponse, false);
}
 
源代码15 项目: beam   文件: PubsubIO.java
@ProcessElement
public void processElement(ProcessContext c) throws IOException, SizeLimitExceededException {
  byte[] payload;
  PubsubMessage message = getFormatFn().apply(c.element());
  payload = message.getPayload();
  Map<String, String> attributes = message.getAttributeMap();

  if (payload.length > maxPublishBatchByteSize) {
    String msg =
        String.format(
            "Pub/Sub message size (%d) exceeded maximum batch size (%d)",
            payload.length, maxPublishBatchByteSize);
    throw new SizeLimitExceededException(msg);
  }

  // Checking before adding the message stops us from violating the max bytes
  if (((currentOutputBytes + payload.length) >= maxPublishBatchByteSize)
      || (output.size() >= maxPublishBatchSize)) {
    publish();
  }

  // NOTE: The record id is always null.
  output.add(
      OutgoingMessage.of(
          com.google.pubsub.v1.PubsubMessage.newBuilder()
              .setData(ByteString.copyFrom(payload))
              .putAllAttributes(attributes)
              .build(),
          c.timestamp().getMillis(),
          null));
  currentOutputBytes += payload.length;
}
 
源代码16 项目: trex-stateless-gui   文件: ConnectionManager.java
private byte[] getServerRPCResponse(String request) throws SizeLimitExceededException {


        byte[] finalRequest = this.dataCompressor.compressStringToBytes(request);

        if (finalRequest.length >= MAX_REQUEST_SIZE) {
            throw new SizeLimitExceededException(MessageFormat.format("Size of request is too large (limit is {0} bytes)", MAX_REQUEST_SIZE));
        }

        byte[] serverResponse;
        boolean success;

        synchronized (sendRequestMonitor) {
            if (connectionTimeout.get()) {
                return null;
            }
            try {
                success = requester.send(finalRequest);
            } catch (ZMQException e) {
                if (e.getErrorCode() == ZError.EFSM) {
                    success = resend(finalRequest);
                } else {
                    throw e;
                }
            }
            if (success) {
                serverResponse = requester.recv(0);
                if (serverResponse == null) {
                    if (requester.base().errno() == ZError.EAGAIN) {
                        int retries = timeout / INTERNAL_TIMEOUT;
                        while (serverResponse == null && retries > 0) {
                            if (connectionTimeout.get()) {
                                return null;
                            }

                            retries--;
                            serverResponse = requester.recv(0);
                        }
                        if (retries == 0 && resend(finalRequest)) {
                            serverResponse = requester.recv(0);
                        }
                    } else {
                        LOG.error("Error sending request");
                    }
                }
            } else {
                LOG.error("Error sending request");
                return null;
            }
        }

        return serverResponse == null
            ? null
            : dataCompressor.decompressBytesToString(serverResponse).getBytes();
    }
 
源代码17 项目: ldapchai   文件: OpenLDAPModifyPasswordRequest.java
/**
 * Creates a new <code>OpenLDAPUser</code> instance.
 *
 * @param dn       the dn whose password is to change
 * @param password the new password
 * @param chaiConfiguration appropriate chaiConfiguration
 * @throws NullPointerException                    if dn or password is null
 * @throws javax.naming.SizeLimitExceededException when the dn or password
 *                                                 is too long
 */
public OpenLDAPModifyPasswordRequest( final String dn, final String password, final ChaiConfiguration chaiConfiguration )
        throws NullPointerException, SizeLimitExceededException
{
    this.chaiConfiguration = chaiConfiguration;

    if ( dn == null )
    {
        throw new NullPointerException( "dn cannot be null" );
    }

    if ( password == null )
    {
        throw new NullPointerException( "password cannot be null" );
    }

    final int dnlen = dn.length();
    final int passlen = password.length();
    final int totallen = 4 + dnlen + passlen;

    if ( dnlen <= 0 )
    {
        throw new SizeLimitExceededException( "dn cannot be 0 length" );
    }

    if ( dnlen > 0xFF )
    {
        throw new SizeLimitExceededException( "dn cannot be larger then 255 characters" );
    }

    if ( passlen <= 0 )
    {
        throw new SizeLimitExceededException( "password cannot be 0 length" );
    }

    if ( passlen > 0xFF )
    {
        throw new SizeLimitExceededException( "password cannot be larger then 255 characters" );
    }

    if ( totallen > 0xFF )
    {
        throw new SizeLimitExceededException( "the length of the dn + the lengh of the password cannot"
                        + " exceed 251 characters" );
    }

    modifyDn = dn;
    modifyPassword = password;
}
 
源代码评论
动弹
沙发等你来抢
 类所在包
 类方法
 同包方法