use of org.wso2.broker.amqp.Server in project carbon-apimgt by wso2.
the class ApisApiServiceImpl method apisApiIdThreatProtectionPoliciesGet.
/**
* Get all threat protection policies associated with an API
* @param apiId APIID
* @param request MSF4J Request
* @return List of threat protection policy ids
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response apisApiIdThreatProtectionPoliciesGet(String apiId, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
List<ThreatProtectionPolicy> policyList = apiPublisher.getThreatProtectionPolicies();
List<ThreatProtectionPolicyDTO> dtoList = new ArrayList<>();
for (ThreatProtectionPolicy policy : policyList) {
dtoList.add(MappingUtil.toThreatProtectionPolicyDTO(policy));
}
return Response.ok().entity(dtoList).build();
} catch (APIManagementException e) {
log.error(e.getMessage(), e);
return Response.status(500).entity("Internal Server Error").build();
}
}
use of org.wso2.broker.amqp.Server in project carbon-apimgt by wso2.
the class ThreatProtectionPoliciesApiServiceImpl method threatProtectionPoliciesPolicyIdGet.
/**
* Get a specific threat protection policy
*
* @param policyId ID of the policy to be retrieved
* @param request
* @return Threat protection policy
* @throws NotFoundException
*/
@Override
public Response threatProtectionPoliciesPolicyIdGet(String policyId, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
ThreatProtectionPolicy policy = apiPublisher.getThreatProtectionPolicy(policyId);
if (policy == null) {
return Response.status(404).entity("Requested policy was not found.").build();
}
return Response.ok().entity(MappingUtil.toThreatProtectionPolicyDTO(policy)).build();
} catch (APIManagementException e) {
log.error(e.getMessage(), e);
}
return Response.status(500).entity("Internal Server Error.").build();
}
use of org.wso2.broker.amqp.Server in project wso2-synapse by wso2.
the class ServerManager method doShutdown.
/**
* Helper method to shutdown the the ServerManager
*/
private void doShutdown() {
ServerState serverState = ServerStateDetectionStrategy.currentState(serverContextInformation, serverConfigurationInformation);
if (serverState == ServerState.INITIALIZED || serverState == ServerState.STOPPED) {
// shutdown debug manager and close TCP connection in the debug interface
if (serverContextInformation.isServerDebugModeEnabled()) {
serverContextInformation.getSynapseDebugManager().shutdownDebugManager();
}
// Shutdown global PasswordManager instance used in synapse
PasswordManager passwordManager = PasswordManager.getInstance();
if (passwordManager.isInitialized()) {
PasswordManager.getInstance().shutDown();
}
// un-register the ServerManager MBean
unRegisterMBean();
// destroy the SynapseController
synapseController.destroy();
// mark as destroyed
changeState(ServerState.UNDETERMINED);
} else {
// if the server cannot be destroyed just set the current state as the server state
changeState(serverState);
}
}
use of org.wso2.broker.amqp.Server in project wso2-synapse by wso2.
the class ServerStateDetectionStrategy method currentState.
/**
* Determine the next possible server state based on current states and other facts
*
* @param contextInformation ServerContextInformation instance
* @param information ServerConfigurationInformation instance
* @return The actual current state possible states for the server
*/
public static ServerState currentState(ServerContextInformation contextInformation, ServerConfigurationInformation information) {
ServerState previousState = contextInformation.getServerState();
String deploymentMode = information.getDeploymentMode();
// if the previous state is ServerState.UNDETERMINED it should be ServerState.INITIALIZABLE
if (previousState == ServerState.UNDETERMINED) {
// before the server state to be ServerState.INITIALIZABLE
if (deploymentMode != null && PRODUCTION_MODE.equals(deploymentMode.trim())) {
SecretManager secretManager = SecretManager.getInstance();
if (secretManager.isInitialized()) {
return ServerState.INITIALIZABLE;
} else {
secretManager.init(SynapsePropertiesLoader.loadSynapseProperties());
if (secretManager.isInitialized()) {
return ServerState.INITIALIZABLE;
}
}
} else {
return ServerState.INITIALIZABLE;
}
}
// if the previous state is deterministic then the current state is the previous state
return previousState;
}
use of org.wso2.broker.amqp.Server in project charon by wso2.
the class JSONEncoder method encodeSCIMException.
/*
* encode scim exceptions
* @param exception
* @return
*/
public String encodeSCIMException(AbstractCharonException exception) {
// outer most json object
JSONObject rootErrorObject = new JSONObject();
// JSON Object containing the error code and error message
JSONObject errorObject = new JSONObject();
try {
// construct error object with details in the exception
errorObject.put(ResponseCodeConstants.SCHEMAS, exception.getSchemas());
if (exception instanceof BadRequestException) {
errorObject.put(ResponseCodeConstants.SCIM_TYPE, ((BadRequestException) (exception)).getScimType());
}
errorObject.put(ResponseCodeConstants.DETAIL, String.valueOf(exception.getDetail()));
errorObject.put(ResponseCodeConstants.STATUS, String.valueOf(exception.getStatus()));
// construct the full json obj.
rootErrorObject = errorObject;
} catch (JSONException e) {
// usually errors occur rarely when encoding exceptions. and no need to pass them to clients.
// sufficient to log them in server side back end.
logger.error("SCIMException encoding error");
}
return rootErrorObject.toString();
}
Aggregations