Search in sources :

Example 91 with ObjectMessage

use of javax.jms.ObjectMessage in project rocketmq-externals by apache.

the class MessageConverter method getContentFromJms.

public static byte[] getContentFromJms(javax.jms.Message jmsMessage) throws Exception {
    byte[] content;
    if (jmsMessage instanceof TextMessage) {
        if (StringUtils.isEmpty(((TextMessage) jmsMessage).getText())) {
            throw new IllegalArgumentException("Message body length is zero");
        }
        content = MsgConvertUtil.string2Bytes(((TextMessage) jmsMessage).getText(), Charsets.UTF_8.toString());
    } else if (jmsMessage instanceof ObjectMessage) {
        if (((ObjectMessage) jmsMessage).getObject() == null) {
            throw new IllegalArgumentException("Message body length is zero");
        }
        content = MsgConvertUtil.objectSerialize(((ObjectMessage) jmsMessage).getObject());
    } else if (jmsMessage instanceof BytesMessage) {
        JmsBytesMessage bytesMessage = (JmsBytesMessage) jmsMessage;
        if (bytesMessage.getBodyLength() == 0) {
            throw new IllegalArgumentException("Message body length is zero");
        }
        content = bytesMessage.getData();
    } else {
        throw new IllegalArgumentException("Unknown message type " + jmsMessage.getJMSType());
    }
    return content;
}
Also used : JmsBytesMessage(org.apache.rocketmq.jms.domain.message.JmsBytesMessage) JmsObjectMessage(org.apache.rocketmq.jms.domain.message.JmsObjectMessage) ObjectMessage(javax.jms.ObjectMessage) JmsBytesMessage(org.apache.rocketmq.jms.domain.message.JmsBytesMessage) BytesMessage(javax.jms.BytesMessage) JmsTextMessage(org.apache.rocketmq.jms.domain.message.JmsTextMessage) TextMessage(javax.jms.TextMessage)

Example 92 with ObjectMessage

use of javax.jms.ObjectMessage in project ArachneCentralAPI by OHDSI.

the class BaseDataNodeMessageServiceImpl method getDataList.

@Override
@PreAuthorize("hasPermission(#dataNode, " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).IMPORT_FROM_DATANODE)")
public <T extends CommonEntityDTO> List<T> getDataList(DN dataNode, CommonAnalysisType analysisType) throws JMSException {
    Long waitForResponse = messagingTimeout;
    Long messageLifeTime = messagingTimeout;
    // Get all Atlases available in user's tenant
    List<IAtlas> atlasList = atlasService.findAll().stream().filter(a -> a.getVersion() != null).collect(Collectors.toList());
    String baseQueue = MessagingUtils.EntitiesList.getBaseQueue(dataNode);
    ProducerConsumerTemplate exchangeTpl = new ProducerConsumerTemplate(destinationResolver, new CommonEntityRequestObject(atlasList.stream().map(IAtlas::getId).collect(Collectors.toList()), analysisType), baseQueue, waitForResponse, messageLifeTime);
    ObjectMessage responseMessage = jmsTemplate.execute(exchangeTpl, true);
    List<T> entityList = (List<T>) responseMessage.getObject();
    Map<Long, IAtlas> atlasMap = atlasList.stream().collect(Collectors.toMap(IAtlas::getId, a -> a));
    entityList.forEach(e -> e.setName(atlasMap.get(e.getOriginId()).getName() + ": " + e.getName()));
    return entityList;
}
Also used : CommonListEntityRequest(com.odysseusinc.arachne.commons.api.v1.dto.CommonListEntityRequest) AtlasService(com.odysseusinc.arachne.portal.service.AtlasService) ConsumerTemplate(com.odysseusinc.arachne.commons.service.messaging.ConsumerTemplate) IAtlas(com.odysseusinc.arachne.portal.model.IAtlas) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ObjectMessage(javax.jms.ObjectMessage) CommonAnalysisType(com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisType) Collectors(java.util.stream.Collectors) JMSException(javax.jms.JMSException) CommonEntityDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityDTO) LinkedHashMap(java.util.LinkedHashMap) Value(org.springframework.beans.factory.annotation.Value) CommonEntityRequestObject(com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityRequestObject) List(java.util.List) DataNode(com.odysseusinc.arachne.portal.model.DataNode) Map(java.util.Map) JmsTemplate(org.springframework.jms.core.JmsTemplate) ProducerConsumerTemplate(com.odysseusinc.arachne.commons.service.messaging.ProducerConsumerTemplate) MessagingUtils.getRequestQueueName(com.odysseusinc.arachne.commons.service.messaging.MessagingUtils.getRequestQueueName) DestinationResolver(org.springframework.jms.support.destination.DestinationResolver) CommonEntityRequestObject(com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityRequestObject) ObjectMessage(javax.jms.ObjectMessage) List(java.util.List) ProducerConsumerTemplate(com.odysseusinc.arachne.commons.service.messaging.ProducerConsumerTemplate) IAtlas(com.odysseusinc.arachne.portal.model.IAtlas) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 93 with ObjectMessage

use of javax.jms.ObjectMessage in project ArachneCentralAPI by OHDSI.

the class BaseDataNodeMessageServiceImpl method getListRequest.

@Override
public CommonListEntityRequest getListRequest(DN dataNode) throws JMSException {
    Map<String, CommonEntityRequestObject> requestMap = new LinkedHashMap<>();
    String requestQueue = getRequestQueueName(MessagingUtils.EntitiesList.getBaseQueue(dataNode));
    ConsumerTemplate consumerTpl = new ConsumerTemplate(destinationResolver, requestQueue, // Give some time for case when new connection to a broker is established
    1000L);
    while (true) {
        ObjectMessage requestMessage = jmsTemplate.execute(consumerTpl, true);
        if (requestMessage == null) {
            break;
        }
        requestMap.put(requestMessage.getJMSCorrelationID(), (CommonEntityRequestObject) requestMessage.getObject());
    }
    return new CommonListEntityRequest(requestMap);
}
Also used : ConsumerTemplate(com.odysseusinc.arachne.commons.service.messaging.ConsumerTemplate) ProducerConsumerTemplate(com.odysseusinc.arachne.commons.service.messaging.ProducerConsumerTemplate) CommonEntityRequestObject(com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityRequestObject) ObjectMessage(javax.jms.ObjectMessage) CommonListEntityRequest(com.odysseusinc.arachne.commons.api.v1.dto.CommonListEntityRequest) LinkedHashMap(java.util.LinkedHashMap)

Example 94 with ObjectMessage

use of javax.jms.ObjectMessage in project ArachneCentralAPI by OHDSI.

the class BaseAnalysisController method getEntityFiles.

public List<MultipartFile> getEntityFiles(DataReferenceDTO entityReference, DataNode dataNode, CommonAnalysisType entityType) throws JMSException, IOException, URISyntaxException {
    Long waitForResponse = datanodeImportTimeout;
    Long messageLifeTime = datanodeImportTimeout;
    String baseQueue = MessagingUtils.Entities.getBaseQueue(dataNode);
    CommonEntityRequestDTO request = new CommonEntityRequestDTO(entityReference.getEntityGuid(), entityType);
    ProducerConsumerTemplate exchangeTpl = new ProducerConsumerTemplate(destinationResolver, request, baseQueue, waitForResponse, messageLifeTime);
    final ObjectMessage responseMessage = jmsTemplate.execute(exchangeTpl, true);
    if (responseMessage == null) {
        String message = String.format(ENTITY_IS_NOT_AVAILABLE, entityType.getTitle(), entityReference.getEntityGuid(), entityReference.getDataNodeId());
        throw new ServiceNotAvailableException(message);
    }
    final List<ImportedFile> importedFiles = (List<ImportedFile>) responseMessage.getObject();
    boolean hasAnalysisRunner = hasAnalysisRunner(importedFiles);
    if (entityType.equals(CommonAnalysisType.ESTIMATION) && !hasAnalysisRunner) {
        return importService.processEstimation(importedFiles);
    }
    List<MultipartFile> files = importedFiles.stream().map(file -> conversionService.convert(file, MockMultipartFile.class)).collect(Collectors.toList());
    if (!hasAnalysisRunner) {
        files.addAll(generateAnalysisFiles(entityType));
    }
    return files;
}
Also used : ServiceNotAvailableException(com.odysseusinc.arachne.portal.exception.ServiceNotAvailableException) RequestParam(org.springframework.web.bind.annotation.RequestParam) Arrays(java.util.Arrays) UploadFilesDTO(com.odysseusinc.arachne.portal.api.v1.dto.UploadFilesDTO) Valid(javax.validation.Valid) CommentUtils.getRecentCommentables(com.odysseusinc.arachne.portal.util.CommentUtils.getRecentCommentables) AnalysisLockDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisLockDTO) Analysis(com.odysseusinc.arachne.portal.model.Analysis) Commentable(com.odysseusinc.arachne.portal.api.v1.dto.Commentable) Sort(org.springframework.data.domain.Sort) ImportedFile(com.odysseusinc.arachne.portal.util.ImportedFile) Resource(org.springframework.core.io.Resource) MessagingUtils(com.odysseusinc.arachne.portal.service.messaging.MessagingUtils) FieldError(org.springframework.validation.FieldError) Set(java.util.Set) AnalysisFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisFileDTO) Page(org.springframework.data.domain.Page) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) IUser(com.odysseusinc.arachne.portal.model.IUser) IOUtils(org.apache.commons.io.IOUtils) SimpMessagingTemplate(org.springframework.messaging.simp.SimpMessagingTemplate) Stream(java.util.stream.Stream) AnalysisFilesSavingService(com.odysseusinc.arachne.portal.service.analysis.AnalysisFilesSavingService) VALIDATION_ERROR(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.VALIDATION_ERROR) DataReference(com.odysseusinc.arachne.portal.model.DataReference) BindingResult(org.springframework.validation.BindingResult) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) RequestBody(org.springframework.web.bind.annotation.RequestBody) SubmissionInsightDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionInsightDTO) NO_ERROR(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.NO_ERROR) StreamSupport(java.util.stream.StreamSupport) CommonEntityRequestDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityRequestDTO) GenericConversionService(org.springframework.core.convert.support.GenericConversionService) IOException(java.io.IOException) HttpUtils.putFileContentToResponse(com.odysseusinc.arachne.portal.util.HttpUtils.putFileContentToResponse) SubmissionInsightUpdateDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionInsightUpdateDTO) DataReferenceDTO(com.odysseusinc.arachne.portal.api.v1.dto.DataReferenceDTO) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) UpdateNotificationDTO(com.odysseusinc.arachne.portal.api.v1.dto.UpdateNotificationDTO) AnalysisUpdateDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisUpdateDTO) PathVariable(org.springframework.web.bind.annotation.PathVariable) AnalysisUnlockRequestDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisUnlockRequestDTO) Date(java.util.Date) URISyntaxException(java.net.URISyntaxException) PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) LoggerFactory(org.slf4j.LoggerFactory) ValidationRuntimeException(com.odysseusinc.arachne.portal.exception.ValidationRuntimeException) ApiOperation(io.swagger.annotations.ApiOperation) PutMapping(org.springframework.web.bind.annotation.PutMapping) AnalysisUnlockRequest(com.odysseusinc.arachne.portal.model.AnalysisUnlockRequest) PERMISSION_DENIED(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult.ErrorCode.PERMISSION_DENIED) ToPdfConverter(com.odysseusinc.arachne.portal.service.ToPdfConverter) BaseSubmissionService(com.odysseusinc.arachne.portal.service.submission.BaseSubmissionService) BaseAnalysisService(com.odysseusinc.arachne.portal.service.analysis.BaseAnalysisService) AnalysisDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisDTO) AlreadyExistException(com.odysseusinc.arachne.portal.exception.AlreadyExistException) CommonAnalysisType(com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisType) UUID(java.util.UUID) ShortBaseAnalysisDTO(com.odysseusinc.arachne.portal.api.v1.dto.ShortBaseAnalysisDTO) JMSException(javax.jms.JMSException) Collectors(java.util.stream.Collectors) FileDTO(com.odysseusinc.arachne.portal.api.v1.dto.FileDTO) List(java.util.List) Principal(java.security.Principal) DataReferenceService(com.odysseusinc.arachne.portal.service.DataReferenceService) AnalysisCreateDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisCreateDTO) AnalysisUnlockRequestStatus(com.odysseusinc.arachne.portal.model.AnalysisUnlockRequestStatus) SubmissionGroupDTO(com.odysseusinc.arachne.portal.api.v1.dto.SubmissionGroupDTO) NotUniqueException(com.odysseusinc.arachne.portal.exception.NotUniqueException) FileDtoContentHandler(com.odysseusinc.arachne.portal.api.v1.dto.converters.FileDtoContentHandler) ClassPathResource(org.springframework.core.io.ClassPathResource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ObjectMessage(javax.jms.ObjectMessage) GET(org.springframework.web.bind.annotation.RequestMethod.GET) Submission(com.odysseusinc.arachne.portal.model.Submission) SubmissionGroupSearch(com.odysseusinc.arachne.portal.model.search.SubmissionGroupSearch) ValidationException(com.odysseusinc.arachne.portal.exception.ValidationException) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ModelAttribute(org.springframework.web.bind.annotation.ModelAttribute) HeraclesAnalysisService(com.odysseusinc.arachne.portal.service.analysis.heracles.HeraclesAnalysisService) JmsTemplate(org.springframework.jms.core.JmsTemplate) ProducerConsumerTemplate(com.odysseusinc.arachne.commons.service.messaging.ProducerConsumerTemplate) SubmissionInsight(com.odysseusinc.arachne.portal.model.SubmissionInsight) POST(org.springframework.web.bind.annotation.RequestMethod.POST) UploadFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.UploadFileDTO) DestinationResolver(org.springframework.jms.support.destination.DestinationResolver) ServiceNotAvailableException(com.odysseusinc.arachne.portal.exception.ServiceNotAvailableException) CommentTopic(com.odysseusinc.arachne.portal.model.CommentTopic) Logger(org.slf4j.Logger) DELETE(org.springframework.web.bind.annotation.RequestMethod.DELETE) CommonFilenameUtils(com.odysseusinc.arachne.commons.utils.CommonFilenameUtils) HttpServletResponse(javax.servlet.http.HttpServletResponse) BaseDataNodeService(com.odysseusinc.arachne.portal.service.BaseDataNodeService) PermissionDeniedException(com.odysseusinc.arachne.portal.exception.PermissionDeniedException) OptionDTO(com.odysseusinc.arachne.commons.api.v1.dto.OptionDTO) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) HeraclesAnalysisKind(com.odysseusinc.arachne.portal.service.analysis.heracles.HeraclesAnalysisKind) ConcurrentSkipListSet(java.util.concurrent.ConcurrentSkipListSet) DataNode(com.odysseusinc.arachne.portal.model.DataNode) MultipartFile(org.springframework.web.multipart.MultipartFile) ImportService(com.odysseusinc.arachne.portal.service.ImportService) NotEmptyException(com.odysseusinc.arachne.portal.exception.NotEmptyException) SubmissionInsightService(com.odysseusinc.arachne.portal.service.submission.SubmissionInsightService) Collections(java.util.Collections) StringUtils(org.springframework.util.StringUtils) InputStream(java.io.InputStream) CommonEntityRequestDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityRequestDTO) ImportedFile(com.odysseusinc.arachne.portal.util.ImportedFile) ProducerConsumerTemplate(com.odysseusinc.arachne.commons.service.messaging.ProducerConsumerTemplate) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) ObjectMessage(javax.jms.ObjectMessage) ArrayList(java.util.ArrayList) List(java.util.List)

Example 95 with ObjectMessage

use of javax.jms.ObjectMessage in project ArachneCentralAPI by OHDSI.

the class BaseDataNodeMessagingController method getEntityRequests.

@ApiOperation("List all EntityRequests")
@RequestMapping(value = "/api/v1/data-nodes/entities", method = GET)
public List<CommonEntityRequestDTO> getEntityRequests(Principal principal) throws PermissionDeniedException, JMSException {
    DataNode dataNode = getDatanode(principal);
    final String requestQueue = getRequestQueueName(MessagingUtils.Entities.getBaseQueue(dataNode));
    ConsumerTemplate consumerTpl = new ConsumerTemplate(destinationResolver, requestQueue, // Give some time for case when new connection to a broker is established
    1000L);
    List<CommonEntityRequestDTO> cohortRequests = new ArrayList<>();
    while (true) {
        ObjectMessage requestMessage = jmsTemplate.execute(consumerTpl, true);
        if (requestMessage == null) {
            break;
        }
        final CommonEntityRequestDTO cohortRequest = (CommonEntityRequestDTO) requestMessage.getObject();
        cohortRequest.setId(requestMessage.getJMSCorrelationID());
        cohortRequests.add(cohortRequest);
    }
    return cohortRequests;
}
Also used : ConsumerTemplate(com.odysseusinc.arachne.commons.service.messaging.ConsumerTemplate) DataNode(com.odysseusinc.arachne.portal.model.DataNode) ObjectMessage(javax.jms.ObjectMessage) CommonEntityRequestDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonEntityRequestDTO) ArrayList(java.util.ArrayList) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ObjectMessage (javax.jms.ObjectMessage)227 Test (org.junit.Test)85 JMSException (javax.jms.JMSException)82 Session (javax.jms.Session)79 Message (javax.jms.Message)70 MessageProducer (javax.jms.MessageProducer)64 MessageConsumer (javax.jms.MessageConsumer)52 Connection (javax.jms.Connection)46 Queue (javax.jms.Queue)40 TextMessage (javax.jms.TextMessage)38 BytesMessage (javax.jms.BytesMessage)30 Destination (javax.jms.Destination)29 MapMessage (javax.jms.MapMessage)28 AbstractServiceComponentAgentFunctionalIntegrationTest (com.hack23.cia.service.component.agent.impl.AbstractServiceComponentAgentFunctionalIntegrationTest)25 StreamMessage (javax.jms.StreamMessage)21 HashMap (java.util.HashMap)18 Serializable (java.io.Serializable)17 Map (java.util.Map)16 ArrayList (java.util.ArrayList)13 QueueSession (javax.jms.QueueSession)11