Search in sources :

Example 91 with Server

use of org.wso2.broker.amqp.Server in project product-iots by wso2.

the class WindowsEnrollment method testServerAvailability.

/**
 * Test the Windows Discovery Get endpoint to see if the server is available.
 *
 * @throws Exception
 */
@Test(groups = Constants.WindowsEnrollment.WINDOWS_ENROLLMENT_GROUP, description = "Test Windows Discovery get.")
public void testServerAvailability() throws Exception {
    client.setHttpHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_SOAP_XML);
    HttpResponse response = client.get(Constants.WindowsEnrollment.DISCOVERY_GET_URL);
    Assert.assertEquals(response.getResponseCode(), HttpStatus.SC_OK);
}
Also used : HttpResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse) Test(org.testng.annotations.Test)

Example 92 with Server

use of org.wso2.broker.amqp.Server in project product-iots by wso2.

the class SampleInstallationTest method waitForRestart.

/**
 * Wait until the server restarts.
 * This method looks for "Mgt console URL:" to be appeared in the terminal.
 * If it does not appear within the given timeout an Exception will be thrown.
 */
private void waitForRestart() {
    ExecutorService service = Executors.newSingleThreadExecutor();
    try {
        Runnable r = new Runnable() {

            @Override
            public void run() {
                try {
                    LogEvent[] logEvents = logViewerClient.getAllRemoteSystemLogs();
                    for (LogEvent event : logEvents) {
                        log.info(event.getMessage() + " @ " + event.getLogTime());
                        if (event.getMessage().contains("Mgt Console URL  : ")) {
                            log.info("Server restarted successfully");
                            Assert.assertTrue(true);
                        }
                    }
                } catch (RemoteException | LogViewerLogViewerException e) {
                    log.error("Error reading logs. \n" + e.getMessage());
                    Assert.assertTrue(false);
                }
            }
        };
        Future<?> f = service.submit(r);
        f.get(Constants.IOT_RESTART_THREAD_TIMEOUT, TimeUnit.MINUTES);
    } catch (final InterruptedException e) {
        log.error("Interrupted " + e.getMessage());
        Assert.assertTrue(false);
    } catch (final TimeoutException e) {
        log.error("Timeout " + e.getMessage());
        Assert.assertTrue(false);
    } catch (final ExecutionException e) {
        log.error("Execution failed " + e.getMessage());
        Assert.assertTrue(false);
    } finally {
        service.shutdown();
    }
}
Also used : LogEvent(org.wso2.carbon.logging.view.stub.types.carbon.LogEvent) LogViewerLogViewerException(org.wso2.carbon.logging.view.stub.LogViewerLogViewerException) ExecutorService(java.util.concurrent.ExecutorService) RemoteException(java.rmi.RemoteException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 93 with Server

use of org.wso2.broker.amqp.Server in project product-iots by wso2.

the class CarbonServerManagerExtension method restartGracefully.

public synchronized void restartGracefully() throws AutomationFrameworkException {
    try {
        int httpsPort = defaultHttpsPort + this.portOffset;
        String backendURL = this.automationContext.getContextUrls().getSecureServiceUrl().replaceAll("(:\\d+)", ":" + httpsPort);
        User superUser = this.automationContext.getSuperTenant().getTenantAdmin();
        ClientConnectionUtil.sendGraceFullRestartRequest(backendURL, superUser.getUserName(), superUser.getPassword());
    } catch (XPathExpressionException var5) {
        throw new AutomationFrameworkException("restart failed", var5);
    }
    long time = System.currentTimeMillis() + 300000L;
    // while(!this.inputStreamHandler.getOutput().contains("Halting JVM") && System.currentTimeMillis() < time) {
    // ;
    // }
    time = System.currentTimeMillis();
    while (System.currentTimeMillis() < time + 5000L) {
        ;
    }
    try {
        ClientConnectionUtil.waitForPort(Integer.parseInt((String) this.automationContext.getInstance().getPorts().get("https")), (String) this.automationContext.getInstance().getHosts().get("default"));
        ClientConnectionUtil.waitForLogin(this.automationContext);
    } catch (XPathExpressionException var4) {
        throw new AutomationFrameworkException("Connection attempt to carbon server failed", var4);
    }
}
Also used : User(org.wso2.carbon.automation.engine.context.beans.User) AutomationFrameworkException(org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException) XPathExpressionException(javax.xml.xpath.XPathExpressionException)

Example 94 with Server

use of org.wso2.broker.amqp.Server in project carbon-apimgt by wso2.

the class ApisApiServiceImpl method updateWSDLOfAPI.

/**
 * Update the WSDL of an API
 *
 * @param apiId UUID of the API
 * @param fileInputStream file data as input stream
 * @param fileDetail file details
 * @param url URL of the WSDL
 * @return 200 OK response if the operation is successful. 400 if the provided inputs are invalid. 500 if a server
 *  error occurred.
 * @throws APIManagementException when error occurred while trying to retrieve the WSDL
 */
@Override
public Response updateWSDLOfAPI(String apiId, String ifMatch, InputStream fileInputStream, Attachment fileDetail, String url, MessageContext messageContext) throws APIManagementException {
    APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
    String organization = RestApiUtil.getValidatedOrganization(messageContext);
    // validate if api exists
    APIInfo apiInfo = validateAPIExistence(apiId);
    // validate API update operation permitted based on the LC state
    validateAPIOperationsPerLC(apiInfo.getStatus().toString());
    WSDLValidationResponse validationResponse = validateWSDLAndReset(fileInputStream, fileDetail, url);
    if (StringUtils.isNotBlank(url)) {
        apiProvider.addWSDLResource(apiId, null, url, organization);
    } else {
        ResourceFile wsdlResource;
        if (APIConstants.APPLICATION_ZIP.equals(fileDetail.getContentType().toString()) || APIConstants.APPLICATION_X_ZIP_COMPRESSED.equals(fileDetail.getContentType().toString())) {
            wsdlResource = new ResourceFile(validationResponse.getWsdlProcessor().getWSDL(), APIConstants.APPLICATION_ZIP);
        } else {
            wsdlResource = new ResourceFile(validationResponse.getWsdlProcessor().getWSDL(), fileDetail.getContentType().toString());
        }
        apiProvider.addWSDLResource(apiId, wsdlResource, null, organization);
    }
    return Response.ok().build();
}
Also used : ResourceFile(org.wso2.carbon.apimgt.api.model.ResourceFile) WSDLValidationResponse(org.wso2.carbon.apimgt.impl.wsdl.model.WSDLValidationResponse) APIInfo(org.wso2.carbon.apimgt.api.model.APIInfo) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Example 95 with Server

use of org.wso2.broker.amqp.Server in project carbon-apimgt by wso2.

the class ApisApiServiceImpl method updateAPIClientCertificateByAlias.

@Override
public Response updateAPIClientCertificateByAlias(String alias, String apiId, InputStream certificateInputStream, Attachment certificateDetail, String tier, MessageContext messageContext) {
    try {
        // validate if api exists
        validateAPIExistence(apiId);
        ContentDisposition contentDisposition;
        String fileName;
        String base64EncodedCert = null;
        APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
        String organization = RestApiUtil.getValidatedOrganization(messageContext);
        API api = apiProvider.getAPIbyUUID(apiId, organization);
        api.setOrganization(organization);
        // validate API update operation permitted based on the LC state
        validateAPIOperationsPerLC(api.getStatus());
        String userName = RestApiCommonUtil.getLoggedInUsername();
        int tenantId = APIUtil.getInternalOrganizationId(organization);
        ClientCertificateDTO clientCertificateDTO = CertificateRestApiUtils.preValidateClientCertificate(alias, api.getId(), organization);
        if (certificateDetail != null) {
            contentDisposition = certificateDetail.getContentDisposition();
            fileName = contentDisposition.getParameter(RestApiConstants.CONTENT_DISPOSITION_FILENAME);
            if (StringUtils.isNotBlank(fileName)) {
                base64EncodedCert = CertificateRestApiUtils.generateEncodedCertificate(certificateInputStream);
            }
        }
        if (StringUtils.isEmpty(base64EncodedCert) && StringUtils.isEmpty(tier)) {
            return Response.ok().entity("Client Certificate is not updated for alias " + alias).build();
        }
        int responseCode = apiProvider.updateClientCertificate(base64EncodedCert, alias, clientCertificateDTO.getApiIdentifier(), tier, tenantId, organization);
        if (ResponseCode.SUCCESS.getResponseCode() == responseCode) {
            // Handle api product case.
            if (API_PRODUCT_TYPE.equals(api.getType())) {
                APIIdentifier apiIdentifier = api.getId();
                APIProductIdentifier apiProductIdentifier = new APIProductIdentifier(apiIdentifier.getProviderName(), apiIdentifier.getApiName(), apiIdentifier.getVersion());
                APIProduct apiProduct = apiProvider.getAPIProduct(apiProductIdentifier);
                apiProduct.setOrganization(organization);
                apiProvider.updateAPIProduct(apiProduct);
            } else {
                apiProvider.updateAPI(api);
            }
            ClientCertMetadataDTO clientCertMetadataDTO = new ClientCertMetadataDTO();
            clientCertMetadataDTO.setAlias(alias);
            clientCertMetadataDTO.setApiId(api.getUUID());
            clientCertMetadataDTO.setTier(clientCertificateDTO.getTierName());
            URI updatedCertUri = new URI(RestApiConstants.CLIENT_CERTS_BASE_PATH + "?alias=" + alias);
            return Response.ok(updatedCertUri).entity(clientCertMetadataDTO).build();
        } else if (ResponseCode.INTERNAL_SERVER_ERROR.getResponseCode() == responseCode) {
            RestApiUtil.handleInternalServerError("Error while updating the client certificate for the alias " + alias + " due to an internal " + "server error", log);
        } else if (ResponseCode.CERTIFICATE_NOT_FOUND.getResponseCode() == responseCode) {
            RestApiUtil.handleResourceNotFoundError("", log);
        } else if (ResponseCode.CERTIFICATE_EXPIRED.getResponseCode() == responseCode) {
            RestApiUtil.handleBadRequest("Error while updating the client certificate for the alias " + alias + " Certificate Expired.", log);
        }
    } catch (APIManagementException e) {
        RestApiUtil.handleInternalServerError("Error while updating the client certificate for the alias " + alias + " due to an internal " + "server error", e, log);
    } catch (IOException e) {
        RestApiUtil.handleInternalServerError("Error while encoding client certificate for the alias " + alias, e, log);
    } catch (URISyntaxException e) {
        RestApiUtil.handleInternalServerError("Error while generating the resource location URI for alias '" + alias + "'", e, log);
    } catch (FaultGatewaysException e) {
        RestApiUtil.handleInternalServerError("Error while publishing the certificate change to gateways for the alias " + alias, e, log);
    }
    return null;
}
Also used : FaultGatewaysException(org.wso2.carbon.apimgt.api.FaultGatewaysException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) APIProvider(org.wso2.carbon.apimgt.api.APIProvider) URI(java.net.URI) APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) APIProduct(org.wso2.carbon.apimgt.api.model.APIProduct) ContentDisposition(org.apache.cxf.jaxrs.ext.multipart.ContentDisposition) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ClientCertMetadataDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.ClientCertMetadataDTO) API(org.wso2.carbon.apimgt.api.model.API) ImportExportAPI(org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) ClientCertificateDTO(org.wso2.carbon.apimgt.api.dto.ClientCertificateDTO) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)28 IOException (java.io.IOException)19 ArrayList (java.util.ArrayList)14 HashMap (java.util.HashMap)14 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)10 File (java.io.File)8 JSONObject (org.json.simple.JSONObject)7 MalformedURLException (java.net.MalformedURLException)6 URL (java.net.URL)6 OMElement (org.apache.axiom.om.OMElement)6 JSONObject (org.json.JSONObject)6 URI (java.net.URI)5 URISyntaxException (java.net.URISyntaxException)5 Test (org.testng.annotations.Test)5 KeyManager (org.wso2.carbon.apimgt.api.model.KeyManager)5 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)5 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)5 Connection (java.sql.Connection)4 SQLException (java.sql.SQLException)4 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)4