Windows Powershell, how to temporarily set Java and Maven varables on the current terminal session

This is a quick tip, in order to configure the Windows Powershell for set the Java and Maven variables when is there another Java installation on the system, but you only want to apply on the current terminal session to avoid change the system configuration.

There are two ways to do that:

1. Replacing current environment variables in session.

$env:JAVA_HOME = "C:\Program Files\Java\jdk-11"
$env:PATH = "$env:JAVA_HOME\bin;" + $env:PATH
$env:M2_HOME = "C:\Program Files\maven\apache-maven-3.5.3"
$env:PATH = "$env:M2_HOME\bin;" + $env:PATH

Execution output:

> java -version
openjdk version "11" 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)
> mvn.cmd -version
Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T13:49:05-06:00)
Maven home: C:\Program Files\maven\apache-maven-3.5.3\bin..
Java version: 11, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk-11
Default locale: es_419, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

2. Replacing current environment variables and execute with the specific Java home

$env:JAVA_HOME = "C:\Program Files\Java\jdk-11"
$M2_HOME = "C:\Program Files\maven\apache-maven-3.5.3"
$env:Path += ";"+$M2_HOME+"\bin"
$env:Path += ";"+$JAVA_HOME+"\bin"

Execution output:

> java -version
java version "1.8.0_321"
Java(TM) SE Runtime Environment (build 1.8.0_321-b07)
Java HotSpot(TM) 64-Bit Server VM (build 25.321-b07, mixed mode)
> & $env:JAVA_HOME\bin\java.exe -version
openjdk version "11" 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)
> mvn.cmd -version
Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T13:49:05-06:00)
Maven home: C:\Program Files\maven\apache-maven-3.5.3\bin..
Java version: 11, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk-11
Default locale: es_419, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

This last is very useful when you have installed different Java versions and you don’t need to change your system configuration.

In order to reset the configuration restart the terminal session.

That’s all, bye

How to do a HTTP request from terminal

A quick tip for use in terminal:

# print string auth 
echo -n "dummyuser:MyPassword" | base64

# Unix terminal (basic auth, doing http request with GET method)

curl -X GET \
  -H "Content-Type: text/xml" \
  -H "Authorization: Basic ZHVtbXl1c2VyOk15UGFzc3dvcmQ=" \
  "http://dummyserver:5000/dir/wsdl?p=ic/6e7abd99891231jij123ndb769978566c470"


# Unix terminal (basic auth, doing http request with POST method to send payload from file)

curl -X POST \
  -H "Content-Type: application/soap+xml" \
  -H "Authorization: Basic ZHVtbXl1c2VyOk15UGFzc3dvcmQ=" \
  -d @./request.xml \
  "https://dummyserver:50001/XISOAPAdapter/MessageServlet?senderParty=&senderService=SYS_LEGACY&receiverParty=&receiverService=&interface=BookingFlight_Out&interfaceNamespace=http://LGCY/namespace"


# Unix terminal (basic auth, doing http request with POST method)

curl -X POST \
  -H "Content-Type: text/xml" \
  -H "Authorization: Basic ZHVtbXl1c2VyOk15UGFzc3dvcmQ=" \
  -d "<soapenv:Envelope>....ommited lines </soapenv:Envelope>" \
  "https://dummyserver:50001/XISOAPAdapter/MessageServlet?senderParty=&senderService=SYS_LEGACY&receiverParty=&receiverService=&interface=BookingFlight_Out&interfaceNamespace=http://LGCY/namespace"



# Windows Powershell (basic auth, doing http request with GET method)

$Username = "dummyuser"
$Password = ConvertTo-SecureString "MyPassword" -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ($Username, $Password)

Invoke-RestMethod -Uri "http://dummyserver:5000/dir/wsdl?p=ic/6e7abd99891231jij123ndb769978566c470" -Method GET -Credential $Credential


# Windows Powershell (basic auth, doing http request with POST method to send payload from file)
 
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("dummyuser:MyPassword"))
$headers = @{
    Authorization = "Basic $base64AuthInfo"
    "Content-Type" = "text/xml"
}

Invoke-RestMethod -Uri "https://dummyserver:50001/XISOAPAdapter/MessageServlet?senderParty=&senderService=SYS_LEGACY&receiverParty=&receiverService=&interface=BookingFlight_Out&interfaceNamespace=http://LGCY/namespace" -Method Post -Headers $headers -Body (Get-Content -Path "request.xml" -Raw)

Bye!

Sonarqube running in Podman containers

This is a quick entry to show how to run sonarqube using Podman. Please note that I’m using windows powershell.

First, create the next directory structure and add the following SQL script into sql directory:

\SONARQUBE
\---sql
    init-dabase.sql

Script content:

-- Creating db user and database for sonarqube

CREATE USER mysonaruser PASSWORD 'mypassword';
CREATE DATABASE sonarqube OWNER mysonaruser;

Open that directory into the terminal, download the images from docker repository and create the volumes.

# Download images

podman pull postgres:15.4
podman pull sonarqube:9.9.2-community

# Create volumes

podman volume create sonarqube_data
podman volume create sonarqube_logs
podman volume create sonarqube_extensions
podman volume create postgres-data

There are two ways to run the containers, creating a network or run in the same pod, please choose only one of the next.

Seguir leyendo

OneDrive blocked by registry policy and how to enable it

A quick tip, if the OneDrive client isn’t execute maybe are blocked by your organization, in some cases changing the value from the registry editor could you help to skip this bloking policy.

Open regedit from execute dialog (WIN+R) and go to HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\OneDrive, then set the value to 0 for the entry DisableFileSyncNGSC and try to execute the client again.

Cheers! =)

Compact VHD file in Windows 10 Home

I found a great tip in GitHub to compact a VHD file without Hyper-V tools and it works great. The Dynamic VHD don’t reduce their size even if the files were deleted from the hard drive, to fix it the «compact» operation is needed. This is included into the Hyper-V tools but this is only available in Windows 10 Pro.

The Compact operation is used to optimize the files. This operation reclaims unused blocks as well as rearranges the blocks to be more efficiently packed, which reduces the size of a virtual hard disk file.

Microsoft documentation

There are another way to do this in Windows 10 Home, using the next commands:

diskpart

# Open window Diskpart 

select vdisk file="C:\path\to\file.vhd"
attach vdisk readonly
compact vdisk
detach vdisk
exit

With this I’ve recovered arround 20 GB of space in my physical hard drive.

See ya.

References

Alternatives to KeyPass

How do you save your sensitive data? like a users, passwords, website links and other sensitive information (no docs), I used to store my credentials in a excel file but I changed it after my identity was stolen.

I’ve never think that gonna happen to me but and I’m still trying to resolve some legal problems after that incident.

Now I’m using software to keep my info «safe» (note the quotes), because the people like me, that works on IT,  we know there are a lot of nasty tricks to exploit vulnerabilities to get sensitive information, and ever exists a way to do this.

Then keeping in mind this risks, I was testing security tools like OnePass, LastPass and DashLane, but some of them are limited in features in their free versions, like the number of credentials that you can store or sync service in cloud, etc. And I can’t pay that service.

My option was the open source alternatives like KeyPass, but I have to use windows, macOS and Linux systems, and I want to recommend this tools with compatibility: Seguir leyendo

Create ssh tunnel with Putty

This is a simple trick to use a unix server as bridge to achieve other host or services like as local service, for example, I’ve a instance of jboss running in a server but I’cant access to the server directly, if I open the url: http://remotehost:8080 the error is not found page in browser.

Then go to putty configuration ( Connection > SSH > Tunnels) and add a simple tunnel:

  • Source port: the port to access the server from your localhost
  • Destination: the hostname:port of the remote service

2019-06-17 17_10_48-PuTTY Configuration Seguir leyendo

Set System Variables in Windows


En ocasiones tenemos los permisos restringidos y no podemos accesar a la configuración de variables del sistema de windowos, pero… existe una alternativa (solo windows 7 y 8).

Puedes establecer y modificar las variables desde la terminal, en el siguiente ejemplo se muestra como agregar la variable para Maven:

Abres una terminal y escribes los siguientes comandos:

setx M2_HOME "C:\Users\asanchez\Apps\apache-maven-3.2.1" /M
setx PATH "%PATH%,%M2_HOME%\bin" /M

Con esto ya tenemos cargadas las variables.

Nota: Para que los cambios se vean reflejados debes cerrar y abrir la terminal.

Espero sea útil. Saludos!

Referencias