Search in sources :

Example 1 with ConnectionOpenRequest

use of com.openmeap.protocol.dto.ConnectionOpenRequest in project OpenMEAP by OpenMEAP.

the class UpdateHandler method getConnectionOpenRequest.

/**
	 * Uses the configuration to put together a ConnectionOpenRequest object.
	 * 
	 * @return
	 */
public ConnectionOpenRequest getConnectionOpenRequest() {
    ConnectionOpenRequest request = new ConnectionOpenRequest();
    request.setApplication(new Application());
    request.getApplication().setInstallation(new ApplicationInstallation());
    request.setSlic(new SLIC());
    Application app = request.getApplication();
    app.setName(config.getApplicationName());
    app.setVersionId(config.getApplicationVersion());
    app.setHashValue(config.getArchiveHash() != null ? config.getArchiveHash() : "");
    ApplicationInstallation dev = request.getApplication().getInstallation();
    dev.setUuid(config.getDeviceUuid());
    SLIC slic = request.getSlic();
    slic.setVersionId(SLICConfig.SLIC_VERSION);
    return request;
}
Also used : SLIC(com.openmeap.protocol.dto.SLIC) ApplicationInstallation(com.openmeap.protocol.dto.ApplicationInstallation) ConnectionOpenRequest(com.openmeap.protocol.dto.ConnectionOpenRequest) Application(com.openmeap.protocol.dto.Application)

Example 2 with ConnectionOpenRequest

use of com.openmeap.protocol.dto.ConnectionOpenRequest in project OpenMEAP by OpenMEAP.

the class ApplicationManagementPortTypeImplTest method before.

@Before
public void before() {
    //if( modelManager==null ) {
    ModelTestUtils.resetTestDb();
    ModelTestUtils.createModel(null);
    modelManager = ModelTestUtils.createModelManager();
    //}
    response = null;
    thrown = false;
    appMgmtSvc = new ApplicationManagementServiceImpl();
    appMgmtSvc.setModelManager(modelManager);
    request = new ConnectionOpenRequest();
    request.setApplication(new com.openmeap.protocol.dto.Application());
    request.getApplication().setInstallation(new com.openmeap.protocol.dto.ApplicationInstallation());
    request.getApplication().getInstallation().setUuid("Device.uuid.1");
    request.getApplication().setName("Application.name");
    request.getApplication().setVersionId("ApplicationVersion.identifier.bundled");
    request.setSlic(new SLIC());
    request.getSlic().setVersionId("CURRENT_VERSION_UNUSED");
}
Also used : SLIC(com.openmeap.protocol.dto.SLIC) ConnectionOpenRequest(com.openmeap.protocol.dto.ConnectionOpenRequest) Before(org.junit.Before)

Example 3 with ConnectionOpenRequest

use of com.openmeap.protocol.dto.ConnectionOpenRequest in project OpenMEAP by OpenMEAP.

the class UpdateHandler method checkForUpdate.

public UpdateHeader checkForUpdate() throws WebServiceException {
    // we'll go ahead and flip the flag that we tried to update now
    // at the beginning of our intent
    config.setLastUpdateAttempt(new Long(new Date().getTime()));
    // put together the communication coordination request
    ConnectionOpenRequest request = getConnectionOpenRequest();
    ConnectionOpenResponse response = makeConnectionOpenRequest(request);
    // we'll use this from now till the next update
    config.setLastAuthToken(response.getAuthToken());
    return response.getUpdate();
}
Also used : ConnectionOpenRequest(com.openmeap.protocol.dto.ConnectionOpenRequest) ConnectionOpenResponse(com.openmeap.protocol.dto.ConnectionOpenResponse) Date(java.util.Date)

Example 4 with ConnectionOpenRequest

use of com.openmeap.protocol.dto.ConnectionOpenRequest in project OpenMEAP by OpenMEAP.

the class AppMgmtClientTest method testRESTOpenConnection.

public void testRESTOpenConnection() throws Exception {
    AppMgmtClientFactory.setDefaultType(RESTAppMgmtClient.class);
    String[] templates = { "xml/connectionResponse-rest-update.json", "xml/connectionResponse-rest-noupdate.json", "xml/connectionResponse.404.text" };
    HttpRequestExecuterFactory.setDefaultType(MockHttpRequestExecuter.class);
    ApplicationManagementService client = AppMgmtClientFactory.newDefault("/nowhere/");
    ConnectionOpenRequest request = new ConnectionOpenRequest();
    request.setApplication(new Application());
    request.getApplication().setInstallation(new ApplicationInstallation());
    request.setSlic(new SLIC());
    // setup the response xml that we'll spoof as though it's from the server
    Hashtable parms = new Hashtable();
    parms.put("AUTH_TOKEN", "auth_token");
    parms.put("UPDATE_TYPE", "required");
    parms.put("UPDATE_URL", "file://none");
    parms.put("STORAGE_NEEDS", String.valueOf(15));
    parms.put("INSTALL_NEEDS", String.valueOf(15));
    parms.put("HASH", "asdf");
    parms.put("HASH_ALG", "MD5");
    parms.put("VERSION_ID", "versionId");
    InputStream inputStream = AppMgmtClientTest.class.getResourceAsStream(templates[0]);
    MockHttpRequestExecuter.setResponseText(Utils.replaceFields(parms, Utils.readInputStream(inputStream, "UTF-8")));
    // setup our request
    SLIC slic = request.getSlic();
    slic.setVersionId("slicVersion");
    Application app = request.getApplication();
    app.setName("appName");
    app.setVersionId("appVersionId");
    ApplicationInstallation appInst = request.getApplication().getInstallation();
    appInst.setUuid("appInstUuid");
    //////////////
    // Verify that a well-formed request will result in a correctly formed response object
    ConnectionOpenResponse response = client.connectionOpen(request);
    Assert.assertTrue(response.getAuthToken().equals("auth_token"));
    Assert.assertTrue(response.getUpdate().getUpdateUrl().equals("file://none"));
    Assert.assertTrue(response.getUpdate().getInstallNeeds().equals(Long.valueOf(16)));
    Assert.assertTrue(response.getUpdate().getStorageNeeds().equals(Long.valueOf(15)));
    Assert.assertTrue(response.getUpdate().getVersionIdentifier().equals("versionId"));
    Assert.assertTrue(response.getUpdate().getHash().getValue().equals("asdf"));
    Assert.assertTrue(response.getUpdate().getHash().getAlgorithm().equals(HashAlgorithm.MD5));
    //////////////
    // Verify that the xml, sans the update header, will generate a response with no update
    MockHttpRequestExecuter.setResponseText(Utils.replaceFields(parms, Utils.readInputStream(AppMgmtClientTest.class.getResourceAsStream(templates[1]), "UTF-8")));
    response = client.connectionOpen(request);
    Assert.assertTrue(response.getAuthToken().equals("auth_token"));
    Assert.assertTrue(response.getUpdate() == null);
    //////////////
    // Verify that a non-200 will result in a WebServiceException
    Boolean thrown = Boolean.FALSE;
    Exception e = null;
    // 304 is not 200
    MockHttpRequestExecuter.setResponseCode(304);
    try {
        response = client.connectionOpen(request);
    } catch (Exception wse) {
        e = wse;
        thrown = Boolean.TRUE;
    }
    Assert.assertTrue(thrown.booleanValue() && e instanceof WebServiceException);
    //////////////
    // Verify that invalid response content will throw an exception
    thrown = Boolean.FALSE;
    e = null;
    MockHttpRequestExecuter.setResponseText(Utils.replaceFields(parms, Utils.readInputStream(AppMgmtClientTest.class.getResourceAsStream(templates[2]), "UTF-8")));
    MockHttpRequestExecuter.setResponseCode(200);
    try {
        response = client.connectionOpen(request);
    } catch (Exception wse) {
        e = wse;
        thrown = Boolean.TRUE;
    }
    Assert.assertTrue(thrown.booleanValue() && e instanceof WebServiceException);
}
Also used : WebServiceException(com.openmeap.protocol.WebServiceException) Hashtable(java.util.Hashtable) InputStream(java.io.InputStream) ConnectionOpenRequest(com.openmeap.protocol.dto.ConnectionOpenRequest) WebServiceException(com.openmeap.protocol.WebServiceException) SLIC(com.openmeap.protocol.dto.SLIC) ApplicationInstallation(com.openmeap.protocol.dto.ApplicationInstallation) ConnectionOpenResponse(com.openmeap.protocol.dto.ConnectionOpenResponse) ApplicationManagementService(com.openmeap.protocol.ApplicationManagementService) Application(com.openmeap.protocol.dto.Application)

Example 5 with ConnectionOpenRequest

use of com.openmeap.protocol.dto.ConnectionOpenRequest 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)

Aggregations

ConnectionOpenRequest (com.openmeap.protocol.dto.ConnectionOpenRequest)6 SLIC (com.openmeap.protocol.dto.SLIC)4 Application (com.openmeap.protocol.dto.Application)3 ApplicationInstallation (com.openmeap.protocol.dto.ApplicationInstallation)3 ConnectionOpenResponse (com.openmeap.protocol.dto.ConnectionOpenResponse)3 ApplicationManagementService (com.openmeap.protocol.ApplicationManagementService)2 WebServiceException (com.openmeap.protocol.WebServiceException)2 Error (com.openmeap.protocol.dto.Error)1 Result (com.openmeap.protocol.dto.Result)1 InputStream (java.io.InputStream)1 Date (java.util.Date)1 Hashtable (java.util.Hashtable)1 Before (org.junit.Before)1 WebApplicationContext (org.springframework.web.context.WebApplicationContext)1