Wednesday, January 3, 2024

Samplelog back xml

<configuration>

<property name="LOGS" value="./logs" />

<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C): %msg%n%throwable
</Pattern>
</layout>
</appender>

<appender name="RollingFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOGS}/test-automation-poc-logger.log</file>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>%d %p %C [%t] %m%n</Pattern>
</encoder>

<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily and when the file reaches 10 MegaBytes -->
<fileNamePattern>${LOGS}/archived/test-runner-logger-%d{yyyy-MM-dd}.%i.log
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>

<!-- LOG everything at INFO level -->
<root level="info">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</root>

<logger name="com.example.test.runner" level="trace" additivity="false">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</logger>

<logger name="com.example.test.framework" level="trace" additivity="false">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</logger>


</configuration>

Sample Custom Exception class

package com.example.test.framework.exception;

/**
* Handle exception when element is not available.
*/
public class ElementNotFoundException extends RuntimeException {
/**
* Instantiates a new {@link ElementNotFoundException}.
*
* @param message the exception message,
*/
public ElementNotFoundException(String message) {
super(message);
}
}

Sample Enum

package com.example.test.framework.enums;

/**
* Message matching type
*/
public enum MessageMatchType {
/** The exact message will be checked. */
EXACT(0),

/** The partial of the original message text is matched. */
PARTIAL(1);

/** The key. */
private int key;

private MessageMatchType(int key) {
this.key = key;

}

public int getKey() {
return key;
}

}

Thursday, November 23, 2023

Java 9 : JShell

 1. How to run Jshell

    get a command prompt windows key + R --> type cmd

2. Check java version, should be higher than 9

    java -version

3. type "jshell"

4. Now you can write syntax and check validity , edit and play on with this

5. /help --> help command

6. /list   --> will list the command typed/executed

7. edit use edit command with command number, number you can select using /list . Once you use edit, it will prompt with shell to edit.

    /edit 2


Below you I have attached series of commands i tried with all mistakes

----------------------------------------------------------------------------------------------------------------------

Microsoft Windows [Version 10.0.22621.2715]

(c) Microsoft Corporation. All rights reserved.


C:\Users\USR>java -version

openjdk version "21" 2023-09-19

OpenJDK Runtime Environment Zulu21.28+85-CA (build 21+35)

OpenJDK 64-Bit Server VM Zulu21.28+85-CA (build 21+35, mixed mode, sharing)


C:\Users\USR>jshell

|  Welcome to JShell -- Version 21

|  For an introduction type: /help intro


jshell> System.out.println("Hello");

Hello


jshell> /help

|  Type a Java language expression, statement, or declaration.

|  Or type one of the following commands:

|  /list [<name or id>|-all|-start]

|       list the source you have typed

|  /edit <name or id>

|       edit a source entry

|  /drop <name or id>

|       delete a source entry

|  /save [-all|-history|-start] <file>

|       Save snippet source to a file

|  /open <file>

|       open a file as source input

|  /vars [<name or id>|-all|-start]

|       list the declared variables and their values

|  /methods [<name or id>|-all|-start]

|       list the declared methods and their signatures

|  /types [<name or id>|-all|-start]

|       list the type declarations

|  /imports

|       list the imported items

|  /exit [<integer-expression-snippet>]

|       exit the jshell tool

|  /env [-class-path <path>] [-module-path <path>] [-add-modules <modules>] ...

|       view or change the evaluation context

|  /reset [-class-path <path>] [-module-path <path>] [-add-modules <modules>]...

|       reset the jshell tool

|  /reload [-restore] [-quiet] [-class-path <path>] [-module-path <path>]...

|       reset and replay relevant history -- current or previous (-restore)

|  /history [-all]

|       history of what you have typed

|  /help [<command>|<subject>]

|       get information about using the jshell tool

|  /set editor|start|feedback|mode|prompt|truncation|format ...

|       set configuration information

|  /? [<command>|<subject>]

|       get information about using the jshell tool

|  /!

|       rerun last snippet -- see /help rerun

|  /<id>

|       rerun snippets by ID or ID range -- see /help rerun

|  /-<n>

|       rerun n-th previous snippet -- see /help rerun

|

|  For more information type '/help' followed by the name of a

|  command or a subject.

|  For example '/help /list' or '/help intro'.

|

|  Subjects:

|

|  intro

|       an introduction to the jshell tool

|  keys

|       a description of readline-like input editing

|  id

|       a description of snippet IDs and how use them

|  shortcuts

|       a description of keystrokes for snippet and command completion,

|       information access, and automatic code generation

|  context

|       a description of the evaluation context options for /env /reload and /reset

|  rerun

|       a description of ways to re-evaluate previously entered snippets


jshell>

/list


   1 : System.out.println("Hello");


jshell> void printMessage(){

   ...>     System.out.print;n("Hello")

   ...> }

|  Error:

|  not a statement

|      System.out.print;n("Hello")

|      ^--------------^

|  Error:

|  ';' expected

|      System.out.print;n("Hello")

|                                 ^


jshell> printMessage()

|  Error:

|  cannot find symbol

|    symbol:   method printMessage()

|  printMessage()

|  ^----------^


jshell> /lsit

|  Invalid command: /lsit

|  Type /help for help.


jshell> /list


   1 : System.out.println("Hello");


jshell>

        void printMessage(){

   ...>     System.out.print;n("Hello");

   ...> }

|  Error:

|  not a statement

|      System.out.print;n("Hello");

|      ^--------------^

|  Error:

|  cannot find symbol

|    symbol:   method n(java.lang.String)

|      System.out.print;n("Hello");

|                       ^


jshell> void printMessage(){

   ...>     System.out.println("Hello");

   ...> }

|  created method printMessage()


jshell> printMessage

|  Error:

|  cannot find symbol

|    symbol:   variable printMessage

|  printMessage

|  ^----------^


jshell> printMessage()

Hello


jshell> /list


   1 : System.out.println("Hello");

   2 : void printMessage(){

           System.out.println("Hello");

       }

   3 : printMessage()


jshell> edit 2

|  Error:

|  ';' expected

|  edit 2

|      ^

|  Error:

|  cannot find symbol

|    symbol:   variable edit

|  edit 2

|  ^--^


jshell> /edit 2

|  modified method printMessage()


jshell> printMessage()

Hello Edited


jshell>


Java 9

1. REPL Jshell

2.    Collection Factory Method

3. HTTP/2 Client

4. Jigsaw Project /Modularity

5. Other features


https://www.youtube.com/watch?v=NJY-D9JLLdQ


1. Test Jshell

Take a command prompt wind + R -> type "cmd"

2. Check java version, must be above 9

java -version 

3. type "jshell" in command prompt

4. This will help you to test simple syntax

-------------------------------------------------------------------------------------------------

C:\Users\USR>java -version

openjdk version "21" 2023-09-19

OpenJDK Runtime Environment Zulu21.28+85-CA (build 21+35)

OpenJDK 64-Bit Server VM Zulu21.28+85-CA (build 21+35, mixed mode, sharing)


C:\Users\USR>jshell

|  Welcome to JShell -- Version 21

|  For an introduction type: /help intro

jshell> System.out.println("Hello");

Hello

jshell>

Monday, September 25, 2023

API Management

Few things to know

Once you done with development and publishing your APIs, then 

How to secure this APIs

How to analyze usage of these APIs

Scale your APIs

Configure 

to rate limit -> eg: 10 requests per minute


Internal(Private)  and Public (APIs visible to others)

--


Public APIs need more

---

Due to visibility and scrutiny they have

If you have few, you may not bother

you might build embedding them with

security, logging , configuration,  into actual API code


So when more and more requirements coming

Specially where micro service --> where APIs get broken

Note : Micro service are not APIs.


smaller APIs focus with specialized operations

Legacy APIs , what to do


API managment is a process of 

  1. Building
  2. Publishing
  3. Securing
  4. Versioning
  5. Observing
  6. Scaling
  7. Cataloging
  8. Retiring

There can be more in future.....

We need to make a system to manage the lifecycle of APIs, so company can focus on adding value to core business (coding,..)


1. API Gateway

Handles the routing and management of all the APIs 

through policies that apply to individual API or set of APIs

2. Developer portal

serves as self service hub - developers to access API documentation, sdks, and other resources needed for consuming APIs

3. API dashboard

Observe API usage

view key API metrics

manage variety of API analytics

4. Unified API central catalogue

organizing, cataloging, indexing and presenting all the public and Private APIs use in Organization

API management will add Flexibility and Power where

you are managing each API independently, to a Unified system where you are orchestrating a complete set of APIs as  a product.

Create a API strategy align with your Companies goals - will save lot of resources and work efficiently


Thursday, September 21, 2023

Mulesoft Training Public URLs are not working

http://mu.learn.mulesoft.com/delta?wsdl

http://mu.learn.mulesoft.com/united/flights/CLE 


Most of the time you find that, the URLs provided by the Mulesoft is not working or you are working in a company where you have restriction on access.

Solution to these issues is to set up those services running inside your machine.

Solution:

Open the jars folder fromStudents Files zip file where you have already downloaded from course resourses.

Locate "mulesoft-training-services-1.8.8.jar"

Just run this jar

java -jar mulesoft-training-services-1.8.8.jar


You will finally get an output on terminal as below

--------------------------------------------



┌───────────────────────────────────────────────────────────────────────────────────────┐

│ (\_/)          M U L E S O F T    T R A I N I N G   &   C E R T I F I C A T I O N     │

│ /   \          Anypoint Platform Development Fundamentals - Services & APIs           │

└───────────────────────────────────────────────────────────────────────────────────────┘


Starting resources:

- Database started.

- Database tables created.

- Database tables populated.

- JMS message broker started.

- United flights web service started.

- JMS service started.

- American flights RAML API started.

- Banking REST API started.

- Accounts REST API started.

- Delta flights web service started.


Published resources:

- Landing page                   : http://localhost:9090

- JMS message broker URL         : tcp://localhost:61616

- JMS default topic name         : apessentials

- JMS web form                   : http://localhost:9090/jmsform.html

- American flights database URL  : jdbc:derby://localhost:1527/memory:training

- Accounts API                   : http://localhost:9090/accounts/api

- Accounts web form              : http://localhost:9090/accounts/show.html

- American flights REST service  : http://localhost:9090/american/flights

- American flights REST API RAML : http://localhost:9090/american/american-flights-api.raml

- Banking API base URL           : http://localhost:9090/api/...

- Banking API RAML               : http://localhost:9090/api/banking-api.raml

- United flights REST service    : http://localhost:9090/united/flights

- Delta flights SOAP service     : http://localhost:9191/delta

- Delta flights SOAP WSDL        : http://localhost:9191/delta?wsdl


Press CTRL-C to terminate this application...