use of com.openmeap.protocol.dto.ConnectionOpenResponse in project OpenMEAP by OpenMEAP.
the class ApplicationManagementServlet method connectionOpenRequest.
/**
* Pulls parameters out of the request and passes them to the ApplicationManagementPortType bean pulled from the WebApplicationContext
*
* @param req
* @return
*/
public Result connectionOpenRequest(HttpServletRequest req) {
WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
ConnectionOpenRequest request = createConnectionOpenRequest(req);
Result result = new Result();
try {
ConnectionOpenResponse response = ((ApplicationManagementService) context.getBean("applicationManagementService")).connectionOpen(request);
result.setConnectionOpenResponse(response);
} catch (WebServiceException wse) {
Error err = new Error();
err.setCode(wse.getType().asErrorCode());
err.setMessage(wse.getMessage());
result.setError(err);
}
return result;
}
use of com.openmeap.protocol.dto.ConnectionOpenResponse in project OpenMEAP by OpenMEAP.
the class ApplicationManagementServiceImpl method connectionOpen.
public ConnectionOpenResponse connectionOpen(ConnectionOpenRequest request) throws WebServiceException {
String reqAppArchHashVal = StringUtils.trimToNull(request.getApplication().getHashValue());
String reqAppVerId = StringUtils.trimToNull(request.getApplication().getVersionId());
String reqAppName = StringUtils.trimToNull(request.getApplication().getName());
ConnectionOpenResponse response = new ConnectionOpenResponse();
GlobalSettings settings = modelManager.getGlobalSettings();
if (StringUtils.isBlank(settings.getExternalServiceUrlPrefix()) && logger.isWarnEnabled()) {
logger.warn("The external service url prefix configured in the admin interface is blank. " + "This will probably cause issues downloading application archives.");
}
Application application = getApplication(reqAppName, reqAppVerId);
// Generate a new auth token for the device to present to the proxy
String authToken;
try {
authToken = AuthTokenProvider.newAuthToken(application.getProxyAuthSalt());
} catch (DigestException e) {
throw new GenericRuntimeException(e);
}
response.setAuthToken(authToken);
// If there is a deployment,
// and the version of that deployment differs in hash value or identifier
// then return an update in the response
Deployment lastDeployment = modelManager.getModelService().getLastDeployment(application);
Boolean reqAppVerDiffers = lastDeployment != null && !lastDeployment.getVersionIdentifier().equals(reqAppVerId);
Boolean reqAppArchHashValDiffers = lastDeployment != null && reqAppArchHashVal != null && !lastDeployment.getApplicationArchive().getHash().equals(reqAppArchHashVal);
// the app hash value is different than reported
if (reqAppVerDiffers || reqAppArchHashValDiffers) {
// TODO: I'm not happy with the discrepancies between the model and schema
// ...besides, this update header should be encapsulated somewhere else
ApplicationArchive currentVersionArchive = lastDeployment.getApplicationArchive();
UpdateHeader uh = new UpdateHeader();
uh.setVersionIdentifier(lastDeployment.getVersionIdentifier());
uh.setInstallNeeds(Long.valueOf(currentVersionArchive.getBytesLength() + currentVersionArchive.getBytesLengthUncompressed()));
uh.setStorageNeeds(Long.valueOf(currentVersionArchive.getBytesLengthUncompressed()));
uh.setType(UpdateType.fromValue(lastDeployment.getType().toString()));
uh.setUpdateUrl(currentVersionArchive.getDownloadUrl(settings));
uh.setHash(new Hash());
uh.getHash().setAlgorithm(HashAlgorithm.fromValue(currentVersionArchive.getHashAlgorithm()));
uh.getHash().setValue(currentVersionArchive.getHash());
response.setUpdate(uh);
}
return response;
}
Aggregations