当前位置: 首页>>代码示例>>Java>>正文


Java ExceptionUtils.getRootCause方法代码示例

本文整理汇总了Java中org.apache.commons.lang3.exception.ExceptionUtils.getRootCause方法的典型用法代码示例。如果您正苦于以下问题:Java ExceptionUtils.getRootCause方法的具体用法?Java ExceptionUtils.getRootCause怎么用?Java ExceptionUtils.getRootCause使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.lang3.exception.ExceptionUtils的用法示例。


在下文中一共展示了ExceptionUtils.getRootCause方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toSyntaxException

import org.apache.commons.lang3.exception.ExceptionUtils; //导入方法依赖的package包/类
/**
 * Convert a JsonParseException into a user-friendly exception
 */
protected static SyntaxErrorException toSyntaxException(JsonParseException e)
{
    Throwable throwable = ExceptionUtils.getRootCause(e);
    String s = "";

    if (throwable != null)
    {
        s = throwable.getMessage();

        if (s.contains("setLenient"))
        {
            s = s.substring(s.indexOf("to accept ") + 10);
        }
    }

    return new SyntaxErrorException("commands.tellraw.jsonException", new Object[] {s});
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:21,代码来源:CommandBase.java

示例2: processCommand

import org.apache.commons.lang3.exception.ExceptionUtils; //导入方法依赖的package包/类
/**
 * Callback when the command is invoked
 */
public void processCommand(ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 2)
    {
        throw new WrongUsageException("commands.tellraw.usage", new Object[0]);
    }
    else
    {
        EntityPlayer entityplayer = getPlayer(sender, args[0]);
        String s = buildString(args, 1);

        try
        {
            IChatComponent ichatcomponent = IChatComponent.Serializer.jsonToComponent(s);
            entityplayer.addChatMessage(ChatComponentProcessor.processComponent(sender, ichatcomponent, entityplayer));
        }
        catch (JsonParseException jsonparseexception)
        {
            Throwable throwable = ExceptionUtils.getRootCause(jsonparseexception);
            throw new SyntaxErrorException("commands.tellraw.jsonException", new Object[] {throwable == null ? "" : throwable.getMessage()});
        }
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:27,代码来源:CommandMessageRaw.java

示例3: retryRequest

import org.apache.commons.lang3.exception.ExceptionUtils; //导入方法依赖的package包/类
@Override
public boolean retryRequest(final IOException exception, final int executionCount, final HttpContext context) {
    final Throwable cause = ExceptionUtils.getRootCause(exception);
    if(cause != null) {
        if(cause instanceof RuntimeException) {
            log.warn(String.format("Cancel retry request with execution count %d for failure %s", executionCount, cause));
            return false;
        }
    }
    final boolean retry = super.retryRequest(exception, executionCount, context);
    if(retry) {
        log.info(String.format("Retry request with failure %s", exception));
    }
    else {
        log.warn(String.format("Cancel retry request with execution count %d for failure %s", executionCount, exception));
    }
    return retry;
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:19,代码来源:ExtendedHttpRequestRetryHandler.java

示例4: toResponse

import org.apache.commons.lang3.exception.ExceptionUtils; //导入方法依赖的package包/类
@Override
public Response toResponse(final DataIntegrityViolationException exception) {
	log.error("DataIntegrityViolationException exception", exception);
	final Throwable root = ExceptionUtils.getRootCause(exception);
	Matcher matcher = PATTERN_FOREIGN_KEY.matcher(StringUtils.trimToEmpty(root.getMessage()));
	final String code;
	if (matcher.find()) {
		// Foreign key
		code = "foreign";
	} else {
		matcher = PATTERN_UNICITY.matcher(root.getMessage());
		if (matcher.find()) {
			// Duplicate entry
			code = "unicity";
		} else {
			// Another SQL error
			code = "unknown";
			matcher = null;
		}
	}

	return toResponse(Status.PRECONDITION_FAILED, newServerError(exception, matcher, code));
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:24,代码来源:DataIntegrityViolationExceptionMapper.java

示例5: canRetry

import org.apache.commons.lang3.exception.ExceptionUtils; //导入方法依赖的package包/类
@Override
public final boolean canRetry(RetryContext context) {
	Throwable rootException = ExceptionUtils.getRootCause(context.getThrowable());
	if (rootException instanceof InterruptedException) {
		return false;
	}
	if ((rootException instanceof NullPointerException) || (rootException instanceof IllegalArgumentException)) {
		return context.getRetryCount() < 2;
	}
	return doCanRetry(context);
}
 
开发者ID:shared-vd,项目名称:tipi-engine,代码行数:12,代码来源:AbstractRetryPolicy.java

示例6: read

import org.apache.commons.lang3.exception.ExceptionUtils; //导入方法依赖的package包/类
@Override
public int read(byte[] b, int off, int len) throws IOException {
  for (int i = off; i < off + len; i++) {
    try {
      b[i] = in.readByte();
    } catch(Exception e) {
      if (ExceptionUtils.getRootCause(e) instanceof EOFException) {
        return i - off;
      } else {
        throw e;
      }
    }
  }
  return len;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:16,代码来源:DataInputInputStream.java

示例7: map

import org.apache.commons.lang3.exception.ExceptionUtils; //导入方法依赖的package包/类
@Override
public BackgroundException map(final OneDriveAPIException failure) {
    if(failure.getResponseCode() > 0) {
        final StringAppender buffer = new StringAppender();
        buffer.append(failure.getMessage());
        buffer.append(failure.getErrorMessage());
        return new HttpResponseExceptionMappingService().map(new HttpResponseException(failure.getResponseCode(), buffer.toString()));
    }
    if(ExceptionUtils.getRootCause(failure) instanceof IOException) {
        return new DefaultIOExceptionMappingService().map((IOException) ExceptionUtils.getRootCause(failure));
    }
    return new InteroperabilityException(failure.getMessage(), failure);
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:14,代码来源:OneDriveExceptionMappingService.java

示例8: map

import org.apache.commons.lang3.exception.ExceptionUtils; //导入方法依赖的package包/类
@Override
public BackgroundException map(final StorageException e) {
    final StringBuilder buffer = new StringBuilder();
    this.append(buffer, e.getMessage());
    if(ExceptionUtils.getRootCause(e) instanceof UnknownHostException) {
        return new NotfoundException(buffer.toString(), e);
    }
    switch(e.getHttpStatusCode()) {
        case 403:
            return new LoginFailureException(buffer.toString(), e);
        case 404:
            return new NotfoundException(buffer.toString(), e);
        case 304:
        case 405:
        case 400:
        case 411:
        case 412:
            return new InteroperabilityException(buffer.toString(), e);
        case 500:
            // InternalError
            // OperationTimedOut
            return new ConnectionTimeoutException(buffer.toString(), e);
        case 503:
            // ServerBusy
            return new RetriableAccessDeniedException(buffer.toString(), e);
    }
    return this.wrap(e, buffer);
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:29,代码来源:AzureExceptionMappingService.java

示例9: testConnectNoServer

import org.apache.commons.lang3.exception.ExceptionUtils; //导入方法依赖的package包/类
@Test(expected = ConnectionRefusedException.class)
public void testConnectNoServer() throws Exception {
    final Host host = new Host(new S3Protocol(), "s3.amazonaws.com", new Credentials(
        System.getProperties().getProperty("s3.key"), System.getProperties().getProperty("s3.secret")
    ));
    final UDTProxyConfigurator proxy = new UDTProxyConfigurator(new S3LocationFeature.S3Region("ap-northeast-1"),
        new LocalhostProxyProvider() {
            @Override
            public Host find(final Location.Name region, final boolean tls) {
                // No server here
                return new Host(new UDTProtocol(), "test-us-east-1-cyberduck", Scheme.udt.getPort());
            }
        }, new DefaultX509TrustManager(), new DefaultX509KeyManager());
    final S3Session tunneled = new S3Session(host);
    proxy.configure(tunneled);
    try {
        assertNotNull(tunneled.open(new DisabledHostKeyCallback(), new DisabledLoginCallback()));
        tunneled.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()
        );
    }
    catch(BackgroundException e) {
        final Throwable cause = ExceptionUtils.getRootCause(e);
        if(cause instanceof ExceptionUDT) {
            throw new UDTExceptionMappingService().map((ExceptionUDT) cause);
        }
        throw e;
    }
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:29,代码来源:UDTProxyConfiguratorTest.java

示例10: map

import org.apache.commons.lang3.exception.ExceptionUtils; //导入方法依赖的package包/类
/**
 * close_notify(0),
 * unexpected_message(10),
 * bad_record_mac(20),
 * decryption_failed_RESERVED(21),
 * record_overflow(22),
 * decompression_failure(30),
 * handshake_failure(40),
 * no_certificate_RESERVED(41),
 * bad_certificate(42),
 * unsupported_certificate(43),
 * certificate_revoked(44),
 * certificate_expired(45),
 * certificate_unknown(46),
 * illegal_parameter(47),
 * unknown_ca(48),
 * access_denied(49),
 * decode_error(50),
 * decrypt_error(51),
 * export_restriction_RESERVED(60),
 * protocol_version(70),
 * insufficient_security(71),
 * internal_error(80),
 * user_canceled(90),
 * no_renegotiation(100),
 * unsupported_extension(110),
 */
@Override
public BackgroundException map(final SSLException failure) {
    final StringBuilder buffer = new StringBuilder();
    for(Throwable cause : ExceptionUtils.getThrowableList(failure)) {
        if(cause instanceof SocketException) {
            // Map Connection has been shutdown: javax.net.ssl.SSLException: java.net.SocketException: Broken pipe
            return new DefaultSocketExceptionMappingService().map((SocketException) cause);
        }
    }
    final String message = failure.getMessage();
    for(Alert alert : Alert.values()) {
        if(StringUtils.contains(message, alert.name())) {
            this.append(buffer, alert.getDescription());
            break;
        }
    }
    if(failure instanceof SSLHandshakeException) {
        if(ExceptionUtils.getRootCause(failure) instanceof CertificateException) {
            log.warn(String.format("Ignore certificate failure %s and drop connection", failure.getMessage()));
            // Server certificate not accepted
            return new ConnectionCanceledException(failure);
        }
        return new SSLNegotiateException(buffer.toString(), failure);
    }
    if(ExceptionUtils.getRootCause(failure) instanceof GeneralSecurityException) {
        this.append(buffer, ExceptionUtils.getRootCause(failure).getMessage());
        return new InteroperabilityException(buffer.toString(), failure);
    }
    this.append(buffer, message);
    return new InteroperabilityException(buffer.toString(), failure);
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:59,代码来源:SSLExceptionMappingService.java

示例11: prepareError

import org.apache.commons.lang3.exception.ExceptionUtils; //导入方法依赖的package包/类
@Override
  public ApmError prepareError (
      final Exception ex,
      final HttpServletRequest request,
      final HttpServletResponse response) {

    final String id = generateUUID ();
    //TODO check if missing data
    final Throwable rootCause = ExceptionUtils.getRootCause (ex);
    final String rootCauseMessage = ExceptionUtils.getRootCauseMessage (ex);

    final String[] rootCauseStackTrace = ExceptionUtils.getRootCauseStackTrace (ex);
    final String culprit = rootCauseStackTrace.length > 0 ?
        rootCauseStackTrace[0] : null;

    final List<ApmStacktrace> stackTrace = new ArrayList<> ();

    for (final StackTraceElement traceElement : ex.getStackTrace ()) {
      final ApmStacktrace trace = new ApmStacktrace ()
//          .withLineno (Integer.valueOf (traceElement.getLineNumber ()).doubleValue ())
          .withAdditionalProperty ("lineno", traceElement.getLineNumber ())
          .withFilename (traceElement.getFileName ())
          .withFunction (traceElement.getMethodName ())
          .withModule (traceElement.getClassName ());
      stackTrace.add (trace);
    }

    return new ApmError ()
        .withId (id)
//        .withTimestamp (LocalDateTime.now ()) //TODO check why it isn't automatically converted to string
        .withAdditionalProperty ("timestamp", getSimpleDateFormat ().format (new Date ()))
        .withCulprit (culprit)
        .withContext (toApmContext (request, response))
        .withException (new ApmException ().withStacktrace (stackTrace).withMessage (rootCauseMessage))
        //.withLog (new ApmLog ().wi)//TODO add log
        ;
  }
 
开发者ID:davidecavestro,项目名称:elastic-apm-java-agent-poc,代码行数:38,代码来源:ApmAgent.java

示例12: toResponse

import org.apache.commons.lang3.exception.ExceptionUtils; //导入方法依赖的package包/类
@Override
public Response toResponse(final TransactionSystemException ex) {
	if (ExceptionUtils.getRootCause(ex) instanceof ConstraintViolationException) {
		// Set the content type, and JSR-303 error into JSON format.
		return toResponse(Status.BAD_REQUEST, new ValidationJsonException((ConstraintViolationException) ExceptionUtils.getRootCause(ex)));
	}
	
	// Not yet managed exception
	log.error("Technical exception", ex);
	return toResponse(Status.INTERNAL_SERVER_ERROR, "technical", ex);
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:12,代码来源:TransactionSystemExceptionMapper.java

示例13: processCommand

import org.apache.commons.lang3.exception.ExceptionUtils; //导入方法依赖的package包/类
/**
 * Callback when the command is invoked
 */
public void processCommand(ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 2)
    {
        throw new WrongUsageException("commands.title.usage", new Object[0]);
    }
    else
    {
        if (args.length < 3)
        {
            if ("title".equals(args[1]) || "subtitle".equals(args[1]))
            {
                throw new WrongUsageException("commands.title.usage.title", new Object[0]);
            }

            if ("times".equals(args[1]))
            {
                throw new WrongUsageException("commands.title.usage.times", new Object[0]);
            }
        }

        EntityPlayerMP entityplayermp = getPlayer(sender, args[0]);
        S45PacketTitle.Type s45packettitle$type = S45PacketTitle.Type.byName(args[1]);

        if (s45packettitle$type != S45PacketTitle.Type.CLEAR && s45packettitle$type != S45PacketTitle.Type.RESET)
        {
            if (s45packettitle$type == S45PacketTitle.Type.TIMES)
            {
                if (args.length != 5)
                {
                    throw new WrongUsageException("commands.title.usage", new Object[0]);
                }
                else
                {
                    int i = parseInt(args[2]);
                    int j = parseInt(args[3]);
                    int k = parseInt(args[4]);
                    S45PacketTitle s45packettitle2 = new S45PacketTitle(i, j, k);
                    entityplayermp.playerNetServerHandler.sendPacket(s45packettitle2);
                    notifyOperators(sender, this, "commands.title.success", new Object[0]);
                }
            }
            else if (args.length < 3)
            {
                throw new WrongUsageException("commands.title.usage", new Object[0]);
            }
            else
            {
                String s = buildString(args, 2);
                IChatComponent ichatcomponent;

                try
                {
                    ichatcomponent = IChatComponent.Serializer.jsonToComponent(s);
                }
                catch (JsonParseException jsonparseexception)
                {
                    Throwable throwable = ExceptionUtils.getRootCause(jsonparseexception);
                    throw new SyntaxErrorException("commands.tellraw.jsonException", new Object[] {throwable == null ? "" : throwable.getMessage()});
                }

                S45PacketTitle s45packettitle1 = new S45PacketTitle(s45packettitle$type, ChatComponentProcessor.processComponent(sender, ichatcomponent, entityplayermp));
                entityplayermp.playerNetServerHandler.sendPacket(s45packettitle1);
                notifyOperators(sender, this, "commands.title.success", new Object[0]);
            }
        }
        else if (args.length != 2)
        {
            throw new WrongUsageException("commands.title.usage", new Object[0]);
        }
        else
        {
            S45PacketTitle s45packettitle = new S45PacketTitle(s45packettitle$type, (IChatComponent)null);
            entityplayermp.playerNetServerHandler.sendPacket(s45packettitle);
            notifyOperators(sender, this, "commands.title.success", new Object[0]);
        }
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:82,代码来源:CommandTitle.java

示例14: exactlyOnceReadWriteSimulator

import org.apache.commons.lang3.exception.ExceptionUtils; //导入方法依赖的package包/类
public void exactlyOnceReadWriteSimulator(final StreamId inStreamId, final StreamId outStreamId,
										  final StreamUtils streamUtils, int numElements,
										  boolean generateData, boolean throttled) throws Exception {

	final int blockAtNum = numElements/2;
	final int sleepPerElement = 1;

	final int checkpointInterval = 100;
	final int taskFailureRestartAttempts = 3;
	final long delayBetweenRestartAttempts = 0L;
	final long startTime = 0L;
	final String jobName = "exactlyOnceReadWriteSimulator";

	//30 sec timeout for all
	final long txTimeout = 30 * 1000;
	final long txTimeoutMax = 30 * 1000;
	final long txTimeoutGracePeriod = 30 * 1000;

	EventStreamWriter<Integer> eventWriter;
	ThrottledIntegerWriter producer = null;

	final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
	env.setParallelism(parallelism);
	env.enableCheckpointing(checkpointInterval);
	env.setRestartStrategy(RestartStrategies.fixedDelayRestart(taskFailureRestartAttempts, delayBetweenRestartAttempts));

	// we currently need this to work around the case where tasks are started too late, a checkpoint was already triggered, and some tasks
	// never see the checkpoint event
	env.getCheckpointConfig().setCheckpointTimeout(2000);

	// the Pravega reader
	final FlinkPravegaReader<Integer> pravegaSource = streamUtils.getFlinkPravegaParams().newReader(inStreamId, startTime, Integer.class);

	// Pravega Writer
	FlinkPravegaWriter<Integer> pravegaExactlyOnceWriter = streamUtils.newExactlyOnceWriter(outStreamId,
			Integer.class, new IdentityRouter<>());

	DataStream<Integer> stream =
	env.addSource(pravegaSource)
			.map(new FailingIdentityMapper<>(numElements * 2 / 3))
			.setParallelism(1)

			.map(new NotifyingMapper<>())
			.setParallelism(1);

			stream.addSink(pravegaExactlyOnceWriter)
			.setParallelism(1);

			stream.addSink(new IntSequenceExactlyOnceValidator(numElements))
			.setParallelism(1);

	if (generateData) {
		eventWriter = streamUtils.createWriter(inStreamId.getName(), inStreamId.getScope());
		producer = new ThrottledIntegerWriter(eventWriter, numElements, blockAtNum, sleepPerElement, false);
		producer.start();
		if (throttled) {
			ThrottledIntegerWriter finalProducer = producer;
			TO_CALL_ON_COMPLETION.set(() -> finalProducer.unThrottle());
		}
	}

	try {
		env.execute(jobName);
	} catch (Exception e) {
		if (!(ExceptionUtils.getRootCause(e) instanceof IntSequenceExactlyOnceValidator.SuccessException)) {
			throw e;
		}
	}

	if (generateData && producer != null) producer.sync();

}
 
开发者ID:pravega,项目名称:nautilus-samples,代码行数:73,代码来源:EventCounterApp.java


注:本文中的org.apache.commons.lang3.exception.ExceptionUtils.getRootCause方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。