use of org.springframework.web.bind.annotation.ResponseBody in project leopard by tanhaichao.
the class JsonViewTrynbResolver method resolveView.
@Override
public ModelAndView resolveView(HttpServletRequest request, HttpServletResponse response, HandlerMethod handler, Exception exception, TrynbInfo trynbInfo) {
// Class<?> returnType = handler.getMethod().getReturnType();
// if (!JsonView.class.isAssignableFrom(returnType)) {
ResponseBody body = handler.getMethodAnnotation(ResponseBody.class);
if (body == null) {
return null;
}
if (corsConfig.isEnable()) {
// response.addHeader("Access-Control-Allow-Headers", "X-Requested-With,X_Requested_With,Content-Type");
// response.addHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
String allowOrigin = corsConfig.getAccessControlAllowOrigin(request);
if (StringUtils.isNotEmpty(allowOrigin)) {
response.addHeader("Access-Control-Allow-Origin", allowOrigin);
response.addHeader("Access-Control-Allow-Credentials", "true");
// response.addHeader("Access-Control-Allow-Methods", "POST");
// response.addHeader("Access-Control-Allow-Headers", "x_requested_with,content-type");
}
}
ErrorJsonView jsonView = new ErrorJsonView();
jsonView.setException(exception);
jsonView.setHandler(handler);
if (exception instanceof StatusCodeException) {
StatusCodeException e = (StatusCodeException) exception;
jsonView.setStatus(e.getStatus());
} else {
jsonView.setStatus(trynbInfo.getStatusCode());
}
jsonView.setMessage(trynbInfo.getMessage());
if (trynbInfo.isTrynbMessage() || trynbInfo.isApiMessage() || trynbInfo.isTranslate()) {
jsonView.setOriginalMessage(ErrorUtil.parseMessage(exception));
}
if (SystemUtils.IS_OS_WINDOWS) {
// TODO 测试代码
jsonView.setDetailMessage(exception.getMessage());
}
jsonView.setException(exception.getClass().getName());
return jsonView;
}
use of org.springframework.web.bind.annotation.ResponseBody in project weixin-java-pay-demo by binarywang.
the class WxErrorController method error.
/**
* Supports other formats like JSON, XML
*
* @param request
*/
@RequestMapping(value = ERROR_PATH)
@ResponseBody
public ResponseEntity<Map<String, Object>> error(HttpServletRequest request) {
Map<String, Object> body = this.getErrorAttributes(request, this.getTraceParameter(request));
HttpStatus status = this.getStatus(request);
return new ResponseEntity<>(body, status);
}
use of org.springframework.web.bind.annotation.ResponseBody in project weixin-java-mp-demo-springboot by binarywang.
the class WxErrorController method error.
/**
* Supports other formats like JSON, XML
*
* @param request
*/
@RequestMapping(value = ERROR_PATH)
@ResponseBody
public ResponseEntity<Map<String, Object>> error(HttpServletRequest request) {
Map<String, Object> body = this.getErrorAttributes(request, this.getTraceParameter(request));
HttpStatus status = this.getStatus(request);
return new ResponseEntity<>(body, status);
}
use of org.springframework.web.bind.annotation.ResponseBody in project powerauth-restful-integration by lime-company.
the class TokenController method removeToken.
@RequestMapping(value = "remove", method = RequestMethod.POST)
@PowerAuth(resourceId = "/pa/token/remove", signatureType = { PowerAuthSignatureTypes.POSSESSION, PowerAuthSignatureTypes.POSSESSION_KNOWLEDGE, PowerAuthSignatureTypes.POSSESSION_BIOMETRY, PowerAuthSignatureTypes.POSSESSION_KNOWLEDGE_BIOMETRY })
@ResponseBody
public ObjectResponse<TokenRemoveResponse> removeToken(@RequestBody ObjectRequest<TokenRemoveRequest> request, PowerAuthApiAuthentication authentication) throws PowerAuthAuthenticationException {
try {
if (authentication != null && authentication.getActivationId() != null) {
// Fetch activation ID
final String activationId = authentication.getActivationId();
// Fetch token ID from the request
final TokenRemoveRequest requestObject = request.getRequestObject();
final String tokenId = requestObject.getTokenId();
// Remove a token, ignore response, since the endpoint should quietly return
powerAuthClient.removeToken(tokenId, activationId);
// Prepare a response
final TokenRemoveResponse responseObject = new TokenRemoveResponse();
responseObject.setTokenId(requestObject.getTokenId());
return new ObjectResponse<>(responseObject);
} else {
throw new PowerAuthAuthenticationException();
}
} catch (PowerAuthAuthenticationException ex) {
throw ex;
} catch (Exception ex) {
throw new PowerAuthAuthenticationException(ex.getMessage());
}
}
use of org.springframework.web.bind.annotation.ResponseBody in project powerauth-restful-integration by lime-company.
the class CustomActivationController method createNewActivation.
@RequestMapping(value = "create", method = RequestMethod.POST)
@ResponseBody
public ObjectResponse<NonPersonalizedEncryptedPayloadModel> createNewActivation(@RequestBody ObjectRequest<NonPersonalizedEncryptedPayloadModel> object) throws PowerAuthAuthenticationException, PowerAuthActivationException {
try {
// Check if there is any user provider to be autowired
if (userProvider == null) {
throw new PowerAuthActivationException();
}
// Prepare an encryptor
final PowerAuthNonPersonalizedEncryptor encryptor = encryptorFactory.buildNonPersonalizedEncryptor(object);
if (encryptor == null) {
throw new PowerAuthActivationException();
}
// Decrypt the request object
ActivationCreateCustomRequest request = encryptor.decrypt(object, ActivationCreateCustomRequest.class);
if (request == null) {
throw new PowerAuthActivationException();
}
// Lookup user ID using a provided identity
final Map<String, String> identity = request.getIdentity();
String userId = userProvider.lookupUserIdForAttributes(identity);
// If no user was found, return error
if (userId == null) {
throw new PowerAuthActivationException();
}
// Create activation for a looked up user and application related to the given application key
ActivationCreateRequest acr = request.getPowerauth();
CreateActivationResponse response = powerAuthClient.createActivation(acr.getApplicationKey(), userId, acr.getActivationIdShort(), acr.getActivationName(), acr.getActivationNonce(), acr.getEphemeralPublicKey(), acr.getEncryptedDevicePublicKey(), acr.getExtras(), acr.getApplicationSignature());
// Process custom attributes using a custom logic
final Map<String, Object> customAttributes = request.getCustomAttributes();
userProvider.processCustomActivationAttributes(customAttributes);
// Prepare the created activation response data
ActivationCreateResponse createResponse = new ActivationCreateResponse();
createResponse.setActivationId(response.getActivationId());
createResponse.setEphemeralPublicKey(response.getEphemeralPublicKey());
createResponse.setActivationNonce(response.getActivationNonce());
createResponse.setEncryptedServerPublicKey(response.getEncryptedServerPublicKey());
createResponse.setEncryptedServerPublicKeySignature(response.getEncryptedServerPublicKeySignature());
// Encrypt response object
final ObjectResponse<NonPersonalizedEncryptedPayloadModel> powerAuthApiResponse = encryptor.encrypt(createResponse);
// Check if activation should be committed instantly and if yes, perform commit
if (userProvider.shouldAutoCommitActivation(identity, customAttributes)) {
powerAuthClient.commitActivation(response.getActivationId());
}
// Return response
return powerAuthApiResponse;
} catch (IOException e) {
throw new PowerAuthActivationException();
}
}
Aggregations