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);
}
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();
}
}
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);
}
}
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();
}
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;
}
Aggregations