Java Code Examples for javax.ws.rs.WebApplicationException#fillInStackTrace()

The following examples show how to use javax.ws.rs.WebApplicationException#fillInStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RESTErrorUtil.java    From ranger with Apache License 2.0 6 votes vote down vote up
public WebApplicationException createRESTException(VXResponse gjResponse) {
	Response errorResponse = Response
			.status(javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST)
			.entity(gjResponse).build();

	WebApplicationException restException = new WebApplicationException(
			errorResponse);
	restException.fillInStackTrace();
	UserSessionBase userSession = ContextUtil.getCurrentUserSession();
	String loginId = null;
	if (userSession != null) {
		loginId = userSession.getLoginId();
	}

	logger.info("Request failed. loginId="
			+ loginId + ", logMessage=" + gjResponse.getMsgDesc(),
			restException);

	return restException;
}
 
Example 2
Source File: RESTErrorUtil.java    From ranger with Apache License 2.0 6 votes vote down vote up
public WebApplicationException generateRESTException(VXResponse gjResponse) {
	Response errorResponse = Response
			.status(gjResponse.getStatusCode())
			.entity(gjResponse).build();

	WebApplicationException restException = new WebApplicationException(
			errorResponse);
	restException.fillInStackTrace();
	UserSessionBase userSession = ContextUtil.getCurrentUserSession();
	String loginId = null;
	if (userSession != null) {
		loginId = userSession.getLoginId();
	}

	logger.info("Request failed. loginId="
			+ loginId + ", logMessage=" + gjResponse.getMsgDesc(),
			restException);

	return restException;
}
 
Example 3
Source File: RESTErrorUtil.java    From ranger with Apache License 2.0 6 votes vote down vote up
public WebApplicationException createGrantRevokeRESTException(String logMessage) {
	RESTResponse resp = new RESTResponse();
	resp.setMsgDesc(logMessage);

	Response errorResponse = Response.status(
			javax.servlet.http.HttpServletResponse.SC_FORBIDDEN).entity(resp).build();

	WebApplicationException restException = new WebApplicationException(
			errorResponse);
	restException.fillInStackTrace();
	UserSessionBase userSession = ContextUtil.getCurrentUserSession();
	String loginId = null;
	if (userSession != null) {
		loginId = userSession.getLoginId();
	}

	logger.info("Request failed. loginId="
			+ loginId + ", logMessage=" + logMessage,
			restException);

	return restException;
}
 
Example 4
Source File: RESTErrorUtil.java    From ranger with Apache License 2.0 6 votes vote down vote up
public WebApplicationException createRESTException(int responseCode,
		String logMessage, boolean logError) {
	Response errorResponse = Response
			.status(responseCode).entity(logMessage).build();

	WebApplicationException restException = new WebApplicationException(
			errorResponse);
	restException.fillInStackTrace();
	UserSessionBase userSession = ContextUtil.getCurrentUserSession();
	String loginId = null;
	if (userSession != null) {
		loginId = userSession.getLoginId();
	}

	if (logError) {
		logger.info("Request failed. loginId="
				+ loginId + ", logMessage=" + logMessage,
				restException);
	}

	return restException;	
}
 
Example 5
Source File: RESTErrorUtil.java    From ranger with Apache License 2.0 6 votes vote down vote up
public WebApplicationException createRESTException(String errorMessage,
			MessageEnums messageEnum, Long objectId, String fieldName,
			String logMessage,int statusCode)
{
	List<VXMessage> messageList = new ArrayList<VXMessage>();
	messageList.add(messageEnum.getMessage(objectId, fieldName));
	VXResponse vResponse = new VXResponse();
	vResponse.setStatusCode(vResponse.STATUS_ERROR);
	vResponse.setMsgDesc(errorMessage);
	vResponse.setMessageList(messageList);
	Response errorResponse = Response.status(statusCode).entity(vResponse).build();
	WebApplicationException restException = new WebApplicationException(errorResponse);
	restException.fillInStackTrace();
	UserSessionBase userSession = ContextUtil.getCurrentUserSession();
	String loginId = null;
	if (userSession != null) {
		loginId = userSession.getLoginId();
	}
	logger.info("Request failed. loginId="
			+ loginId + ", logMessage=" + vResponse.getMsgDesc(),
			restException);
	return restException;
}
 
Example 6
Source File: RESTErrorUtil.java    From ranger with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param logMessage
 *            This is optional
 * @return
 */
public WebApplicationException create403RESTException(String logMessage) {
	Response errorResponse = Response.status(
			javax.servlet.http.HttpServletResponse.SC_FORBIDDEN).build();

	WebApplicationException restException = new WebApplicationException(
			errorResponse);
	restException.fillInStackTrace();
	// TODO:Future:Open: Need to log all these and add user to
	// block list if this is deliberate
	// Get user information
	UserSessionBase userSession = ContextUtil.getCurrentUserSession();
	String loginId = null;
	if (userSession != null) {
		loginId = userSession.getLoginId();
	}

	String requestInfo = "";
	try {
		RequestContext reqContext = ContextUtil.getCurrentRequestContext();
		if (reqContext != null) {
			requestInfo = reqContext.toString();
			requestInfo += ", timeTaken="
					+ (System.currentTimeMillis() - reqContext
							.getStartTime());
		}
	} catch (Throwable contextEx) {
		logger.error("Error getting request info", contextEx);
	}

	logger.error("Access restricted. loginId="
			+ loginId + ", logMessage=" + logMessage + ", requestInfo="
			+ requestInfo, restException);

	return restException;
}