public EgovIntegrationMessage sendSync(EgovIntegrationMessage requestMessage, long timeout) { LOG.debug("sendSync called with timeout"); if (requestMessage == null) { LOG.error("requestMessage is null"); throw new IllegalArgumentException(); } LOG.debug("Create MessageSender without Callback"); MessageSender sender = new MessageSender(this, requestMessage, null); LOG.debug("Start MessageSender"); sender.start(); LOG.debug("Wait for the termination of MessageSender"); try { sender.join(timeout); } catch (InterruptedException e) { LOG.debug("MessageSender was interrupted", e); } if (sender.isAlive()) { LOG.debug("MessageSender is alive over 'timeout'."); sender.interrupt(); EgovIntegrationMessageHeader responseHeader = new SimpleMessageHeader(requestMessage.getHeader()); responseHeader.setResultCode(ResultCode.TIME_OUT); return new SimpleMessage(responseHeader); } else { LOG.debug("MessageSender finished to send and receive messages."); return sender.getResponseMessage(); } }
public EgovIntegrationMessage receive(long timeout) { LOG.debug("receive with timeout"); LOG.debug("wait for the termination of MessageSender"); try { sender.join(timeout); } catch (InterruptedException e) { LOG.debug("MessageSender was interrupted", e); } if (sender.isAlive()) { LOG.debug("MessageSender is alive over 'timeout'"); sender.interrupt(); EgovIntegrationMessageHeader responseHeader = new SimpleMessageHeader(sender.requestMessage.getHeader()); responseHeader.setResultCode(ResultCode.TIME_OUT); return new SimpleMessage(responseHeader); } else { LOG.debug("MessageSender finished to send and receive messages."); return sender.getResponseMessage(); } }
@Test public void testCreateRequestMessageSucceeds() throws Exception { EgovWebService service = new EgovWebService("test", 5000, integrationDefinition, echoClient); EgovIntegrationMessage requestMessage = service.createRequestMessage(); assertNotNull(requestMessage); assertNotNull(requestMessage.getHeader()); EgovIntegrationMessageHeader header = requestMessage.getHeader(); assertEquals(integrationDefinition.getId(), header.getIntegrationId()); assertEquals(providerOrganization.getId(), header.getProviderOrganizationId()); assertEquals(providerSystem.getId(), header.getProviderSystemId()); assertEquals(providerService.getId(), header.getProviderServiceId()); assertEquals(consumerOrganization.getId(), header.getConsumerOrganizationId()); assertEquals(consumerSystem.getId(), header.getConsumerSystemId()); assertNotNull(requestMessage.getBody()); assertEquals(0, requestMessage.getBody().size()); }
@Test public void testDoSendSucceeds() throws Exception { EgovWebService service = new EgovWebService("test", 5000, integrationDefinition, echoClient); EgovIntegrationMessage requestMessage = service.createRequestMessage(); EgovIntegrationMessage responseMessage = service.doSend(requestMessage); assertNotNull(responseMessage); assertNotNull(responseMessage.getHeader()); EgovIntegrationMessageHeader requestHeader = requestMessage.getHeader(); EgovIntegrationMessageHeader responseHeader = responseMessage.getHeader(); assertEquals(requestHeader.getIntegrationId(), responseHeader.getIntegrationId()); assertEquals( requestHeader.getProviderOrganizationId(), responseHeader.getProviderOrganizationId()); assertEquals(requestHeader.getProviderSystemId(), responseHeader.getProviderSystemId()); assertEquals(requestHeader.getProviderServiceId(), responseHeader.getProviderServiceId()); assertEquals( requestHeader.getConsumerOrganizationId(), responseHeader.getConsumerOrganizationId()); assertEquals(requestHeader.getConsumerSystemId(), responseHeader.getConsumerSystemId()); assertEquals(requestHeader.getRequestSendTime(), responseHeader.getRequestSendTime()); assertNotNull(responseHeader.getRequestReceiveTime()); assertNotNull(responseHeader.getResponseSendTime()); assertNotNull(responseHeader.getResponseReceiveTime()); assertEquals(ResultCode.OK, responseHeader.getResultCode()); }