Java Code Examples for org.apache.cxf.common.logging.LogUtils#log()

The following examples show how to use org.apache.cxf.common.logging.LogUtils#log() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SSLUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
public static String getKeyPassword(String keyPassword, Logger log) {
    final String logMsg;
    if (keyPassword != null) {
        logMsg = "KEY_PASSWORD_SET";
    } else {
        keyPassword =
            SystemPropertyAction.getProperty("javax.net.ssl.keyPassword");
        if (keyPassword == null) {
            keyPassword =
                SystemPropertyAction.getProperty("javax.net.ssl.keyStorePassword");
        }
        logMsg = keyPassword != null
                 ? "KEY_PASSWORD_SYSTEM_PROPERTY_SET"
                 : "KEY_PASSWORD_NOT_SET";
    }
    LogUtils.log(log, Level.FINE, logMsg);
    return keyPassword;
}
 
Example 2
Source File: SSLUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
public static String getKeystoreType(String keyStoreType, Logger log, String def) {
    final String logMsg;
    if (keyStoreType != null) {
        logMsg = "KEY_STORE_TYPE_SET";
    } else {
        keyStoreType = SystemPropertyAction.getProperty("javax.net.ssl.keyStoreType", null);
        if (keyStoreType == null) {
            keyStoreType = def;
            logMsg = "KEY_STORE_TYPE_NOT_SET";
        } else {
            logMsg = "KEY_STORE_TYPE_SYSTEM_SET";
        }
    }
    LogUtils.log(log, Level.FINE, logMsg, keyStoreType);
    return keyStoreType;
}
 
Example 3
Source File: SoapFaultFactory.java    From cxf with Apache License 2.0 6 votes vote down vote up
Fault createSoap12Fault(SequenceFault sf, Message msg) {
    SoapFault fault = (SoapFault)createSoap11Fault(sf);
    fault.setSubCode(sf.getFaultCode());
    Object detail = sf.getDetail();
    if (null == detail) {
        return fault;
    }

    try {
        RMProperties rmps = RMContextUtils.retrieveRMProperties(msg, false);
        AddressingProperties maps = RMContextUtils.retrieveMAPs(msg, false, false);
        EncoderDecoder codec = ProtocolVariation.findVariant(rmps.getNamespaceURI(),
            maps.getNamespaceURI()).getCodec();
        setDetail(fault, detail, codec);
    } catch (Exception ex) {
        LogUtils.log(LOG, Level.SEVERE, "MARSHAL_FAULT_DETAIL_EXC", ex);
        ex.printStackTrace();
    }
    return fault;
}
 
Example 4
Source File: SSLUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
public static String getKeystore(String keyStoreLocation, Logger log) {
    final String logMsg;
    if (keyStoreLocation != null) {
        logMsg = "KEY_STORE_SET";
    } else {
        keyStoreLocation = SystemPropertyAction.getProperty("javax.net.ssl.keyStore");
        if (keyStoreLocation != null) {
            logMsg = "KEY_STORE_SYSTEM_PROPERTY_SET";
        } else {
            keyStoreLocation =
                SystemPropertyAction.getProperty("user.home") + "/.keystore";
            logMsg = "KEY_STORE_NOT_SET";
        }
    }
    LogUtils.log(log, Level.FINE, logMsg, keyStoreLocation);
    return keyStoreLocation;
}
 
Example 5
Source File: SSLUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
public static KeyManager[] loadKeyStore(KeyManagerFactory kmf,
                                           KeyStore ks,
                                           InputStream is,
                                           String keyStoreLocation,
                                           String keyStorePassword,
                                           Logger log) {
    KeyManager[] keystoreManagers = null;
    try {
        ks.load(is, keyStorePassword.toCharArray());
        kmf.init(ks, keyStorePassword.toCharArray());
        keystoreManagers = kmf.getKeyManagers();
        LogUtils.log(log,
                     Level.FINE,
                     "LOADED_KEYSTORE",
                     keyStoreLocation);
    } catch (Exception e) {
        LogUtils.log(log,
                     Level.WARNING,
                     "FAILED_TO_LOAD_KEYSTORE",
                     new Object[]{keyStoreLocation, e.getMessage()});
    }
    return keystoreManagers;
}
 
Example 6
Source File: SSLUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static String[] getCiphersuitesToInclude(List<String> cipherSuitesList,
                                       FiltersType filters,
                                       String[] defaultCipherSuites,
                                       String[] supportedCipherSuites,
                                       Logger log) {
    // CipherSuites are returned in the following priority:
    // 1) If we have defined explicit "cipherSuite" configuration
    // 2) If we have defined ciphersuites via a system property.
    // 3) The default JVM CipherSuites, if no filters have been defined
    // 4) Filter the supported cipher suites (*not* the default JVM CipherSuites)
    if (!(cipherSuitesList == null || cipherSuitesList.isEmpty())) {
        return getCiphersFromList(cipherSuitesList, log, false);
    }

    String[] cipherSuites = getSystemCiphersuites(log);
    if (cipherSuites != null) {
        return cipherSuites;
    }

    // If we have no explicit cipherSuites (for the include case as above), and no filters,
    // then just use the defaults
    if ((defaultCipherSuites != null && defaultCipherSuites.length != 0)
        && (filters == null || !(filters.isSetInclude() || filters.isSetExclude()))) {
        LogUtils.log(log, Level.FINE, "CIPHERSUITES_SET", Arrays.toString(defaultCipherSuites));
        return defaultCipherSuites;
    }

    LogUtils.log(log, Level.FINE, "CIPHERSUITES_NOT_SET");

    return getFilteredCiphersuites(filters, supportedCipherSuites, log, false);
}
 
Example 7
Source File: SSLUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static String getTruststore(String trustStoreLocation, Logger log) {
    final String logMsg;
    if (trustStoreLocation != null) {
        logMsg = "TRUST_STORE_SET";
    } else {
        trustStoreLocation = SystemPropertyAction.getProperty("javax.net.ssl.trustStore");
        if (trustStoreLocation != null) {
            logMsg = "TRUST_STORE_SYSTEM_PROPERTY_SET";
        } else {
            logMsg = "TRUST_STORE_NOT_SET";
        }
    }
    LogUtils.log(log, Level.FINE, logMsg, trustStoreLocation);
    return trustStoreLocation;
}
 
Example 8
Source File: SSLUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static String getKeystoreProvider(String keyStoreProvider, Logger log) {
    final String logMsg;
    if (keyStoreProvider != null) {
        logMsg = "KEY_STORE_PROVIDER_SET";
    } else {
        keyStoreProvider = SystemPropertyAction.getProperty("javax.net.ssl.keyStoreProvider", null);
        if (keyStoreProvider == null) {
            logMsg = "KEY_STORE_PROVIDER_NOT_SET";
        } else {
            logMsg = "KEY_STORE_PROVIDER_SYSTEM_SET";
        }
    }
    LogUtils.log(log, Level.FINE, logMsg, keyStoreProvider);
    return keyStoreProvider;
}
 
Example 9
Source File: ConfigurerImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void initWildcardDefinitionMap() {
    if (null != appContexts) {
        for (ApplicationContext appContext : appContexts) {
            for (String n : appContext.getBeanDefinitionNames()) {
                if (isWildcardBeanName(n)) {
                    AutowireCapableBeanFactory bf = appContext.getAutowireCapableBeanFactory();
                    BeanDefinitionRegistry bdr = (BeanDefinitionRegistry) bf;
                    BeanDefinition bd = bdr.getBeanDefinition(n);
                    String className = bd.getBeanClassName();
                    if (null != className) {
                        final String name = n.charAt(0) != '*' ? n
                                : "." + n.replaceAll("\\.", "\\."); //old wildcard
                        try {
                            Matcher matcher = Pattern.compile(name).matcher("");
                            List<MatcherHolder> m = wildCardBeanDefinitions.get(className);
                            if (m == null) {
                                m = new ArrayList<>();
                                wildCardBeanDefinitions.put(className, m);
                            }
                            MatcherHolder holder = new MatcherHolder(n, matcher);
                            m.add(holder);
                        } catch (PatternSyntaxException npe) {
                            //not a valid patter, we'll ignore
                        }
                    } else {
                        LogUtils.log(LOG, Level.WARNING, "WILDCARD_BEAN_ID_WITH_NO_CLASS_MSG", n);
                    }
                }
            }
        }
    }
}
 
Example 10
Source File: PhaseInterceptorChain.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void doDefaultLogging(Message message, Exception ex, String description) {
    FaultMode mode = message.get(FaultMode.class);
    if (mode == FaultMode.CHECKED_APPLICATION_FAULT) {
        if (isFineLogging) {
            LogUtils.log(LOG, Level.FINE,
                         "Application " + description
                         + "has thrown exception, unwinding now", ex);
        } else if (LOG.isLoggable(Level.INFO)) {
            Throwable t = ex;
            if (ex instanceof Fault
                && ex.getCause() != null) {
                t = ex.getCause();
            }

            LogUtils.log(LOG, Level.INFO,
                         "Application " + description
                         + "has thrown exception, unwinding now: "
                         + t.getClass().getName()
                         + ": " + ex.getMessage());
        }
    } else if (LOG.isLoggable(Level.WARNING)) {
        if (mode == FaultMode.UNCHECKED_APPLICATION_FAULT) {
            LogUtils.log(LOG, Level.WARNING,
                         "Application " + description
                         + "has thrown exception, unwinding now", ex);
        } else {
            LogUtils.log(LOG, Level.WARNING,
                         "Interceptor for " + description
                         + "has thrown exception, unwinding now", ex);
        }
    }
}
 
Example 11
Source File: ContextUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * @param message the current message
 * @param isProviderContext true if the binding provider request context
 * available to the client application as opposed to the message context
 * visible to handlers
 * @param isOutbound true if the message is outbound
 * @param warnIfMissing log a warning  message if properties cannot be retrieved
 * @return the current addressing properties
 */
public static AddressingProperties retrieveMAPs(
                                               Message message,
                                               boolean isProviderContext,
                                               boolean isOutbound,
                                               boolean warnIfMissing) {
    boolean isRequestor = ContextUtils.isRequestor(message);
    String mapProperty =
        ContextUtils.getMAPProperty(isRequestor,
                                    isProviderContext,
                                    isOutbound);
    LOG.log(Level.FINE,
            "retrieving MAPs from context property {0}",
            mapProperty);

    AddressingProperties maps =
        (AddressingProperties)message.get(mapProperty);
    if (maps == null && isOutbound && !isRequestor
        && message.getExchange() != null && message.getExchange().getInMessage() != null) {
        maps = (AddressingProperties)message.getExchange().getInMessage().get(mapProperty);
    }

    if (maps != null) {
        LOG.log(Level.FINE, "current MAPs {0}", maps);
    } else if (!isProviderContext) {
        LogUtils.log(LOG, warnIfMissing ? Level.WARNING : Level.FINE,
            "MAPS_RETRIEVAL_FAILURE_MSG");
    }
    return maps;
}
 
Example 12
Source File: SSLUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static String[] getCiphersFromList(List<String> cipherSuitesList,
                                           Logger log,
                                           boolean exclude) {
    String[] cipherSuites = cipherSuitesList.toArray(new String[0]);
    if (log.isLoggable(Level.FINE)) {
        LogUtils.log(log, Level.FINE,
            exclude ? "CIPHERSUITES_EXCLUDED" : "CIPHERSUITES_SET", String.join(", ", cipherSuites));
    }
    return cipherSuites;
}
 
Example 13
Source File: SpringBusFactory.java    From cxf with Apache License 2.0 5 votes vote down vote up
public Bus createBus(URL[] urls, boolean includeDefaults) {
    try {
        return finishCreatingBus(createAppContext(urls, includeDefaults));
    } catch (BeansException ex) {
        LogUtils.log(LOG, Level.WARNING, "APP_CONTEXT_CREATION_FAILED_MSG", ex, (Object[])null);
        throw new RuntimeException(ex);
    }
}
 
Example 14
Source File: AbstractRMInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleMessage(Message msg) throws Fault {

        try {
            handle(msg);
        } catch (SequenceFault sf) {

            // log the fault as it may not be reported back to the client

            Endpoint e = msg.getExchange().getEndpoint();
            Binding b = null;
            if (null != e) {
                b = e.getBinding();
            }
            if (null != b) {
                RMManager m = getManager();
                LOG.fine("Manager: " + m);
                BindingFaultFactory bff = m.getBindingFaultFactory(b);
                Fault f = bff.createFault(sf, msg);
                // log with warning instead sever, as this may happen for some delayed messages
                LogUtils.log(LOG, Level.WARNING, "SEQ_FAULT_MSG", bff.toString(f));
                throw f;
            }
            throw new Fault(sf);
        }  catch (RMException ex) {
            throw new Fault(ex);
        }
    }
 
Example 15
Source File: DestinationSequence.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void run() {
    synchronized (DestinationSequence.this) {
        DestinationSequence.this.scheduledTermination = null;
        RMEndpoint rme = destination.getReliableEndpoint();
        long lat = Math.max(rme.getLastControlMessage(), rme.getLastApplicationMessage());
        if (0 == lat) {
            return;
        }
        long now = System.currentTimeMillis();
        if (now - lat >= maxInactivityTimeout) {

            // terminate regardless outstanding acknowledgments - as we assume that the client is
            // gone there is no point in sending a SequenceAcknowledgment
            LogUtils.log(LOG, Level.WARNING, "TERMINATING_INACTIVE_SEQ_MSG",
                         DestinationSequence.this.getIdentifier().getValue());
            DestinationSequence.this.destination.terminateSequence(DestinationSequence.this, true);
            Source source = rme.getSource();
            if (source != null) {
                SourceSequence ss = source.getAssociatedSequence(DestinationSequence.this.getIdentifier());
                if (ss != null) {
                    source.removeSequence(ss);
                }
            }
        } else {
           // reschedule
            SequenceTermination st = new SequenceTermination();
            st.updateInactivityTimeout(maxInactivityTimeout);
            DestinationSequence.this.destination.getManager().getTimer()
                .schedule(st, maxInactivityTimeout);
        }
    }
}
 
Example 16
Source File: RMTxStore.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected Connection verifyConnection() {
    Connection con;
    if (connection == null) {
        // return a new connection
        con = createConnection();
    } else {
        // return the cached connection or create and cache a new one if the old one is dead
        synchronized (this) {
            if (createdConnection && nextReconnectAttempt > 0
                && (maxReconnectAttempts < 0 || maxReconnectAttempts > reconnectAttempts)) {
                if (System.currentTimeMillis() > nextReconnectAttempt) {
                    // destroy the broken connection
                    destroy();
                    // try to reconnect
                    reconnectAttempts++;
                    init();
                    // reset the next reconnect attempt time
                    nextReconnectAttempt = 0;
                } else {
                    LogUtils.log(LOG, Level.INFO, "WAIT_RECONNECT_MSG");
                }
            }
        }
        con = connection;
    }

    return con;
}
 
Example 17
Source File: SSLUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static String getTrustStoreAlgorithm(
                                    String trustStoreMgrFactoryAlgorithm,
                                    Logger log) {
    final String logMsg;
    if (trustStoreMgrFactoryAlgorithm != null) {
        logMsg = "TRUST_STORE_ALGORITHM_SET";
    } else {
        trustStoreMgrFactoryAlgorithm =
            TrustManagerFactory.getDefaultAlgorithm();
        logMsg = "TRUST_STORE_ALGORITHM_NOT_SET";
    }
    LogUtils.log(log, Level.FINE, logMsg, trustStoreMgrFactoryAlgorithm);
    return trustStoreMgrFactoryAlgorithm;
}
 
Example 18
Source File: DatatypeFactory.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static Duration createDuration(String s) {
    try {
        return javax.xml.datatype.DatatypeFactory.newInstance().newDuration(s);
    } catch (DatatypeConfigurationException ex) {
        LogUtils.log(LOG, Level.SEVERE, "DATATYPE_FACTORY_INSTANTIATION_EXC", ex);
    }
    return null;
}
 
Example 19
Source File: BusFactory.java    From cxf with Apache License 2.0 4 votes vote down vote up
private static String getBusFactoryClass(ClassLoader classLoader) {

        // next check system properties
        String busFactoryClass = SystemPropertyAction.getPropertyOrNull(BusFactory.BUS_FACTORY_PROPERTY_NAME);
        if (isValidBusFactoryClass(busFactoryClass)) {
            return busFactoryClass;
        }

        try {
            // next, check for the services stuff in the jar file
            String serviceId = "META-INF/services/" + BusFactory.BUS_FACTORY_PROPERTY_NAME;
            InputStream is;

            if (classLoader == null) {
                classLoader = Thread.currentThread().getContextClassLoader();
            }

            if (classLoader == null) {
                is = ClassLoader.getSystemResourceAsStream(serviceId);
            } else {
                is = classLoader.getResourceAsStream(serviceId);
            }
            if (is == null) {
                serviceId = "META-INF/cxf/" + BusFactory.BUS_FACTORY_PROPERTY_NAME;

                if (classLoader == null) {
                    classLoader = Thread.currentThread().getContextClassLoader();
                }

                if (classLoader == null) {
                    is = ClassLoader.getSystemResourceAsStream(serviceId);
                } else {
                    is = classLoader.getResourceAsStream(serviceId);
                }
            }

            String busFactoryCondition = null;

            if (is != null) {
                try (BufferedReader rd = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
                    busFactoryClass = rd.readLine();
                    busFactoryCondition = rd.readLine();
                }
            }
            if (isValidBusFactoryClass(busFactoryClass)
                && busFactoryCondition != null) {
                try {
                    Class<?> cls = ClassLoaderUtils.loadClass(busFactoryClass, BusFactory.class)
                        .asSubclass(BusFactory.class);
                    if (busFactoryCondition.startsWith("#")) {
                        busFactoryCondition = busFactoryCondition.substring(1);
                    }
                    int idx = busFactoryCondition.indexOf(',');
                    while (idx != -1) {
                        cls.getClassLoader().loadClass(busFactoryCondition.substring(0, idx));
                        busFactoryCondition = busFactoryCondition.substring(idx + 1);
                        idx = busFactoryCondition.indexOf(',');
                    }
                    cls.getClassLoader().loadClass(busFactoryCondition);
                } catch (ClassNotFoundException | NoClassDefFoundError e) {
                    busFactoryClass = DEFAULT_BUS_FACTORY;
                }

            }

        } catch (Exception ex) {
            LogUtils.log(LOG, Level.SEVERE, "FAILED_TO_DETERMINE_BUS_FACTORY_EXC", ex);
        }
        return busFactoryClass;
    }
 
Example 20
Source File: Servant.java    From cxf with Apache License 2.0 4 votes vote down vote up
public Object invoke(Exchange exchange, Object o) {
    LOG.fine("Invoking on RM Endpoint");
    final ProtocolVariation protocol = RMContextUtils.getProtocolVariation(exchange.getInMessage());
    OperationInfo oi = exchange.getBindingOperationInfo().getOperationInfo();
    if (null == oi) {
        LOG.fine("No operation info.");
        return null;
    }

    if (RM10Constants.INSTANCE.getCreateSequenceOperationName().equals(oi.getName())
        || RM11Constants.INSTANCE.getCreateSequenceOperationName().equals(oi.getName())
        || RM10Constants.INSTANCE.getCreateSequenceOnewayOperationName().equals(oi.getName())
        || RM11Constants.INSTANCE.getCreateSequenceOnewayOperationName().equals(oi.getName())) {
        try {
            return Collections.singletonList(createSequence(exchange.getInMessage()));
        } catch (RuntimeException ex) {
            LOG.log(Level.WARNING, "Sequence creation rejected", ex);
            SequenceFault sf =
                new SequenceFaultFactory(protocol.getConstants()).createCreateSequenceRefusedFault();
            Endpoint e = exchange.getEndpoint();
            Binding b = null == e ? null : e.getBinding();
            if (null != b) {
                RMManager m = reliableEndpoint.getManager();
                LOG.fine("Manager: " + m);
                BindingFaultFactory bff = m.getBindingFaultFactory(b);
                Fault f = bff.createFault(sf, exchange.getInMessage());
                // log with warning instead sever, as this may happen for some delayed messages
                LogUtils.log(LOG, Level.WARNING, "SEQ_FAULT_MSG", bff.toString(f));
                throw f;
            }
            throw new Fault(sf);
        }
    } else if (RM10Constants.INSTANCE.getCreateSequenceResponseOnewayOperationName().equals(oi.getName())
        || RM11Constants.INSTANCE.getCreateSequenceResponseOnewayOperationName().equals(oi.getName())) {
        EncoderDecoder codec = protocol.getCodec();
        CreateSequenceResponseType createResponse =
            codec.convertReceivedCreateSequenceResponse(getParameter(exchange.getInMessage()));
        createSequenceResponse(createResponse, protocol);
    } else if (RM10Constants.INSTANCE.getTerminateSequenceOperationName().equals(oi.getName())
        || RM11Constants.INSTANCE.getTerminateSequenceOperationName().equals(oi.getName())) {
        Object tsr = terminateSequence(exchange.getInMessage());
        if (tsr != null) {
            return Collections.singletonList(tsr);
        }
    } else if (RM11Constants.INSTANCE.getCloseSequenceOperationName().equals(oi.getName())) {
        return Collections.singletonList(closeSequence(exchange.getInMessage()));
    }

    return null;
}