Search in sources :

Example 46 with JAXBElement

use of javax.xml.bind.JAXBElement in project camel by apache.

the class HeaderTesterImpl method addReplyOutOfBandHeader.

private void addReplyOutOfBandHeader() {
    if (context != null) {
        MessageContext ctx = context.getMessageContext();
        if (ctx != null) {
            try {
                OutofBandHeader ob = new OutofBandHeader();
                ob.setName("testOobReturnHeaderName");
                ob.setValue("testOobReturnHeaderValue");
                ob.setHdrAttribute("testReturnHdrAttribute");
                JAXBElement<OutofBandHeader> job = new JAXBElement<OutofBandHeader>(new QName(Constants.TEST_HDR_NS, Constants.TEST_HDR_RESPONSE_ELEM), OutofBandHeader.class, null, ob);
                Header hdr = new Header(new QName(Constants.TEST_HDR_NS, Constants.TEST_HDR_RESPONSE_ELEM), job, new JAXBDataBinding(ob.getClass()));
                List<Header> hdrList = CastUtils.cast((List<?>) ctx.get(Header.HEADER_LIST));
                hdrList.add(hdr);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
}
Also used : OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) Header(org.apache.cxf.headers.Header) QName(javax.xml.namespace.QName) OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) MessageContext(javax.xml.ws.handler.MessageContext) JAXBElement(javax.xml.bind.JAXBElement) JAXBException(javax.xml.bind.JAXBException)

Example 47 with JAXBElement

use of javax.xml.bind.JAXBElement in project camel by apache.

the class HeaderTesterWithInsertionImpl method verifyHeader.

private void verifyHeader(Object hdr, String headerName, String headerValue) {
    if (hdr instanceof Header && ((Header) hdr).getObject() instanceof Node) {
        Header hdr1 = (Header) hdr;
        try {
            JAXBElement<?> job = (JAXBElement<?>) JAXBContext.newInstance(org.apache.cxf.outofband.header.ObjectFactory.class).createUnmarshaller().unmarshal((Node) hdr1.getObject());
            OutofBandHeader ob = (OutofBandHeader) job.getValue();
            if (!headerName.equals(ob.getName())) {
                throw new RuntimeException("test failed expected name ' + headerName + ' but found '" + ob.getName() + "'");
            }
            if (!headerValue.equals(ob.getValue())) {
                throw new RuntimeException("test failed expected name ' + headerValue + ' but found '" + ob.getValue() + "'");
            }
        } catch (JAXBException ex) {
            throw new RuntimeException("test failed", ex);
        }
    } else {
        throw new RuntimeException("test failed. Unexpected type " + hdr.getClass());
    }
}
Also used : OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) Header(org.apache.cxf.headers.Header) Node(org.w3c.dom.Node) JAXBException(javax.xml.bind.JAXBException) OutofBandHeader(org.apache.cxf.outofband.header.OutofBandHeader) JAXBElement(javax.xml.bind.JAXBElement)

Example 48 with JAXBElement

use of javax.xml.bind.JAXBElement in project nifi by apache.

the class TemplateSerializerTest method validateDiffWithChangingComponentIdAndAdditionalElements.

@Test
public void validateDiffWithChangingComponentIdAndAdditionalElements() throws Exception {
    // Create initial template (TemplateDTO)
    FlowSnippetDTO snippet = new FlowSnippetDTO();
    Set<ProcessorDTO> procs = new HashSet<>();
    for (int i = 4; i > 0; i--) {
        ProcessorDTO procDTO = new ProcessorDTO();
        procDTO.setType("Processor" + i + ".class");
        procDTO.setId(ComponentIdGenerator.generateId().toString());
        procs.add(procDTO);
    }
    snippet.setProcessors(procs);
    TemplateDTO origTemplate = new TemplateDTO();
    origTemplate.setDescription("MyTemplate");
    origTemplate.setId("MyTemplate");
    origTemplate.setSnippet(snippet);
    byte[] serTemplate = TemplateSerializer.serialize(origTemplate);
    // Deserialize Template into TemplateDTO
    ByteArrayInputStream in = new ByteArrayInputStream(serTemplate);
    JAXBContext context = JAXBContext.newInstance(TemplateDTO.class);
    Unmarshaller unmarshaller = context.createUnmarshaller();
    XMLStreamReader xsr = XmlUtils.createSafeReader(in);
    JAXBElement<TemplateDTO> templateElement = unmarshaller.unmarshal(xsr, TemplateDTO.class);
    TemplateDTO deserTemplate = templateElement.getValue();
    // Modify deserialized template
    FlowSnippetDTO deserSnippet = deserTemplate.getSnippet();
    Set<ProcessorDTO> deserProcs = deserSnippet.getProcessors();
    int c = 0;
    for (ProcessorDTO processorDTO : deserProcs) {
        if (c % 2 == 0) {
            processorDTO.setName("Hello-" + c);
        }
        c++;
    }
    // add new Processor
    ProcessorDTO procDTO = new ProcessorDTO();
    procDTO.setType("ProcessorNew" + ".class");
    procDTO.setId(ComponentIdGenerator.generateId().toString());
    deserProcs.add(procDTO);
    // Serialize modified template
    byte[] serTemplate2 = TemplateSerializer.serialize(deserTemplate);
    RawText rt1 = new RawText(serTemplate);
    RawText rt2 = new RawText(serTemplate2);
    EditList diffList = new EditList();
    diffList.addAll(new HistogramDiff().diff(RawTextComparator.DEFAULT, rt1, rt2));
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try (DiffFormatter diff = new DiffFormatter(out)) {
        diff.format(diffList, rt1, rt2);
        BufferedReader reader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(out.toByteArray()), StandardCharsets.UTF_8));
        List<String> changes = reader.lines().peek(System.out::println).filter(line -> line.startsWith("+") || line.startsWith("-")).collect(Collectors.toList());
        assertEquals("+            <name>Hello-0</name>", changes.get(0));
        assertEquals("+            <name>Hello-2</name>", changes.get(1));
        assertEquals("+        <processors>", changes.get(2));
        assertEquals("+            <type>ProcessorNew.class</type>", changes.get(4));
        assertEquals("+        </processors>", changes.get(5));
    }
}
Also used : HistogramDiff(org.eclipse.jgit.diff.HistogramDiff) XmlUtils(org.apache.nifi.security.xml.XmlUtils) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RawTextComparator(org.eclipse.jgit.diff.RawTextComparator) HashSet(java.util.HashSet) ByteArrayInputStream(java.io.ByteArrayInputStream) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) XMLStreamReader(javax.xml.stream.XMLStreamReader) RawText(org.eclipse.jgit.diff.RawText) JAXBContext(javax.xml.bind.JAXBContext) ComponentIdGenerator(org.apache.nifi.util.ComponentIdGenerator) Unmarshaller(javax.xml.bind.Unmarshaller) EditList(org.eclipse.jgit.diff.EditList) JAXBElement(javax.xml.bind.JAXBElement) Set(java.util.Set) Test(org.junit.Test) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) DiffFormatter(org.eclipse.jgit.diff.DiffFormatter) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) BufferedReader(java.io.BufferedReader) Assert.assertEquals(org.junit.Assert.assertEquals) FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) XMLStreamReader(javax.xml.stream.XMLStreamReader) InputStreamReader(java.io.InputStreamReader) HistogramDiff(org.eclipse.jgit.diff.HistogramDiff) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) JAXBContext(javax.xml.bind.JAXBContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RawText(org.eclipse.jgit.diff.RawText) ByteArrayInputStream(java.io.ByteArrayInputStream) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) BufferedReader(java.io.BufferedReader) EditList(org.eclipse.jgit.diff.EditList) Unmarshaller(javax.xml.bind.Unmarshaller) DiffFormatter(org.eclipse.jgit.diff.DiffFormatter) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 49 with JAXBElement

use of javax.xml.bind.JAXBElement in project coprhd-controller by CoprHD.

the class UcsDiscoveryWorker method reconcileVhbas.

private void reconcileVhbas(ComputeSystem cs, Map<String, LsServer> associatedLsServers, VhbaHelper lookUpVsan) {
    _log.info("Reconciling Vhbas");
    URIQueryResultList uris = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeSystemComputeElemetsConstraint(cs.getId()), uris);
    List<ComputeElement> elements = _dbClient.queryObject(ComputeElement.class, uris, true);
    for (ComputeElement computeElement : elements) {
        Map<String, ComputeElementHBA> removeVhbas = new HashMap<>();
        Map<String, ComputeElementHBA> addVhbas = new HashMap<>();
        Map<String, ComputeElementHBA> updateVhbas = new HashMap<>();
        URIQueryResultList uriVhbas = new URIQueryResultList();
        _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeElementComputeElemetHBAsConstraint(computeElement.getId()), uriVhbas);
        List<ComputeElementHBA> vbhas = _dbClient.queryObject(ComputeElementHBA.class, uriVhbas, true);
        for (ComputeElementHBA hba : vbhas) {
            removeVhbas.put(hba.getLabel(), hba);
        }
        LsServer lsServer = associatedLsServers.get(computeElement.getLabel());
        if (lsServer != null && lsServer.getContent() != null && !lsServer.getContent().isEmpty()) {
            for (Serializable contentElement : lsServer.getContent()) {
                if (contentElement instanceof JAXBElement<?> && ((JAXBElement) contentElement).getValue() instanceof VnicFc) {
                    VnicFc vnicFc = (VnicFc) ((JAXBElement) contentElement).getValue();
                    ComputeElementHBA hba = removeVhbas.get(vnicFc.getName());
                    if (hba != null) {
                        updateVhbas.put(vnicFc.getName(), hba);
                        removeVhbas.remove(hba.getLabel());
                        updateComputeElementHBA(hba, vnicFc);
                    } else {
                        hba = new ComputeElementHBA();
                        addVhbas.put(vnicFc.getName(), hba);
                        createComputeElementHBA(cs, computeElement, hba, vnicFc);
                    }
                }
            }
        }
        createDataObjects(new ArrayList<DataObject>(addVhbas.values()));
        persistDataObjects(new ArrayList<DataObject>(updateVhbas.values()));
        // Do not delete vHBAs that are still linked to the ViPR host
        Iterator<Map.Entry<String, ComputeElementHBA>> vhbaIterator = removeVhbas.entrySet().iterator();
        while (vhbaIterator.hasNext()) {
            Map.Entry<String, ComputeElementHBA> entry = vhbaIterator.next();
            if (entry.getValue().getHost() != null) {
                vhbaIterator.remove();
            } else {
                _log.info("vHBA is marked for deletion {}", entry.getKey());
            }
        }
        deleteDataObjects(new ArrayList<DataObject>(removeVhbas.values()));
    }
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) LsServer(com.emc.cloud.platform.ucs.out.model.LsServer) ComputeElementHBA(com.emc.storageos.db.client.model.ComputeElementHBA) JAXBElement(javax.xml.bind.JAXBElement) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) VnicFc(com.emc.cloud.platform.ucs.out.model.VnicFc) DataObject(com.emc.storageos.db.client.model.DataObject) DiscoveredDataObject(com.emc.storageos.db.client.model.DiscoveredDataObject) ComputeElement(com.emc.storageos.db.client.model.ComputeElement) Map(java.util.Map) HashMap(java.util.HashMap)

Example 50 with JAXBElement

use of javax.xml.bind.JAXBElement in project coprhd-controller by CoprHD.

the class UcsDiscoveryWorker method reconcileComputeBootDef.

private ComputeBootDef reconcileComputeBootDef(LsbootDef lsBootDef, UCSServiceProfileTemplate spt, ComputeSystem cs) {
    ComputeBootDef bootDef = null;
    URIQueryResultList bootDefUris = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getServiceProfileTemplateComputeBootDefsConstraint(spt.getId()), bootDefUris);
    List<ComputeBootDef> bootDefs = _dbClient.queryObject(ComputeBootDef.class, bootDefUris, true);
    if (!bootDefs.isEmpty()) {
        bootDef = bootDefs.get(0);
        bootDef.setComputeSystem(cs.getId());
        bootDef.setServiceProfileTemplate(spt.getId());
        // bootDef.setDn(lsBootDef.getDn());
        if (lsBootDef.getEnforceVnicName().equals("yes")) {
            bootDef.setEnforceVnicVhbaNames(true);
        } else {
            bootDef.setEnforceVnicVhbaNames(false);
        }
        _dbClient.persistObject(bootDef);
    }
    if (bootDef == null) {
        bootDef = new ComputeBootDef();
        URI uri = URIUtil.createId(ComputeBootDef.class);
        bootDef.setId(uri);
        bootDef.setComputeSystem(cs.getId());
        bootDef.setServiceProfileTemplate(spt.getId());
        // bootDef.setDn(lsBootDef.getDn());
        if (lsBootDef.getEnforceVnicName().equals("yes")) {
            bootDef.setEnforceVnicVhbaNames(true);
        } else {
            bootDef.setEnforceVnicVhbaNames(false);
        }
        _dbClient.createObject(bootDef);
    }
    ComputeSanBoot sanBoot = null;
    ComputeLanBoot lanBoot = null;
    URIQueryResultList sanBootUris = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeBootDefComputeSanBootConstraint(bootDef.getId()), sanBootUris);
    List<ComputeSanBoot> sanBootList = _dbClient.queryObject(ComputeSanBoot.class, sanBootUris, true);
    if (sanBootList != null && !sanBootList.isEmpty()) {
        sanBoot = sanBootList.get(0);
    }
    URIQueryResultList lanBootUris = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeBootDefComputeLanBootConstraint(bootDef.getId()), lanBootUris);
    List<ComputeLanBoot> lanBootList = _dbClient.queryObject(ComputeLanBoot.class, lanBootUris, true);
    if (lanBootList != null && !lanBootList.isEmpty()) {
        lanBoot = lanBootList.get(0);
    }
    boolean hasLanBoot = false;
    boolean hasSanBoot = false;
    Integer nonSanBootOrder = null;
    Integer sanBootOrder = null;
    if (lsBootDef.getContent() != null && !lsBootDef.getContent().isEmpty()) {
        for (Serializable element : lsBootDef.getContent()) {
            if (element instanceof JAXBElement<?>) {
                if (((JAXBElement) element).getValue() instanceof LsbootLan) {
                    LsbootLan lsbootLan = (LsbootLan) ((JAXBElement) element).getValue();
                    lanBoot = reconcileComputeLanBoot(lsbootLan, lanBoot, bootDef, null);
                    hasLanBoot = true;
                    Integer order = Integer.parseInt(lsbootLan.getOrder());
                    if (nonSanBootOrder == null) {
                        nonSanBootOrder = order;
                    } else if (order < nonSanBootOrder) {
                        nonSanBootOrder = order;
                    }
                } else if (((JAXBElement) element).getValue() instanceof LsbootStorage) {
                    LsbootStorage lsbootStorage = (LsbootStorage) ((JAXBElement) element).getValue();
                    sanBoot = reconcileComputeSanBoot(lsbootStorage, sanBoot, bootDef, null);
                    hasSanBoot = true;
                    sanBootOrder = Integer.parseInt(lsbootStorage.getOrder());
                } else if (((JAXBElement) element).getValue() instanceof LsbootSan) {
                    LsbootSan lsbootSan = (LsbootSan) ((JAXBElement) element).getValue();
                    sanBoot = reconcileComputeSanBoot(lsbootSan, sanBoot, bootDef, null);
                    hasSanBoot = true;
                    sanBootOrder = Integer.parseInt(lsbootSan.getOrder());
                } else if (((JAXBElement) element).getValue() instanceof LsbootVirtualMedia) {
                    LsbootVirtualMedia lsbootVirtualMedia = (LsbootVirtualMedia) ((JAXBElement) element).getValue();
                    Integer order = Integer.parseInt(lsbootVirtualMedia.getOrder());
                    if (nonSanBootOrder == null) {
                        nonSanBootOrder = order;
                    } else if (order < nonSanBootOrder) {
                        nonSanBootOrder = order;
                    }
                } else if (((JAXBElement) element).getValue() instanceof LsbootIScsi) {
                    LsbootIScsi lsbootIScsi = (LsbootIScsi) ((JAXBElement) element).getValue();
                    Integer order = Integer.parseInt(lsbootIScsi.getOrder());
                    if (nonSanBootOrder == null) {
                        nonSanBootOrder = order;
                    } else if (order < nonSanBootOrder) {
                        nonSanBootOrder = order;
                    }
                }
            }
        }
    }
    if (hasSanBoot && nonSanBootOrder != null) {
        sanBoot = (ComputeSanBoot) _dbClient.queryObject(sanBoot.getId());
        if (nonSanBootOrder < sanBootOrder) {
            sanBoot.setIsFirstBootDevice(false);
        } else {
            sanBoot.setIsFirstBootDevice(true);
        }
        _dbClient.persistObject(sanBoot);
    }
    if (!hasSanBoot && sanBoot != null) {
        List<ComputeSanBoot> sanBoots = new ArrayList<ComputeSanBoot>();
        sanBoots.add(sanBoot);
        deleteComputeSanBoot(sanBoots);
    }
    if (!hasLanBoot && lanBoot != null) {
        List<ComputeLanBoot> lanBoots = new ArrayList<ComputeLanBoot>();
        lanBoots.add(lanBoot);
        deleteComputeLanBoot(lanBoots);
    }
    return bootDef;
}
Also used : Serializable(java.io.Serializable) LsbootVirtualMedia(com.emc.cloud.platform.ucs.out.model.LsbootVirtualMedia) ArrayList(java.util.ArrayList) JAXBElement(javax.xml.bind.JAXBElement) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) ComputeLanBoot(com.emc.storageos.db.client.model.ComputeLanBoot) LsbootSan(com.emc.cloud.platform.ucs.out.model.LsbootSan) ComputeBootDef(com.emc.storageos.db.client.model.ComputeBootDef) ComputeSanBoot(com.emc.storageos.db.client.model.ComputeSanBoot) LsbootLan(com.emc.cloud.platform.ucs.out.model.LsbootLan) LsbootStorage(com.emc.cloud.platform.ucs.out.model.LsbootStorage) LsbootIScsi(com.emc.cloud.platform.ucs.out.model.LsbootIScsi)

Aggregations

JAXBElement (javax.xml.bind.JAXBElement)650 QName (javax.xml.namespace.QName)194 Element (org.w3c.dom.Element)124 RequestSecurityTokenType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenType)102 RequestSecurityTokenResponseType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenResponseType)95 ArrayList (java.util.ArrayList)93 MessageImpl (org.apache.cxf.message.MessageImpl)92 WrappedMessageContext (org.apache.cxf.jaxws.context.WrappedMessageContext)90 Test (org.junit.Test)87 STSPropertiesMBean (org.apache.cxf.sts.STSPropertiesMBean)86 StaticSTSProperties (org.apache.cxf.sts.StaticSTSProperties)83 Crypto (org.apache.wss4j.common.crypto.Crypto)82 JAXBException (javax.xml.bind.JAXBException)81 PasswordCallbackHandler (org.apache.cxf.sts.common.PasswordCallbackHandler)77 JAXBContext (javax.xml.bind.JAXBContext)75 CustomTokenPrincipal (org.apache.wss4j.common.principal.CustomTokenPrincipal)72 Unmarshaller (javax.xml.bind.Unmarshaller)65 ServiceMBean (org.apache.cxf.sts.service.ServiceMBean)61 StaticService (org.apache.cxf.sts.service.StaticService)61 RequestSecurityTokenResponseCollectionType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenResponseCollectionType)58