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:org.jasig.portlet.blackboardvcportlet.dao.ws.impl.MultimediaWSDaoImpl.java

@Override
public List<BlackboardMultimediaResponse> getRepositoryMultimedias(String creatorId, Long multimediaId,
        String description) {//w ww. j a  v  a2 s  .c o  m
    BlackboardListRepositoryMultimedia request = new ObjectFactory().createBlackboardListRepositoryMultimedia();
    if (creatorId == null && multimediaId == null && description == null) {
        throw new IllegalStateException("You must specify a creator, multimedia ID, or a description");
    }

    if (creatorId != null) {
        request.setCreatorId(creatorId);
    }
    if (multimediaId != null) {
        request.setMultimediaId(multimediaId);
    }

    if (description != null) {
        request.setDescription(description);
    }
    @SuppressWarnings("unchecked")
    final JAXBElement<BlackboardMultimediaResponseCollection> objSessionResponse = (JAXBElement<BlackboardMultimediaResponseCollection>) sasWebServiceOperations
            .marshalSendAndReceiveToSAS("http://sas.elluminate.com/ListRespositoryMultimedia", request);
    return objSessionResponse.getValue().getMultimediaResponses();
}

From source file:cz.lbenda.dataman.db.DbConfig.java

/** Load configuration from given resource from input stream
 * @param reader reader from which is read configuration
 * @param readId flag which inform if newId will be reader from reader or is ignored */
public void load(@Nonnull Reader reader, boolean readId) {
    try {//from w  w w . j a  v  a  2s.c  om
        JAXBContext jc = JAXBContext.newInstance(cz.lbenda.dataman.schema.dataman.ObjectFactory.class);
        Unmarshaller u = jc.createUnmarshaller();
        //noinspection unchecked
        JAXBElement<SessionType> element = (JAXBElement<SessionType>) u.unmarshal(reader);
        //noinspection ConstantConditions
        if (element.getValue() instanceof SessionType) {
            fromSessionType(element.getValue(), readId);
        } else {
            LOG.error("The file doesn't contains single session config");
            throw new RuntimeException("The file doesn't contains single session config");
        }
    } catch (JAXBException e) {
        LOG.error("Problem with read configuration from XML: " + e.toString(), e);
        throw new RuntimeException("Problem with read configuration from XML: " + e.toString(), e);
    }
}

From source file:org.n52.youngs.harvest.PoxCswSource.java

@Override
public Collection<SourceRecord> getRecords(long startPosition, long maxRecords, Report report) {
    log.debug("Requesting {} records from catalog starting at {}", maxRecords, startPosition);
    Collection<SourceRecord> records = Lists.newArrayList();

    HttpEntity entity = createRequest(startPosition, maxRecords);

    try {//from   www  .j  a v  a 2  s  .  co  m
        log.debug("GetRecords request: {}", EntityUtils.toString(entity));

        String response = Request.Post(getEndpoint().toString()).body(entity)
                .addHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_XML.getMimeType())
                .addHeader(HttpHeaders.ACCEPT_CHARSET, Charsets.UTF_8.name()).execute().returnContent()
                .asString(Charsets.UTF_8);
        log.trace("Response: {}", response);
        JAXBElement<GetRecordsResponseType> jaxb_response = unmarshaller
                .unmarshal(new StreamSource(new StringReader(response)), GetRecordsResponseType.class);
        BigInteger numberOfRecordsReturned = jaxb_response.getValue().getSearchResults()
                .getNumberOfRecordsReturned();
        log.debug("Got response with {} records", numberOfRecordsReturned);

        List<Object> nodes = jaxb_response.getValue().getSearchResults().getAny();
        if (!nodes.isEmpty()) {
            log.debug("Found {} \"any\" nodes.", nodes.size());
            nodes.stream().filter(n -> n instanceof Node).map(n -> (Node) n).map(n -> new NodeSourceRecord(n))
                    .forEach(records::add);
        }

        List<JAXBElement<? extends AbstractRecordType>> jaxb_records = jaxb_response.getValue()
                .getSearchResults().getAbstractRecord();
        if (!jaxb_records.isEmpty()) {
            log.debug("Found {} \"AbstractRecordType\" records.", jaxb_records.size());
            DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            jaxb_records.stream().map(type -> {
                return getNode(type, context, db);
            }).filter(Objects::nonNull).map(n -> new NodeSourceRecord(n)).forEach(records::add);
        }
    } catch (IOException | JAXBException | ParserConfigurationException e) {
        log.error("Could not retrieve records from endpoint {}", getEndpoint(), e);
        report.addMessage(String.format("Error retrieving record from endpoint %s: %s", this, e));
    }

    log.debug("Decoded {} records", records.size());
    return records;
}

From source file:be.fedict.eid.applet.service.signer.xps.XPSSignatureVerifier.java

private List<String> getSignatureResourceNames(URL url)
        throws IOException, ParserConfigurationException, SAXException, TransformerException, JAXBException {
    List<String> signatureResourceNames = new LinkedList<String>();
    ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream(url.openStream(), "UTF8", true, true);
    ZipArchiveEntry zipEntry;/*w w w .j av a  2  s .c o m*/
    while (null != (zipEntry = zipInputStream.getNextZipEntry())) {
        if ("_rels/.rels".equals(zipEntry.getName())) {
            break;
        }
    }
    if (null == zipEntry) {
        LOG.debug("no _rels/.rels relationship part present");
        return signatureResourceNames;
    }

    String dsOriginPart = null;
    JAXBElement<CTRelationships> packageRelationshipsElement = (JAXBElement<CTRelationships>) this.relationshipsUnmarshaller
            .unmarshal(zipInputStream);
    CTRelationships packageRelationships = packageRelationshipsElement.getValue();
    List<CTRelationship> packageRelationshipList = packageRelationships.getRelationship();
    for (CTRelationship packageRelationship : packageRelationshipList) {
        if (OOXMLSignatureVerifier.DIGITAL_SIGNATURE_ORIGIN_REL_TYPE.equals(packageRelationship.getType())) {
            dsOriginPart = packageRelationship.getTarget();
            break;
        }
    }
    if (null == dsOriginPart) {
        LOG.debug("no Digital Signature Origin part present");
        return signatureResourceNames;
    }
    LOG.debug("Digital Signature Origin part: " + dsOriginPart);
    String dsOriginName = dsOriginPart.substring(dsOriginPart.lastIndexOf("/") + 1);
    LOG.debug("Digital Signature Origin base: " + dsOriginName);
    String dsOriginSegment = dsOriginPart.substring(0, dsOriginPart.lastIndexOf("/")) + "/";
    LOG.debug("Digital Signature Origin segment: " + dsOriginSegment);
    String dsOriginRels = dsOriginSegment + "_rels/" + dsOriginName + ".rels";
    LOG.debug("Digital Signature Origin relationship part: " + dsOriginRels);
    if (dsOriginRels.startsWith("/")) {
        dsOriginRels = dsOriginRels.substring(1);
    }

    zipInputStream = new ZipArchiveInputStream(url.openStream(), "UTF8", true, true);
    while (null != (zipEntry = zipInputStream.getNextZipEntry())) {
        if (dsOriginRels.equals(zipEntry.getName())) {
            break;
        }
    }
    if (null == zipEntry) {
        LOG.debug("no Digital Signature Origin relationship part present");
        return signatureResourceNames;
    }

    JAXBElement<CTRelationships> dsoRelationshipsElement = (JAXBElement<CTRelationships>) this.relationshipsUnmarshaller
            .unmarshal(zipInputStream);
    CTRelationships dsoRelationships = dsoRelationshipsElement.getValue();
    List<CTRelationship> dsoRelationshipList = dsoRelationships.getRelationship();
    for (CTRelationship dsoRelationship : dsoRelationshipList) {
        if (OOXMLSignatureVerifier.DIGITAL_SIGNATURE_REL_TYPE.equals(dsoRelationship.getType())) {
            String signatureResourceName;
            if (dsoRelationship.getTarget().startsWith("/")) {
                signatureResourceName = dsoRelationship.getTarget();
            } else {
                signatureResourceName = dsOriginSegment + dsoRelationship.getTarget();
            }
            if (signatureResourceName.startsWith("/")) {
                signatureResourceName = signatureResourceName.substring(1);
            }
            LOG.debug("signature resource name: " + signatureResourceName);
            signatureResourceNames.add(signatureResourceName);
        }
    }

    return signatureResourceNames;
}

From source file:com.bluexml.side.portal.alfresco.reverse.reverser.EclipseReverser.java

protected void readAnyElements(Map<String, String> props, List<Object> any) {
    for (Object object : any) {
        String nodeName = null;/*from w  w w . j  a  v  a 2 s .  c om*/
        String nodeValue = null;
        if (object instanceof Element) {
            System.out.println(" any Element (w3c) ?" + object);
            Element el = (Element) object;
            nodeName = el.getNodeName();
            nodeValue = el.getTextContent();
            props.put(nodeName, nodeValue);
        } else if (object instanceof JAXBElement) {
            JAXBElement<String> jaxbE = (JAXBElement<String>) object;
            QName name = jaxbE.getName();
            nodeName = name.getLocalPart();
            nodeValue = jaxbE.getValue();
        }

        props.put(nodeName, nodeValue);
    }
}

From source file:edu.harvard.i2b2.eclipse.plugins.patientSet.util.PmServiceController.java

public void setUserInfo(String responseXML) throws Exception {
    //log.info("PM response message: /n"+responseXML);
    UserInfoBean.pmResponse(responseXML);

    JAXBUtil jaxbUtil = new JAXBUtil(new String[] { "edu.harvard.i2b2.pm.datavo.pm", //$NON-NLS-1$
            "edu.harvard.i2b2.pm.datavo.i2b2message" //$NON-NLS-1$
    });//from ww w .j  a  va  2  s . c  o m
    JAXBElement jaxbElement = jaxbUtil.unMashallFromString(responseXML);
    ResponseMessageType responseMessageType = (ResponseMessageType) jaxbElement.getValue();

    String procStatus = responseMessageType.getResponseHeader().getResultStatus().getStatus().getType();
    String procMessage = responseMessageType.getResponseHeader().getResultStatus().getStatus().getValue();

    //String serverVersion = responseMessageType.getMessageHeader()
    //.getSendingApplication().getApplicationVersion();
    //System.setProperty("serverVersion", serverVersion);

    if (procStatus.equals("ERROR")) { //$NON-NLS-1$
        setMsg(procMessage);
    } else if (procStatus.equals("WARNING")) { //$NON-NLS-1$
        setMsg(procMessage);
    } else {
        BodyType bodyType = responseMessageType.getMessageBody();
        JAXBUnWrapHelper helper = new JAXBUnWrapHelper();
        ConfigureType response = (ConfigureType) helper.getObjectByClass(bodyType.getAny(),
                ConfigureType.class);

        userInfoBean.setEnvironment(response.getEnvironment());
        userInfoBean.setUserName(response.getUser().getUserName());
        userInfoBean.setUserFullName(response.getUser().getFullName());
        //userInfoBean.setUserPassword(response.getUser().getPassword());
        userInfoBean.setUserKey(response.getUser().getKey());
        userInfoBean.setUserDomain(response.getUser().getDomain());
        userInfoBean.setHelpURL(response.getHelpURL());

        //Save Global variables in properties
        if (response.getGlobalData() != null) {
            for (ParamType param : response.getGlobalData().getParam())
                userInfoBean.setGlobals(param.getName(), param.getValue());
        }
        //Save projects         
        if (response.getUser().getProject() != null)
            //userInfoBean.setProjects( response.getUser().getProject());

            //Save Cell
            if (response.getCellDatas() != null) {
            }
        //userInfoBean.setCellDatas(response.getCellDatas());
    }
}

From source file:be.fedict.eid.idp.sp.protocol.ws_federation.sts.SecurityTokenServiceClient.java

/**
 * Validates the given SAML assertion via the eID IdP WS-Trust STS
 * validation service./*from www .  j  a va 2  s . c o m*/
 * 
 * @param samlAssertionElement
 *            the SAML assertion DOM element to be validated.
 * @param expectedSAMLAudience
 *            the optional (but recommended) expected value for SAML
 *            Audience.
 */
public void validateToken(Element samlAssertionElement, String expectedSAMLAudience) {
    RequestSecurityTokenType request = this.objectFactory.createRequestSecurityTokenType();
    List<Object> requestContent = request.getAny();

    requestContent.add(this.objectFactory.createRequestType(WSTrustConstants.VALIDATE_REQUEST_TYPE));

    requestContent.add(this.objectFactory.createTokenType(WSTrustConstants.STATUS_TOKEN_TYPE));

    ValidateTargetType validateTarget = this.objectFactory.createValidateTargetType();
    requestContent.add(this.objectFactory.createValidateTarget(validateTarget));

    BindingProvider bindingProvider = (BindingProvider) this.port;
    WSSecuritySoapHandler.setAssertion(samlAssertionElement, bindingProvider);
    SecurityTokenReferenceType securityTokenReference = this.wsseObjectFactory
            .createSecurityTokenReferenceType();
    validateTarget.setAny(this.wsseObjectFactory.createSecurityTokenReference(securityTokenReference));
    securityTokenReference.getOtherAttributes().put(
            new QName(WSTrustConstants.WS_SECURITY_11_NAMESPACE, "TokenType"),
            WSTrustConstants.SAML2_WSSE11_TOKEN_TYPE);
    KeyIdentifierType keyIdentifier = this.wsseObjectFactory.createKeyIdentifierType();
    securityTokenReference.getAny().add(this.wsseObjectFactory.createKeyIdentifier(keyIdentifier));
    String samlAssertionId = samlAssertionElement.getAttribute("ID");
    LOG.debug("SAML assertion ID: " + samlAssertionId);
    keyIdentifier.setValue(samlAssertionId);
    keyIdentifier.getOtherAttributes().put(new QName(WSTrustConstants.WS_SECURITY_NAMESPACE, "ValueType"),
            "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLID");

    if (null != expectedSAMLAudience) {
        AppliesTo appliesTo = this.policyObjectFactory.createAppliesTo();
        requestContent.add(appliesTo);
        EndpointReferenceType endpointReference = this.addrObjectFactory.createEndpointReferenceType();
        appliesTo.getAny().add(this.addrObjectFactory.createEndpointReference(endpointReference));
        AttributedURIType address = this.addrObjectFactory.createAttributedURIType();
        endpointReference.setAddress(address);
        address.setValue(expectedSAMLAudience);
    }

    RequestSecurityTokenResponseCollectionType response = this.port.requestSecurityToken(request);

    if (null == response) {
        throw new SecurityException("missing RSTRC");
    }
    List<RequestSecurityTokenResponseType> responseList = response.getRequestSecurityTokenResponse();
    if (1 != responseList.size()) {
        throw new SecurityException("response list should contain 1 entry");
    }
    RequestSecurityTokenResponseType requestSecurityTokenResponse = responseList.get(0);
    List<Object> requestSecurityTokenResponseContent = requestSecurityTokenResponse.getAny();
    boolean hasStatus = false;
    for (Object requestSecurityTokenResponseObject : requestSecurityTokenResponseContent) {
        if (requestSecurityTokenResponseObject instanceof JAXBElement) {
            JAXBElement jaxbElement = (JAXBElement) requestSecurityTokenResponseObject;
            QName qname = jaxbElement.getName();
            if (WSTrustConstants.TOKEN_TYPE_QNAME.equals(qname)) {
                String tokenType = (String) jaxbElement.getValue();
                if (false == WSTrustConstants.STATUS_TOKEN_TYPE.equals(tokenType)) {
                    throw new SecurityException("invalid response token type: " + tokenType);
                }
            } else if (STATUS_QNAME.equals(qname)) {
                StatusType status = (StatusType) jaxbElement.getValue();
                String statusCode = status.getCode();
                if (false == WSTrustConstants.VALID_STATUS_CODE.equals(statusCode)) {
                    String reason = status.getReason();
                    throw new SecurityException("invalid token: " + reason);
                }
                hasStatus = true;
            }
        }
    }
    if (false == hasStatus) {
        throw new SecurityException("missing wst:Status");
    }
}

From source file:eu.trentorise.smartcampus.permissionprovider.manager.AttributesAdapter.java

/**
 * Load attributes from the XML descriptor.
 * @throws JAXBException/*from   w  w  w  .  j av  a2 s. co m*/
 */
protected void init() throws JAXBException {
    JAXBContext jaxb = JAXBContext.newInstance(AuthorityMapping.class, Authorities.class);
    Unmarshaller unm = jaxb.createUnmarshaller();
    JAXBElement<Authorities> element = (JAXBElement<Authorities>) unm
            .unmarshal(new StreamSource(getClass().getResourceAsStream("authorities.xml")), Authorities.class);
    Authorities auths = element.getValue();
    authorities = new HashMap<String, AuthorityMapping>();
    authorityMatches = ArrayListMultimap.create();//new HashMap<String, AuthorityMatching>();
    identityAttributes = new HashMap<String, Set<String>>();
    for (AuthorityMapping mapping : auths.getAuthorityMapping()) {
        Authority auth = authorityRepository.findOne(mapping.getName());
        if (auth == null) {
            auth = new Authority();
            auth.setName(mapping.getName());
            auth.setRedirectUrl(mapping.getUrl());
            authorityRepository.saveAndFlush(auth);
        }
        authorities.put(mapping.getName(), mapping);
        Set<String> identities = new HashSet<String>();
        if (mapping.getIdentifyingAttributes() != null) {
            identities.addAll(mapping.getIdentifyingAttributes());
        }
        identityAttributes.put(auth.getName(), identities);
    }
    if (auths.getAuthorityMatching() != null) {
        for (AuthorityMatching am : auths.getAuthorityMatching()) {
            for (Match match : am.getAuthority()) {
                authorityMatches.put(match.getName(), am);
            }
        }
    }
}

From source file:org.jasig.portlet.blackboardvcportlet.dao.ws.impl.MultimediaWSDaoImpl.java

@Override
public BlackboardMultimediaResponse uploadRepositoryMultimedia(String creatorId, String filename,
        String description, DataHandler content) {
    BlackboardUploadRepositoryContent request = new ObjectFactory().createBlackboardUploadRepositoryContent();
    request.setCreatorId(creatorId);//from   w w w  .  j av a 2s .c  om
    request.setDescription(description);
    request.setFilename(filename);
    request.setContent(content);

    JAXBElement<BlackboardUploadRepositoryContent> realRequest = new ObjectFactory()
            .createUploadRepositoryMultimedia(request);

    @SuppressWarnings("unchecked")
    JAXBElement<BlackboardMultimediaResponseCollection> response = (JAXBElement<BlackboardMultimediaResponseCollection>) sasWebServiceOperations
            .marshalSendAndReceiveToSAS("http://sas.elluminate.com/UploadRepositoryMultimedia", realRequest);
    return DataAccessUtils.singleResult(response.getValue().getMultimediaResponses());

}

From source file:com.evolveum.midpoint.model.impl.scripting.ScriptingExpressionEvaluator.java

public Data evaluateExpression(JAXBElement<? extends ScriptingExpressionType> expression, Data input,
        ExecutionContext context, OperationResult parentResult) throws ScriptExecutionException {
    return evaluateExpression((ScriptingExpressionType) expression.getValue(), input, context, parentResult);
}