diff --git a/pom.xml b/pom.xml index 6b0ac4c..6376c5a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,11 +4,11 @@ 4.0.0 com.example - demo + admin 0.0.1-SNAPSHOT jar - hpdemo + AdminProject Demo project for Spring Boot @@ -29,12 +29,30 @@ org.springframework.boot spring-boot-starter - + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + org.springframework.boot spring-boot-starter-test test + + + + org.apache.tomcat + tomcat-jasper + 8.5.11 + + + javax.servlet + jstl + diff --git a/src/main/java/AdminApplication.java b/src/main/java/AdminApplication.java new file mode 100644 index 0000000..68fe93a --- /dev/null +++ b/src/main/java/AdminApplication.java @@ -0,0 +1,15 @@ +package com; + + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class AdminApplication { + + public static void main(String[] args) { + + SpringApplication.run(AdminApplication.class, args); + } +} + diff --git a/src/main/java/com/example/ApplicationStart.java b/src/main/java/com/example/ApplicationStart.java new file mode 100644 index 0000000..9001bdb --- /dev/null +++ b/src/main/java/com/example/ApplicationStart.java @@ -0,0 +1,25 @@ +/* +package com.example; + +import com.example.inversionOfControl.Mobile; +import com.example.inversionOfControl.StoreConfiguration; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +@SpringBootApplication +public class ApplicationStart { + + public static void main(String[] args) { + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(StoreConfiguration.class); + Mobile mobile1 = (Mobile) context.getBean("getAndriod"); + System.out.println(mobile1.getModel()); + + + Mobile mobile11 = (Mobile) context.getBean("getApple"); + System.out.println(mobile11.getModel()); + + SpringApplication.run(ApplicationStart.class, args); + } +} +*/ diff --git a/src/main/java/com/example/HpdemoApplication.java b/src/main/java/com/example/HpdemoApplication.java deleted file mode 100644 index 0b991fe..0000000 --- a/src/main/java/com/example/HpdemoApplication.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.example; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class HpdemoApplication { - - public static void main(String[] args) { - SpringApplication.run(HpdemoApplication.class, args); - } -} diff --git a/src/main/java/com/example/SalesForceURLTest.java b/src/main/java/com/example/SalesForceURLTest.java deleted file mode 100644 index 610356f..0000000 --- a/src/main/java/com/example/SalesForceURLTest.java +++ /dev/null @@ -1,85 +0,0 @@ -import java.io.IOException; -import java.net.HttpURLConnection; -import java.net.InetSocketAddress; -import java.net.Proxy; -import java.net.URL; - -public class SalesForceURLTest { - - public static void main(String args[]) throws Exception { - - String[] hostList = { "https://test.salesforce.com"}; - - for (int i = 0; i < hostList.length; i++) { - - String url = hostList[i]; - getStatus(url); - - } - - System.out.println("Task completed..."); - } - - public static String getStatus(String url) throws IOException { - - String result = ""; - int code = 200; - try { - /* Without proxy settings code - URL siteURL = new URL(url); - HttpURLConnection connection = (HttpURLConnection) siteURL.openConnection(); - connection.setRequestMethod("GET"); - connection.setConnectTimeout(3000); - connection.connect(); - code = connection.getResponseCode();*/ - - // With Proxy Settings - /* System.setProperty("http.proxyHost", "proxy-mwg-http.ca.sunlife"); - System.setProperty("http.proxyPort", "8080"); - System.setProperty("http.proxyUser", "user.qps@sunlife.com.intsb"); - System.setProperty("http.proxyPassword", "4qps1997aj1nGNuDAVOHqo6iLAxlSTYe");*/ - URL siteURL = new URL(url); - /*Proxy proxy1 = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy-mwg-http.ca.sunlife", 8080)); - HttpURLConnection connection1 = (HttpURLConnection) siteURL.openConnection(proxy1); - connection1.setRequestMethod("GET"); - connection1.setConnectTimeout(3000); - connection1.setRequestProperty( "http.proxyUser", "user.qps@sunlife.com.intsb" ); - connection1.setRequestProperty( "http.proxyPassword", "4qps1997aj1nGNuDAVOHqo6iLAxlSTYe" ); - connection1.connect(); - code = connection1.getResponseCode(); - System.out.println(url + "\t\t Connection is using proxy with port 8080 :" + connection1.usingProxy()); - - if (code == 200) { - result = "-> Green <-\t" + "Code: " + code; - ; - } else { - result = "-> Yellow <-\t" + "Code: " + code; - }*/ - - Proxy proxy2 = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxy-mwg-http.ca.sunlife", 8443)); - HttpURLConnection connection2 = (HttpURLConnection) siteURL.openConnection(proxy2); - connection2.setRequestMethod("GET"); - connection2.setConnectTimeout(3000); - connection2.setRequestProperty( "http.proxyUser", "user.qps@sunlife.com.intsb" ); - connection2.setRequestProperty( "http.proxyPassword", "4qps1997aj1nGNuDAVOHqo6iLAxlSTYe" ); - connection2.connect(); - code = connection2.getResponseCode(); - - System.out.println(url + "\t\t Connection is using proxy with port 8443:" + connection2.usingProxy()); - - - if (code == 200) { - result = "-> Green <-\t" + "Code: " + code; - ; - } else { - result = "-> Yellow <-\t" + "Code: " + code; - } - } catch (Exception e) { - e.printStackTrace(); - result = "-> Red <-\t" + "Wrong domain - Exception: " + e.getMessage(); - - } - System.out.println(url + "\t\tStatus:" + result); - return result; - } -} diff --git a/src/main/java/com/example/SplitStringTest.java b/src/main/java/com/example/SplitStringTest.java deleted file mode 100644 index 52c03cf..0000000 --- a/src/main/java/com/example/SplitStringTest.java +++ /dev/null @@ -1,475 +0,0 @@ -package sunlife.us.dc.messagecenter.plugin.gcsdocgengateway.sample.processor; - - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.commons.codec.binary.Base64; -import org.apache.commons.lang.StringEscapeUtils; -import org.apache.commons.lang.StringUtils; -import org.junit.Test; - -import javax.xml.datatype.DatatypeFactory; -import javax.xml.datatype.XMLGregorianCalendar; -import java.beans.XMLDecoder; -import java.io.*; -import java.net.MalformedURLException; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import java.util.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - - -public class SplitStringTest { - String completeString = "1.0~96449~[EventResponse]"; - //String alpha = "{policy=[[218445,865231]], party=[115], doctype=Claim Approval Letter, user=null, caseNumber=[NTN-19-DI-01]}"; - - private static String serialize(Serializable o) throws IOException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(baos); - oos.writeObject(o); - oos.close(); - return Base64.encodeBase64String(baos.toByteArray()); - } - - private static Object deserialize(String s) throws IOException, - ClassNotFoundException { - byte[] data = Base64.decodeBase64(s); - ObjectInputStream ois = new ObjectInputStream( - new ByteArrayInputStream(data)); - Object o = ois.readObject(); - ois.close(); - return o;//(o.toString().substring(1, o.toString().length()-1)); - } - - /** - * To get a value from string of hashmap by passing key that existed in Hashmap before converting to String. - * Sample string: {fld_category=Principal category, test=test 1, fld_categoryID=1} - * - * @param string - * @param key - * @return value - */ - public static String getValueFromStringOfHashMap(String string, String key) { - - - int start_index = string.indexOf(key) + key.length() + 1; - int end_index = string.indexOf(",", start_index); - if (end_index == -1) { // because last key value pair doesn't have trailing comma (,) - end_index = string.indexOf("}"); - } - String value = string.substring(start_index, end_index); - - return value; - } - - /*@Test - public void testStringHelper() { - InteractiveCreateDocumentRequestContract contract = StringHelper.translateStringToObject(alpha); - System.out.println( " print contract : Policies " + contract.getPolicy().get(0) + ":::" + contract.getPolicy().get(1)); - System.out.println( " print contract : Party " + contract.getParty().get(0)); - System.out.println( " print contract : docType " + contract.getDoctype()); - System.out.println( " print contract : user " + contract.getUser()); - System.out.println( " print contract : case " + contract.getCaseNumber().get(0)); - }*/ - - @Test - public void testStringSplits() { - String versionNum = completeString.split("~")[0]; - System.out.println(versionNum); - String docId = completeString.split("~")[1]; - System.out.println(docId); - - } - - @Test - public void testFirstNameSplit() { - String firstName = null; - // String name = "SRIDHAR REDDY SANGALA"; - String name = "DIIntaketext5 Approval6"; - String[] parts = name.trim().split( "\\s+" ); - System.out.println( "FirstName out of name tag is : " + parts[0] ); - System.out.println( "FirstName out of name tag is : " + parts[1] ); - firstName = parts[0]; - System.out.println( firstName ); - - } - - @Test - public void testCaseNumberSplit() { - //String caseNumber1 = "NTN-100423-ABS-01"; - //String caseNumber1 = "NTN-57930-DI-02-SA-01"; - String caseNumber1 = "NTN-57930"; - String[] parts1 = caseNumber1.split( "-" ); - //String[] parts2 = caseNumber2.split("-"); - //String[] parts3 = caseNumber3.split("-"); - System.out.println( parts1.length ); - //System.out.println( parts2.length); - //System.out.println( parts3.length); - if (parts1.length > 2) { - System.out.println( parts1[0] ); - String case1 = caseNumber1.substring( caseNumber1.indexOf( caseNumber1.split( "-" )[0] ), caseNumber1.indexOf( caseNumber1.split( "-" )[2] ) - 1 ); - System.out.println( case1 ); - } else { - String case1 = caseNumber1; - System.out.println( case1 ); - } - } - - @Test - public void testEmailIdSplit() { - String emailid = "CHRIS.KERR@SUNLIFE.COM"; - //String emailid = "SYSADMIN"; - Pattern pattern = Pattern.compile("[a-zA-Z0-9]*"); - //Pattern pattern = Pattern.compile("[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"); - Matcher mat = pattern.matcher(emailid); - if (!(StringUtils.isAlphanumeric(emailid))) { - System.out.println("Inside the block "); - String email2UserId = StringUtils.remove(emailid, "@SUNLIFE.COM"); - System.out.println(email2UserId); - } else { - System.out.println("Outside the block "); - System.out.println(emailid); - } - - } - - @Test - public void testXMLGregorianCalendar() { - /* Create Date Object */ - Date date = new Date(); - XMLGregorianCalendar xmlDate = null; - GregorianCalendar gc = new GregorianCalendar(); - gc.setTime(date); - - try { - xmlDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(gc); - } catch (Exception e) { - e.printStackTrace(); - } - - System.out.println("XMLGregorianCalendar :- " + xmlDate); - } - - @Test - public void testMap() { - ObjectMapper oMapper = new ObjectMapper(); - HashMap mapQueryParams = new HashMap<>(); - mapQueryParams.put("doctype", "doc"); - mapQueryParams.put("party", "[[218454,267858]]"); - mapQueryParams.put("policy", "[[115,112]]"); - mapQueryParams.put("caseNumber", "[100]"); - mapQueryParams.put("user", "user"); - try { - String serstring = serialize(mapQueryParams); - - //Map map = oMapper.convertValue(deserialize("rO0ABXQAjntwb2xpY3k9W1syMTg0NDUsMjA0MjQ1XV0sIHBhcnR5PVtbMTE1LDQ3XV0sIGRvY3R5cGU9Q2hhbmdlIGluIERlZmluaXRpb24gb2YgRGlzYWJpbGl0eSBBcHByb3ZhbCBMZXR0ZXIsIHVzZXI9bnVsbCwgY2FzZU51bWJlcj1bTlROLTE5LURJLTAxXX0="),new TypeReference>() {}); - XMLDecoder xmlDecoder = new XMLDecoder(new ByteArrayInputStream(serstring.getBytes())); - Map parsedMap = (Map) xmlDecoder.readObject(); - for (Map.Entry entry : parsedMap.entrySet()) { - System.out.println(entry.getKey() + ":" + entry.getValue().toString()); - } - - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void testRegexStartEndCharacter() { - String party = "[115,111,200,300]"; - if (party.startsWith("[")) { - StringBuilder sb = new StringBuilder(party); // starts with [ ends with ] - String result = sb.deleteCharAt(0).toString(); - result = sb.deleteCharAt(result.lastIndexOf(']')).toString(); - System.out.println(result); - List items = Arrays.asList(result.split("\\s*,\\s*")); - System.out.println(items.size()); - for (String s : items) { - System.out.println(s); - } - - } else { - System.out.println("hello"); - } - } - /* - public void testMap1() { - *//* HashMap mapQueryParams = new HashMap<>(); - mapQueryParams.put("doctype", "doc"); - mapQueryParams.put("party", "[[218454,267858]]"); - mapQueryParams.put("policy", new ArrayList<>().add("115")); - mapQueryParams.put("caseNumber", "[100]"); - mapQueryParams.put("user", "user"); - String string = "rO0ABXQAjntwb2xpY3k9W1syMTg0NDUsMjA0MjQ1XV0sIHBhcnR5PVtbMTE1LDQ3XV0sIGRvY3R5cGU9Q2hhbmdlIGluIERlZmluaXRpb24gb2YgRGlzYWJpbGl0eSBBcHByb3ZhbCBMZXR0ZXIsIHVzZXI9bnVsbCwgY2FzZU51bWJlcj1bTlROLTE5LURJLTAxXX0"; - String result = getValueFromStringOfHashMap(string, "doctype"); - String party = getValueFromStringOfHashMap(string, "party"); - String policy = getValueFromStringOfHashMap(string, "policy"); - System.out.println(result); - System.out.println(party); - System.out.println(policy);*//* - - try { - JSONObject jsonObject = new JSONObject("{policy=[[218445,204245]], party=[[115,266,57]], doctype=Claim Approval Letter, user=null, caseNumber=[NTN-19-DI-01]}"); - // JSONObject jObject = new JSONObject(output); // json - JSONObject data = jObject.getJSONObject("data"); - System.out.println(jsonObject.get("policy")); - }catch (JSONException err){ - System.out.println(err.getMessage()); - } - }*/ - - @Test - public void testListItems() { - List list1 = new ArrayList<>(); - //list1.add("218454"); - list1.add(" "); - list1.add("267858"); - list1.add("267958"); - - for (String eachParty : list1) { - if (eachParty.equals(list1.get(0))) { - System.out.println(list1.get(0)); - } else { - System.out.println(" not first in the list " + eachParty); - } - } - - } - - /* @Test - public void testjsonString(){ - String jsonString = null; - try { - jsonString = new JSONObject() - .put("JSON1", "Hello World!") - .put("JSON2", "Hello my World!") - .put("JSON3", new JSONObject() - .put("key1", "value1")).toString(); - } catch (Exception e) { - e.printStackTrace(); - } - - System.out.println(jsonString); - }*/ - - /*@Test - public void testmapjson() { - JSONObject jsonObject = null; - JSONArray array = null; - try { - List list1 = new ArrayList<>(); - list1.add(218454); - list1.add(267858); - list1.add(267958); - array = new JSONArray(); - jsonObject = new JSONObject(); - - jsonObject.put("doctype", "doc"); - jsonObject .put("policy", "218454, 267858, 267958"); - jsonObject.put("party", "115"); - jsonObject.put("caseNumber", "100,101"); - jsonObject.put("user", "user"); - - //jsonObject.put("pluginMap", mapQueryParams); - //System.out.println(jsonObject.toString()); - ObjectMapper mapper = new ObjectMapper(); - JSONParser parser = new JSONParser(); - System.out.println(parser.parse(jsonObject.toString())); - Map map = mapper.readValue(jsonObject.toString(), Map.class); - System.out.println(map); - } catch (Exception e) { - e.printStackTrace(); - } - - }*/ - - @Test - public void testStringList() { - ArrayList list = new ArrayList(); - list.add(""); - list.add(" "); - list.add("three"); - StringBuilder sb = new StringBuilder(); - for (String s : list) { - if (sb.length() != 0 && s.isEmpty()) { - sb.append(","); - } - sb.append(s); - } - System.out.println(sb.toString()); - } - - @Test - public void testRemovingCommaSplchars() { - List s1 = getListFromString("[ ,\"212\"]"); - for (String s : s1) { - if (s.isEmpty()) { - System.out.println(" s is empty " + s); - } else { - System.out.println(" s is empty " + s); - } - } - } - - private List getListFromString(String alphaNumeric) { - StringBuilder sb = new StringBuilder(alphaNumeric); // starts with [ ends with ] - String result = sb.deleteCharAt(0).toString(); - result = sb.deleteCharAt(result.lastIndexOf(']')).toString(); - return Arrays.asList(result.split("\\s*,\\s*")); - } - - @Test - public void testMultiple() { - List s3 = getListFromString("[\"212\"]"); - System.out.println(" size is " + s3.size()); - for (String s : s3) { - if (s.isEmpty()) { - System.out.println(" s is empty " + s); - } else { - System.out.println(" s is empty " + s); - } - } - - List s4 = getListFromString("[\"212\",\"215\"]"); - System.out.println(" size is " + s4.size()); - for (String s : s4) { - if (s.isEmpty()) { - System.out.println(" s is empty " + s); - } else { - System.out.println(" s is empty " + s); - } - } - } - - - @Test - public void testRemoveSpecialChars() { - String party = "[212]"; - - if (party.startsWith("[")) { - StringBuilder sb = new StringBuilder(party); // starts with [ ends with ] - String result = sb.deleteCharAt(0).toString(); - result = sb.deleteCharAt(result.lastIndexOf(']')).toString(); - System.out.println(result); - } - } - - - @Test - public void testRegex() { - String partyKey = "55f2fd19-1f38-4569-aa96-22b1e2aa3b69"; - Pattern pattern = Pattern.compile("[^A-Za-z0-9]"); - Matcher matcher = pattern.matcher(partyKey); - - boolean b = matcher.find(); - if (b == true) - System.out.println("There is a special character in my string:- " + partyKey); - else - System.out.println("There is no special character in my String :- " + partyKey); - } - - @Test - public void testPrefixRemove() { - String documentId = "DG_12345678"; - if (documentId.matches("[0-9]+")) { - System.out.println(" yes it is Number" + documentId); - } else { - /*System.out.println(" No it is not a Number " + documentId); - documentId = documentId.replaceAll("DG_", ""); - System.out.println(" Number " + documentId);*/ - if (documentId.startsWith("DG_")) { - String ddocumentId = documentId.replaceAll("DG_", ""); - System.out.println("Inside condition " + ddocumentId); - } else { - System.out.println(" what's up "); - } - } - } - - @Test - public void testKeyValuePairSplit() { - String jsonObjectString = "{status=completed, documentid=DG_1234}"; - Map map = new HashMap(); - String removeBrackets = jsonObjectString.substring(1, jsonObjectString.length() - 1); - String[] keyValueStrings = removeBrackets.split(","); - /*for(int i =0; i < keyValueStrings.length ; i++) { - String[] items =keyValueStrings[i].split("="); - System.out.println("Key : " + items[0] + " and Value : " + items[1]); - }*/ - - for (String eachString : keyValueStrings) { - String[] keyValue = eachString.split(" *= *"); - map.put(keyValue[0], keyValue[1]); - System.out.println("Key : " + keyValue[0] + " - Value : " + keyValue[1]); - } - - } - - @Test - public void testEscapeCharcs() throws MalformedURLException, UnsupportedEncodingException { - String mcurl = "http://dev-dgpapps.us.sunlife/doc-manager/index.xhtml?source-system=GCSDI&requester-code=GCSDI&requester-token=EKgPuy8lsKNH%2FBiywQLWDkyIxA2IYFOSHjrxKbJe3JOr&user-id=k344&doc-id=DG_98800"; - String pluginUrl1 = "http://dev-dgpapps.us.sunlife/doc-manager/index.xhtml?source-system=GCSDI&requester-code=GCSDI&requester-token=EKgPuy8lsKNH%2FBiywQLWDkyIxA2IYFOSHjrxKbJe3JOr&user-id=k344&doc-id=DG_98800"; - String mc = StringEscapeUtils.unescapeXml(mcurl); - //String plugin = StringEscapeUtils.escapeJava(pluginUrl1); - System.out.println(new URL(mc)); - //System.out.println(plugin); - - String token = "EKgPuy8lsKNH%2FBiywQLWDkyIxA2IYFOSHjrxKbJe3JOr"; - String convertToken1 = StringEscapeUtils.unescapeXml(token); - // System.out.println(convertToken1); - String result = java.net.URLDecoder.decode(mcurl, StandardCharsets.UTF_8.name()); - // System.out.println(result); - Map myMap = new HashMap<>(); - - String nextTest = "{requester-code=GCSDI, source-system=GCSDI, contentid=DG_98801, doc-id=98801, status=null, user-id=k344, requester-token=EKgPuy8lsKNH/FBiywQLWDkyIxA2IYFOSHjrxKbJe3JOr, appid=GCSDI}"; - String[] pairs = nextTest.split(","); - for (String pair : pairs) { - //String pair = pairs[i]; - String[] keyValue = pair.split("="); - myMap.put(keyValue[0], keyValue[1]); - } - System.out.println(myMap); - - for (String entry : myMap.keySet()) { - if (entry.equalsIgnoreCase(myMap.get("doc-id"))) { - String conId = myMap.get("doc-id"); - System.out.println(conId); - } - } - - } - - - @Test - public void testList() { - List stringList = new ArrayList<>(); - stringList.add("913"); - stringList.add("708"); - // stringList.add("2748"); - if (stringList.size() == 1) { - System.out.println(" only 1"); - } else if (stringList.size() > 1) { - System.out.println(" two items"); - } else { - System.out.println(" only 2"); - } - } - - private XMLGregorianCalendar getXMLGregorianCalendar() { - /* Create Date Object */ - Date date = new Date(); - XMLGregorianCalendar xmlDate = null; - GregorianCalendar gc = new GregorianCalendar(); - gc.setTime( date ); - - try { - xmlDate = DatatypeFactory.newInstance().newXMLGregorianCalendar( gc ); - xmlDate.setTimezone( -2147483648 ); - xmlDate.setMillisecond( -2147483648 ); - } catch (Exception e) { - e.printStackTrace(); - } - System.out.println( "XMLGregorianCalendar :- " + xmlDate ); - return xmlDate; - } -} diff --git a/src/main/java/com/example/Utilities.java b/src/main/java/com/example/Utilities.java deleted file mode 100644 index 03158c0..0000000 --- a/src/main/java/com/example/Utilities.java +++ /dev/null @@ -1,94 +0,0 @@ -/** - * @author : Sridhar Reddy Sangala - * @Date : 10/31/2021 - * @Time : 10:38 AM - * @project : learning - */ -public class Utilities { - final static String hey = " Hello "; - - public static void main(String[] args) { - Animal aDog = new Dog(); - aDog.eat(); - aDog.makeSound(); - aDog.sleep(); - - Animal aCat = new Cat(); - aCat.eat(); - aCat.makeSound(); - aCat.sleep(); - - Vehicle car = new Car(); - car.start(); - car.stop(); - - Vehicle aero = new Aeroplane(); - aero.start(); - aero.stop(); - String[] recipientDataWithDataRootXml = stringData.split( Pattern.quote( "$$" ) ); - - } - - // To handle special character in sender Name, profileName and senderDepartment field etc - private static String getSpecialCharInFieldValueHandled(String exRecepientInfoDataString) { - exRecepientInfoDataString = handleSpecialCharacterForFieldName(exRecepientInfoDataString, "firstName", "\"firstName\":", "\"firstName\":\""); - exRecepientInfoDataString = handleSpecialCharacterForFieldName(exRecepientInfoDataString, "lastName", "\"lastName\":", "\"lastName\":\""); - } - - public static String handleSpecialCharacterForFieldName(String exRecepientInfoDataString, String fieldName, String s, String s1) { - if (exRecepientInfoDataString.contains(fieldName)) { - String cdcJsonExtractString1 = exRecepientInfoDataString.substring(0, exRecepientInfoDataString.indexOf(s)); - String cdcJsonExtractString2 = exRecepientInfoDataString.substring(exRecepientInfoDataString.indexOf(s)); - String fieldNameSectionValue = StringUtils.substringBetween(cdcJsonExtractString2, s, ",\""); - if (!StringHelper.isEmptyString(fieldNameSectionValue) && !fieldNameSectionValue.equalsIgnoreCase("null")) { - exRecepientInfoDataString = cdcJsonExtractString1 + s1 + getCharacterConverted(fieldNameSectionValue.replace("\"", "")) - + cdcJsonExtractString2.substring(cdcJsonExtractString2.indexOf("\",\"")); - } - } - return exRecepientInfoDataString; - } - - // get special character converted to character sequence - public static String getCharSequenceForSpecialCharatcer(String recipientInfoString) { - String recipientInfoStringUpdated = recipientInfoString; - try { - recipientInfoStringUpdated = recipientInfoString.replaceAll("&(?![a-z]{1,6};)", "&").replaceAll("'(?![a-z]{1,6};)", "'"); - MCUtilities.logIfDebug( LOGGER, "Special character converted for just & and ' string looks like : " + recipientInfoStringUpdated ); - } catch (Exception e) { - MCUtilities.logIfDebug( LOGGER, "exception is : " + e ); - } - return recipientInfoStringUpdated; - } - - // get special character allowed ( 1!2"34$5%6^7&8*9()10_11+12}{13{}14:15@16?17>18<#19@20]21^_~á ñ ò ú & ' "- ) converted for any string - public static String getCharacterConverted(String inputString) { - String convertedString = inputString; - try { - // MCUtilities.logIfDebug( LOGGER, "Special character received looks like : " + convertedString ); - convertedString = StringEscapeUtils.escapeXml(new String((inputString.getBytes("ISO-8859-1")), "UTF-8")); - // MCUtilities.logIfDebug( LOGGER, "Special character after conversion looks like : " + convertedString ); - } catch (Exception e) { - MCUtilities.logIfDebug( LOGGER, "exception is : " + e ); - } - return convertedString; - } - - - @Test - public void removeNS2andXMlTag() { - String request = " \n" + - "\n" + - " DocumentRESTBroadcast\n" + - " hello"; - String afterRemoval = removeInvalidCharacters(request); - System.out.println(afterRemoval); - } - - private String removeInvalidCharacters(String input) { - String x = input.replaceAll("\\<\\?xml(.+?)\\?\\>", "").trim(); - return x; - } - - - -} diff --git a/src/main/java/com/example/XMLHelper.java b/src/main/java/com/example/XMLHelper.java deleted file mode 100644 index a905fca..0000000 --- a/src/main/java/com/example/XMLHelper.java +++ /dev/null @@ -1,279 +0,0 @@ -package sunlife.us.dc.messagecenter.plugin.gcsdocgengateway.utils; - -import com.ctc.wstx.exc.WstxIOException; -import org.apache.commons.io.IOUtils; -import org.apache.log4j.Logger; -import org.w3c.dom.Document; -import org.w3c.dom.NodeList; -import org.xml.sax.InputSource; -import sunlife.us.dc.log.LogFactory; -import sunlife.us.dc.messagecenter.plugin.gcsdocgengateway.processor.JAXBContextFactory; -import sunlife.us.dc.messagecenter.ws.webservice.impl.gcs.readclaimdata.ReadClaimData; - -import javax.xml.bind.*; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.transform.stream.StreamSource; -import java.io.*; - -/** - * XMLHelper class. - */ -public final class XMLHelper { - - private static Logger LOGGER = LogFactory.getLogger(XMLHelper.class); - - /** - * Marshal input Object to String xml. - * - * @param type Class type to be marshaled. - * @param object Object to be marshaled. - * @return String xml. - */ - public static String marshalObjToXml(final Class type, final Object object) { - LOGGER.debug("XMLHelper.marshalObjToXml()"); - final StringWriter writer = new StringWriter(); - try { - final JAXBContext jaxbContext = JAXBContext.newInstance(type); - final Marshaller marshaller = jaxbContext.createMarshaller(); - marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); - marshaller.marshal(object, writer); - } - catch (JAXBException e) { - LOGGER.error(e.getMessage(), e); - } - - return writer.toString(); - } - - /** - * Unmarshal target element of input String xml to Class type object. - * - * @param type Class type to unmarshal. - * @param inputXml String input xml to unmarshal. - * @param element String target element of input xml to unmarshal. - * @return Object object. - */ - public static Object unmarshalXmlToObj(final Class type, final String inputXml, final String element) { - LOGGER.debug("XMLHelper.unmarshalXmlToObj()"); - - final InputStream is = IOUtils.toInputStream(inputXml); - final XMLInputFactory factory = XMLInputFactory.newInstance(); - - Object object = null; - try { - final XMLStreamReader reader = factory.createXMLStreamReader(is); - while (reader.hasNext()) { - final int event = reader.next(); - if (event == XMLStreamConstants.START_ELEMENT && reader.getLocalName().equals(element)) { - break; - } - } - - final JAXBContext jaxbContext = JAXBContext.newInstance(type); - final Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); - JAXBElement jaxbElement = (JAXBElement) jaxbUnmarshaller.unmarshal(reader, type); - object = jaxbElement.getValue(); - }catch (WstxIOException e){ - LOGGER.debug("Exception in XMLHelper.unmarshalXmlToObj() : "+ e.toString()); - } - catch (Exception e) { - LOGGER.error(e.getMessage(), e); - } - - return object; - } - - /** - * Get target element value of input String xml. - * - * @param inputXml String input xml. - * @param element String target element of input xml. - * @return String value. - */ - public static String getElementValue(final String inputXml, final String element) { - //LOGGER.debug("XMLHelper.getElementValue()"); - - String value = null; - final InputStream is = IOUtils.toInputStream(inputXml); - final XMLInputFactory factory = XMLInputFactory.newInstance(); - - try { - final XMLStreamReader reader = factory.createXMLStreamReader(is); - while (reader.hasNext()) { - final int event = reader.next(); - if (event == XMLStreamConstants.START_ELEMENT && reader.getLocalName().equals(element)) { - value = StringHelper.safeTrim(reader.getElementText()); - break; - } - } - } - catch (Exception e) { - LOGGER.error(e.getMessage(), e); - } - - return value; - } - - /** - * Encode String xml. - * - * @param str xml to be encoded. - * @return string value - */ - public static String encodeXmlAttribute(final String str) { - if (str == null) { - return null; - } - - final int len = str.length(); - if (len == 0) { - return str; - } - - final StringBuffer encoded = new StringBuffer(); - for (int i = 0; i < len; i++) { - char c = str.charAt(i); - if (c == '<') { - encoded.append("<"); - } - else if (c == '\"') { - encoded.append("""); - } - else if (c == '>') { - encoded.append(">"); - } - else if (c == '\'') { - encoded.append("'"); - } - else if (c == '&') { - encoded.append("&"); - } - else { - encoded.append(c); - } - } - return encoded.toString(); - } - - /** - * Removes xml tag and ns2 prefix - * @param input - * @return - */ - public static String removeInvalidCharacters(String input) { - String x = input.replaceAll("\\<\\?xml(.+?)\\?\\>", "").trim(); - return x; - } - - /** - * @param inputXML - * @param - * @param - * @return Object - * @throws Exception - */ - public static Object unMarshallerXMLtoJavaObject(final String inputXML){ - try { - JAXBContextFactory factory = JAXBContextFactory.getInstance(); - JAXBContext jaxbContext = factory.getJaxBContext(ReadClaimData.class); - Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); - XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); - InputStreamReader inputStreamReader = new InputStreamReader(new ByteArrayInputStream(inputXML.getBytes())); - XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(inputStreamReader); - JAXBElement jaxbElement = unmarshaller.unmarshal(xmlStreamReader, Object.class); - // MCUtilities.logIfDebug(LOGGER, "Inside unmarshall method " ); - return jaxbElement.getValue(); - - } catch (JAXBException e){ - e.printStackTrace(); - LOGGER.error(LOGGER, e); - } catch (XMLStreamException xmle) { - LOGGER.error(LOGGER, xmle); - } catch (Exception oe){ - LOGGER.error(LOGGER, oe); - } - return null; - } - - /** - * @param inputXML - * @param - * @param - * @return Object - * @throws Exception - */ - public static Document convertStringToXMLDocument(final String inputXML){ - - //Parser that produces DOM object trees from XML content - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - - //API to obtain DOM Document instance - DocumentBuilder builder = null; - Document doc = null; - try - { - //Create DocumentBuilder with default configuration - builder = factory.newDocumentBuilder(); - - //Parse the content to Document object - doc = builder.parse( new InputSource( new StringReader( inputXML ) ) ); - } - catch (Exception e) - { - e.printStackTrace(); - } - return doc; - } - private final static String precedingUTFCharactersReplacement = "\\[|\\]"; - public static String invalidCharacters(String input) { - return input.replaceAll(precedingUTFCharactersReplacement,""); - } - - /** - * - * @param xml - * @param cls - * @return - * @throws Exception - */ - public static Object transformWebComposerXmlToObject(final String xml, final Class cls) throws JAXBException { - JAXBContext jaxbContext = JAXBContext.newInstance(sunlife.us.dc.messagecenter.ws.webservice.impl.gcs.readdocdata.ReadDocData.class); - Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); - StringReader reader = new StringReader(xml); - final StreamSource source = new StreamSource(reader); - JAXBElement jaxbElement = unmarshaller.unmarshal(source, cls); - return jaxbElement.getValue(); - } - - public static boolean checkIfElementPresent(final String inputXml, final String elementTag) { - //LOGGER.debug("XMLHelper.getElementValue()"); - - Boolean value = false; - - try { - Document document = convertStringToXMLDocument( inputXml ); - if (document != null) { - NodeList nodeList = document.getElementsByTagName( "*" ); - for (int i = 0; i < nodeList.getLength(); i++) { - if (nodeList.item( i ).getNodeName().equalsIgnoreCase( elementTag )) { - value = Boolean.TRUE; - } - } - } - - } catch (Exception e) { - LOGGER.error( e.getMessage(), e ); - } - - return value; - } - /** - * Private constructor. - */ - private XMLHelper() { } -} diff --git a/src/main/java/com/example/dependencyInjection/Colour.java b/src/main/java/com/example/dependencyInjection/Colour.java new file mode 100644 index 0000000..5b25b65 --- /dev/null +++ b/src/main/java/com/example/dependencyInjection/Colour.java @@ -0,0 +1,12 @@ +package com.example.dependencyInjection; + +public class Colour { + + public void getAndriodColour() { + System.out.println("White"); + } + + public void getAppleColour() { + System.out.println("Black"); + } +} diff --git a/src/main/java/com/example/inversionOfControl/Andriod.java b/src/main/java/com/example/inversionOfControl/Andriod.java new file mode 100644 index 0000000..f0dbaad --- /dev/null +++ b/src/main/java/com/example/inversionOfControl/Andriod.java @@ -0,0 +1,27 @@ +package com.example.inversionOfControl; + +import com.example.dependencyInjection.Colour; +import org.springframework.stereotype.Component; + +@Component +public class Andriod implements Mobile { + Colour color; + + public Andriod() { + System.out.println("Default Andriod Constructor"); + } + + public Andriod(Colour colour) { + this.color = colour; + } + + + @Override + public String getModel() { + color.getAndriodColour(); + String ONE_PLUS = "onePlus"; + return ONE_PLUS; + } + + +} diff --git a/src/main/java/com/example/inversionOfControl/Apple.java b/src/main/java/com/example/inversionOfControl/Apple.java new file mode 100644 index 0000000..e046969 --- /dev/null +++ b/src/main/java/com/example/inversionOfControl/Apple.java @@ -0,0 +1,24 @@ +package com.example.inversionOfControl; + +import com.example.dependencyInjection.Colour; +import org.springframework.stereotype.Component; + +@Component +public class Apple implements Mobile { + Colour color; + + public Apple() { + System.out.println("Default Apple Constructor"); + } + + public Apple(Colour colour) { + this.color = colour; + } + + @Override + public String getModel() { + color.getAppleColour(); + String IPHONE_PRO_16 = "iPhone16Pro"; + return IPHONE_PRO_16; + } +} diff --git a/src/main/java/com/example/inversionOfControl/Mobile.java b/src/main/java/com/example/inversionOfControl/Mobile.java new file mode 100644 index 0000000..040225a --- /dev/null +++ b/src/main/java/com/example/inversionOfControl/Mobile.java @@ -0,0 +1,7 @@ +package com.example.inversionOfControl; + +public interface Mobile { + String getModel(); + + +} diff --git a/src/main/java/com/example/inversionOfControl/StoreConfiguration.java b/src/main/java/com/example/inversionOfControl/StoreConfiguration.java new file mode 100644 index 0000000..1de3c2b --- /dev/null +++ b/src/main/java/com/example/inversionOfControl/StoreConfiguration.java @@ -0,0 +1,26 @@ +package com.example.inversionOfControl; + +import com.example.dependencyInjection.Colour; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class StoreConfiguration { + + @Bean + public Colour getColour() { + return new Colour(); + } + + @Bean + public Mobile getAndriod(Colour getColour) { + return new Andriod(getColour); + } + + //Error : Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'getApple' available +// Fix : @Bean annotation was missing on getApple , it had only for getAndriod + @Bean + public Mobile getApple(Colour getColour) { + return new Apple(getColour); + } +} diff --git a/src/main/java/com/home/controllers/HomeController.java b/src/main/java/com/home/controllers/HomeController.java new file mode 100644 index 0000000..080d7f8 --- /dev/null +++ b/src/main/java/com/home/controllers/HomeController.java @@ -0,0 +1,14 @@ +package com.home.controllers; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class HomeController { + + @GetMapping(value = "/") + public String getHome() { + // it will be considered as a file ( jsp) not as content + return "/WEB-INF/views/home.jsp"; + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..054c6e7 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,2 @@ +--=If the port 8080 is already in use then we can configure new port to use as below +server.port=8091 \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/frontControllerDispatcher-servlet.xml b/src/main/webapp/WEB-INF/frontControllerDispatcher-servlet.xml new file mode 100644 index 0000000..9da2f25 --- /dev/null +++ b/src/main/webapp/WEB-INF/frontControllerDispatcher-servlet.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/views/display.jsp b/src/main/webapp/WEB-INF/views/display.jsp new file mode 100644 index 0000000..e69de29 diff --git a/src/main/webapp/WEB-INF/views/home.jsp b/src/main/webapp/WEB-INF/views/home.jsp new file mode 100644 index 0000000..228a105 --- /dev/null +++ b/src/main/webapp/WEB-INF/views/home.jsp @@ -0,0 +1,13 @@ + + + + HTML Login Form + + + +

Welcome to Spring MVC Application

+ + + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/views/sucess.jsp b/src/main/webapp/WEB-INF/views/sucess.jsp new file mode 100644 index 0000000..e69de29 diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..25d6d8f --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,17 @@ + + + + Archetype Created Web Application + + + frontControllerDispatcher + org.springframework.web.servlet.DispatcherServlet + + + + frontControllerDispatcher + / + + \ No newline at end of file diff --git a/src/test/java/com/example/HpdemoApplicationTests.java b/src/test/java/com/example/ApplicationStartTests.java similarity index 74% rename from src/test/java/com/example/HpdemoApplicationTests.java rename to src/test/java/com/example/ApplicationStartTests.java index b0e4ca5..ad90bbf 100644 --- a/src/test/java/com/example/HpdemoApplicationTests.java +++ b/src/test/java/com/example/ApplicationStartTests.java @@ -7,10 +7,10 @@ @RunWith(SpringRunner.class) @SpringBootTest -public class HpdemoApplicationTests { +public class ApplicationStartTests { - @Test - public void contextLoads() { - } + @Test + public void contextLoads() { + } }