Search in sources :

Example 6 with ConnectionOpenResponse

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;
}
Also used : WebServiceException(com.openmeap.protocol.WebServiceException) Error(com.openmeap.protocol.dto.Error) ConnectionOpenRequest(com.openmeap.protocol.dto.ConnectionOpenRequest) ConnectionOpenResponse(com.openmeap.protocol.dto.ConnectionOpenResponse) ApplicationManagementService(com.openmeap.protocol.ApplicationManagementService) WebApplicationContext(org.springframework.web.context.WebApplicationContext) Result(com.openmeap.protocol.dto.Result)

Example 7 with ConnectionOpenResponse

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;
}
Also used : DigestException(com.openmeap.digest.DigestException) Deployment(com.openmeap.model.dto.Deployment) UpdateHeader(com.openmeap.protocol.dto.UpdateHeader) GlobalSettings(com.openmeap.model.dto.GlobalSettings) ConnectionOpenResponse(com.openmeap.protocol.dto.ConnectionOpenResponse) GenericRuntimeException(com.openmeap.util.GenericRuntimeException) Hash(com.openmeap.protocol.dto.Hash) Application(com.openmeap.model.dto.Application) ApplicationArchive(com.openmeap.model.dto.ApplicationArchive)

Aggregations

ConnectionOpenResponse (com.openmeap.protocol.dto.ConnectionOpenResponse)7 ApplicationManagementService (com.openmeap.protocol.ApplicationManagementService)3 WebServiceException (com.openmeap.protocol.WebServiceException)3 ConnectionOpenRequest (com.openmeap.protocol.dto.ConnectionOpenRequest)3 Hash (com.openmeap.protocol.dto.Hash)2 Result (com.openmeap.protocol.dto.Result)2 UpdateHeader (com.openmeap.protocol.dto.UpdateHeader)2 Hashtable (java.util.Hashtable)2 DigestException (com.openmeap.digest.DigestException)1 HttpRequestException (com.openmeap.http.HttpRequestException)1 HttpResponse (com.openmeap.http.HttpResponse)1 JSONObjectBuilder (com.openmeap.json.JSONObjectBuilder)1 Application (com.openmeap.model.dto.Application)1 ApplicationArchive (com.openmeap.model.dto.ApplicationArchive)1 Deployment (com.openmeap.model.dto.Deployment)1 GlobalSettings (com.openmeap.model.dto.GlobalSettings)1 Application (com.openmeap.protocol.dto.Application)1 ApplicationInstallation (com.openmeap.protocol.dto.ApplicationInstallation)1 Error (com.openmeap.protocol.dto.Error)1 SLIC (com.openmeap.protocol.dto.SLIC)1