Follow by Email

Tuesday, November 29, 2016

Origin http://localhost:4200 not found in Access-Control-Allow-Origin header.

Problem
In my angularjs 2 application I am using a restful service

http://jsonplaceholder.typicode.com/users

When I try to call this service I get below error

Origin http://localhost:4200 not found in Access-Control-Allow-Origin header.

All solutions were suggesting to add  No 'Access-Control-Allow-Origin' header which was not an option for me because I had no control on the server.

Reason
For my case the reason was the network (My office network) to which I was connected it was not allowing this port for some reason.

Solution

Changed the network and it was working fine :).

Monday, October 17, 2016

org.springframework.jdbc.BadSqlGrammarException CallableStatementCallback; bad SQL grammar

I was getting below exception in my code where my query in the function was perfectly working fine in oracle but in java code giving me this error




org.springframework.jdbc.BadSqlGrammarException: CallableStatementCallback; bad SQL grammar [{call schema.package.function(?, ?, ?)}]; nested exception is java.sql.SQLException: Invalid column name




Thanks to this thread
http://forum.spring.io/forum/spring-projects/data/22853-preparedstatementcallback-bad-sql-grammar




I noticed there  was no ORA error message in the exception , which means the call was executed successfully in JDBC level , and than I had to check my mapper defined for this execution there I was trying to get  a column from resultset which was not selected in the original query hence the problem " java.sql.SQLException: Invalid column name"


Solution
I added the missing column in my query and got rid of this exception. Good Lesson Learned.


Lesson Learned : If there is no ORA error in your exception chances are that the JDBC call was ok and now something wrong in your java code .

Saturday, October 15, 2016

java.net.SocketException: Broken pipe

Reason :


I was facing this exception when I was trying to create a resultset with a lot of records in it , later I found the data set was so huge that even in PL/SQL it was showing memory issues.


Solution :


I had to restrict my query to be executed for a specific date range which user may select and warn the user about any possible issues when the date is very long.



Saturday, September 3, 2016

Remove padding beneath H3,h2,ui tag





I was developing a printer friendly HTML page and was facing a problem where H2,h3 and ui tags were adding extra spaces at top and bottom of the text.


Thanks to the below stackoverflow answer I found out that there is a default margin and padding in these tags and had to write a small css to override those


h3{ padding: 0px; margin: 0px; }
ui{ margin: 0px; }


notice that I am not using padding:0 for ui because if I do it is going to remove the padding and my ui will not appear aligned with the border which I don't want.




http://stackoverflow.com/questions/1235134/remove-padding-beneath-h3-tag

Sunday, June 12, 2016

Where does Eclipse copy our web application after deployment?

Thanks to below stackoverflow thread I was able to find it quickly , keeping it in my blog so that it is easy to search in future.


http://stackoverflow.com/questions/4543868/where-does-eclipse-store-generated-servlet-files-for-tomcat




Below is copy pasted from above link


go to your application work space directory(not eclipse installation directory) in windows explorer(not in eclipse IDE explorer).


Here under the .metadata folder you will find your application under below path


\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\work\Catalina\localhost



Wednesday, May 18, 2016

How to ignore zero decimal place values in Crystal Reports

I had this requirement where I wanted to show a decimal number with 2 decimal points in my report but when there is no decimal value I wanted to show the integer part only i.e.


I wanted to show


50


instead of
50.00 (default behavior)


I had to define a custom formula for this


here is the procedure


  1. right click on your field in crystal report
  2. Format field
  3. Click on Number tab
  4. Press customize button
  5. Define a formula for Decimals as below
Crystal Report Formula
if CurrentFieldValue - truncate(CurrentFieldValue) <> 0 then
2
else
0


This basically means that if the current value has no decimals show 0 or no decimal places , else show 2.


Thanks to an answer in below stackoverflow thread from where I got to know about "CurrentFieldValue "


http://stackoverflow.com/questions/17284732/how-to-ignore-zero-decimal-place-values-in-crystal-reports


Thursday, May 5, 2016

SCRIPT438: Object doesn't support this property or method

Problem :
When trying to click on a check box I was getting this error message

SCRIPT438: Object doesn't support this property or method

Reason : 

The reason was that the Id of my inbox and the function it was calling on click was the same

<INPUT type="checkbox" id="isGeneral" onclick="isGeneral(this)" />

Solution :

Changed the function name like

<INPUT type="checkbox" id="isGeneral" onclick="isGeneralBestPractice(this)" />


And it was working fine after that.

Tuesday, April 26, 2016

Failed to execute goal org.codehaus.mojo:aspectj-maven-plugin


Problem :


Trying to build my project in Maven , getting below error and build unsuccessful

ERROR] Failed to execute goal org.codehaus.mojo:aspectj-maven-plugin:1.2:compile (default) on project DrillingBestPractices: Compiler errors :

[ERROR] error at import org.apache.catalina.connector.Request;
[ERROR] ^^^^^^^^^^^^^^^^^^

[ERROR]  absolute Path of my class
The import org.apache.catalina cannot be resolved


Solution :

The import was not being used in the class , so just had to delete it from the related class. and then the project was successfully built in Maven.

Surprise :

IDE was not complaining about this import , no compilation error which means the related jar file was in the build path. IDE however was showing me an un used warning for this import. It is strange that Maven was actually complaining about this import. However as said in the solution problem was resolved by removing the unused import in error message.

Lesson Learned :


Pay close attention to Maven error log and you will find a hint where the problem might be.



Saturday, March 26, 2016

Tiles javax.servlet.ServletException: Could not resolve view with name 'myTileName' in servlet with name 'My Servlet'









Problem :

Tiles javax.servlet.ServletException: Could not resolve view with name 'myTileName'  in servlet with name 'My Servlet'


Soluiton

The above error was facd when there was no related tiles definition in the related layout file of tiles , once the tile definition was created this error was gone.


Note I thaught initially that it was not picking the page correctly but the problem was it was not finding the tiles definition.

Wednesday, February 10, 2016

JSTL : Adding a custom EL function

I am out putting URLS in my JSP pages and wanted to encode those URLS to avoid cross site scripting , The bets solution I can think about was to create a custom EL function for URL encoding and use it in my jsp pages.


Below is how to do that


Create a class with your function




package com.mycompany.myproject.util;

import java.net.URI;

import java.net.URISyntaxException;

import javax.servlet.jsp.tagext.TagSupport;

 

@SuppressWarnings("serial")

public class FunctionForJSTL  {

 

       /**

        * This method will return the encoded URL

        * http://stackoverflow.com/questions/5053975/how-to-url-encode-a-string-with-jstl

        * From above Stackoverflow link

        *  URLEncoder.encode() is actually not the correct way to encode a URL. It is the correct way to encode a URL parameter. It changes spaces to + for example. The correct technique is new URI(null, url, null).toASCIIString(), which for example changes spaces to %20.

        * @param url

        * @return

        * @throws URISyntaxException

        */

       public static String urlEncode(String url) throws URISyntaxException{

              String escapedURL=null;

              if(url!=null){

                     escapedURL =new URI(null, url, null).toASCIIString();

                     return escapedURL;

              }

              else

                     return url;

       }

}


Create TLD file put it under WEB-INF



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

<taglib

    xmlns="http://java.sun.com/xml/ns/javaee"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"

    version="2.1">

    <display-name>Custom Functions</display-name>   

    <tlib-version>1.0</tlib-version>

    <uri>http://example.com/functions</uri>

    <function>

        <name>urlEncode</name>

        <function-class>com.mycompany.myproject.util.FunctionForJSTL</function-class>

        <function-signature>java.lang.String urlEncode(java.lang.String)</function-signature>

    </function>

</taglib>

Use In your JSP

Taglib import statement

<%@taglib uri="/WEB-INF/functions.tld" prefix="f" %>

JSP EL

${f:urlEncode(anyURL)}