Docker Registry – HTTP status: 503 Service Unavailable

October 15, 2019 Leave a comment

Occasionally the ‘docker pull’ command would return a HTTP Status: 503 Service Unavailable error. This error might happen because of docker registry outage. In case of such error message, as a first step, check the following URL – status.docker.com

When I was troubleshooting similar issue – I logged into status.docker.com and actually found that a few docker services were down, including docker registry.

If this status.docker.com is all Green, then consider other troubleshooting options.

 

Screen Shot 2019-10-15 at 10.01.38 PMScreen Shot 2019-10-15 at 10.01.51 PM

Categories: Uncategorized

Switching easily between Java JDKs on Mac OS X

April 17, 2017 Leave a comment

Quickly switching between multiple java versions on Mac Terminal

Categories: Uncategorized

error: RPC failed; curl 56 SSLRead() return error -9806 fatal: The remote end hung up unexpectedly fatal: early EOF

April 17, 2017 Leave a comment

I came across this error when cloning a large git repository using a WiFi connection.

One quick setting to help overcome is to increase the http.postBuffer size in git and restart the cloning process. Use following command to increase the postBuffer size.

git config –global http.postBuffer 8M

In my case after trial and error I adjusted it to 8M. This may vary depending on the data which is pulled.

http.postBuffer from git documentation

Maximum size in bytes of the buffer used by smart HTTP transports when POSTing data to the remote system. For requests larger than this buffer size, HTTP/1.1 and Transfer-Encoding: chunked is used to avoid creating a massive pack file locally. Default is 1 MiB, which is sufficient for most requests.For reference – Git documentation link to various git config options

Git documentation for more git-config options – git-config documentation

 

Categories: Uncategorized

Retrieve passwords from FileZilla

April 23, 2014 1 comment

FileZilla client stores connection credentials in plain text. Following are the steps to recover lost FTP credentials from filezilla in Windows 7

Step 1: Open folder C:\Users\<YourName>\AppData\Roaming\FileZilla (If FileZilla is not found in Roaming folder, search it in other folders of AppData )

Step 2: Open file recentservers.xml. This file will contains the information all the recent connections made through file zilla along with passowords.

That’s it. By now we should have retrieved our lost passwords.

 

Categories: Uncategorized Tags:

Automatic requests being fired while executing a JAX-WS web service asynhronous call

June 17, 2013 Leave a comment

Further to my earlier post about how to send asynchronous requests using jax-ws. There might be an issue with long running server side operations when an asynchronous call is invoked. The issue could be that the asynchronous request the user has sent can automatically get triggered again after some point in time, causing undesirable effects on the server side.

Going deep and trying to understand the problem, I observed that the same client was sending a new request which was a replica of the original request. This was causing the server side operations to run again, and was giving undesired results.  On searching the web I came across this bug from Sun website.

SOAP request’s in the raw form are sent as HTTP post requests. In Java (JDK) implementation of POST, when a POST request is sent using sun.net.www.http.HTTPClient, the client waits for a fixed amount of time to receive a response from the server. If no response is received during the stipulated time it automatically fires the same request to the server, and JDK implementation is programmed with this assumption. Since POST requests are non idempotent (One which modifies database or server side when performing an operation Eg: POST, PUT, DELETE http methods) it may have undersirable effects in some conditions and the user may not want the request to be retried again by HTTPClient.

JDK provides a flexibility to the user to avoid the default auto retry behavior. This behavior is controlled by using the property

sun.net.http.retryPost

which is by default set to true. If we want the default retry behavior to be disabled, just set

sun.net.http.retryPost=false

in the system properties (-D sun.net.http.retryPost=false).

Note: Setting the property programmatically using System.setProperty(“sun.net.http.retryPost “, false) may not work as the value is initialized in the static block in the HttpClient class of JDK. More details in the reference section.

References:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6382788

http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/sun/net/www/http/HttpClient.java

http://www.coderanch.com/t/490463/sockets/java/Timeout-retry-URLHTTPRequest

Categories: web services Tags: ,

How to make asynchronous call to SOAP Web Service using JAX-WS

June 8, 2013 2 comments

Before I show an example of how to invoke asynchronous web service using JAX-WS let’s take a brief know how about synchronous and asynchronous calls.

Synchronous Web service call : A program calling the web service sends a request to the web service and waits till the web service returns the response, before executing the next statement.

Asynchronous Web service call : A program calling the web service sends a request to the web service and proceeds with the execution of remaining statements even before the web service has returned any response.  (This may be because a web service might take time to compute and generate the response, and the client doesn’t want to wait till it receives the response)

I was trying a scenario where I send a web service request and was not interested in the response. The web service would usually take a longer time to process and because of this the program execution in the client was stuck at the web service invocation call. This usually is the case with any of the synchronous call. I just wanted to send the request to the web service and proceed with execution remaining steps in the client without waiting for the web service to return.

Example of how to make asynchronous calls to JAX-WS Web service

1) Create a sample JAX-WS Web service and publish it

@WebService
public class SimpleSOAPServiceImpl{

	@WebMethod
	public String sayHello(@WebParam(name = "echo") String echo) {
		try {
			Thread.sleep(1000*60*5); // Sleep for 5 minutes
			return "Hello "+echo;
		}
		catch(InterruptedException ex) {
			// Exception Handling code here..
		}
		return null;
	}

	public static void main(String args[]) {
		Endpoint.publish("http://localhost:1234/MySOAPService", new SimpleSOAPServiceImpl());
	}
}

2) Create a binding xml to be used with wsimport

<!--?xml version="1.0" encoding="UTF-8" standalone="yes"?-->

        <!-- Applies to all the methods in the wsdl. If set to true all the methods can be          invoked asynchronously -->
        <enableAsyncMapping>true</enableAsyncMapping>

        <!-- Applies asynchronous binding only to selected methods -->
        <!-- Uncomment below binding section, when the above 'enableAsyncMapping' tag         is set to false -->
        <!--
        <bindings node="wsdl:definitions/wsdl:portType[@name='SimpleSOAPServiceImpl']/wsdl:operation[@name='sayHello']">
     		<enableAsyncMapping>true</enableAsyncMapping>
 		</bindings>
 		 -->

3) Run wsimport to generate client artifacts. (I ran from command prompt)

D:/> wsimport http://localhost:1234/MySOAPService?wsdl -b asyncBinding.xml -s .

4) Check the generated interface after running wsimport. This will have 2 extra methods(sayHelloAsync) for each method which was specified in the binding file

// Asynchronous Method
public Response sayHelloAsync(
		@WebParam(name = "echo", targetNamespace = "")
		String echo);

// Asynchronous Method
public Future<?> sayHelloAsync(
        @WebParam(name = "echo", targetNamespace = "")
        String echo,
        @WebParam(name = "asyncHandler", targetNamespace = "")
        AsyncHandler asyncHandler);

// Synchronous Method
public String sayHello(
        @WebParam(name = "echo", targetNamespace = "")
        String echo);

5) Invoke the web service from client

public class Client {
	public static void main(String args[]) throws Exception {
		SimpleSOAPServiceImplService service = new SimpleSOAPServiceImplService();
		SimpleSOAPServiceImpl port = service.getSimpleSOAPServiceImplPort();

		port.sayHelloAsync("This is Asynchrous call.. ");
		// port.sayHello("This is synchronous call");

		System.out.println("Execute this statement before async call is complete.. ");

	}
}

The above client prints Execute this statement before async call is complete.. even before the web service actually finishes processing.

The beauty of making asynchronous calls from JAX-WS is that the web service need not be modified to support any asynchronous calls and remains as is. All magic happens at the client side.

Following reference document details the usage of making asynchronous calls using JAXWS

References

https://today.java.net/pub/a/today/2006/09/19/asynchronous-jax-ws-web-services.html

Categories: web services Tags: ,

Path Vs Classpath

As a Java Developer one frequently encounters these terms but often gets confused when to use what.

Here I found an informative article explaining both: http://geek.starbean.net/?p=38

Note: Following content is reflected from the above article.

Still a lot of people don’t understand the purpose of these system variables. They don’t know when to set it, what it really does and therefore cannot determine that this IS or IS NOT a path or classpath problem.

The PATH variable is a Windows system variable that Windows uses to find executable files. When you type a command in the cmd window, e.g. “javac”, Windows will search in your PATH to find the program to execute. The search sequence is as follows:

Current Dir > PATH Variable > Command Interpreter

In the example, the interpreter will first look in the Current Dir for a javac.com, javac.exe or javac.bat respectively. If found, it will be executed. If not it continues its search through the PATH variable in definition sequence and extension sequence. This means for PATH=C:\Temp;C:\Windows, C:\Temp\javac.com will be searched 1st, followed by C:\Temp\javac.exe, C:\Temp\javac.bat, C:\Windows\javac.com, and so on.

Once the PATH is exhausted, the interpreter will be checked if it is a interpreter command (such as “copy”). If so it will be invoked. Finally the interpreter will return a “Bad command or file name” if the command is not found.

All these means that if you’re getting a “Bad command or file name”, it is likely a PATH problem. It also means if you’re somehow running the wrong program, it may be a program of the same name in a path earlier than yours (useful for java version conflicts).

The CLASSPATH variable is a Java runtime system variable that Java uses to find class files. When Java tries to load a class, it will lookup its ClassLoader. If the class is not yet loaded, Java tries to find the class in the CLASSPATH variable. Sometimes the CLASSPATH may be appended from the runtime command line directly.

This means that if you’re getting a ClassNotFoundException during runtime, or “Unable to resolve symbol” during compile, you may have a CLASSPATH problem. (NOTE: Typos and other errors may also raise same compile error). If the classes are in the current directory and still cannot be found try adding “.” (current dir) to the classpath or check if the sources are in java packages.

To check the current PATH on cmd, type “PATH” or “set PATH”. To check the CLASSPATH, type “set CLASSPATH”.

To fix the PATH or CLASSPATH, you can either set it on the command line directly or set it through System Environment Variables. To set it from cmd, type “set CLASSPATH=someClassPath”. To append to the existing PATH or CLASSPATH, use %xxx%. E.g. “set CLASSPATH=%CLASSPATH%;.” to append the current directory into the classpath without affecting the existing classpath. Setting the variables on cmd only persists for that session. If you start another cmd or close this cmd the variables will be reset.

To persist the variables permanantly, you can set it through System Environment Variables. For XP Pro, go to the “System Properties” first. You can get there by

  1. Start > Control Panel > System
  2. Start, right-click “My Computer”, select “Properties”
  3. Press [WindowsKey]+[Break] simultaneously

with option 3 being the fastest. From there, click the “Advanced” tab and click “Environment Variables” at the bottom. Set either the User variables or System variables. The User variables only affect your Windows Login, and System variables will affect everyone. User variables will overwrite any System variable settings.

 

 

Categories: Uncategorized Tags: ,

Objects in Java are passed by value

December 19, 2012 Leave a comment

I often used to get confused with the behavior of java language when passing primitives method arguments Vs passing Array or Objects as method arguments. In this post I analyze the behavior of passing arguments types to the methods:

Let’s start with this example by passing primitives to as the method arguments:

Example 1:

public static void main(String[] args) {
int x = 10;
int y = 10;
add(x, y);
System.out.println("x = "+x); // Prints 10
System.out.println("y = "+y); // Prints 10
}

public static void add(int x, int y) {
x = x+10;
y = y+10;
System.out.println("x = "+x); // Prints 20
System.out.println("y = "+y); // Prints 20
}

As we see in the above example the primitive values are passed by value and the actual primitive values doesn’t change in the main method and they still print the original values.

Now let’s take an example of passing Objects as the method arguments and see the behavior

Example 2:

public static void main(String[] args) {
StringBuffer strBuf = new StringBuffer();
add(strBuf);
System.out.println("strBuf = "+strBuf); // Prints Hello World !!!
}

public static void add(StringBuffer strBufCopy) {
strBufCopy.append("Hello World !!! ");
System.out.println("strBuf = "+strBufCopy); // Prints Hello World !!!
}

Here the actual value of ‘strBuf’ varaible in the main method got changed after the modification in the add method. This makes us think “is StringBuffer (Objects) passed by reference” ?

Lets take another example by passing an Array as the method variable.

Example 3:

public static void main(String[] args) {
int[] integerArray = {1,2,3};
add(integerArray);
for(int i : integerArray) {
System.out.print(i+","); // Prints 100,100,100,
}
}

public static void add(int[] intArray) {
for(int i=0; i<intArray.length; i++) {
intArray[i] = 100;
}
for(int i : intArray) {
System.out.print(i+","); // Prints 100,100,100,
}
}

Again the actual value of integerArray got changed in the main method. Is Array passed by reference ?

Java strictly uses pass by value. Lets see the explanation:

Following is the way the above three examples work:

Example 1: In case of primitives a separate copy of values (x,y) was made and passed to the method, and the method was manipulating the copy of the primitive not the actual primitive. Thus the primitive values in the main method remains unaffected after calling the add method.

Example 2: It’s a different story when we pass an Object reference as the method argument. The object reference is still passed as Pass by Value, but refers to the same StringBuffer object created in the main method. Now we have two different object references ‘strBuf’ and ‘strBufCopy’ referring to the same StringBuffer Object. Now when we append a value using strBufCopy reference we are still referring the same old StringBuffer object created in the main method. Hence any change would directly refer to the actual object. This is the reason why we get Hello World !! printed in both strBuf and the strBufCopy.

Example 3: The explanation for this is same as Example 2, hence arrays in java are nothing but objects.

With the above example we conclude that Java is strictly pass by value.

Categories: Programming, Technical Tags:

Host Name Verification Failed when invoking HTTPS endpoint through WSO2 ESB

September 7, 2012 Leave a comment

If encountered with this exception, set the HostNameVerifier property in axis2.xml to AllowAll.

Go to <WSO2ESB_HOME>/repository/conf/axis2.xml. Under <transportSender name=”https” tag set the following property:

<parameter name="HostnameVerifier">AllowAll</parameter>

This would essentially turn HostNameVerification off. For more information about other options please refer HostNameVerifier Doc

Hope this helps.

Categories: Technical, wso2 esb Tags: ,

Invoking Secured Web service through WSO2 ESB

August 31, 2012 8 comments

Steps for invoking Secured Web service through WSO2 ESB:

  1. Create a webservice with Wssp1.2-2007-Https-UsernameToken-Plain.xml on Weblogic (or any other app. Server).

  2. Download SSL certificate associated with the webservice (through Internet Explorer) (This can be done by accessing https wsdl endpoint)

  3. Import SSL certificate of the webservice to client-truststore.jks of WSO2 ESB located at <WSO2_HOME>/repository/resources/security using Java Keytool

  4. Add a policy file with Rampart configurations to Local Entries section on WSO2 ESB

    1. Use password Callbackhandler in the policy file to fetch the password for the provided username

    2. For writing a Password CallbackHandler refer http://wso2.org/library/3733

    3. Generate a .jar file (Eg:mycallbackhandler.jar) using ecplise and copy it at <WSO2_HOME>/repository/components/lib

    4. Sample policy file

  5. <wsp:Policy wsu:Id="UTOverTransport" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
    	<wsp:ExactlyOne>
    	  <wsp:All>
    		<sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
    		  <wsp:Policy>
    			<sp:TransportToken>
    			  <wsp:Policy>
    				<sp:HttpsToken RequireClientCertificate="false"/>
    			  </wsp:Policy>
    			</sp:TransportToken>
    			<sp:AlgorithmSuite>
    			  <wsp:Policy>
    				<sp:Basic128/>
    			  </wsp:Policy>
    			</sp:AlgorithmSuite>
    			<sp:Layout>
    			  <wsp:Policy>
    				<sp:Lax/>
    			  </wsp:Policy>
    			</sp:Layout>
    			<sp:IncludeTimestamp/>
    		  </wsp:Policy>
    		</sp:TransportBinding>
    		<sp:SignedSupportingTokens xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
    			<wsp:Policy>
    				<sp:UsernameToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient" />
    		  </wsp:Policy>
    		</sp:SignedSupportingTokens>
    		
    		<ramp:RampartConfig xmlns:ramp="http://ws.apache.org/rampart/policy"> 
    			<ramp:user>SAML2</ramp:user>
    			<ramp:passwordCallbackClass>com.webservice.security.wso2.callback.PasswordCallback</ramp:passwordCallbackClass>
    		</ramp:RampartConfig>
    		
    	  </wsp:All>
    	</wsp:ExactlyOne>
    </wsp:Policy>
    
  6. Configure HTTPS webservice endpoint in WSO2

    1. Associate the policy uploaded in Step 3, to the endpoint using Advanced options by enabling WS-Secuirty checkbox.

  7. Create simple a Custom Proxy for to use the above endpoint

  8. Engage Rampart Module to the WSO2 ESB proxy which accesses the endpoint.

    1. WebServices List Select your proxy Click Modules Select rampart-xxx from Modules drop down Click Engage

  9. Execute the Proxy from SOAP UI or any testing tool, it should return proper data.