Search in sources :

Example 6 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class PGPDataFormatUtil method findPublicKeys.

public static List<PGPPublicKey> findPublicKeys(List<String> useridParts, boolean forEncryption, PGPPublicKeyRingCollection pgpPublicKeyringCollection) {
    List<PGPPublicKey> result = new ArrayList<PGPPublicKey>(useridParts.size());
    for (Iterator<PGPPublicKeyRing> keyRingIter = pgpPublicKeyringCollection.getKeyRings(); keyRingIter.hasNext(); ) {
        PGPPublicKeyRing keyRing = keyRingIter.next();
        PGPPublicKey primaryKey = keyRing.getPublicKey();
        String[] foundKeyUserIdForUserIdPart = findFirstKeyUserIdContainingOneOfTheParts(useridParts, primaryKey);
        if (foundKeyUserIdForUserIdPart == null) {
            LOG.debug("No User ID found in primary key with key ID {} containing one of the parts {}", primaryKey.getKeyID(), useridParts);
            continue;
        }
        LOG.debug("User ID {} found in primary key with key ID {} containing one of the parts {}", new Object[] { foundKeyUserIdForUserIdPart[0], primaryKey.getKeyID(), useridParts });
        // add adequate keys to the result
        for (Iterator<PGPPublicKey> keyIter = keyRing.getPublicKeys(); keyIter.hasNext(); ) {
            PGPPublicKey key = keyIter.next();
            if (forEncryption) {
                if (isEncryptionKey(key)) {
                    LOG.debug("Public encryption key with key user ID {} and key ID {} added to the encryption keys", foundKeyUserIdForUserIdPart[0], Long.toString(key.getKeyID()));
                    result.add(key);
                }
            } else if (!forEncryption && isSignatureKey(key)) {
                // not used!
                result.add(key);
                LOG.debug("Public key with key user ID {} and key ID {} added to the signing keys", foundKeyUserIdForUserIdPart[0], Long.toString(key.getKeyID()));
            }
        }
    }
    return result;
}
Also used : PGPPublicKeyRing(org.bouncycastle.openpgp.PGPPublicKeyRing) ArrayList(java.util.ArrayList) PGPPublicKey(org.bouncycastle.openpgp.PGPPublicKey)

Example 7 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class CxfEndpoint method setupHandlers.

protected void setupHandlers(ClientFactoryBean factoryBean, Client client) throws Exception {
    if (factoryBean instanceof JaxWsClientFactoryBean && handlers != null) {
        AnnotationHandlerChainBuilder builder = new AnnotationHandlerChainBuilder();
        Method m = factoryBean.getClass().getMethod("getServiceFactory");
        JaxWsServiceFactoryBean sf = (JaxWsServiceFactoryBean) m.invoke(factoryBean);
        @SuppressWarnings("rawtypes") List<Handler> chain = new ArrayList<Handler>(handlers);
        chain.addAll(builder.buildHandlerChainFromClass(sf.getServiceClass(), sf.getEndpointInfo().getName(), sf.getServiceQName(), factoryBean.getBindingId()));
        if (!chain.isEmpty()) {
            ResourceManager resourceManager = getBus().getExtension(ResourceManager.class);
            List<ResourceResolver> resolvers = resourceManager.getResourceResolvers();
            resourceManager = new DefaultResourceManager(resolvers);
            resourceManager.addResourceResolver(new WebServiceContextResourceResolver());
            ResourceInjector injector = new ResourceInjector(resourceManager);
            for (Handler<?> h : chain) {
                if (Proxy.isProxyClass(h.getClass()) && getServiceClass() != null) {
                    injector.inject(h, getServiceClass());
                    injector.construct(h, getServiceClass());
                } else {
                    injector.inject(h);
                    injector.construct(h);
                }
            }
        }
        ((JaxWsEndpointImpl) client.getEndpoint()).getJaxwsBinding().setHandlerChain(chain);
    }
}
Also used : JaxWsClientFactoryBean(org.apache.cxf.jaxws.JaxWsClientFactoryBean) JaxWsServiceFactoryBean(org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean) AnnotationHandlerChainBuilder(org.apache.cxf.jaxws.handler.AnnotationHandlerChainBuilder) ModCountCopyOnWriteArrayList(org.apache.cxf.common.util.ModCountCopyOnWriteArrayList) ArrayList(java.util.ArrayList) CookieHandler(org.apache.camel.http.common.cookie.CookieHandler) Handler(javax.xml.ws.handler.Handler) Method(java.lang.reflect.Method) ResourceManager(org.apache.cxf.resource.ResourceManager) DefaultResourceManager(org.apache.cxf.resource.DefaultResourceManager) ResourceInjector(org.apache.cxf.common.injection.ResourceInjector) DefaultResourceManager(org.apache.cxf.resource.DefaultResourceManager) ResourceResolver(org.apache.cxf.resource.ResourceResolver) WebServiceContextResourceResolver(org.apache.cxf.jaxws.context.WebServiceContextResourceResolver) WebServiceContextResourceResolver(org.apache.cxf.jaxws.context.WebServiceContextResourceResolver)

Example 8 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class DefaultCxfBinding method getPayloadBodyElements.

protected static List<Source> getPayloadBodyElements(Message message, Map<String, String> nsMap) {
    // take the namespace attribute from soap envelop
    Map<String, String> bodyNC = CastUtils.cast((Map<?, ?>) message.get("soap.body.ns.context"));
    if (bodyNC != null) {
        // if there is no Node and the addNamespaceContext option is enabled, this map is available
        nsMap.putAll(bodyNC);
    } else {
        Document soapEnv = (Document) message.getContent(Node.class);
        if (soapEnv != null) {
            NamedNodeMap attrs = soapEnv.getFirstChild().getAttributes();
            for (int i = 0; i < attrs.getLength(); i++) {
                Node node = attrs.item(i);
                if (!node.getNodeValue().equals(Soap11.SOAP_NAMESPACE) && !node.getNodeValue().equals(Soap12.SOAP_NAMESPACE)) {
                    nsMap.put(node.getLocalName(), node.getNodeValue());
                }
            }
        }
    }
    MessageContentsList inObjects = MessageContentsList.getContentsList(message);
    if (inObjects == null) {
        return new ArrayList<Source>(0);
    }
    org.apache.cxf.message.Exchange exchange = message.getExchange();
    BindingOperationInfo boi = exchange.getBindingOperationInfo();
    OperationInfo op = boi.getOperationInfo();
    if (boi.isUnwrapped()) {
        op = boi.getWrappedOperation().getOperationInfo();
    }
    List<MessagePartInfo> partInfos = null;
    boolean client = Boolean.TRUE.equals(message.get(Message.REQUESTOR_ROLE));
    if (client) {
        // it is a response
        partInfos = op.getOutput().getMessageParts();
    } else {
        // it is a request
        partInfos = op.getInput().getMessageParts();
    }
    List<Source> answer = new ArrayList<Source>();
    for (MessagePartInfo partInfo : partInfos) {
        if (!inObjects.hasValue(partInfo)) {
            continue;
        }
        Object part = inObjects.get(partInfo);
        if (part instanceof Holder) {
            part = ((Holder<?>) part).value;
        }
        if (part instanceof Source) {
            Element element = null;
            if (part instanceof DOMSource) {
                element = getFirstElement(((DOMSource) part).getNode());
            }
            if (element != null) {
                addNamespace(element, nsMap);
                answer.add(new DOMSource(element));
            } else {
                answer.add((Source) part);
            }
            if (LOG.isTraceEnabled()) {
                LOG.trace("Extract body element {}", element == null ? "null" : getXMLString(element));
            }
        } else if (part instanceof Element) {
            addNamespace((Element) part, nsMap);
            answer.add(new DOMSource((Element) part));
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Unhandled part type '{}'", part.getClass());
            }
        }
    }
    return answer;
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) DOMSource(javax.xml.transform.dom.DOMSource) NamedNodeMap(org.w3c.dom.NamedNodeMap) MessageContentsList(org.apache.cxf.message.MessageContentsList) Node(org.w3c.dom.Node) Holder(javax.xml.ws.Holder) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source)

Example 9 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class ConverterTest method testFallbackConverter.

@Test
public void testFallbackConverter() throws Exception {
    CamelContext context = new DefaultCamelContext();
    Exchange exchange = new DefaultExchange(context);
    MessageContentsList list = new MessageContentsList();
    NodeListWrapper nl = new NodeListWrapper(new ArrayList<Element>());
    list.add(nl);
    exchange.getIn().setBody(list);
    Node node = exchange.getIn().getBody(Node.class);
    assertNull(node);
    File file = new File("src/test/resources/org/apache/camel/component/cxf/converter/test.xml");
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    documentBuilderFactory.setNamespaceAware(true);
    DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
    Document document = documentBuilder.parse(file);
    document.getDocumentElement().normalize();
    List<Element> elements = new ArrayList<Element>();
    elements.add(document.getDocumentElement());
    nl = new NodeListWrapper(elements);
    list.clear();
    list.add(nl);
    exchange.getIn().setBody(list);
    node = exchange.getIn().getBody(Node.class);
    assertNotNull(node);
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) DefaultExchange(org.apache.camel.impl.DefaultExchange) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) MessageContentsList(org.apache.cxf.message.MessageContentsList) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DocumentBuilder(javax.xml.parsers.DocumentBuilder) File(java.io.File) Test(org.junit.Test)

Example 10 with ArrayList

use of java.util.ArrayList in project camel by apache.

the class CxfPayloadConverterTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    File file = new File("src/test/resources/org/apache/camel/component/cxf/converter/test.xml");
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    documentBuilderFactory.setNamespaceAware(true);
    DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
    document = documentBuilder.parse(file);
    document.getDocumentElement().normalize();
    List<Source> body = new ArrayList<Source>();
    body.add(new DOMSource(document.getDocumentElement()));
    List<Source> staxbody = new ArrayList<Source>();
    staxbody.add(new StAXSource(StaxUtils.createXMLStreamReader(new FileInputStream(file), "utf-8")));
    payload = new CxfPayload<String[]>(new ArrayList<String[]>(), body, null);
    emptyPayload = new CxfPayload<String[]>(new ArrayList<String[]>(), new ArrayList<Source>(), null);
    staxpayload = new CxfPayload<String[]>(new ArrayList<String[]>(), staxbody, null);
    inputStream = new FileInputStream(file);
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ArrayList(java.util.ArrayList) StAXSource(javax.xml.transform.stax.StAXSource) File(java.io.File) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source) SAXSource(javax.xml.transform.sax.SAXSource) StAXSource(javax.xml.transform.stax.StAXSource) FileInputStream(java.io.FileInputStream) Before(org.junit.Before)

Aggregations

ArrayList (java.util.ArrayList)55702 Test (org.junit.Test)8169 List (java.util.List)6815 HashMap (java.util.HashMap)5856 IOException (java.io.IOException)3899 Map (java.util.Map)3195 File (java.io.File)3090 HashSet (java.util.HashSet)2245 Iterator (java.util.Iterator)1591 Test (org.testng.annotations.Test)1074 SQLException (java.sql.SQLException)1046 ResultSet (java.sql.ResultSet)1017 Date (java.util.Date)997 Set (java.util.Set)917 LinkedHashMap (java.util.LinkedHashMap)886 PreparedStatement (java.sql.PreparedStatement)882 Collection (java.util.Collection)751 LinkedList (java.util.LinkedList)677 BufferedReader (java.io.BufferedReader)663 Path (org.apache.hadoop.fs.Path)611