Search in sources :

Example 26 with Log

use of org.apache.commons.logging.Log in project jbosstools-hibernate by jbosstools.

the class HibernatePlugin method start.

public void start(BundleContext context) throws Exception {
    super.start(context);
    configureLog4jHooks();
    Log log = LogFactory.getLog(HibernatePlugin.class);
    // $NON-NLS-1$
    log.info("HibernatePlugin Started");
}
Also used : Log(org.apache.commons.logging.Log)

Example 27 with Log

use of org.apache.commons.logging.Log in project spring-cloud-config by spring-cloud.

the class JGitEnvironmentRepositoryTests method shouldPrintStacktraceIfDebugEnabled.

@Test
public void shouldPrintStacktraceIfDebugEnabled() throws Exception {
    final Log mockLogger = mock(Log.class);
    JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment, new JGitEnvironmentProperties()) {

        @Override
        public void afterPropertiesSet() throws Exception {
            this.logger = mockLogger;
        }
    };
    envRepository.afterPropertiesSet();
    when(mockLogger.isDebugEnabled()).thenReturn(true);
    envRepository.warn("", new RuntimeException());
    verify(mockLogger).warn(eq(""));
    verify(mockLogger).debug(eq("Stacktrace for: "), any(RuntimeException.class));
    int numberOfInvocations = mockingDetails(mockLogger).getInvocations().size();
    assertEquals("should call isDebugEnabled warn and debug", 3, numberOfInvocations);
}
Also used : Log(org.apache.commons.logging.Log) Test(org.junit.Test)

Example 28 with Log

use of org.apache.commons.logging.Log in project spring-cloud-sleuth by spring-cloud.

the class SpanSubscriberTests method should_pass_tracing_info_when_using_reactor_async.

@Test
public void should_pass_tracing_info_when_using_reactor_async() {
    Span span = this.tracer.nextSpan().name("foo").start();
    final AtomicReference<Span> spanInOperation = new AtomicReference<>();
    log.info("Hello");
    try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(span)) {
        Flux.just(1, 2, 3).publishOn(Schedulers.single()).log("reactor.1").map(d -> d + 1).map(d -> d + 1).publishOn(Schedulers.newSingle("secondThread")).log("reactor.2").map((d) -> {
            spanInOperation.set(SpanSubscriberTests.this.tracer.currentSpan());
            return d + 1;
        }).map(d -> d + 1).blockLast();
        Awaitility.await().untilAsserted(() -> {
            then(spanInOperation.get().context().traceId()).isEqualTo(span.context().traceId());
        });
        then(this.tracer.currentSpan()).isEqualTo(span);
    } finally {
        span.finish();
    }
    then(this.tracer.currentSpan()).isNull();
    Span foo2 = this.tracer.nextSpan().name("foo").start();
    try (Tracer.SpanInScope ws = this.tracer.withSpanInScope(foo2)) {
        Flux.just(1, 2, 3).publishOn(Schedulers.single()).log("reactor.").map(d -> d + 1).map(d -> d + 1).map((d) -> {
            spanInOperation.set(SpanSubscriberTests.this.tracer.currentSpan());
            return d + 1;
        }).map(d -> d + 1).blockLast();
        then(this.tracer.currentSpan()).isEqualTo(foo2);
        // parent cause there's an async span in the meantime
        then(spanInOperation.get().context().traceId()).isEqualTo(foo2.context().traceId());
    } finally {
        foo2.finish();
    }
    then(this.tracer.currentSpan()).isNull();
}
Also used : BeforeClass(org.junit.BeforeClass) RunWith(org.junit.runner.RunWith) Span(brave.Span) Hooks(reactor.core.publisher.Hooks) Autowired(org.springframework.beans.factory.annotation.Autowired) AtomicReference(java.util.concurrent.atomic.AtomicReference) Sampler(brave.sampler.Sampler) Schedulers(reactor.core.scheduler.Schedulers) SpringRunner(org.springframework.test.context.junit4.SpringRunner) Tracing(brave.Tracing) AfterClass(org.junit.AfterClass) Tracer(brave.Tracer) EnableAutoConfiguration(org.springframework.boot.autoconfigure.EnableAutoConfiguration) Publisher(org.reactivestreams.Publisher) Mono(reactor.core.publisher.Mono) Test(org.junit.Test) BDDAssertions.then(org.assertj.core.api.BDDAssertions.then) BaseSubscriber(reactor.core.publisher.BaseSubscriber) Configuration(org.springframework.context.annotation.Configuration) Flux(reactor.core.publisher.Flux) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Subscription(org.reactivestreams.Subscription) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) Bean(org.springframework.context.annotation.Bean) Awaitility(org.awaitility.Awaitility) Tracer(brave.Tracer) AtomicReference(java.util.concurrent.atomic.AtomicReference) Span(brave.Span) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 29 with Log

use of org.apache.commons.logging.Log in project carbon-business-process by wso2.

the class SVGGenerateServlet method processRequest.

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
 * Handles the HTTP process request which creates the SVG graph for a bpel process
 *
 * @param request  servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException      if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    Log log = LogFactory.getLog(SVGGenerateServlet.class);
    HttpSession session = request.getSession(true);
    // Get the bpel process id
    String pid = CharacterEncoder.getSafeText(request.getParameter("pid"));
    ServletConfig config = getServletConfig();
    String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
    ConfigurationContext configContext = (ConfigurationContext) config.getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
    String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
    String processDef = null;
    ProcessManagementServiceClient client = null;
    SVGInterface svg = null;
    String svgStr = null;
    ServletOutputStream sos = null;
    sos = response.getOutputStream();
    try {
        client = new ProcessManagementServiceClient(cookie, backendServerURL, configContext, request.getLocale());
        // Gets the bpel process definition needed to create the SVG from the processId
        processDef = client.getProcessInfo(QName.valueOf(pid)).getDefinitionInfo().getDefinition().getExtraElement().toString();
        BPELInterface bpel = new BPELImpl();
        // Converts the bpel process definition to an omElement which is how the AXIS2 Object Model (AXIOM)
        // represents an XML document
        OMElement bpelStr = bpel.load(processDef);
        /**
         * Process the OmElement containing the bpel process definition
         * Process the subactivites of the bpel process by iterating through the omElement
         */
        bpel.processBpelString(bpelStr);
        // Create a new instance of the LayoutManager for the bpel process
        LayoutManager layoutManager = BPEL2SVGFactory.getInstance().getLayoutManager();
        // Set the layout of the SVG to vertical
        layoutManager.setVerticalLayout(true);
        // Get the root activity i.e. the Process Activity
        layoutManager.layoutSVG(bpel.getRootActivity());
        svg = new SVGImpl();
        // Set the root activity of the SVG i.e. the Process Activity
        svg.setRootActivity(bpel.getRootActivity());
        // Set the content type of the HTTP response as "image/svg+xml"
        response.setContentType("image/svg+xml");
        // Get the SVG graph created for the process as a SVG string
        svgStr = svg.generateSVGString();
        // Checks whether the SVG string generated contains a value
        if (svgStr != null) {
            // stream to write binary data into the response
            sos.write(svgStr.getBytes(Charset.defaultCharset()));
            sos.flush();
            sos.close();
        }
    } catch (ProcessManagementException e) {
        log.error("SVG Generation Error", e);
        String errorSVG = "<svg version=\"1.1\"\n" + "     xmlns=\"http://www.w3.org/2000/svg\"><text y=\"50\">Could not display SVG</text></svg>";
        sos.write(errorSVG.getBytes(Charset.defaultCharset()));
        sos.flush();
        sos.close();
    }
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Log(org.apache.commons.logging.Log) ServletOutputStream(javax.servlet.ServletOutputStream) BPELImpl(org.wso2.carbon.bpel.ui.bpel2svg.impl.BPELImpl) HttpSession(javax.servlet.http.HttpSession) ServletConfig(javax.servlet.ServletConfig) ProcessManagementServiceClient(org.wso2.carbon.bpel.ui.clients.ProcessManagementServiceClient) OMElement(org.apache.axiom.om.OMElement) ProcessManagementException(org.wso2.carbon.bpel.stub.mgt.ProcessManagementException) SVGImpl(org.wso2.carbon.bpel.ui.bpel2svg.impl.SVGImpl)

Example 30 with Log

use of org.apache.commons.logging.Log in project carbon-business-process by wso2.

the class PNGGenarateServlet method processRequest.

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
 *
 * @param request  servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException      if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    Log log = LogFactory.getLog(PNGGenarateServlet.class);
    HttpSession session = request.getSession(true);
    String pid = CharacterEncoder.getSafeText(request.getParameter("pid"));
    ServletConfig config = getServletConfig();
    String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
    ConfigurationContext configContext = (ConfigurationContext) config.getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
    String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
    String processDef;
    ProcessManagementServiceClient client;
    SVGInterface svg;
    String svgStr;
    try {
        client = new ProcessManagementServiceClient(cookie, backendServerURL, configContext, request.getLocale());
        // Gets the bpel process definition needed to create the SVG from the processId
        processDef = client.getProcessInfo(QName.valueOf(pid)).getDefinitionInfo().getDefinition().getExtraElement().toString();
        BPELInterface bpel = new BPELImpl();
        // Converts the bpel process definition to an omElement which is how the AXIS2 Object Model (AXIOM)
        // represents an XML document
        OMElement bpelStr = bpel.load(processDef);
        /**
         * Process the OmElement containing the bpel process definition
         * Process the subactivites of the bpel process by iterating through the omElement
         */
        bpel.processBpelString(bpelStr);
        // Create a new instance of the LayoutManager for the bpel process
        LayoutManager layoutManager = BPEL2SVGFactory.getInstance().getLayoutManager();
        // Set the layout of the SVG to vertical
        layoutManager.setVerticalLayout(true);
        // Get the root activity i.e. the Process Activity
        layoutManager.layoutSVG(bpel.getRootActivity());
        svg = new SVGImpl();
        // Set the root activity of the SVG i.e. the Process Activity
        svg.setRootActivity(bpel.getRootActivity());
        // Set the content type of the HTTP response as "image/png"
        response.setContentType("image/png");
        // Create an instance of ServletOutputStream to write the output
        ServletOutputStream sos = response.getOutputStream();
        // Convert the image as a byte array of a PNG
        byte[] pngBytes = svg.toPNGBytes();
        // stream to write binary data into the response
        sos.write(pngBytes);
        sos.flush();
        sos.close();
    } catch (ProcessManagementException e) {
        log.error("PNG Generation Error", e);
    }
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Log(org.apache.commons.logging.Log) BPELImpl(org.wso2.carbon.bpel.ui.bpel2svg.impl.BPELImpl) ServletOutputStream(javax.servlet.ServletOutputStream) HttpSession(javax.servlet.http.HttpSession) ServletConfig(javax.servlet.ServletConfig) ProcessManagementServiceClient(org.wso2.carbon.bpel.ui.clients.ProcessManagementServiceClient) OMElement(org.apache.axiom.om.OMElement) ProcessManagementException(org.wso2.carbon.bpel.stub.mgt.ProcessManagementException) SVGImpl(org.wso2.carbon.bpel.ui.bpel2svg.impl.SVGImpl)

Aggregations

Log (org.apache.commons.logging.Log)188 Test (org.junit.Test)51 Test (org.junit.jupiter.api.Test)40 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)35 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)19 BeanFactory (org.springframework.beans.factory.BeanFactory)17 CountDownLatch (java.util.concurrent.CountDownLatch)15 LogConfigurationException (org.apache.commons.logging.LogConfigurationException)15 ArrayList (java.util.ArrayList)12 File (java.io.File)11 QueueChannel (org.springframework.integration.channel.QueueChannel)11 MethodInvocation (org.aopalliance.intercept.MethodInvocation)10 IOException (java.io.IOException)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 Log4JLogger (org.apache.commons.logging.impl.Log4JLogger)9 Message (org.springframework.messaging.Message)8 List (java.util.List)7 ApplicationEventPublisher (org.springframework.context.ApplicationEventPublisher)7 InputStream (java.io.InputStream)6 LogFactory (org.apache.commons.logging.LogFactory)6