Search in sources :

Example 1 with Entry

use of com.predic8.membrane.annot.model.doc.Doc.Entry in project service-proxy by membrane.

the class LimitedMemoryExchangeStore method getAllExchangesAsList.

public synchronized List<AbstractExchange> getAllExchangesAsList() {
    List<AbstractExchange> ret = new LinkedList<AbstractExchange>();
    for (Map.Entry<AbstractExchange, Request> entry : inflight.entrySet()) {
        AbstractExchange ex = entry.getKey();
        Request req = entry.getValue();
        Exchange newEx = new Exchange(null);
        newEx.setId(ex.getId());
        newEx.setRequest(req);
        newEx.setRule(ex.getRule());
        newEx.setRemoteAddr(ex.getRemoteAddr());
        newEx.setTime(ex.getTime());
        newEx.setTimeReqSent(ex.getTimeReqSent() != 0 ? ex.getTimeReqSent() : ex.getTimeReqReceived());
        newEx.setTimeResReceived(System.currentTimeMillis());
        ret.add(newEx);
    }
    ret.addAll(exchanges);
    return ret;
}
Also used : AbstractExchange(com.predic8.membrane.core.exchange.AbstractExchange) Exchange(com.predic8.membrane.core.exchange.Exchange) AbstractExchange(com.predic8.membrane.core.exchange.AbstractExchange) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 2 with Entry

use of com.predic8.membrane.annot.model.doc.Doc.Entry in project service-proxy by membrane.

the class RuleManager method openPorts.

public synchronized void openPorts() throws IOException {
    HashMap<IpPort, SSLProvider> sslProviders;
    try {
        HashMap<IpPort, SSLContextCollection.Builder> sslContexts = new HashMap<IpPort, SSLContextCollection.Builder>();
        for (Rule rule : rules) {
            SSLContext sslContext = rule.getSslInboundContext();
            if (sslContext != null) {
                IpPort ipPort = new IpPort(rule.getKey().getIp(), rule.getKey().getPort());
                SSLContextCollection.Builder builder = sslContexts.get(ipPort);
                if (builder == null) {
                    builder = new SSLContextCollection.Builder();
                    sslContexts.put(ipPort, builder);
                }
                builder.add(sslContext);
            }
        }
        sslProviders = new HashMap<IpPort, SSLProvider>();
        for (Map.Entry<IpPort, SSLContextCollection.Builder> entry : sslContexts.entrySet()) sslProviders.put(entry.getKey(), entry.getValue().build());
    } catch (ConfigurationException e) {
        throw new IOException(e);
    }
    for (Rule rule : rules) {
        IpPort ipPort = new IpPort(rule.getKey().getIp(), rule.getKey().getPort());
        router.getTransport().openPort(rule.getKey().getIp(), rule.getKey().getPort(), sslProviders.get(ipPort));
    }
}
Also used : SSLContextCollection(com.predic8.membrane.core.transport.ssl.SSLContextCollection) HashMap(java.util.HashMap) IpPort(com.predic8.membrane.core.transport.http.IpPort) SSLContext(com.predic8.membrane.core.transport.ssl.SSLContext) IOException(java.io.IOException) ConfigurationException(com.predic8.membrane.core.config.ConfigurationException) SSLProvider(com.predic8.membrane.core.transport.ssl.SSLProvider) Rule(com.predic8.membrane.core.rules.Rule) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with Entry

use of com.predic8.membrane.annot.model.doc.Doc.Entry in project service-proxy by membrane.

the class MCUtil method addXML.

private static void addXML(Object object, String id, XMLStreamWriter xew, SerializationContext sc) throws XMLStreamException {
    if (object == null)
        throw new InvalidParameterException("'object' must not be null.");
    Class<? extends Object> clazz = object.getClass();
    MCElement e = clazz.getAnnotation(MCElement.class);
    if (e == null)
        throw new IllegalArgumentException("'object' must be @MCElement-annotated.");
    BeanWrapperImpl src = new BeanWrapperImpl(object);
    xew.writeStartElement(e.name());
    if (id != null)
        xew.writeAttribute("id", id);
    HashSet<String> attributes = new HashSet<String>();
    for (Method m : clazz.getMethods()) {
        if (!m.getName().startsWith("set"))
            continue;
        String propertyName = AnnotUtils.dejavaify(m.getName().substring(3));
        MCAttribute a = m.getAnnotation(MCAttribute.class);
        if (a != null) {
            Object value = src.getPropertyValue(propertyName);
            String str;
            if (value == null)
                continue;
            else if (value instanceof String)
                str = (String) value;
            else if (value instanceof Boolean)
                str = ((Boolean) value).toString();
            else if (value instanceof Integer)
                str = ((Integer) value).toString();
            else if (value instanceof Long)
                str = ((Long) value).toString();
            else if (value instanceof Enum<?>)
                str = value.toString();
            else {
                MCElement el = value.getClass().getAnnotation(MCElement.class);
                if (el != null) {
                    str = defineBean(sc, value, null, true);
                } else {
                    str = "?";
                    sc.incomplete = true;
                }
            }
            if (a.attributeName().length() > 0)
                propertyName = a.attributeName();
            attributes.add(propertyName);
            xew.writeAttribute(propertyName, str);
        }
    }
    for (Method m : clazz.getMethods()) {
        if (!m.getName().startsWith("set"))
            continue;
        String propertyName = AnnotUtils.dejavaify(m.getName().substring(3));
        MCOtherAttributes o = m.getAnnotation(MCOtherAttributes.class);
        if (o != null) {
            Object value = src.getPropertyValue(propertyName);
            if (value instanceof Map<?, ?>) {
                Map<?, ?> map = (Map<?, ?>) value;
                for (Map.Entry<?, ?> entry : map.entrySet()) {
                    Object key = entry.getKey();
                    Object val = entry.getValue();
                    if (!(key instanceof String) || !(val instanceof String)) {
                        sc.incomplete = true;
                        key = "incompleteAttributes";
                        val = "?";
                    }
                    if (attributes.contains(key))
                        continue;
                    attributes.add((String) key);
                    xew.writeAttribute((String) key, (String) val);
                }
            } else {
                xew.writeAttribute("incompleteAttributes", "?");
                sc.incomplete = true;
            }
        }
    }
    List<Method> childElements = new ArrayList<Method>();
    for (Method m : clazz.getMethods()) {
        if (!m.getName().startsWith("set"))
            continue;
        String propertyName = AnnotUtils.dejavaify(m.getName().substring(3));
        MCChildElement c = m.getAnnotation(MCChildElement.class);
        if (c != null) {
            childElements.add(m);
        }
        MCTextContent t = m.getAnnotation(MCTextContent.class);
        if (t != null) {
            Object value = src.getPropertyValue(propertyName);
            if (value == null) {
                continue;
            } else if (value instanceof String) {
                xew.writeCharacters((String) value);
            } else {
                xew.writeCharacters("?");
                sc.incomplete = true;
            }
        }
    }
    Collections.sort(childElements, new Comparator<Method>() {

        @Override
        public int compare(Method o1, Method o2) {
            MCChildElement c1 = o1.getAnnotation(MCChildElement.class);
            MCChildElement c2 = o2.getAnnotation(MCChildElement.class);
            return c1.order() - c2.order();
        }
    });
    for (Method m : childElements) {
        String propertyName = AnnotUtils.dejavaify(m.getName().substring(3));
        Object value = src.getPropertyValue(propertyName);
        if (value != null) {
            if (value instanceof Collection<?>) {
                for (Object item : (Collection<?>) value) addXML(item, null, xew, sc);
            } else {
                addXML(value, null, xew, sc);
            }
        }
    }
    xew.writeEndElement();
}
Also used : MCChildElement(com.predic8.membrane.annot.MCChildElement) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) ArrayList(java.util.ArrayList) InvalidParameterException(java.security.InvalidParameterException) MCElement(com.predic8.membrane.annot.MCElement) MCAttribute(com.predic8.membrane.annot.MCAttribute) HashSet(java.util.HashSet) MCTextContent(com.predic8.membrane.annot.MCTextContent) Method(java.lang.reflect.Method) MCOtherAttributes(com.predic8.membrane.annot.MCOtherAttributes) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with Entry

use of com.predic8.membrane.annot.model.doc.Doc.Entry in project service-proxy by membrane.

the class Schemas method assembleDocumentation.

private void assembleDocumentation(Writer w, AbstractJavadocedInfo aji) throws IOException {
    Doc doc = aji.getDoc(processingEnv);
    if (doc == null)
        return;
    w.append("<xsd:annotation>\r\n");
    w.append("<xsd:documentation>");
    for (Entry e : doc.getEntries()) {
        w.append(xmlEscape("<h3><b>"));
        w.append(xmlEscape(capitalize(e.getKey()) + ":"));
        w.append(xmlEscape("</b></h3> "));
        w.append(xmlEscape(e.getValueAsXMLSnippet(false)));
        w.append(xmlEscape("<br/>"));
    }
    w.append("</xsd:documentation>\r\n");
    w.append("</xsd:annotation>\r\n");
}
Also used : Entry(com.predic8.membrane.annot.model.doc.Doc.Entry) Doc(com.predic8.membrane.annot.model.doc.Doc)

Aggregations

HashMap (java.util.HashMap)2 Map (java.util.Map)2 MCAttribute (com.predic8.membrane.annot.MCAttribute)1 MCChildElement (com.predic8.membrane.annot.MCChildElement)1 MCElement (com.predic8.membrane.annot.MCElement)1 MCOtherAttributes (com.predic8.membrane.annot.MCOtherAttributes)1 MCTextContent (com.predic8.membrane.annot.MCTextContent)1 Doc (com.predic8.membrane.annot.model.doc.Doc)1 Entry (com.predic8.membrane.annot.model.doc.Doc.Entry)1 ConfigurationException (com.predic8.membrane.core.config.ConfigurationException)1 AbstractExchange (com.predic8.membrane.core.exchange.AbstractExchange)1 Exchange (com.predic8.membrane.core.exchange.Exchange)1 Rule (com.predic8.membrane.core.rules.Rule)1 IpPort (com.predic8.membrane.core.transport.http.IpPort)1 SSLContext (com.predic8.membrane.core.transport.ssl.SSLContext)1 SSLContextCollection (com.predic8.membrane.core.transport.ssl.SSLContextCollection)1 SSLProvider (com.predic8.membrane.core.transport.ssl.SSLProvider)1 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 InvalidParameterException (java.security.InvalidParameterException)1