List of usage examples for javax.xml.bind JAXBElement getValue
public T getValue()
Return the content model and attribute values for this element.
See #isNil() for a description of a property constraint when this value is null
From source file:com.microsoft.exchange.integration.AbstractIntegrationTest.java
/** * Utility method to issue {@link ExchangeWebServices#deleteItem(DeleteItem)} on the * {@link NonEmptyArrayOfBaseItemIdsType} argument. * Skips the call if the argument is empty * @param itemIds/* w ww .j a v a2 s. c o m*/ */ public void deleteItems(NonEmptyArrayOfBaseItemIdsType itemIds) { if (itemIds != null && !itemIds.getItemIdsAndOccurrenceItemIdsAndRecurringMasterItemIds().isEmpty()) { DeleteItem request = new DeleteItem(); request.setSendMeetingCancellations(CalendarItemCreateOrDeleteOperationType.SEND_TO_NONE); request.setDeleteType(DisposalType.HARD_DELETE); request.setItemIds(itemIds); DeleteItemResponse response = ewsClient.deleteItem(request); log.info("submitted DeleteItem request for " + itemIds); ArrayOfResponseMessagesType responseMessages = response.getResponseMessages(); for (JAXBElement<? extends ResponseMessageType> m : responseMessages .getCreateItemResponseMessagesAndDeleteItemResponseMessagesAndGetItemResponseMessages()) { if (!ResponseCodeType.NO_ERROR.equals(m.getValue().getResponseCode())) { String capture = capture(response); log.error("suspected failure detected for DeleteItem: " + capture); break; } } } }
From source file:be.fedict.trust.xkms2.XKMSPortImpl.java
public ValidateResultType validate(ValidateRequestType body) { LOG.debug("validate"); List<X509Certificate> certificateChain = new LinkedList<X509Certificate>(); String trustDomain = null;/* w w w .j a v a 2 s .c om*/ boolean returnRevocationData = false; Date validationDate = null; List<byte[]> ocspResponses = new LinkedList<byte[]>(); List<byte[]> crls = new LinkedList<byte[]>(); byte[] timestampToken = null; List<byte[]> attributeCertificates = new LinkedList<byte[]>(); /* * Get certification chain from QueryKeyBinding */ QueryKeyBindingType queryKeyBinding = body.getQueryKeyBinding(); KeyInfoType keyInfo = queryKeyBinding.getKeyInfo(); List<Object> keyInfoContent = keyInfo.getContent(); for (Object keyInfoObject : keyInfoContent) { JAXBElement<?> keyInfoElement = (JAXBElement<?>) keyInfoObject; Object elementValue = keyInfoElement.getValue(); if (elementValue instanceof X509DataType) { X509DataType x509Data = (X509DataType) elementValue; List<Object> x509DataContent = x509Data.getX509IssuerSerialOrX509SKIOrX509SubjectName(); for (Object x509DataObject : x509DataContent) { if (!(x509DataObject instanceof JAXBElement)) { continue; } JAXBElement<?> x509DataElement = (JAXBElement<?>) x509DataObject; if (!X509_CERT_QNAME.equals(x509DataElement.getName())) { continue; } byte[] x509DataValue = (byte[]) x509DataElement.getValue(); try { X509Certificate certificate = getCertificate(x509DataValue); certificateChain.add(certificate); } catch (CertificateException e) { return createResultResponse(ResultMajorCode.SENDER, ResultMinorCode.MESSAGE_NOT_SUPPORTED); } } } } /* * Get optional trust domain name from UseKeyWith */ if (body.getQueryKeyBinding().getUseKeyWith().size() > 0) { for (UseKeyWithType useKeyWith : body.getQueryKeyBinding().getUseKeyWith()) { if (useKeyWith.getApplication().equals(XKMSConstants.TRUST_DOMAIN_APPLICATION_URI)) { trustDomain = useKeyWith.getIdentifier(); LOG.debug("validate against trust domain " + trustDomain); } } } /* * Get optional returning of used revocation data from RespondWith */ if (body.getRespondWith().contains(XKMSConstants.RETURN_REVOCATION_DATA_URI)) { LOG.debug("will return used revocation data..."); returnRevocationData = true; } /* * Get optional validation date from TimeInstant field for historical * validation */ if (null != body.getQueryKeyBinding().getTimeInstant()) { validationDate = getDate(body.getQueryKeyBinding().getTimeInstant().getTime()); } /* * Check for message extensions, these can be: * * RevocatioDataMessageExtension: historical validation, contains to be * used OCSP/CRL data * * TSAMessageExtension: TSA validation, contains encoded XAdES timestamp * token * * AttributeCertificateMessageExtension: Attribute certificate * validation, contains XAdES CertifiedRole element containing the * encoded Attribute certificate */ for (MessageExtensionAbstractType messageExtension : body.getMessageExtension()) { if (messageExtension instanceof RevocationDataMessageExtensionType) { RevocationDataMessageExtensionType revocationDataMessageExtension = (RevocationDataMessageExtensionType) messageExtension; parseRevocationDataExtension(revocationDataMessageExtension, ocspResponses, crls); } else if (messageExtension instanceof TSAMessageExtensionType) { TSAMessageExtensionType tsaMessageExtension = (TSAMessageExtensionType) messageExtension; timestampToken = parseTSAExtension(tsaMessageExtension); } else if (messageExtension instanceof AttributeCertificateMessageExtensionType) { AttributeCertificateMessageExtensionType attributeCertificateMessageExtension = (AttributeCertificateMessageExtensionType) messageExtension; parseAttributeCertificateExtension(attributeCertificateMessageExtension, attributeCertificates); } else { LOG.error("invalid message extension: " + messageExtension.getClass().toString()); return createResultResponse(ResultMajorCode.SENDER, ResultMinorCode.MESSAGE_NOT_SUPPORTED); } } /* * Check gathered data */ if (null != validationDate && ocspResponses.isEmpty() && crls.isEmpty()) { LOG.error("Historical validation requested but no revocation data provided"); return createResultResponse(ResultMajorCode.SENDER, ResultMinorCode.MESSAGE_NOT_SUPPORTED); } else if (null != timestampToken && !certificateChain.isEmpty()) { LOG.error("Cannot both add a timestamp token and a seperate certificate chain"); return createResultResponse(ResultMajorCode.SENDER, ResultMinorCode.MESSAGE_NOT_SUPPORTED); } else if (!attributeCertificates.isEmpty() && certificateChain.isEmpty()) { LOG.error("No certificate chain provided for the attribute certificates"); return createResultResponse(ResultMajorCode.SENDER, ResultMinorCode.MESSAGE_NOT_SUPPORTED); } else if (body.getMessageExtension().size() > 1) { LOG.error("Only 1 message extension at a time is supported"); return createResultResponse(ResultMajorCode.SENDER, ResultMinorCode.MESSAGE_NOT_SUPPORTED); } /* * Validate! */ ValidationResult validationResult; try { if (null != timestampToken) { validationResult = this.trustService.validateTimestamp(trustDomain, timestampToken, returnRevocationData); } else if (!attributeCertificates.isEmpty()) { validationResult = this.trustService.validateAttributeCertificates(trustDomain, attributeCertificates, certificateChain, returnRevocationData); } else if (null == validationDate) { validationResult = this.trustService.validate(trustDomain, certificateChain, returnRevocationData); } else { validationResult = this.trustService.validate(trustDomain, certificateChain, validationDate, ocspResponses, crls); } } catch (TrustDomainNotFoundException e) { LOG.error("invalid trust domain"); return createResultResponse(ResultMajorCode.SENDER, ResultMinorCode.TRUST_DOMAIN_NOT_FOUND); } catch (CRLException e) { LOG.error("CRLException: " + e.getMessage(), e); return createResultResponse(ResultMajorCode.SENDER, ResultMinorCode.MESSAGE_NOT_SUPPORTED); } catch (IOException e) { LOG.error("IOException: " + e.getMessage(), e); return createResultResponse(ResultMajorCode.SENDER, ResultMinorCode.MESSAGE_NOT_SUPPORTED); } catch (CertificateException e) { LOG.error("CertificateException: " + e.getMessage(), e); return createResultResponse(ResultMajorCode.SENDER, ResultMinorCode.MESSAGE_NOT_SUPPORTED); } catch (NoSuchProviderException e) { LOG.error("NoSuchProviderException: " + e.getMessage(), e); return createResultResponse(ResultMajorCode.SENDER, ResultMinorCode.MESSAGE_NOT_SUPPORTED); } catch (TSPException e) { LOG.error("TSPException: " + e.getMessage(), e); return createResultResponse(ResultMajorCode.SENDER, ResultMinorCode.MESSAGE_NOT_SUPPORTED); } catch (CMSException e) { LOG.error("CMSException: " + e.getMessage(), e); return createResultResponse(ResultMajorCode.SENDER, ResultMinorCode.MESSAGE_NOT_SUPPORTED); } catch (NoSuchAlgorithmException e) { LOG.error("NoSuchAlgorithmException: " + e.getMessage(), e); return createResultResponse(ResultMajorCode.SENDER, ResultMinorCode.MESSAGE_NOT_SUPPORTED); } catch (CertStoreException e) { LOG.error("CertStoreException: " + e.getMessage(), e); return createResultResponse(ResultMajorCode.SENDER, ResultMinorCode.MESSAGE_NOT_SUPPORTED); } /* * Create validation result response */ ValidateResultType validateResult = createResultResponse(ResultMajorCode.SUCCESS, null); ObjectFactory objectFactory = new ObjectFactory(); List<KeyBindingType> keyBindings = validateResult.getKeyBinding(); KeyBindingType keyBinding = objectFactory.createKeyBindingType(); keyBindings.add(keyBinding); StatusType status = objectFactory.createStatusType(); keyBinding.setStatus(status); String statusValue; if (validationResult.isValid()) { statusValue = XKMSConstants.KEY_BINDING_STATUS_VALID_URI; } else { statusValue = XKMSConstants.KEY_BINDING_STATUS_INVALID_URI; } status.setStatusValue(statusValue); /* * Add InvalidReason URI's */ if (!validationResult.isValid()) { switch (validationResult.getReason()) { case INVALID_TRUST: { status.getInvalidReason().add(XKMSConstants.KEY_BINDING_REASON_ISSUER_TRUST_URI); break; } case INVALID_REVOCATION_STATUS: { status.getInvalidReason().add(XKMSConstants.KEY_BINDING_REASON_REVOCATION_STATUS_URI); break; } case INVALID_SIGNATURE: { status.getInvalidReason().add(XKMSConstants.KEY_BINDING_REASON_SIGNATURE_URI); break; } case INVALID_VALIDITY_INTERVAL: { status.getInvalidReason().add(XKMSConstants.KEY_BINDING_REASON_VALIDITY_INTERVAL_URI); break; } } } /* * Add used revocation data if requested */ if (returnRevocationData) { addRevocationData(validateResult, validationResult.getRevocationData()); } return validateResult; }
From source file:com.microsoft.exchange.impl.ExchangeResponseUtilsImpl.java
@Override public boolean parseDeleteFolderResponse(DeleteFolderResponse response) { if (confirmSuccess(response)) { ArrayOfResponseMessagesType arrayOfResponseMessages = response.getResponseMessages(); List<JAXBElement<? extends ResponseMessageType>> deleteFolderResponseMessages = arrayOfResponseMessages .getCreateItemResponseMessagesAndDeleteItemResponseMessagesAndGetItemResponseMessages(); for (JAXBElement<? extends ResponseMessageType> message : deleteFolderResponseMessages) { ResponseMessageType value = message.getValue(); return value.getResponseClass().equals(ResponseClassType.SUCCESS) && value.getResponseCode().equals(ResponseCodeType.NO_ERROR); }//w ww .j a v a 2 s.c om } return false; }
From source file:com.aurel.track.configExchange.importer.EntityImporter.java
public List<ImportResult> importFile(InputStream is, ImportContext importContext) throws EntityImporterException { boolean overwriteExisting = importContext.isOverrideExisting(); boolean overrideOnlyNotModifiedByUser = importContext.isOverrideOnlyNotModifiedByUser(); boolean clearChildren = importContext.isClearChildren(); String type = importContext.getEntityType(); Map<String, String> extraAttributes = importContext.getAttributeMap(); LOGGER.debug("Import file overwriteExisting=" + overwriteExisting + " type=" + type); List<ImportResult> result = new ArrayList<ImportResult>(); Unmarshaller unmarshaller = null; try {//from w w w .j av a2 s.c o m unmarshaller = EntityExporter.getUnmarshaller(); } catch (JAXBException e) { throw new EntityImporterException("JAXBException:" + e.getMessage(), e); } catch (SAXException e) { throw new EntityImporterException("SAXException:" + e.getMessage(), e); } JAXBElement<TrackplusRoot> root = null; try { root = (JAXBElement<TrackplusRoot>) unmarshaller.unmarshal(is); } catch (JAXBException e) { throw new EntityImporterException("JAXBException:" + e.getMessage(), e); } TrackplusRoot trackplusExchangeRoot = root.getValue(); //collect all dependences as map List<DependencyData> globalDependencyList = trackplusExchangeRoot.getEntityDependency(); for (DependencyData dependency : globalDependencyList) { String dependencyType = dependency.getType(); Map<Integer, Entity> entityMap = globalDependencies.get(dependencyType); if (entityMap == null) { entityMap = new HashMap<Integer, Entity>(); globalDependencies.put(dependencyType, entityMap); } List<Entity> dependencyEntityList = dependency.getTrackEntity(); for (Entity dependencyEntity : dependencyEntityList) { entityMap.put(Integer.parseInt(dependencyEntity.getEntityId()), dependencyEntity); } } // save dependency first LOGGER.debug("Saving dependences...."); for (DependencyData dependency : globalDependencyList) { List<Entity> dependencyEntityList = dependency.getTrackEntity(); for (Entity dependencyEntity : dependencyEntityList) { EntityImportContext entityImportContext = new EntityImportContext(); entityImportContext.setEntity(dependencyEntity); entityImportContext.setAttributeMap(toAttributeMap(dependencyEntity.getEntityAttribute())); entityImportContext.setOverrideExisting(false); entityImportContext.setClearChildren(false); saveEntity(entityImportContext); } } LOGGER.debug("Dependences saved!"); // save entity list List<Entity> entityExchangeList = trackplusExchangeRoot.getEntityExchange(); LOGGER.debug("entityExchangeList size:" + entityExchangeList.size()); Map<String, String> attributes; for (Entity entity : entityExchangeList) { LOGGER.debug("entity " + entity.getType() + " id:" + entity.getEntityId()); if (type != null && !type.equals(entity.getType())) { LOGGER.debug("invalid entity type"); continue; } attributes = toAttributeMap(entity.getEntityAttribute()); //override attributes if (extraAttributes != null) { Iterator<String> it = extraAttributes.keySet().iterator(); while (it.hasNext()) { String key = it.next(); String value = extraAttributes.get(key); if (value == null) { attributes.remove(key); } else { attributes.put(key, value); } } } EntityImportContext entityImportContext = new EntityImportContext(); entityImportContext.setEntity(entity); entityImportContext.setAttributeMap(attributes); entityImportContext.setOverrideExisting(overwriteExisting); entityImportContext.setClearChildren(clearChildren); entityImportContext.setOverrideOnlyNotModifiedByUser(overrideOnlyNotModifiedByUser); ImportResult importResult = saveEntity(entityImportContext); result.add(importResult); } return result; }
From source file:hermes.impl.DefaultXMLHelper.java
public MessageSet readContent(Reader reader) throws Exception { JAXBContext jc = contextTL.get(); Unmarshaller u = jc.createUnmarshaller(); JAXBElement<MessageSet> node = u.unmarshal(new StreamSource(new ReaderInputStream(reader)), MessageSet.class); return node.getValue(); }
From source file:com.microsoft.exchange.impl.ExchangeResponseUtilsImpl.java
@Override public boolean confirmSuccessOrWarning(BaseResponseMessageType response) { List<String> errors = new ArrayList<String>(); List<String> warnings = new ArrayList<String>(); ArrayOfResponseMessagesType messages = response.getResponseMessages(); List<JAXBElement<? extends ResponseMessageType>> inner = messages .getCreateItemResponseMessagesAndDeleteItemResponseMessagesAndGetItemResponseMessages(); for (JAXBElement<? extends ResponseMessageType> innerResponse : inner) { if (innerResponse != null && innerResponse.getValue() != null) { String parsedMsg = parseInnerResponse(innerResponse); ResponseMessageType innerResponseValue = innerResponse.getValue(); ResponseClassType responseClass = innerResponseValue.getResponseClass(); switch (responseClass) { case WARNING: log.warn(parsedMsg);/*from w ww. j av a 2s.c o m*/ warnings.add(parsedMsg); break; case ERROR: log.error(parsedMsg); errors.add(parsedMsg); break; default: break; } } } if (CollectionUtils.isEmpty(errors)) { return true; } else { return false; } }
From source file:edu.harvard.i2b2.eclipse.plugins.adminTool.utils.PmServiceController.java
/** * Function to send getUserInfo request to PM web service * // w ww. j av a2 s . c om * @param userid * @param password * @param projectID * @param project * @param demo Flag to indicate if we are in demo mode * @return A String containing the PM web service response */ @SuppressWarnings("rawtypes") public String setUserPassword(String userid, PasswordType password, String projectURL, String domain, String newPassword, String username) throws Exception { String response = null; try { ////////////// GetUserRequestMessage reqMsg1 = new GetUserRequestMessage(userid, password, domain); //RoleType userConfig = new RoleType(); //userConfig.getProject().add(project); //userConfig.setProjectId(pid); String requestString = null; requestString = reqMsg1.doBuildXML(username); MessageUtil.getInstance().setRequest("URL: " + projectURL + "getServices" + "\n" + requestString); //log.info("PM request: /n"+getUserInfoRequestString); if (System.getProperty("webServiceMethod").equals("SOAP")) { response = sendSOAP(new EndpointReference(projectURL), requestString, "http://rpdr.partners.org/GetUserConfiguration", "GetUserConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$ } else { response = sendREST(new EndpointReference(projectURL + "getServices"), requestString); //$NON-NLS-1$ } if (response == null) { log.info("no pm response received"); return "error"; } MessageUtil.getInstance().setResponse("URL: " + projectURL + "getServices" + "\n" + response); JAXBUtil jaxbUtil = new JAXBUtil(new String[] { "edu.harvard.i2b2.crcxmljaxb.datavo.pm", "edu.harvard.i2b2.crcxmljaxb.datavo.i2b2message" }); JAXBElement jaxbElement = jaxbUtil.unMashallFromString(response); 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); String fullname = null; boolean isadmin = false; if (procStatus.equals("ERROR")) { //setMsg(procMessage); } else if (procStatus.equals("WARNING")) { //setMsg(procMessage); } else { BodyType bodyType = responseMessageType.getMessageBody(); JAXBUnWrapHelper helper = new JAXBUnWrapHelper(); UserType userType = (UserType) helper.getObjectByClass(bodyType.getAny(), UserType.class); fullname = userType.getFullName(); isadmin = userType.isIsAdmin(); } //////////////// SetUserPasswordRequestMessage reqMsg = new SetUserPasswordRequestMessage(userid, password, domain); //RoleType userConfig = new RoleType(); //userConfig.getProject().add(project); //userConfig.setProjectId(pid); requestString = null; UserType user = new UserType(); user.setUserName(username); edu.harvard.i2b2.crcxmljaxb.datavo.pm.PasswordType newPasswordType = new edu.harvard.i2b2.crcxmljaxb.datavo.pm.PasswordType(); newPasswordType.setValue(newPassword); user.setPassword(newPasswordType); user.setDomain(domain); user.setIsAdmin(isadmin); if (fullname != null) { user.setFullName(fullname); } else { user.setFullName("i2b2 User");//UserInfoBean.getInstance().getUserFullName()); } requestString = reqMsg.doBuildXML(user); MessageUtil.getInstance().setRequest("URL: " + projectURL + "getServices" + "\n" + requestString); //log.info("PM request: /n"+getUserInfoRequestString); if (System.getProperty("webServiceMethod").equals("SOAP")) { response = sendSOAP(new EndpointReference(projectURL), requestString, "http://rpdr.partners.org/GetUserConfiguration", "GetUserConfiguration"); //$NON-NLS-1$ //$NON-NLS-2$ } else { response = sendREST(new EndpointReference(projectURL + "getServices"), requestString); //$NON-NLS-1$ } if (response == null) { log.info("no pm response received"); return "error"; } MessageUtil.getInstance().setResponse("URL: " + projectURL + "getServices" + "\n" + response); } catch (AxisFault e) { log.error(e.getMessage()); setMsg(Messages.getString("LoginHelper.PMUnavailable")); } catch (Exception e) { log.error(e.getMessage()); setMsg(e.getMessage()); } return response; }
From source file:org.opentravel.schemacompiler.repository.impl.RemoteRepositoryClient.java
/** * Contacts the repository web service at the specified endpoint URL, and returns the repository * meta-data information./*from www . ja v a 2 s .c om*/ * * @param endpointUrl * the URL endpoint of the OTA2.0 repository web service * @return RepositoryInfoType * @throws RepositoryException * thrown if the remote web service is not available */ @SuppressWarnings("unchecked") public static RepositoryInfoType getRepositoryMetadata(String endpointUrl) throws RepositoryException { try { HttpGet getRequest = new HttpGet(endpointUrl + REPOSITORY_METADATA_ENDPOINT); HttpResponse response = execute(getRequest); if (response.getStatusLine().getStatusCode() != HTTP_RESPONSE_STATUS_OK) { throw new RepositoryException(getResponseErrorMessage(response)); } Unmarshaller unmarshaller = RepositoryFileManager.getSharedJaxbContext().createUnmarshaller(); JAXBElement<RepositoryInfoType> jaxbElement = (JAXBElement<RepositoryInfoType>) unmarshaller .unmarshal(response.getEntity().getContent()); return jaxbElement.getValue(); } catch (JAXBException e) { throw new RepositoryException("The format of the repository meta-data is unreadable.", e); } catch (IOException e) { throw new RepositoryException("The remote repository is unavailable.", e); } }
From source file:com.evolveum.midpoint.testing.model.client.sample.TestExchangeConnector.java
private static String getOrig(PolyStringType polyStringType) { if (polyStringType == null) { return null; }//from w ww .j ava 2 s .co m StringBuilder sb = new StringBuilder(); for (Object o : polyStringType.getContent()) { if (o instanceof String) { sb.append(o); } else if (o instanceof Element) { Element e = (Element) o; if ("orig".equals(e.getLocalName())) { return e.getTextContent(); } } else if (o instanceof JAXBElement) { JAXBElement je = (JAXBElement) o; if ("orig".equals(je.getName().getLocalPart())) { return (String) je.getValue(); } } } return sb.toString(); }
From source file:ch.lipsch.subsonic4j.internal.SubsonicServiceImpl.java
private synchronized Response unmarshalResponse(InputStream inputStream) throws JAXBException { Object unmarshallObj = jaxbUnmarshaller.unmarshal(inputStream); JAXBElement element = (JAXBElement) unmarshallObj; Response response = (Response) element.getValue(); return response; }