Search in sources :

Example 1 with Response

use of org.wso2.msf4j.Response in project siddhi by wso2.

the class SiddhiApiServiceImpl method siddhiArtifactUndeploySiddhiAppGet.

@Override
public Response siddhiArtifactUndeploySiddhiAppGet(String siddhiAppName) throws NotFoundException {
    String jsonString = new Gson().toString();
    if (siddhiAppName != null) {
        if (siddhiAppRunTimeMap.containsKey(siddhiAppName)) {
            siddhiAppRunTimeMap.remove(siddhiAppName);
            siddhiAppConfigurationMap.remove(siddhiAppName);
            siddhiAppSpecificInputHandlerMap.remove(siddhiAppName);
            jsonString = new Gson().toJson(new ApiResponseMessage(ApiResponseMessage.OK, "Siddhi app removed successfully"));
        } else {
            jsonString = new Gson().toJson(new ApiResponseMessage(ApiResponseMessage.ERROR, "There is no siddhi app exist " + "with provided name : " + siddhiAppName));
        }
    } else {
        jsonString = new Gson().toJson(new ApiResponseMessage(ApiResponseMessage.ERROR, "nvalid Request"));
    }
    return Response.ok().entity(jsonString).build();
}
Also used : ApiResponseMessage(org.wso2.siddhi.service.api.ApiResponseMessage) Gson(com.google.gson.Gson)

Example 2 with Response

use of org.wso2.msf4j.Response in project siddhi by wso2.

the class SiddhiApiServiceImpl method siddhiArtifactDeployPost.

@Override
public Response siddhiArtifactDeployPost(String siddhiApp) throws NotFoundException {
    log.info("SiddhiApp = " + siddhiApp);
    String jsonString = new Gson().toString();
    try {
        SiddhiApp parsedSiddhiApp = SiddhiCompiler.parse(siddhiApp);
        String siddhiAppName = AnnotationHelper.getAnnotationElement(SiddhiServiceConstants.ANNOTATION_NAME_NAME, null, parsedSiddhiApp.getAnnotations()).getValue();
        if (!siddhiAppRunTimeMap.containsKey(siddhiApp)) {
            SiddhiAppConfiguration siddhiAppConfiguration = new SiddhiAppConfiguration();
            siddhiAppConfiguration.setName(siddhiAppName);
            siddhiAppConfigurationMap.put(siddhiAppName, siddhiAppConfiguration);
            SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
            if (siddhiAppRuntime != null) {
                Set<String> streamNames = siddhiAppRuntime.getStreamDefinitionMap().keySet();
                Map<String, InputHandler> inputHandlerMap = new ConcurrentHashMap<>(streamNames.size());
                for (String streamName : streamNames) {
                    inputHandlerMap.put(streamName, siddhiAppRuntime.getInputHandler(streamName));
                }
                siddhiAppSpecificInputHandlerMap.put(siddhiAppName, inputHandlerMap);
                siddhiAppRunTimeMap.put(siddhiAppName, siddhiAppRuntime);
                siddhiAppRuntime.start();
                jsonString = new Gson().toJson(new ApiResponseMessage(ApiResponseMessage.OK, "Siddhi app is deployed " + "and runtime is created"));
            }
        } else {
            jsonString = new Gson().toJson(new ApiResponseMessage(ApiResponseMessage.ERROR, "There is a Siddhi app already " + "exists with same name"));
        }
    } catch (Exception e) {
        jsonString = new Gson().toJson(new ApiResponseMessage(ApiResponseMessage.ERROR, e.getMessage()));
    }
    return Response.ok().entity(jsonString).build();
}
Also used : ApiResponseMessage(org.wso2.siddhi.service.api.ApiResponseMessage) InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiApp(org.wso2.siddhi.query.api.SiddhiApp) Gson(com.google.gson.Gson) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiAppConfiguration(org.wso2.siddhi.service.util.SiddhiAppConfiguration) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) NotFoundException(org.wso2.siddhi.service.api.NotFoundException)

Example 3 with Response

use of org.wso2.msf4j.Response in project siddhi by wso2.

the class SiddhiApiTestCase method testDeployAndUndeploy.

@Test
public /**
 * Check deploy and undeploy functionality
 */
void testDeployAndUndeploy() throws NotFoundException {
    SiddhiApiServiceImpl apiService = new SiddhiApiServiceImpl();
    String siddhiApp = "@app:name('filterTest1') " + "" + "define stream cseEventStream (symbol string, price float, volume long);" + "" + "@info(name = 'query1') " + "from cseEventStream[70 > price] " + "select symbol, price " + "insert into outputStream;" + "" + "@info(name = 'query2') " + "from outputStream[70 > price] " + "select symbol, price " + "insert into outputStream2 ;";
    Response response = apiService.siddhiArtifactDeployPost(siddhiApp);
    Assert.assertEquals(response.getStatus(), 200, "HTTP 200 should be returned");
    Assert.assertTrue(response.getEntity().toString().contains("Siddhi app is deployed and runtime is created"), "Siddhi App creation message should be returned");
    Response undeployResponse = apiService.siddhiArtifactUndeploySiddhiAppGet("filterTest1");
    Assert.assertEquals(undeployResponse.getStatus(), 200, "HTTP 200 should be returned");
    Assert.assertTrue(undeployResponse.getEntity().toString().contains("Siddhi app removed successfully"), "Siddhi App removed message should be returned");
}
Also used : Response(javax.ws.rs.core.Response) SiddhiApiServiceImpl(org.wso2.siddhi.service.impl.SiddhiApiServiceImpl) Test(org.testng.annotations.Test)

Example 4 with Response

use of org.wso2.msf4j.Response in project product-apim by wso2.

the class TestUtil method generateClient.

public static DCRClientInfo generateClient() throws APIManagementException {
    DCRClientInfo dcrClientInfo = new DCRClientInfo();
    dcrClientInfo.setClientName("apim-integration-test");
    dcrClientInfo.setGrantTypes(Arrays.asList(new String[] { "password", "client_credentials" }));
    try {
        Response response = DCRMServiceStubFactory.getDCRMServiceStub(DYNAMIC_CLIENT_REGISTRATION_ENDPOINT, username, password, "wso2carbon").registerApplication(dcrClientInfo);
        DCRClientInfo dcrClientInfoResponse = (DCRClientInfo) new GsonDecoder().decode(response, DCRClientInfo.class);
        clientId = dcrClientInfoResponse.getClientId();
        clientSecret = dcrClientInfoResponse.getClientSecret();
        return dcrClientInfoResponse;
    } catch (APIManagementException | IOException e) {
        logger.error("Couldn't create client", e);
        throw new APIManagementException("Couldn't create client", e);
    }
}
Also used : Response(feign.Response) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) GsonDecoder(feign.gson.GsonDecoder) IOException(java.io.IOException) DCRClientInfo(org.wso2.carbon.apimgt.core.auth.dto.DCRClientInfo)

Example 5 with Response

use of org.wso2.msf4j.Response in project product-apim by wso2.

the class TestUtil method generateToken.

private static void generateToken(String username, String password, String scopes) throws APIManagementException {
    if (StringUtils.isEmpty(clientId) | StringUtils.isEmpty(clientSecret)) {
        generateClient();
    }
    OAuth2ServiceStubs.TokenServiceStub tokenServiceStub = getOauth2Client();
    Response response = tokenServiceStub.generatePasswordGrantAccessToken(username, password, scopes, -1, clientId, clientSecret);
    if (response.status() == APIMgtConstants.HTTPStatusCodes.SC_200_OK) {
        // 200 - Success
        logger.debug("A new access token is successfully generated.");
        try {
            OAuth2TokenInfo oAuth2TokenInfo = (OAuth2TokenInfo) new GsonDecoder().decode(response, OAuth2TokenInfo.class);
            accessTokenInfo = new TokenInfo(oAuth2TokenInfo.getAccessToken(), System.currentTimeMillis() + oAuth2TokenInfo.getExpiresIn());
        } catch (IOException e) {
            throw new KeyManagementException("Error occurred while parsing token response", e, ExceptionCodes.ACCESS_TOKEN_GENERATION_FAILED);
        }
    }
}
Also used : Response(feign.Response) GsonDecoder(feign.gson.GsonDecoder) OAuth2TokenInfo(org.wso2.carbon.apimgt.core.auth.dto.OAuth2TokenInfo) IOException(java.io.IOException) OAuth2ServiceStubs(org.wso2.carbon.apimgt.core.auth.OAuth2ServiceStubs) KeyManagementException(org.wso2.carbon.apimgt.core.exception.KeyManagementException) OAuth2TokenInfo(org.wso2.carbon.apimgt.core.auth.dto.OAuth2TokenInfo)

Aggregations

Response (javax.ws.rs.core.Response)370 Test (org.junit.Test)345 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)339 Test (org.testng.annotations.Test)329 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)278 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)248 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)217 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)201 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)189 ArrayList (java.util.ArrayList)186 HashMap (java.util.HashMap)185 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)158 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)153 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)153 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)149 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)141 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)139 IOException (java.io.IOException)105 BJSON (org.ballerinalang.model.values.BJSON)94 Request (org.wso2.msf4j.Request)92