Example usage for javax.xml.bind JAXBElement getValue

List of usage examples for javax.xml.bind JAXBElement getValue

Introduction

In this page you can find the example usage for javax.xml.bind JAXBElement getValue.

Prototype

public T getValue() 

Source Link

Document

Return the content model and attribute values for this element.

See #isNil() for a description of a property constraint when this value is null

Usage

From source file:com.microsoft.exchange.impl.ExchangeResponseUtilsImpl.java

@Override
public Pair<Set<ItemIdType>, Integer> parseFindItemIdResponse(FindItemResponse response) {

    confirmSuccess(response);/*w ww .j  av  a 2s.co m*/
    Set<ItemIdType> foundItemIds = new HashSet<ItemIdType>();
    Integer nextOffset = -1;
    ArrayOfResponseMessagesType findItemResponseMessages = response.getResponseMessages();
    List<JAXBElement<? extends ResponseMessageType>> itemResponseMessages = findItemResponseMessages
            .getCreateItemResponseMessagesAndDeleteItemResponseMessagesAndGetItemResponseMessages();
    for (JAXBElement<? extends ResponseMessageType> element : itemResponseMessages) {
        FindItemResponseMessageType itemType = (FindItemResponseMessageType) element.getValue();
        FindItemParentType rootFolder = itemType.getRootFolder();

        Boolean includesLastItemInRange = rootFolder.isIncludesLastItemInRange();
        Integer totalItemsInView = rootFolder.getTotalItemsInView();

        if (!includesLastItemInRange) {
            nextOffset = rootFolder.getIndexedPagingOffset();
        }
        ArrayOfRealItemsType items = rootFolder.getItems();
        List<ItemType> calendarItems = items.getItemsAndMessagesAndCalendarItems();
        for (ItemType it : calendarItems) {
            foundItemIds.add(it.getItemId());
        }

        log.info("parseFindItemIdResponse: foundItems=" + foundItemIds.size() + ", totalItemsInview="
                + totalItemsInView + " , nextOffset" + nextOffset + ", includesLast="
                + includesLastItemInRange);
    }

    Pair<Set<ItemIdType>, Integer> pair = Pair.of(foundItemIds, nextOffset);
    return pair;
}

From source file:com.microsoft.exchange.impl.ExchangeResponseUtilsImpl.java

@Override
public Set<BaseFolderType> parseGetFolderResponse(GetFolderResponse getFolderResponse) {
    confirmSuccess(getFolderResponse);//from www  . j  a v  a2 s. c o  m
    Set<BaseFolderType> folders = new HashSet<BaseFolderType>();
    ArrayOfResponseMessagesType responseMessages = getFolderResponse.getResponseMessages();
    List<JAXBElement<? extends ResponseMessageType>> getFolderResponseMessages = responseMessages
            .getCreateItemResponseMessagesAndDeleteItemResponseMessagesAndGetItemResponseMessages();
    for (JAXBElement<? extends ResponseMessageType> responseMessage : getFolderResponseMessages) {
        FolderInfoResponseMessageType folderInfo = (FolderInfoResponseMessageType) responseMessage.getValue();
        List<BaseFolderType> f = folderInfo.getFolders().getFoldersAndCalendarFoldersAndContactsFolders();
        if (!CollectionUtils.isEmpty(f)) {
            folders.addAll(f);
        }
    }
    return folders;
}

From source file:com.microsoft.exchange.impl.ExchangeResponseUtilsImpl.java

@Override
public List<BaseFolderType> parseFindFolderResponse(FindFolderResponse findFolderResponse) {
    ArrayOfResponseMessagesType findFolderResponseMessages = findFolderResponse.getResponseMessages();
    List<JAXBElement<? extends ResponseMessageType>> folderItemResponseMessages = findFolderResponseMessages
            .getCreateItemResponseMessagesAndDeleteItemResponseMessagesAndGetItemResponseMessages();
    for (JAXBElement<? extends ResponseMessageType> responseElement : folderItemResponseMessages) {
        FindFolderResponseMessageType itemType = (FindFolderResponseMessageType) responseElement.getValue();
        if (null != itemType && null != itemType.getRootFolder()
                && null != itemType.getRootFolder().getFolders() && null != itemType.getRootFolder()
                        .getFolders().getFoldersAndCalendarFoldersAndContactsFolders()) {
            FindFolderParentType rootFolder = itemType.getRootFolder();
            ArrayOfFoldersType folders = rootFolder.getFolders();
            return folders.getFoldersAndCalendarFoldersAndContactsFolders();
        }/* w w  w .  j  a v  a 2 s. c  o m*/
    }
    return null;
}

From source file:com.microsoft.exchange.impl.ExchangeResponseUtilsImpl.java

@Override
public Set<String> parseResolveNamesResponse(ResolveNamesResponse response) {
    Set<String> addresses = new HashSet<String>();
    if (confirmSuccessOrWarning(response)) {
        ArrayOfResponseMessagesType arrayOfResponseMessagesType = response.getResponseMessages();
        List<JAXBElement<? extends ResponseMessageType>> responseMessagesList = arrayOfResponseMessagesType
                .getCreateItemResponseMessagesAndDeleteItemResponseMessagesAndGetItemResponseMessages();
        for (JAXBElement<? extends ResponseMessageType> element : responseMessagesList) {
            ResolveNamesResponseMessageType rnrmt = (ResolveNamesResponseMessageType) element.getValue();
            ArrayOfResolutionType arrayOfResolutionType = rnrmt.getResolutionSet();
            List<ResolutionType> resolutions = arrayOfResolutionType.getResolutions();
            for (ResolutionType resolution : resolutions) {
                ContactItemType contact = resolution.getContact();
                EmailAddressDictionaryType emailAddresses = contact.getEmailAddresses();
                List<EmailAddressDictionaryEntryType> entries = emailAddresses.getEntries();
                for (EmailAddressDictionaryEntryType entry : entries) {
                    String value = entry.getValue();
                    if (StringUtils.isNotBlank(value)) {
                        value = value.toLowerCase();
                        value = StringUtils.removeStartIgnoreCase(value, "smtp:");
                        addresses.add(value);
                    }//from   w  w w.  j  a v a2  s  . com
                }
            }
        }
    }
    return addresses;
}

From source file:com.microsoft.exchange.impl.ExchangeResponseUtilsImpl.java

protected Set<FolderIdType> parseFolderResponse(BaseResponseMessageType response) {
    confirmSuccess(response);/*from  w  ww.j a  v a  2s.  co m*/
    Set<FolderIdType> folderIds = new HashSet<FolderIdType>();
    ArrayOfResponseMessagesType responseMessages = response.getResponseMessages();
    List<JAXBElement<? extends ResponseMessageType>> createItemResponseMessages = responseMessages
            .getCreateItemResponseMessagesAndDeleteItemResponseMessagesAndGetItemResponseMessages();
    for (JAXBElement<? extends ResponseMessageType> responeElement : createItemResponseMessages) {
        FolderInfoResponseMessageType itemInfo = (FolderInfoResponseMessageType) responeElement.getValue();
        ArrayOfFoldersType folders = itemInfo.getFolders();
        if (null != folders
                && !CollectionUtils.isEmpty(folders.getFoldersAndCalendarFoldersAndContactsFolders())) {
            List<BaseFolderType> foldersAndCalendarFoldersAndContactsFolders = folders
                    .getFoldersAndCalendarFoldersAndContactsFolders();
            for (BaseFolderType bFolderIdType : foldersAndCalendarFoldersAndContactsFolders) {
                FolderIdType folderId = bFolderIdType.getFolderId();
                log.trace(" folderName= " + bFolderIdType.getDisplayName() + ", folderId=" + folderId);
                folderIds.add(folderId);
            }
        } else {
            log.error("No folders returned");
        }
    }
    return folderIds;
}

From source file:com.microsoft.exchange.impl.ExchangeResponseUtilsImpl.java

@Override
public boolean confirmSuccess(BaseResponseMessageType response) {
    Boolean success = null;/*from  w w  w  .  j av  a  2s  . c  o m*/

    ArrayOfResponseMessagesType messages = response.getResponseMessages();
    List<JAXBElement<? extends ResponseMessageType>> inner = messages
            .getCreateItemResponseMessagesAndDeleteItemResponseMessagesAndGetItemResponseMessages();
    for (JAXBElement<? extends ResponseMessageType> innerResponse : inner) {
        if (success == null) {
            success = ResponseCodeType.NO_ERROR.equals(innerResponse.getValue().getResponseCode());
        } else {
            success = success && ResponseCodeType.NO_ERROR.equals(innerResponse.getValue().getResponseCode());
        }
        if (!success || !ResponseCodeType.NO_ERROR.equals(innerResponse.getValue().getResponseCode())) {
            ResponseCodeType responseCode = innerResponse.getValue().getResponseCode();
            String err = parseInnerResponse(innerResponse);

            if (ResponseCodeType.ERROR_INTERNAL_SERVER_ERROR.equals(responseCode)
                    || ResponseCodeType.ERROR_INTERNAL_SERVER_TRANSIENT_ERROR.equals(responseCode)) {
                //TODO recover (switch Credentials)
            }

            if (ResponseCodeType.ERROR_TIMEOUT_EXPIRED.equals(responseCode)) {
                throw new ExchangeTimeoutRuntimeException(err);
            }

            if (ResponseCodeType.ERROR_CANNOT_DELETE_OBJECT.equals(responseCode)) {
                throw new ExchangeCannotDeleteRuntimeException(err);
            }

            if (ResponseCodeType.ERROR_ITEM_NOT_FOUND.equals(responseCode)) {
                throw new ExchangeItemNotFoundRuntimeException(err);
            }

            if (ResponseCodeType.ERROR_EXCEEDED_FIND_COUNT_LIMIT.equals(responseCode)) {
                throw new ExchangeExceededFindCountLimitRuntimeException(err);
            }

            throw new ExchangeRuntimeException(err);
        }
    }
    return success;
}

From source file:com.evolveum.midpoint.testing.model.client.sample.AbstractTestForExchangeConnector.java

protected static <T> T unmarshallFile(File file) throws JAXBException, FileNotFoundException {
    JAXBContext jc = ModelClientUtil.instantiateJaxbContext();
    Unmarshaller unmarshaller = jc.createUnmarshaller();

    InputStream is = null;//from   w  w  w. j a v  a2 s  . c o  m
    JAXBElement<T> element = null;
    try {
        is = new FileInputStream(file);
        element = (JAXBElement<T>) unmarshaller.unmarshal(is);
    } finally {
        if (is != null) {
            IOUtils.closeQuietly(is);
        }
    }
    if (element == null) {
        return null;
    }
    return element.getValue();
}

From source file:com.helger.peppol.bdxrclient.BDXRClientReadOnly.java

/**
 * Gets a signed service metadata object given by its service group id and its
 * document type. This is a specification compliant method.
 *
 * @param aServiceGroupID//from   w  w w.j  a v a 2 s .  co m
 *        The service group id of the service metadata to get. May not be
 *        <code>null</code>.
 * @param aDocumentTypeID
 *        The document type of the service metadata to get. May not be
 *        <code>null</code>.
 * @return A signed service metadata object. Never <code>null</code>.
 * @throws SMPClientException
 *         in case something goes wrong
 * @throws SMPClientUnauthorizedException
 *         A HTTP Forbidden was received, should not happen.
 * @throws SMPClientNotFoundException
 *         The service group id or document type did not exist.
 * @throws SMPClientBadRequestException
 *         The request was not well formed.
 * @see #getServiceRegistrationOrNull(IParticipantIdentifier,
 *      IDocumentTypeIdentifier)
 */
@Nonnull
public SignedServiceMetadataType getServiceRegistration(@Nonnull final IParticipantIdentifier aServiceGroupID,
        @Nonnull final IDocumentTypeIdentifier aDocumentTypeID) throws SMPClientException {
    ValueEnforcer.notNull(aServiceGroupID, "ServiceGroupID");
    ValueEnforcer.notNull(aDocumentTypeID, "DocumentTypeID");

    try {
        final String sURI = m_sSMPHost + IdentifierHelper.getIdentifierURIPercentEncoded(aServiceGroupID)
                + "/services/" + IdentifierHelper.getIdentifierURIPercentEncoded(aDocumentTypeID);
        Request aRequest = Request.Get(sURI);
        SignedServiceMetadataType aMetadata = executeRequest(aRequest).handleResponse(
                SMPHttpResponseHandlerSigned.create(new BDXRMarshallerSignedServiceMetadataType()));

        // If the Redirect element is present, then follow 1 redirect.
        if (aMetadata.getServiceMetadata() != null && aMetadata.getServiceMetadata().getRedirect() != null) {
            final RedirectType aRedirect = aMetadata.getServiceMetadata().getRedirect();

            // Follow the redirect
            s_aLogger.info("Following a redirect from '" + sURI + "' to '" + aRedirect.getHref() + "'");
            aRequest = Request.Get(aRedirect.getHref());
            aMetadata = executeRequest(aRequest).handleResponse(
                    SMPHttpResponseHandlerSigned.create(new BDXRMarshallerSignedServiceMetadataType()));

            // Check that the certificateUID is correct.
            boolean bCertificateSubjectFound = false;
            outer: for (final Object aObj : aMetadata.getSignature().getKeyInfo().getContent()) {
                final Object aInfoValue = ((JAXBElement<?>) aObj).getValue();
                if (aInfoValue instanceof X509DataType) {
                    final X509DataType aX509Data = (X509DataType) aInfoValue;
                    for (final Object aX509Obj : aX509Data.getX509IssuerSerialOrX509SKIOrX509SubjectName()) {
                        final JAXBElement<?> aX509element = (JAXBElement<?>) aX509Obj;
                        // Find the first subject (of type string)
                        if (aX509element.getValue() instanceof String) {
                            final String sSubject = (String) aX509element.getValue();
                            if (!aRedirect.getCertificateUID().equals(sSubject)) {
                                throw new SMPClientException(
                                        "The certificate UID of the redirect did not match the certificate subject. Subject is '"
                                                + sSubject + "'. Required certificate UID is '"
                                                + aRedirect.getCertificateUID() + "'");
                            }
                            bCertificateSubjectFound = true;
                            break outer;
                        }
                    }
                }
            }

            if (!bCertificateSubjectFound)
                throw new SMPClientException("The X509 certificate did not contain a certificate subject.");
        }
        return aMetadata;
    } catch (final Exception ex) {
        throw getConvertedException(ex);
    }
}

From source file:com.microsoft.exchange.integration.AbstractIntegrationTest.java

/**
 * Create a single {@link CalendarItemType} and submit with {@link ExchangeWebServicesClient#createItem(CreateItem)}.
 * Then attempt to update the item with {@link ExchangeWebServices#updateItem(com.microsoft.exchange.messages.UpdateItem)}.
 * //  www.  j  a va 2s. c om
 * @throws JAXBException 
 */
@Test
public void testUpdateCalendarItemChangeLocation() throws JAXBException {
    NonEmptyArrayOfBaseItemIdsType createdIds = new NonEmptyArrayOfBaseItemIdsType();
    try {
        initializeCredentials();

        CalendarItemType calendarItem = new CalendarItemType();
        final Date start = DateHelp.parseDateTimePhrase("20121217-1200");
        final Date end = DateHelp.parseDateTimePhrase("20121217-1300");

        calendarItem.setStart(DateHelp.convertDateToXMLGregorianCalendar(start));
        calendarItem.setEnd(DateHelp.convertDateToXMLGregorianCalendar(end));
        calendarItem.setSubject("integration test: testCreateCalendarItem");
        calendarItem.setLocation("test location");
        BodyType body = new BodyType();
        body.setBodyType(BodyTypeType.TEXT);
        body.setValue("test ran at " + new Date());
        calendarItem.setBody(body);

        CreateItem request = new CreateItem();
        request.setSendMeetingInvitations(CalendarItemCreateOrDeleteOperationType.SEND_TO_ALL_AND_SAVE_COPY);

        NonEmptyArrayOfAllItemsType arrayOfItems = new NonEmptyArrayOfAllItemsType();
        arrayOfItems.getItemsAndMessagesAndCalendarItems().add(calendarItem);
        request.setItems(arrayOfItems);
        DistinguishedFolderIdType folder = new DistinguishedFolderIdType();
        folder.setId(DistinguishedFolderIdNameType.CALENDAR);
        TargetFolderIdType target = new TargetFolderIdType();
        target.setDistinguishedFolderId(folder);
        request.setSavedItemFolderId(target);

        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        CreateItemResponse response = ewsClient.createItem(request);
        stopWatch.stop();
        Assert.assertNotNull(response);
        String captured = capture(response);
        log.debug("CreateItem request (1 CalendarItem) completed in " + stopWatch + ", response: " + captured);

        ArrayOfResponseMessagesType responseMessages = response.getResponseMessages();
        Assert.assertNotNull(responseMessages);
        Assert.assertEquals(1, responseMessages
                .getCreateItemResponseMessagesAndDeleteItemResponseMessagesAndGetItemResponseMessages().size());
        JAXBElement<? extends ResponseMessageType> m = responseMessages
                .getCreateItemResponseMessagesAndDeleteItemResponseMessagesAndGetItemResponseMessages().get(0);
        Assert.assertEquals(ResponseCodeType.NO_ERROR, m.getValue().getResponseCode());

        ItemInfoResponseMessageType itemType = (ItemInfoResponseMessageType) m.getValue();
        ArrayOfRealItemsType itemArray = itemType.getItems();
        ItemType item = itemArray.getItemsAndMessagesAndCalendarItems().get(0);
        createdIds.getItemIdsAndOccurrenceItemIdsAndRecurringMasterItemIds().add(item.getItemId());

        // leaf
        CalendarItemType updatedItem = new CalendarItemType();
        updatedItem.setLocation("new location from testUpdateCalendarItem");
        // 1: parent of leaf
        SetItemFieldType changeDescription = new SetItemFieldType();
        PathToUnindexedFieldType path = new PathToUnindexedFieldType();

        path.setFieldURI(UnindexedFieldURIType.CALENDAR_LOCATION);
        changeDescription.setPath(objectFactoryCreatePath(path));
        changeDescription.setCalendarItem(updatedItem);

        // 2: parent of 1
        NonEmptyArrayOfItemChangeDescriptionsType updates = new NonEmptyArrayOfItemChangeDescriptionsType();
        updates.getAppendToItemFieldsAndSetItemFieldsAndDeleteItemFields().add(changeDescription);
        // 3: parent of 2
        ItemChangeType change = new ItemChangeType();
        change.setItemId(item.getItemId());
        change.setUpdates(updates);
        // 4: parent of 3
        NonEmptyArrayOfItemChangesType changes = new NonEmptyArrayOfItemChangesType();
        changes.getItemChanges().add(change);

        UpdateItem updateRequest = new UpdateItem();
        updateRequest
                .setSendMeetingInvitationsOrCancellations(CalendarItemUpdateOperationType.SEND_ONLY_TO_CHANGED);
        // conflict resolution is required
        updateRequest.setConflictResolution(ConflictResolutionType.AUTO_RESOLVE);
        updateRequest.setItemChanges(changes);

        log.debug("sending UpdateItem request: " + capture(updateRequest));
        UpdateItemResponse updateResponse = this.ewsClient.updateItem(updateRequest);
        captured = capture(updateResponse);
        log.debug("UpdateItem request (1 CalendarItem) completed, response: " + captured);
        ArrayOfResponseMessagesType updateMessages = updateResponse.getResponseMessages();
        Assert.assertNotNull(updateMessages);
        Assert.assertEquals(1, updateMessages
                .getCreateItemResponseMessagesAndDeleteItemResponseMessagesAndGetItemResponseMessages().size());
        JAXBElement<? extends ResponseMessageType> u = updateMessages
                .getCreateItemResponseMessagesAndDeleteItemResponseMessagesAndGetItemResponseMessages().get(0);
        Assert.assertEquals(ResponseCodeType.NO_ERROR, u.getValue().getResponseCode());
    } finally {
        deleteItems(createdIds);
    }
}

From source file:be.fedict.eid.applet.service.signer.ooxml.OOXMLSignatureFacet.java

private CTTypes getContentTypes() throws IOException, JAXBException {
    URL ooxmlUrl = this.signatureService.getOfficeOpenXMLDocumentURL();
    ZipInputStream zipInputStream = new ZipInputStream(ooxmlUrl.openStream());
    ZipEntry zipEntry;/*from  w  w  w . j a va  2 s .  c om*/
    InputStream contentTypesInputStream = null;
    while (null != (zipEntry = zipInputStream.getNextEntry())) {
        if (!"[Content_Types].xml".equals(zipEntry.getName())) {
            continue;
        }
        contentTypesInputStream = zipInputStream;
        break;
    }
    if (null == contentTypesInputStream) {
        return null;
    }
    JAXBContext jaxbContext = JAXBContext
            .newInstance(be.fedict.eid.applet.service.signer.jaxb.opc.contenttypes.ObjectFactory.class);
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    JAXBElement<CTTypes> contentTypesElement = (JAXBElement<CTTypes>) unmarshaller
            .unmarshal(contentTypesInputStream);
    return contentTypesElement.getValue();
}