Search in sources :

Example 36 with JeesuiteBaseException

use of com.mendmix.common.JeesuiteBaseException in project jeesuite-libs by vakinge.

the class ReactiveGlobalExceptionHandler method exceptionHandler.

@ExceptionHandler(Exception.class)
@ResponseBody
public WrapperResponse<?> exceptionHandler(ServerHttpRequest request, ServerHttpResponse response, Exception e) {
    WrapperResponse<?> resp = new WrapperResponse<>();
    e = (Exception) getActualThrowable(e);
    if (e instanceof JeesuiteBaseException) {
        JeesuiteBaseException e1 = (JeesuiteBaseException) e;
        resp.setCode(e1.getCode());
        resp.setMsg(e1.getMessage());
    } else if (e instanceof MethodArgumentNotValidException) {
        resp.setCode(400);
        List<ObjectError> errors = ((MethodArgumentNotValidException) e).getBindingResult().getAllErrors();
        String fieldName;
        StringBuilder fieldNames = new StringBuilder();
        for (ObjectError error : errors) {
            fieldName = parseFieldName(error);
            fieldNames.append(fieldName).append(",");
        }
        resp.setBizCode("error.parameter.notValid");
        resp.setMsg("参数错误[" + fieldNames.toString() + "]");
    } else {
        Throwable parent = e.getCause();
        if (parent instanceof IllegalStateException) {
            resp.setCode(501);
            resp.setMsg(e.getMessage());
        } else {
            resp.setCode(500);
            resp.setMsg("系统繁忙");
        }
    }
    // 
    ActionLogCollector.onResponseEnd(response.getRawStatusCode(), e);
    return resp;
}
Also used : WrapperResponse(com.mendmix.common.model.WrapperResponse) ObjectError(org.springframework.validation.ObjectError) JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) List(java.util.List) MethodArgumentNotValidException(org.springframework.web.bind.MethodArgumentNotValidException) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 37 with JeesuiteBaseException

use of com.mendmix.common.JeesuiteBaseException in project jeesuite-libs by vakinge.

the class QiniuProvider method getObjectInputStream.

@Override
public InputStream getObjectInputStream(String bucketName, String fileKey) {
    bucketName = buildBucketName(bucketName);
    String downloadUrl = getDownloadUrl(bucketName, fileKey, 600);
    Request request = new Request.Builder().url(downloadUrl).build();
    okhttp3.Response re = null;
    try {
        re = httpClient.newCall(request).execute();
        if (re.isSuccessful()) {
            return re.body().byteStream();
        }
        throw new JeesuiteBaseException(re.code(), re.message());
    } catch (IOException e) {
        throw new JeesuiteBaseException(e.getMessage());
    }
}
Also used : JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) Request(okhttp3.Request) IOException(java.io.IOException)

Example 38 with JeesuiteBaseException

use of com.mendmix.common.JeesuiteBaseException in project jeesuite-libs by vakinge.

the class QiniuProvider method getObjectBytes.

@Override
public byte[] getObjectBytes(String bucketName, String fileKey) {
    bucketName = buildBucketName(bucketName);
    String downloadUrl = getDownloadUrl(bucketName, fileKey, 600);
    Request request = new Request.Builder().url(downloadUrl).build();
    okhttp3.Response re = null;
    try {
        re = httpClient.newCall(request).execute();
        if (re.isSuccessful()) {
            return re.body().bytes();
        }
        throw new JeesuiteBaseException(re.code(), re.message());
    } catch (IOException e) {
        throw new JeesuiteBaseException(e.getMessage());
    }
}
Also used : JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) Request(okhttp3.Request) IOException(java.io.IOException)

Example 39 with JeesuiteBaseException

use of com.mendmix.common.JeesuiteBaseException in project jeesuite-libs by vakinge.

the class QiniuProvider method buildBucketUrlPrefix.

protected String buildBucketUrlPrefix(String buketName) {
    String rs = "";
    String path = "/v6/domain/list?tbl=" + buketName + "\n";
    String accessToken = auth.sign(path);
    String url = "http://api.qiniu.com/v6/domain/list?tbl=" + buketName;
    OkHttpClient client = new OkHttpClient();
    Request request = new Request.Builder().url(url).addHeader("Host", "api.qiniu.com").addHeader("Content-Type", "application/x-www-form-urlencoded").addHeader("Authorization", "QBox " + accessToken).build();
    okhttp3.Response re = null;
    try {
        re = client.newCall(request).execute();
        if (re.isSuccessful() == true) {
            String[] reArr = JsonUtils.toObject(re.body().string(), String[].class);
            if (reArr.length > 0) {
                rs = reArr[0];
                if (!rs.endsWith(FilePathHelper.DIR_SPLITER)) {
                    rs = rs.concat(FilePathHelper.DIR_SPLITER);
                }
            }
        } else {
            throw new JeesuiteBaseException(re.message());
        }
    } catch (IOException e) {
        throw new JeesuiteBaseException(e.getMessage());
    }
    return rs;
}
Also used : OkHttpClient(okhttp3.OkHttpClient) JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException) Request(okhttp3.Request) IOException(java.io.IOException)

Example 40 with JeesuiteBaseException

use of com.mendmix.common.JeesuiteBaseException in project jeesuite-libs by vakinge.

the class QiniuProvider method exists.

@Override
public boolean exists(String bucketName, String fileKey) {
    bucketName = buildBucketName(bucketName);
    fileKey = resolveFileKey(bucketName, fileKey);
    try {
        bucketManager.stat(bucketName, fileKey);
        return true;
    } catch (QiniuException e) {
        if (e.code() == 612)
            return false;
        throw new JeesuiteBaseException(e.code(), e.getMessage());
    }
}
Also used : QiniuException(com.qiniu.common.QiniuException) JeesuiteBaseException(com.mendmix.common.JeesuiteBaseException)

Aggregations

JeesuiteBaseException (com.mendmix.common.JeesuiteBaseException)44 IOException (java.io.IOException)13 CObjectMetadata (com.mendmix.cos.CObjectMetadata)4 CUploadResult (com.mendmix.cos.CUploadResult)4 CosServiceException (com.qcloud.cos.exception.CosServiceException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4 Request (okhttp3.Request)4 ApiInfo (com.mendmix.common.model.ApiInfo)2 WrapperResponse (com.mendmix.common.model.WrapperResponse)2 BizSystemModule (com.mendmix.gateway.model.BizSystemModule)2 COSObject (com.qcloud.cos.model.COSObject)2 QiniuException (com.qiniu.common.QiniuException)2 InputStreamReader (java.io.InputStreamReader)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 InvalidKeyException (java.security.InvalidKeyException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 SignatureException (java.security.SignatureException)2 Map (java.util.Map)2