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;
}
}
Wednesday, January 3, 2024
Sample Enum
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
- Building
- Publishing
- Securing
- Versioning
- Observing
- Scaling
- Cataloging
- 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...
Monday, August 28, 2023
How to check Wifi password from Windows machine
It is east to use shell commands to find the password
1. open power shell
2. find all the listed wifis
3. check the password of the selected wifi network
Step 2:
netsh wlan show profile "name=SLT wifi" key=clear
Step 3:
netsh wlan show profile "name=your wifi name" key=clear
3PRnfigqWlCS85vZkZmYa6zS
Saturday, July 8, 2023
Springboot 3.1 - Spring security - Create Basic Oauth2 client - Continue
Let's continue add security features for the basic application we have built. As you can see, we have used the basic inbuild features of the spring security where default username=user and with generated password.
So let's start configuring.
1. we will create class "SecurityConfig" and let's put that inside "config" package
2. Annotate with @Configuration and @EnableWebSecurity
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
3. create new bean with "SecurityFilterChain" with "HttpSecurity"
below is the sample
@Bean
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
return http.build();
}
So up to now, the full continue code of the "SecurityConfig" class would looks like below.
Note: we need to add Exception
package com.example.danwega.outh2.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;
@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
return http.build();
}
}
4. Now let's start adding security features or configure Spring security environment. We will start modifying bean we created "SecurityFilterChain"
let's authorize http requests.
- we use authorizeHttpRequests
- with this we use matchers requestMatchers
- For home anybody can go -> auth.requestMatchers("/").permitAll()
- For any other request use authentication --> auth.anyRequest().authenticated()
@Bean
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
return http
.authorizeHttpRequests(auth -> {
auth.requestMatchers("/").permitAll();
auth.anyRequest().authenticated();
})
.build();
}
5. Now how are you going to login. So for now, let's give a formLogin with defaults
@Bean
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
return http
.authorizeHttpRequests(auth -> {
auth.requestMatchers("/").permitAll();
auth.anyRequest().authenticated();
})
.formLogin(Customizer.withDefaults())
.build();
}
let's change the code to static import for "withDefaults"
@Bean
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
return http
.authorizeHttpRequests(auth -> {
auth.requestMatchers("/").permitAll();
auth.anyRequest().authenticated();
})
.formLogin(withDefaults())
.build();
}
Now user have to log with user name and password to login
6. without just providing a formLogin, we need to provide a oauth2 login as we are using oauth2.
we add auth2Login with defaults for now.
.oauth2Login(withDefaults())@Bean
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
return http
.authorizeHttpRequests(auth -> {
auth.requestMatchers("/").permitAll();
auth.anyRequest().authenticated();
})
.oauth2Login(withDefaults())
.formLogin(withDefaults())
.build();
}
That's it for now
7. configure properties to say what oauth2 client, providers we provide.
let's use log level just to what's happening inside when we running the code
logging:
level:
org:
springframework:
security: TRACE
here we will try to configure for GitHub and Google.
let's first try with GitHub
Github
click your top right corner icon showing you --> go to "settings" --> left side go to "developer settings" in left bottom corner --> select "OAuth2 app" in left panel
8. Let's Register new application. you can give your details as needed, below is sample set
Application name: Spring Security OAuth2 client
Homepage url : localhost:8210
Application description : optional for now
Authorization callback url : localhost:8210/login/oauth2/code/github
call back url is set according to documentation. when it is google final part will be "google", instead of "github"
localhost:8210/login/oauth2/code/google
Click Register Application to finish the process. This will go to page and show you "client secret" and some other information
9.