<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by AJawhar on Medium]]></title>
        <description><![CDATA[Stories by AJawhar on Medium]]></description>
        <link>https://medium.com/@alaajawhar123?source=rss-11f12cc62aa5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*K7NWbXcGMzsruOF0</url>
            <title>Stories by AJawhar on Medium</title>
            <link>https://medium.com/@alaajawhar123?source=rss-11f12cc62aa5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 14:53:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alaajawhar123/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Generate Curl from HttpRequest in Spring]]></title>
            <link>https://medium.com/@alaajawhar123/generate-curl-from-httprequest-in-spring-b85d8567360d?source=rss-11f12cc62aa5------2</link>
            <guid isPermaLink="false">https://medium.com/p/b85d8567360d</guid>
            <category><![CDATA[spring-framework]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[postman]]></category>
            <category><![CDATA[app-development]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[AJawhar]]></dc:creator>
            <pubDate>Wed, 31 May 2023 07:14:59 GMT</pubDate>
            <atom:updated>2023-05-31T07:18:25.549Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever found yourself in a situation where you needed to reproduce a specific API call to test your changes or fix a bug? When working on a large project with multiple security layers, authentication, and authorization mechanisms, using tools like Postman to test your APIs can become challenging.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/582/1*ZJYlA1gRmx4PeLLoONb_Bg.png" /><figcaption>CURL Command</figcaption></figure><h3>What is CURL command</h3><p>That’s where the CURL command comes in handy. CURL is a powerful command-line tool available in Linux that allows you to consume APIs directly.</p><p>here a sample of CURL command:</p><pre>curl &#39;http://localhost:8082/hazoura/riddle/list&#39; -H &#39;Content-Type: application/json&#39; -d &#39;{<br>    &quot;count&quot;: &quot;as&quot;<br>}&#39;lin</pre><p>In Postman, you can even import a CURL command and have it readily available for testing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-5-UgrLa25WcjciA7iWoDQ.png" /><figcaption>Import Button in Postman</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1gBqjjrLvppXsTYEsOqC2Q.png" /><figcaption>Paste Your Curl in Postman</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ipPlptMGP9kgYbdf_L0pZA.png" /><figcaption>result of importing CURL into Postman</figcaption></figure><h3>How can we generate a CURL to replicate our API</h3><h4>Web</h4><p>If you are developing a web application and encounter any issues with your API, you can conveniently obtain its CURL command by following these steps then inject it into Postman shown before.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*1R834ilIn2wIvonbKvB-5w.png" /><figcaption>Copy CURL command from your browser</figcaption></figure><h4>Mobile</h4><p>But how can we generate a CURL command to replicate API requests when developing a backend for a mobile app? It&#39;s not as straightforward as inspecting network requests in a web browser. However, the only way is to generate it through code from the backend side.</p><p>Let’s take a look at how we can generate a curl command from the backend:</p><pre>private static requestToCurl(https://medium.com/HttpServletRequest%20request,%20%3Cbr%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Object%20requestBody) throws IOException {<br><br>        StringBuilder result = new StringBuilder();<br><br>        result.append(&quot;curl --location --request &quot;);<br><br>        // output method<br>        result.append(request.getMethod()).append(&quot; &quot;);<br><br>        // output url<br>        result.append(&quot;\&quot;&quot;)<br>              .append(request.getRequestURL().toString())<br>              .append(&quot;\&quot;&quot;);<br><br>        // output headers<br>        for (Enumeration&lt;String&gt; headerNames = request.getHeaderNames(); headerNames.hasMoreElements(); ) {<br>            String headerName = (String) headerNames.nextElement();<br>            result<br>                .append(&quot; -H \&quot;&quot;)<br>                .append(headerName).append(&quot;: &quot;)<br>                .append(request.getHeader(headerName))<br>                .append(&quot;\&quot;&quot;);<br>        }<br><br>        // output parameters<br>        for (Enumeration&lt;String&gt; parameterNames = request.getParameterNames(); parameterNames.hasMoreElements(); ) {<br>            String parameterName = (String) parameterNames.nextElement();<br>            result.append(&quot; -d \&quot;&quot;)<br>                  .append(parameterName)<br>                  .append(&quot;=&quot;)<br>                  .append(request.getParameter(parameterName))<br>                  .append(&quot;\&quot;&quot;);<br>        }<br><br>        // output body<br>        if (RequestMethod.POST.name().equalsIgnoreCase(request.getMethod())) {<br>            String body = JsonUtil.OBJECT_MAPPER.writeValueAsString(requestBody);<br>            if (body.length() &gt; 0) {<br>                result<br>                    .append(&quot; -d \&#39;&quot;)<br>                    .append(body)<br>                    .append(&quot;\&#39;&quot;);<br>            }<br>        }<br><br>        return result.toString();<br>    }</pre><p>we concatenate the various parts of the HttpRequest (method, headers, body, and URL) into a single string. Finally</p><p>By injecting this code in your backend application as interceptor or a filter, you can easily generate the curl command that corresponds to the API request sent by the mobile app. This allows you to reproduce the request and investigate any issues or debug the behavior efficiently.</p><p>In the following code I am injecting it in an interceptor</p><pre>public class CurlGeneratorInterceptor extends RequestBodyAdviceAdapter {<br><br>     @Autowired<br>     public HttpServletRequest httpServletRequest;<br><br>    @Override<br>    public boolean supports(MethodParameter methodParameter, Type targetType,<br>                            Class&lt;? extends HttpMessageConverter&lt;?&gt;&gt; converterType) {<br>        return Boolean.TRUE;<br>    }<br><br>    @Override<br>    public Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType,<br>                                Class&lt;? extends HttpMessageConverter&lt;?&gt;&gt; converterType) {<br>        try {<br>            log.debug(&quot;Curl: [\n&quot; + requestToCurl(https://medium.com/this.httpServletRequest%3Cbr%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20,%20body) + &quot;\n]&quot;);<br>        } catch (Exception e) {<br>            log.error(&quot;Error while generating curl Command: &quot;, e);<br>        }<br>        return body;<br>    }<br><br>    private static String requestToCurl(https://medium.com/HttpServletRequest%20request%3Cbr%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20,%20Object%20requestBody) throws IOException {<br>        // Code showed before<br>    }<br>}</pre><h3>Final Word</h3><p>Using the generated curl command, you can test your changes, share it with others for collaboration, or even use it as documentation for your API endpoints.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b85d8567360d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Self-Injection In Spring]]></title>
            <link>https://medium.com/@alaajawhar123/self-injection-in-spring-7fc0d47e58ec?source=rss-11f12cc62aa5------2</link>
            <guid isPermaLink="false">https://medium.com/p/7fc0d47e58ec</guid>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[spring-framework]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[aspectj]]></category>
            <category><![CDATA[spring-aop]]></category>
            <dc:creator><![CDATA[AJawhar]]></dc:creator>
            <pubDate>Thu, 23 Feb 2023 21:31:08 GMT</pubDate>
            <atom:updated>2023-02-23T21:31:08.408Z</atom:updated>
            <content:encoded><![CDATA[<p>Aspect-Oriented Programming (AOP) is a programming paradigm that aims to enhance the maintainability, and reusability of software systems. The idea behind AOP is to identify the cross-cutting concerns, such as logging, error handling, and security, and encapsulate them in separate modules, called aspects, that can be applied to the different modules of the system without modifying their code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*rgl-KahmPj5uZqcsejv6WQ.png" /><figcaption>Self-Injection In Spring</figcaption></figure><h3>AOP Limitation</h3><p>However, AOP has some limitations, one of which is that it cannot be applied to self-invoking methods. Self-invocation refers to a situation in which a method calls itself recursively, without any external intervention. In this case, the method is responsible for executing its own behavior and cannot be modified by an external aspect.</p><p>The reason why AOP cannot be applied to self-invoking methods is that aspects are typically implemented as interceptors that wrap the method being intercepted. An interceptor is a piece of code that executes before or after the intercepted method and can modify its behavior or the data it operates on. However, in the case of self-invoking methods, there is no external call to intercept, as the method calls itself. Therefore, the interceptor cannot be applied to modify the behavior of the method, as it may intercept the interceptor itself, leading to an infinite loop.</p><p>Consider the following example of a self-invoking method in Java:</p><pre>@Service<br>public class MyClass {<br><br>    public void executeTransaction(Transaction trx) {<br>       if(this.isValidTransaction(trx)) {<br>        // CODE GOES HERE...<br>       }<br>    }<br><br>    public Boolean isValidTransaction(Transaction trx) {<br>       // CODE GOES HERE...<br>    }<br>}</pre><h3>Self-injection</h3><p>To overcome this limitation of AOP, a technique known as self-injection can be used here which involve injecting the Service(Bean) inside itself</p><p>The code shown previously will be transformed as follows:</p><pre>@Service<br>public class MyClass {<br><br>    @Autowired<br>    private MyClass myClass;<br><br>    public void executeTransaction(Transaction trx) {<br>       if(myClass.isValidTransaction(trx)) {<br>        // CODE GOES HERE...<br>       }<br>    }<br><br>    public Boolean isValidTransaction(Transaction trx) {<br>       // CODE GOES HERE...<br>    }<br>}</pre><p>By injecting the bean in itself, we overcome the AOP limitation where no longer the same object calling itself, it is another instance (different reference) calling it.</p><h3>Self-Injection Risk</h3><p>Although self-injection can be used to overcome the AOP limitation of not being able to apply aspects to self-invoking methods, it can also introduce new risks to the software system.</p><ol><li>self-injection can lead to circular dependencies between modules, which can make the code difficult to maintain and test. self-injection can make the debugging harder when trying to understanding how the code is behaving, as it creates additional complexity and makes it harder to track the flow of data between different parts of the system.</li><li>self-injection can lead to memory leaks and performance issues, as it creates additional instances of the same class that need to be managed by the garbage collector. This can lead to increased memory usage and slower performance, especially in systems that process large amounts of data or have high concurrency.</li></ol><p>While self-injection can be a useful technique in some cases, it should be used with caution and only when necessary to overcome specific limitations of AOP. It is important to carefully consider the potential risks and trade-offs before using self-injection in a software system.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7fc0d47e58ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[C-namespace In Spring]]></title>
            <link>https://medium.com/@alaajawhar123/c-namespace-in-spring-722b8639bbad?source=rss-11f12cc62aa5------2</link>
            <guid isPermaLink="false">https://medium.com/p/722b8639bbad</guid>
            <dc:creator><![CDATA[AJawhar]]></dc:creator>
            <pubDate>Thu, 16 Feb 2023 08:09:47 GMT</pubDate>
            <atom:updated>2023-02-16T08:09:47.014Z</atom:updated>
            <content:encoded><![CDATA[<p>In Spring, a namespace is a mechanism that allows developers to configure Spring beans using XML syntax. Spring has multiple namespaces, including the core namespace</p><ul><li>Core namespace: <a href="http://www.springframework.org/schema/beans">http://www.springframework.org/schema/beans</a></li><li>Context namespace: <a href="http://www.springframework.org/schema/context">http://www.springframework.org/schema/context</a></li><li>AOP namespace: <a href="http://www.springframework.org/schema/aop">http://www.springframework.org/schema/aop</a></li><li>TX namespace: <a href="http://www.springframework.org/schema/tx">http://www.springframework.org/schema/tx</a></li></ul><p>Each namespace provides its own set of elements and attributes for configuring specific Spring components and features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K1NbbfyXPXO1pzYtzCVgXg.png" /><figcaption>Configure Spring in XML</figcaption></figure><h3>What is C-Namespace?</h3><p>The C-namespace makes it easy to configure the core components of a Spring application, such as beans, properties, and other basic settings, without the need to write lengthy XML code.</p><p>Spring c-namespace is an XML shortcut and replacement of the &lt;constructor-arg/&gt; subelement of the &lt;bean/&gt; tag. To enable the c-namespace feature, we need to add the xmlns:c=&quot;http://www.springframework.org/schema/c&quot; into the XML file. Note that this namespace does not have a separate XSD file; therefore, IDEs such as IntelliJ do not recognize it.</p><h3>Spring c-namespace example</h3><p>let’s suppose we have created User.java class under com.ajawhar.module as shown in the project structure below</p><pre>src<br>├───main<br>│   ├───java<br>│   │   └───com<br>│   │       └───ajawhar<br>│   │           │   Application.java<br>│   │           └───models<br>│   │                   User.java<br>│   └───resources<br>│           my-beans.xml<br>└───test<br>    └───java</pre><pre>package com.ajawhar.models;<br><br>public class User {<br><br>    private String name;<br>    private String occupation;<br><br>    public User(String name, String occupation) {<br>        this.name = name;<br>        this.occupation = occupation;<br>    }<br><br>    @Override<br>    public String toString() {<br><br>        final var sb = new StringBuilder(&quot;User{&quot;);<br>        sb.append(&quot;name=&#39;&quot;).append(name).append(&#39;\&#39;&#39;);<br>        sb.append(&quot;, occupation=&#39;&quot;).append(occupation).append(&#39;\&#39;&#39;);<br>        sb.append(&#39;}&#39;);<br>        return sb.toString();<br>    }<br>}</pre><p>Now let’s dive into the my-beans.xml configuration:</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;<br>        xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;<br>        xmlns:c=&quot;http://www.springframework.org/schema/c&quot;<br>        xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans<br>            http://www.springframework.org/schema/beans/spring-beans.xsd&quot;&gt;<br><br>    &lt;bean name=&quot;user1&quot; class=&quot;com.ajawhar.models.User&quot;&gt;<br>        &lt;constructor-arg name=&quot;name&quot; value=&quot;John Doe&quot;/&gt;<br>        &lt;constructor-arg name=&quot;occupation&quot; value=&quot;gardener&quot;/&gt;<br>    &lt;/bean&gt;<br><br>    &lt;bean name=&quot;user2&quot; class=&quot;com.ajawhar.models.User&quot;<br>            c:name=&quot;Peter Smith&quot; c:occupation=&quot;teacher&quot;/&gt;<br><br>&lt;/beans&gt;</pre><p>The my-beans.xml file declares two beans: user1 and user2. The user1 uses &lt;constructor-arg/&gt; to inject its values, while user2 uses c:name and c:occupation attributes.</p><p>This is the User class that is managed by Spring container. It must contain a constructor because we use constructor-based injection in our application.</p><h3>Test Our Code</h3><p>Now let’s test our code by running the main function in the Application class. It retrieves the two beans and prints them to the console.</p><pre>package com.ajawhar;<br><br>import org.springframework.context.support.GenericXmlApplicationContext;<br><br>public class Application {<br><br>    public static void main(String[] args) {<br><br>        var ctx = new GenericXmlApplicationContext(&quot;my-beans.xml&quot;);<br><br>        var u1 = ctx.getBean(&quot;user1&quot;);<br>        var u2 = ctx.getBean(&quot;user2&quot;);<br><br>        System.out.println(u1);<br>        System.out.println(u2);<br><br>        ctx.close();<br>    }<br>}</pre><p>output:</p><pre>18:35:13.859 INFO  com.ajawhar.Application - User{name=&#39;John Doe&#39;, occupation=&#39;gardener&#39;} <br>18:35:13.859 INFO  com.ajawhar.Application - User{name=&#39;Peter Smith&#39;, occupation=&#39;teacher&#39;}</pre><p>In this tutorial, I have shown how to use constructor-based injection with c-namespace.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=722b8639bbad" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Global Exception Handling in Spring]]></title>
            <link>https://medium.com/@alaajawhar123/global-exception-handling-in-spring-ec4420208cff?source=rss-11f12cc62aa5------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec4420208cff</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[hibernate-jpa]]></category>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[exception-handling]]></category>
            <dc:creator><![CDATA[AJawhar]]></dc:creator>
            <pubDate>Sun, 29 Jan 2023 13:06:06 GMT</pubDate>
            <atom:updated>2023-01-29T13:06:06.282Z</atom:updated>
            <content:encoded><![CDATA[<p>Spring is a popular framework for building Java applications, and one of its strengths is the ability to handle exceptions globally. In this article, we will explore how to implement global exception handling in a Spring application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7IFAFla4Fly0yxuF0H31RA.png" /></figure><h3>Why Global Exception Handling?</h3><p>Advantages of Global Exception Handling:</p><ol><li><strong>Centralized Exception Handling</strong>: By implementing a global exception handler, all exceptions thrown in the application can be handled in a single location (DRY concept), making it easier to maintain and debug the application.</li><li><strong>Easy Maintenance</strong>: With global exception handling, it is easier to update the error handling logic in a single location, reducing the maintenance overhead and improving the efficiency of the development process.</li><li><strong>Separation of Concerns</strong>: Global exception handling allows for a separation of concerns between the main application logic and the exception handling logic, making it easier to develop and maintain the application.</li></ol><h3>Implementing Global Exception Handling in Spring</h3><p>There are several ways to implement global exception handling in a Spring application. Here, we will discuss two popular methods: using a <strong><em>ControllerAdvice</em></strong> class and using a <strong><em>HandlerExceptionResolver</em></strong> interface.</p><h4>1. ControllerAdvice</h4><p>The <strong><em>ControllerAdvice</em></strong> class is a simple way to handle exceptions globally in a Spring application. This class allows you to define a global exception handler method that will be called whenever an exception is thrown in your application.</p><p>To implement a ControllerAdvice class, follow these steps:</p><ol><li>Create a new class and annotate it with <strong><em>@ControllerAdvice</em></strong>.</li><li>Define a method to handle exceptions, annotated with <strong><em>@ExceptionHandler</em></strong>.</li><li>In the exception handler method, you can return a response with an error message or status code, or you can redirect the user to an error page.</li></ol><p>The example below show us an example for <strong><em>ControllerAdvice</em></strong> implementation</p><pre>@ControllerAdvice<br>public class GlobalExceptionHandler {<br>    @ExceptionHandler(Exception.class)<br>    public ResponseEntity&lt;String&gt; handleException(Exception ex) {<br>        return new ResponseEntity&lt;&gt;(&quot;An error has occurred&quot;, <br>                  HttpStatus.INTERNAL_SERVER_ERROR);<br>    }<br>}</pre><h4>2. HandlerExceptionResolver</h4><p>The <strong><em>HandlerExceptionResolver</em></strong> interface is another way to implement global exception handling in a Spring application. This interface provides a mechanism to catch exceptions thrown by controllers and resolve them.</p><p>To implement a <strong><em>HandlerExceptionResolver</em></strong>, follow these steps:</p><ol><li>Create a new class and implement the <strong><em>HandlerExceptionResolver </em></strong>interface.</li><li>Override the <strong><em>resolveException()</em></strong> method and provide the logic to handle the exception.</li><li>Register the custom <strong><em>HandlerExceptionResolver</em></strong> in the Spring application context.</li></ol><p>Here an example of <strong><em>HandlerExceptionResolver </em></strong>exception handling:</p><pre>@Component<br>public class GlobalExceptionResolver implements HandlerExceptionResolver {<br>    @Override<br>    public ModelAndView resolveException(HttpServletRequest request, <br>              HttpServletResponse response, Object handler, Exception ex) {<br><br>        ModelAndView modelAndView = new ModelAndView();<br>        modelAndView.setViewName(&quot;error&quot;);<br>        modelAndView.addObject(&quot;errorMessage&quot;, &quot;An error has occurred&quot;);<br>        return modelAndView;<br>    }<br>}</pre><h3>Conclusion</h3><p>Global exception handling is an important aspect of building robust and reliable applications. In this article, we discussed two popular methods to implement global exception handling in a Spring application: using a ControllerAdvice class and using a HandlerExceptionResolver interface. Both methods provide a centralized approach to handling exceptions, making it easier to maintain and debug the application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec4420208cff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Colorful Logging In Spring]]></title>
            <link>https://medium.com/@alaajawhar123/colorful-logging-in-spring-da2722bc08d1?source=rss-11f12cc62aa5------2</link>
            <guid isPermaLink="false">https://medium.com/p/da2722bc08d1</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[logging-and-monitoring]]></category>
            <category><![CDATA[logback]]></category>
            <category><![CDATA[log4j]]></category>
            <dc:creator><![CDATA[AJawhar]]></dc:creator>
            <pubDate>Wed, 18 Jan 2023 15:27:54 GMT</pubDate>
            <atom:updated>2023-01-18T16:28:58.040Z</atom:updated>
            <content:encoded><![CDATA[<p>Logging is an essential part of any application, and it is used to track the flow of execution and help identify any issues that may arise. One way to make logging more visually appealing and easier to read is by using colorful logging.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-GZm_Y3Ugc2J7rGB8k7Xcw.jpeg" /></figure><p>Logback in the other hand is a popular logging framework for Java-based applications, and it provides colorful logging through the use of encoders.</p><p>Colored logging can make it easier to identify different types of log messages, such as</p><ul><li>errors</li><li>warnings</li><li>informational</li></ul><p>For example, you can configure Logback to display error messages in red, warning messages in yellow, and informational messages in green as shown in the image bellow</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CxuZF_3TeTYooolWnYKs0w.png" /><figcaption>Colorful logs</figcaption></figure><p>This makes it much easier to quickly scan through log files and identify any issues that need to be addressed.</p><p>To enable colored logging in Logback, you will need to add the following dependency to your project:</p><pre>&lt;dependency&gt;<br>    &lt;groupId&gt;ch.qos.logback&lt;/groupId&gt;<br>    &lt;artifactId&gt;logback-core&lt;/artifactId&gt;<br>    &lt;version&gt;1.2.3&lt;/version&gt;<br>&lt;/dependency&gt;</pre><p>Next, you will need to configure an encoder in your logback.xml file. The following is an example of how logback.xml should look like:</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;included&gt;<br>    &lt;conversionRule conversionWord=&quot;customHighlightingLogLevel&quot; converterClass=&quot;com.emcrey.common.config.CustomHighlightingLogLevel&quot; /&gt;<br>    &lt;conversionRule conversionWord=&quot;customHighlightingPackageName&quot; converterClass=&quot;com.emcrey.common.config.CustomHighlightingPackageName&quot; /&gt;<br> &lt;conversionRule conversionWord=&quot;customHighlightingMessage&quot; converterClass=&quot;com.emcrey.common.config.CustomHighlightingMessage&quot; /&gt;<br><br><br> &lt;appender name=&quot;STDOUT&quot; class=&quot;ch.qos.logback.core.ConsoleAppender&quot;&gt;<br>  &lt;encoder&gt;<br>   &lt;pattern&gt;%customHighlightingLogLevel(%d{yyyy-MM-dd HH:mm:ss} %-5level) %customHighlightingPackageName(%logger{40}.%M\(%line\)): %customHighlightingMessage(%msg%n)&lt;/pattern&gt;<br>  &lt;/encoder&gt;<br> &lt;/appender&gt;<br> <br> &lt;appender name=&quot;FILE&quot; class=&quot;ch.qos.logback.core.FileAppender&quot;&gt;<br>  &lt;file&gt;/tmp/logs/apex-fraud-broker.log&lt;/file&gt;<br>  &lt;append&gt;true&lt;/append&gt;<br>  &lt;immediateFlush&gt;true&lt;/immediateFlush&gt;<br>  &lt;encoder&gt;<br>   &lt;pattern&gt;%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{40}.%M\(%line\): %msg%n&lt;/pattern&gt;<br>  &lt;/encoder&gt;<br> &lt;/appender&gt;<br> <br> &lt;logger name=&quot;com.emcrey&quot; level=&quot;debug&quot;&gt;<br>  &lt;appender-ref ref=&quot;STDOUT&quot;/&gt;<br>  &lt;appender-ref ref=&quot;FILE&quot;/&gt;<br> &lt;/logger&gt;<br> <br> &lt;logger name=&quot;org.springframework&quot; level=&quot;error&quot;&gt;<br>  &lt;appender-ref ref=&quot;STDOUT&quot;/&gt;<br>  &lt;appender-ref ref=&quot;FILE&quot;/&gt;<br> &lt;/logger&gt;<br>&lt;/included&gt;</pre><p>In this example, The pattern used includes the timestamp, log level, logger name, and message.</p><p>In the XML configuration above you can notice that we are pointing to a specific classes, these classes you have to create them which will customize the color for different log levels. You can do this by adding the following classes in your code:</p><pre>public class CustomHighlightingLogLevel <br>              extends ForegroundCompositeConverterBase&lt;ILoggingEvent&gt; {<br><br>    @Override<br>    protected String getForegroundColorCode(ILoggingEvent event) {<br>        Level level = event.getLevel();<br>        switch (level.toInt()) {<br>            case Level.ERROR_INT:<br>                return ANSIConstants.RED_FG;<br>            case Level.WARN_INT:<br>                return ANSIConstants.YELLOW_FG;<br>            default:<br>                return ANSIConstants.DEFAULT_FG;<br>        }<br>    }<br>}</pre><pre>public class CustomHighlightingMessage <br>                  extends ForegroundCompositeConverterBase&lt;ILoggingEvent&gt; {<br><br>    @Override<br>    protected String getForegroundColorCode(ILoggingEvent event) {<br>        Level level = event.getLevel();<br>        switch (level.toInt()) {<br>            case Level.ERROR_INT:<br>                return ANSIConstants.RED_FG;<br>            case Level.WARN_INT:<br>                return ANSIConstants.YELLOW_FG;<br>            default:<br>                return ANSIConstants.DEFAULT_FG;<br>        }<br>    }<br>}</pre><pre>public class CustomHighlightingPackageName <br>                extends ForegroundCompositeConverterBase&lt;ILoggingEvent&gt; {<br><br>    @Override<br>    protected String getForegroundColorCode(ILoggingEvent event) {<br>        Level level = event.getLevel();<br>        switch (level.toInt()) {<br>            case Level.ERROR_INT:<br>                return ANSIConstants.RED_FG;<br>            case Level.WARN_INT:<br>                return ANSIConstants.YELLOW_FG;<br>            default:<br>                return ANSIConstants.CYAN_FG;<br>        }<br>    }<br>}</pre><h3>Conclusion</h3><p>Colorful logging can greatly improve the readability and ease of identifying issues in log files. By configuring an encoder and adding the appropriate dependencies, developers can easily enable colorful logging in their applications, making it easier to quickly scan through log files and identify any potential issues. This can greatly improve the efficiency of debugging and troubleshooting processes. Therefore, implementing colorful logging in Logback is a valuable addition to any Java-based application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da2722bc08d1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spring VS .NET. Which one is better]]></title>
            <link>https://medium.com/@alaajawhar123/spring-vs-net-which-one-is-better-b49d7fd559f7?source=rss-11f12cc62aa5------2</link>
            <guid isPermaLink="false">https://medium.com/p/b49d7fd559f7</guid>
            <category><![CDATA[spring-framework]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[dot-net-core]]></category>
            <category><![CDATA[dot-net-framework]]></category>
            <dc:creator><![CDATA[AJawhar]]></dc:creator>
            <pubDate>Tue, 10 Jan 2023 13:23:29 GMT</pubDate>
            <atom:updated>2023-01-10T13:23:53.700Z</atom:updated>
            <content:encoded><![CDATA[<h3>Spring VS .NET. Which one is better?</h3><p>Spring Framework and the .NET Framework are both popular frameworks for building web and enterprise applications. Both frameworks have their own set of pros and cons and are better suited for certain types of projects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QRFmgJcJ4chg5hgt2Pl69A.png" /><figcaption>Spring vs .NET</figcaption></figure><h3>Spring Framework</h3><p>The Spring Framework is a Java-based framework that provides a lightweight and flexible architecture for building enterprise applications.</p><h4>Pros</h4><p>allows developers to create high-performance and scalable applications with minimal effort.</p><p>Spring also offers a wide range of features and modules for different aspects of application development, such as data access, security, and caching.</p><p>Spring is a open-source framework and have a big community of developers behind it, this bring support, tutorials, and lots of libraries or modules.</p><h4>Cons</h4><ol><li>Steep learning curve: The Spring Framework can be quite complex and has a lot of features and modules, which can make it difficult for new developers to learn and use effectively.</li><li>Hard to maintain legacy code: Spring Framework has been around for quite a while and has gone through multiple major releases, each of which has introduced new features. as a result it can make it difficult to upgrade the application from an old version to the newest version.</li></ol><h3>.NET</h3><p>On the other hand, .NET Framework is a framework developed by Microsoft for building web and enterprise applications using languages such as C# and F#.</p><h4>Pros</h4><ol><li>The main advantage of .NET framework is its integration with other Microsoft technologies such as Visual Studio, SQL Server and Windows.</li><li>It is a more robust framework and has a lot of built-in features and functionalities.</li><li>It has a big community too and lots of companies already use it. (you are likely to find more jobs requiring .NET)</li></ol><h4>Cons</h4><ol><li>Closed-source and licensing costs: While .NET Core (the open-source version) is now available, some parts of the .NET Framework are closed-source and may come with licensing costs.</li><li>Limited cross-platform support: .NET Framework is primarily designed to run on Windows, and while it can be run on other platforms using tools like Mono, it is not as well-supported as Java on other platforms.</li><li>Higher system requirements: The .NET Framework requires a higher version of windows as a operating system and more resources to run applications built with it.</li><li>Ties to Microsoft ecosystem: While integration with other Microsoft technologies can be an advantage, it also means that .NET-based applications are more tightly tied to the Microsoft ecosystem and may have limited portability to other platforms.</li></ol><h4>Which one should I use</h4><p>One key factor to consider when choosing between the two frameworks is the type of application you are building.</p><h4>.NET</h4><ol><li>if you are developing a project that requires integration with other Microsoft technologies such as SQL Server, Visual Studio or is required to run on Windows, then .NET Framework would be a good choice.</li><li>if you are a student and looking for a job in software industry you are likely to learn .NET because it is used by many companies.</li></ol><h4>Spring</h4><ol><li>Spring Framework is generally considered to be more lightweight and flexible than .NET Framework, so it may be a better choice for projects where performance is a concern.</li><li>You should also consider the team skills, if your team is more experienced with one of the frameworks, this could be a factor to decide, if your team is more experienced with Java and Spring, it could be more productive to use it.</li></ol><h4>Conclusion</h4><p>In conclusion, both Spring Framework and .NET Framework are powerful tools for building web and enterprise applications. The best choice will depends on the specific technical requirements of your project, such as the need for integration with other technologies, performance, and your team skills and experience.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b49d7fd559f7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>