use of org.openecard.ws.schema.Status in project open-ecard by ecsec.
the class HTTPBindingTest method testWaitForChange.
/**
* Tests the HttpStatusChangeHandler by sending:
* 1. a get status to get the session identifier
* 2. a get status with session identifier to set up event queue
* 3. after 30 sec. a waitForChange
* 4. after 45 sec. a waitForChange to see if the event queue still exists
* 5. after 70 sec. a waitForChange to see if the event queue has correctly been removed due to timeout
* 6. a waitForChange as POST request
*/
@Test(enabled = !true)
public void testWaitForChange() {
try {
// Request a "get status" with GET and without optional session parameter
URL u = new URL("http", "127.0.0.1", 24727, "/getStatus");
String response = httpRequest(u, false);
Assert.assertNotNull(response);
logger.debug(response);
Status status = (Status) m.unmarshal(m.str2doc(response));
String session = status.getConnectionHandle().get(0).getChannelHandle().getSessionIdentifier();
// Request a "get status" with GET and with optional session parameter
u = new URL("http", "127.0.0.1", 24727, "/getStatus?session=" + session);
response = httpRequest(u, false);
Assert.assertNotNull(response);
logger.debug(response);
Thread.sleep(30 * 1000);
// Request a "waitForChange" with GET
u = new URL("http", "127.0.0.1", 24727, "/waitForChange?session=" + session);
response = httpRequest(u, false);
Assert.assertNotNull(response);
logger.debug(response);
Thread.sleep(45 * 1000);
// Request a "waitForChange" with GET
u = new URL("http", "127.0.0.1", 24727, "/waitForChange?session=" + session);
response = httpRequest(u, false);
Assert.assertNotNull(response);
logger.debug(response);
Thread.sleep(70 * 1000);
// Request a "waitForChange" with GET
u = new URL("http", "127.0.0.1", 24727, "/waitForChange?session=" + session);
response = httpRequest(u, false);
// we expect response code 400, therefore response must be null
Assert.assertNull(response);
// Request a "waitForChange" with POST
// response = httpRequest(u, true);
// we expect response code 405, therefore response must be null
// Assert.assertNull(response);
} catch (Exception e) {
logger.debug(e.getMessage(), e);
Assert.fail();
}
}
use of org.openecard.ws.schema.Status in project open-ecard by ecsec.
the class HTTPBindingTest method testGetStatus.
/**
* Tests the HttpStatusHandler by sending:
* 1. a GET request without optional session parameter
* 2. a GET request with optional session parameter
* 3. a POST request
* 4. a GET request with optional and malformed session parameter
*/
@Test(enabled = !true)
public void testGetStatus() {
try {
// Request a "get status" with GET and without optional session parameter
URL u = new URL("http", "127.0.0.1", 24727, "/getStatus");
String response = httpRequest(u, false);
Assert.assertNotNull(response);
logger.debug(response);
Status status = (Status) m.unmarshal(m.str2doc(response));
String session = status.getConnectionHandle().get(0).getChannelHandle().getSessionIdentifier();
// Request a "get status" with GET and with optional session parameter
u = new URL("http", "127.0.0.1", 24727, "/getStatus?session=" + session);
response = httpRequest(u, false);
Assert.assertNotNull(response);
logger.debug(response);
// Request a "get status" with POST
// response = httpRequest(u, true);
// we expect response code 405, therefore response must be null
// Assert.assertNull(response);
// Request a "get status" with GET and with optional malformed session parameter
u = new URL("http", "127.0.0.1", 24727, "/getStatus?session=");
response = httpRequest(u, false);
// we expect response code 400, therefore response must be null
Assert.assertNull(response);
} catch (Exception e) {
logger.debug(e.getMessage(), e);
Assert.fail();
}
}
use of org.openecard.ws.schema.Status in project open-ecard by ecsec.
the class StatusHandler method handleRequest.
/**
* Handles a Status-Request by returning a status message describing the capabilities if the App.
*
* @param statusRequest Status Request possibly containing a session identifier for event registration.
* @return Status message.
*/
public StatusResponse handleRequest(StatusRequest statusRequest) {
Status status = new Status();
// user agent
StatusType.UserAgent ua = new StatusType.UserAgent();
ua.setName(AppVersion.getName());
ua.setVersionMajor(BigInteger.valueOf(AppVersion.getMajor()));
ua.setVersionMinor(BigInteger.valueOf(AppVersion.getMinor()));
ua.setVersionSubminor(BigInteger.valueOf(AppVersion.getPatch()));
status.setUserAgent(ua);
// API versions
StatusType.SupportedAPIVersions apiVersion = new StatusType.SupportedAPIVersions();
apiVersion.setName("http://www.bsi.bund.de/ecard/api");
apiVersion.setVersionMajor(ECardConstants.ECARD_API_VERSION_MAJOR);
apiVersion.setVersionMinor(ECardConstants.ECARD_API_VERSION_MINOR);
apiVersion.setVersionSubminor(ECardConstants.ECARD_API_VERSION_SUBMINOR);
status.getSupportedAPIVersions().add(apiVersion);
// supported cards
List<CardInfoType> cifs = rec.getCardInfos();
List<StatusType.SupportedCards> supportedCards = getSupportedCards(protocols, cifs);
status.getSupportedCards().addAll(supportedCards);
// supported DID protocols
status.getSupportedDIDProtocols().addAll(protocols);
// TODO: additional features
// add available cards
status.getConnectionHandle().addAll(getCardHandles());
// register session for wait for change
if (statusRequest.hasSessionIdentifier()) {
String sessionIdentifier = statusRequest.getSessionIdentifier();
eventHandler.addQueue(sessionIdentifier);
}
return new StatusResponse(status);
}
Aggregations