Fix STS VMware vFabric start issue.

Issue:

starting vmware vfabric tc server developer edition* encountered a problem

Resolution-1:

  • Close all Java related processed, programs, servers, IDEs.
  • Go to task manager, kill java process.
  • STSIssue-TaskManagerRestart everything and test again.

Resolution-2:

  • If Resolution-1 one does nit work, i am assuming Server instance may have been corrupted.
  • Close all Java related processed, programs, servers, IDEs.
  • Go to task manager, kill java process.
  • Find server location.

STS-FindLocation

  • Navigate two directories back to reach following.

           ..spring-tool-suite-3.6.0\sts-bundle\vfabric-tc-server-developer-2.9.6.RELEASE

  • Take backup of “base-instance” directory by renaming it.
  • Create new “base-instance” by following below steps.
  • Start command prompt in admin mode.
  • Follow guide.

Internationalization Spring 3.1.1

servlet-context.xml is src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml

xmlns:mvc = “http://www.springframework.org/schema/mvc”

servlet-context.xml is src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml

<!– i18n –>
<bean id=”messageSource”
class=”org.springframework.context.support.ReloadableResourceBundleMessageSource”>

<!– if you are keeping files in src/main provide value: “classpath:messages” –>

<property name=”basename” value=”/resources/i18n/messages” />
<property name=”defaultEncoding” value=”UTF-8″/>
</bean>

<mvc:interceptors>
<bean class=”org.springframework.web.servlet.i18n.LocaleChangeInterceptor”>
<property name=”paramName” value=”lang” />
</bean>
</mvc:interceptors>

<bean id=”localeResolver”
class=”org.springframework.web.servlet.i18n.CookieLocaleResolver”>
<property name=”defaultLocale” value=”fr”/>
</bean>

Message files

i18n-1

Working:

i18n-2

i18n-e

 

messages_en.properties:

home.button.download = Download

messages_es.properties:

home.button.download = Descargar

Note: Set property file encoding as “UTF-8”

JSP:

<spring:message code=”home.button.download” text=”” />

Array can be created like this which can be used in JS later:

<script type=”text/javascript”>
var i18n_js = new Array();
i18n_js[‘home.button.download’] = “<spring:message code=’home.button.download’ javaScriptEscape=’true’ />”;
i18n_js[‘home.app.title’] = “<spring:message code=’home.app.title’ javaScriptEscape=’true’ />”;
i18n_js[‘home.app.sub.title’] = “<spring:message code=’home.app.sub.title’ javaScriptEscape=’true’ />”;
</script>

ATG formhandler AJAX call using Jquery, JSON

Story:

  1. Click on Anchor tag
  2. Anchor tag invokes javascript function using attribute onClick()
  3. Javascript function submits a jsp form using ajax, which calls formhandler
  4. This Javascript function also define success method
  5. formhandler sets some parameter values.
  6. Control is redirected to success page by form handler.
  7. Success JSP creates JSON object.
  8. Javascript success function recieves this JSON object as response.
  9. Javascript parse this JSON object as required.

 

JSP Anchor tag:
On click on this link, formhandler method should be invoked and should return some result.

<a href="#" onClick="invokeTestMethod();">Test</a>

Javascript function:

function invokeTestMethod(){
 
//define success method
 var options = {
 success : resultOfTestMethod
 }
 
 //submit form using ajax
 $('#<form ID>').ajaxSubmit(options); 
}

JSP Form:

In JSP i have created one form which will be submitted by JQurey on click on the link:

 <dsp:form id="<form name>" name="<form name>" method="post" action="${requestURI}">
              <dsp:input type="hidden" bean="MyFormHandler.updateAddressSuccessUrl" value="<Success JSP>"/>
              <dsp:input type="hidden" bean="MyFormHandler.updateAddressErrorURL" value="<Error JSP>"/>
              <dsp:input type="hidden" bean="MyFormHandler.testMethod" value=""/> 
 </dsp:form>

FormHandler method:

public final boolean handleTestMethod(final DynamoHttpServletRequest pRequest,
 final DynamoHttpServletResponse pResponse) throws ServletException,
 IOException {
setTestString("Mohut");
 return checkFormRedirect(updateAddressSuccessUrl,updateAddressErrorURL, pRequest,pResponse);
 }

Success JSP:

<dsp:page>
<dsp:importbean bean="/path/MyFormHandler"/>
 <json:array name="addressList">
 <json:object>
 <json:property name="<propert name>">
 <dsp:valueof bean="MyFormHandler.testString"/>
 </json:property>
 </json:object>
 </json:array>
</dsp:page>

Javascript success method:

function resultOfTestMethod(responseText, statusText, xhr, $form){
var addressArray = JSON.parse(responseText);
}

 

Parse google map JSON result using “javax.json” package

Java code:

import java.io.IOException;

import java.io.InputStream;

import javax.json.Json;
import javax.json.JsonArray;
import javax.json.JsonNumber;
import javax.json.JsonObject;
import javax.json.JsonReader;
import javax.json.JsonString;

 

public class MapMain {

static InputStream is;
static JsonReader rdr;
static JsonObject obj,lJsonObj;
static JsonArray results;
static GeocodeImplementation geocodeImplementation;
static JsonNumber longitude;
static JsonNumber latitude;
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
geocodeImplementation = new GeocodeImplementation();
String[] addresses = {
“1600 Amphitheatre Parkway, Mountain View, CA 94043, USA”,
“Forum Mall No. 21 Hosur Road Bengaluru Karnataka 560095”,
“RMZ Ecospace Marathahalli-Sarjapur Outer Ring Rd Adarsh Palm Retreat Bellandur Bangalore Karnataka 560103”,
“Sony World 100 Feet Rd Koramangala 4 Block Ejipura Bangalore Karnataka 560095”,
“Brigade Rd Shanthala Nagar Ashok Nagar Bangalore Karnataka”,
“Talakadu Jaladhama Resorts No-37 s1 II floor Basco court Gandhi Bazaar main road Basavanagudi Bangalore Karnataka 560004”,
“tanishq 11th Main Rd Jayanagar 3 East Block KV Layout Jayanagar Bangalore Karnataka 560011”,
“Wrong address”
};

for(int i=0;i<addresses.length;i++){
System.out.println(“================ ” + addresses[i] + ” ================”);
is = geocodeImplementation.getJSONByGoogle(addresses[i]);
rdr = Json.createReader(is);
obj = rdr.readObject();
results = obj.getJsonArray(“results”);
JsonString resultStatus;
resultStatus = obj.getJsonString(“status”);
System.out.print(resultStatus);
System.out.println(“: “);
System.out.println(“———–“);

for (JsonObject result : results.getValuesAs(JsonObject.class)) {
lJsonObj = result.getJsonObject(“geometry”).getJsonObject(“location”);
longitude = lJsonObj.getJsonNumber(“lng”);
latitude = lJsonObj.getJsonNumber(“lat”);
System.out.println(“longitude: ” + longitude + ” latitude: ” + latitude);

}
}
}

}

 

Sample JSON and its output from code above:

code_output

json

References:

Jar: http://www.java2s.com/Code/Jar/j/Downloadjavaxjson10jar.htm

Code Sample: http://www.oracle.com/technetwork/articles/java/json-1973242.html

Display buffered image on JSP

Only JSP

<%

BufferedImage bImage = ImageIO.read(new File(“/home/mohit/Desktop/mohit.jpg”));//give the path of an image
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write( bImage, “jpg”, baos );
baos.flush();
byte[] imageInByteArray = baos.toByteArray();
baos.close();
String b64 = javax.xml.bind.DatatypeConverter.printBase64Binary(imageInByteArray);

%>

<img src=”data:image/jpg;base64, <%=b64%>” alt=”Image not found” />

When buffered image is passed to JSP as session attribute

Servlet

request.getSession().setAttribute(“bufferedimage”, bufferedimage);

JSP

<%

BufferedImage bImage =  (BufferedImage) session.getAttribute(“bufferedimage”);

ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write( bImage, “jpg”, baos );
baos.flush();
byte[] imageInByteArray = baos.toByteArray();
baos.close();
String b64 = javax.xml.bind.DatatypeConverter.printBase64Binary(imageInByteArray);

%>

<img src=”data:image/jpg;base64, <%=b64%>” alt=”Image not found” />

When buffered image stream is passed to JSP as session attribute

Servlet

ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(bufferedimage, “jpg”, baos );
baos.flush();
byte[] imageInByteArray = baos.toByteArray();
baos.close();
String b64 = javax.xml.bind.DatatypeConverter.printBase64Binary(imageInByteArray);
request.getSession().setAttribute(“b64”, b64);

JSP

<img src=”data:image/jpg;base64, <%=b64%>” alt=”Image not found” />

Enable eclipse debug for weblogic server

Set following code in bat file used to start weblogic server:

set JAVA_OPTIONS=-Dweblogic.j2ee.application.tmpDir=c:/temp %JAVA_OPTIONS%

set JAVA_OPTIONS= %JAVA_OPTIONS% -Dcom.sun.xml.ws.transport.http.client.HttpTransportPipe.dump=true -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=7077

 

Verification:

You should see something like following on weblogic console.

weblogicdebug

 

 

And then use debug port 7077 (or anything else) as mentioned in this file.

How to create and integrate NEW repository in ATG

Layman and simple language i will use here.

Repository = 1 property file (responsible for connecting to Data source defined in your application server)

Tools used:

  • Oracle ATG10.2
  • Oracle webllogic server
  • Oracle DB

Steps:

  1. Get DB details (Schema Name, SID, Password, IP, PORT)
  2. Connect to you schema, create a table and insert some data. (Table must have a primary key)
  3. Choose JNDI name of your choice.
  4. Go to Weblogic server where your ATG commerce application will run.
  5. Create a Datasource with any name using JNDI and DB details from Step 1 and 3.
  6. Go to your development tool, i use eclipse.
  7. Create repository property file with any name you like, under any sub folder of “config”. e.g. myrepo.properties

Continue reading