Search in sources :

Example 36 with Server

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();
    }
}
Also used : ThreatProtectionPolicy(org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy) ThreatProtectionPolicyDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.ThreatProtectionPolicyDTO) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ArrayList(java.util.ArrayList) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher)

Example 37 with Server

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();
}
Also used : ThreatProtectionPolicy(org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher)

Example 38 with Server

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);
    }
}
Also used : PasswordManager(org.wso2.securevault.PasswordManager)

Example 39 with Server

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;
}
Also used : SecretManager(org.wso2.securevault.secret.SecretManager)

Example 40 with Server

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();
}
Also used : JSONObject(org.json.JSONObject) BadRequestException(org.wso2.charon3.core.exceptions.BadRequestException) JSONException(org.json.JSONException)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)10 HashMap (java.util.HashMap)8 File (java.io.File)7 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)7 JSONEncoder (org.wso2.charon3.core.encoder.JSONEncoder)6 CharonException (org.wso2.charon3.core.exceptions.CharonException)6 InternalErrorException (org.wso2.charon3.core.exceptions.InternalErrorException)6 NotFoundException (org.wso2.charon3.core.exceptions.NotFoundException)6 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)6 SCIMResourceTypeSchema (org.wso2.charon3.core.schema.SCIMResourceTypeSchema)6 XPathExpressionException (javax.xml.xpath.XPathExpressionException)5 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)5 Test (org.testng.annotations.Test)5 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)5 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)5 AutomationFrameworkException (org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException)5 ThreatProtectionPolicy (org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy)4 HttpResponse (org.wso2.carbon.automation.test.utils.http.client.HttpResponse)4