Make every controller to log request.getRemoteAddr() and request.getRequestURI() - spring-boot

I wrote the following sample code to check logs. This code works. I'm using Spring Boot 2.7.1.
All controllers have this line of code: log.debug("IP " + request.getRemoteAddr() + " -> " + request.getRequestURI());
Since throughout the code for this project I would like all controllers to have this line of code, I am wondering if there is a way to achieve the same result in a more compact way. In other words, I would not want to repeat this line of code every time. I would prefer the log.debug with IP and URL to happen automatically for each controller. Is this possible?
package ...;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
#RestController
public class TestMe {
private final Logger log = LoggerFactory.getLogger(this.getClass());
#GetMapping("/testme")
#ResponseBody
public String testme(HttpServletRequest request) {
log.debug("IP " + request.getRemoteAddr() + " -> " + request.getRequestURI());
return "I'm working! :-)";
}
#GetMapping("/testerror")
#ResponseBody
public int testerror(HttpServletRequest request) {
log.debug("IP " + request.getRemoteAddr() + " -> " + request.getRequestURI());
return 1 / 0;
}
#GetMapping("/testexception")
#ResponseBody
public int testexception(HttpServletRequest request) {
log.debug("IP " + request.getRemoteAddr() + " -> " + request.getRequestURI());
throw new IllegalStateException("Test Exception");
}
#GetMapping("/testlogs")
#ResponseBody
public String testlogs(HttpServletRequest request) {
log.debug("IP " + request.getRemoteAddr() + " -> " + request.getRequestURI());
log.trace("test log TRACE level");
log.debug("test log DEBUG level");
log.info("test log INFO level");
log.warn("test log WARN level");
log.error("test log ERROR level");
return "Please check the logs";
}
/**
* Spring Controller to handle all requests not matched by the previous Controllers,
* #return
*/
#RequestMapping (value = "/**", method = {RequestMethod.GET, RequestMethod.POST})
public String greetings(HttpServletRequest request) {
log.debug("IP " + request.getRemoteAddr() + " -> " + request.getRequestURI());
log.warn("Unmapped request handling from IP " + request.getRemoteAddr() + " -> " + request.getRequestURI());
return "Greetings! Please check the logs";
}
}

Assuming that all my Controllers are in the xxx.layer1controllers package, the following class is a possible solution:
package ...;
import javax.servlet.http.HttpServletRequest;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
#Component
#Aspect
public class MyAspect {
private final Logger log = LoggerFactory.getLogger(this.getClass());
// info: https://www.baeldung.com/spring-aop-pointcut-tutorial & https://stackoverflow.com/a/39508845/1277576
#Before("within(xxx.layer1controllers..*))")
public void logController(JoinPoint joinPoint) throws Exception {
if (joinPoint.getArgs().length > 0 && joinPoint.getArgs()[0] instanceof HttpServletRequest) {
HttpServletRequest request = (HttpServletRequest) joinPoint.getArgs()[0];
log.debug("IP " + request.getRemoteAddr() + " -> " + request.getRequestURI());
} else {
log.warn("Let's remember to add a HttpServletRequest parameter to " + joinPoint.getSignature().toShortString());
}
}
}

Related

Spring batch file reader record with different delimiters within a record

I have below sample input file where elements can be of any size after 3rd "|" delimiter . A person can have any number of addresses separated by "," and each address element is separated by ":" delimiter. Can you please advise if there is any file reader that can handle this kind of data record? Thanks
id1|name1|male|1:new york:NY:10019, 2:philadelphia:PA:19382, 3:columbus:OH:23415|USA
id2|name2|female|1:new york:NY:10019, 2:philadelphia:PA:19382, 3:columbus:OH:23415, 4:west chester:PA:19341|USA
id3|name3|male|1:new york:NY:10019|USA
id4|name4|female|1:new york:NY:10019, 2:philadelphia:PA:19382|USA
This is a custom requirement and there is no built-in way to do that in Spring Batch. You can however leverage the FlatFileItemReader with a custom FieldSetMapper. Here is a quick example:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.item.file.FlatFileItemReader;
import org.springframework.batch.item.file.builder.FlatFileItemReaderBuilder;
import org.springframework.batch.item.file.mapping.DefaultLineMapper;
import org.springframework.batch.item.file.mapping.FieldSetMapper;
import org.springframework.batch.item.file.transform.DelimitedLineTokenizer;
import org.springframework.batch.item.file.transform.FieldSet;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.FileSystemResource;
import org.springframework.validation.BindException;
#Configuration
#EnableBatchProcessing
public class MyJob {
#Bean
public FlatFileItemReader<Person> itemReader() {
DefaultLineMapper<Person> lineMapper =new DefaultLineMapper<>();
lineMapper.setLineTokenizer(new DelimitedLineTokenizer("|"));
lineMapper.setFieldSetMapper(new PersonMapper());
return new FlatFileItemReaderBuilder<Person>()
.name("personItemReader")
.resource(new FileSystemResource("persons.csv"))
.lineMapper(lineMapper)
.build();
}
#Bean
public Job job(JobBuilderFactory jobs, StepBuilderFactory steps) {
return jobs.get("job")
.start(steps.get("step")
.chunk(2)
.reader(itemReader())
.writer(items -> items.forEach(System.out::println))
.build())
.build();
}
public static void main(String[] args) throws Exception {
ApplicationContext context = new AnnotationConfigApplicationContext(MyJob.class);
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
Job job = context.getBean(Job.class);
jobLauncher.run(job, new JobParameters());
}
static class Person {
String id, name, gender, country;
List<String> addresses = new ArrayList<>(); // TODO create and use Address class instead of String
#Override
public String toString() {
return "Person{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
", gender='" + gender + '\'' +
", country='" + country + '\'' +
", addresses=" + addresses +
'}';
}
}
static class PersonMapper implements FieldSetMapper<Person> {
#Override
public Person mapFieldSet(FieldSet fieldSet) throws BindException {
Person p = new Person();
p.id = fieldSet.readString(0);
p.name = fieldSet.readString(1);
p.gender = fieldSet.readString(2);
p.addresses.addAll(Arrays.asList(fieldSet.readString(3).split(","))); // TODO split address as needed
p.country = fieldSet.readString(4);
return p;
}
}
}
With your file as input, this prints:
Person{id='id1', name='name1', gender='male', country='USA', addresses=[1:new york:NY:10019, 2:philadelphia:PA:19382, 3:columbus:OH:23415]}
Person{id='id2', name='name2', gender='female', country='USA', addresses=[1:new york:NY:10019, 2:philadelphia:PA:19382, 3:columbus:OH:23415, 4:west chester:PA:19341]}
Person{id='id3', name='name3', gender='male', country='USA', addresses=[1:new york:NY:10019]}
Person{id='id4', name='name4', gender='female', country='USA', addresses=[1:new york:NY:10019, 2:philadelphia:PA:19382]}
As mentioned in the code comment, it is up to you now to create a domain class for addresses and parse the 4th field as needed.

#OnSkipInWrite is Not Called in SkipListener

I am reading the csv file and inserting data to database using spring batch(read,process and write).I am using "jpaRepository.save" in itemWriter class to save the data into the database. And I am trying to catch the skipped item and the skipped message in #OnSkipInWrite method but this method is not called even if data are skipped. And in batch_step_execution table :
read_count = 18, write_count = 10, write_skip_count = 0, roll_back_count =8.
Why the write_skip_count is 0? I just want to know which item was skipped and what was the exceptional message. My step :
#Bean
public Step step() throws IOException {
return stepBuilderFactory.get("step").<Entity, Entity>chunk(1).reader(multiResourceItemReader())
.processor(processor()).writer(writer()).faultTolerant().skip(Exception.class).skipLimit(100)
.listener(new stepExecutionListener()).build();
}
This is my Listener class.
public class StepExecutionListener{
private static final Logger LOG = Logger.getLogger(StepExecutionListener.class);
#OnSkipInRead
public void onSkipInRead(Throwable t) {
LOG.error("On Skip in Read Error : " + t.getMessage());
}
#OnSkipInWrite
public void onSkipInWrite(Entity item, Throwable t) {
LOG.error("Skipped in write due to : " + t.getMessage());
}
#OnSkipInProcess
public void onSkipInProcess(Entity item, Throwable t) {
LOG.error("Skipped in process due to: " + t.getMessage());
}
#OnWriteError
public void onWriteError(Exception exception, List<? extends Entity> items) {
LOG.error("Error on write on " + items + " : " + exception.getMessage());
}}
Why #OnSkipInWrite and #OnWriteError is not called? Any help would be much appreciated. Thanks in advance.
I can't see from what you shared why the skip listener is not called but here is a self-contained example using your listener:
import java.util.Arrays;
import java.util.List;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.annotation.OnSkipInProcess;
import org.springframework.batch.core.annotation.OnSkipInRead;
import org.springframework.batch.core.annotation.OnSkipInWrite;
import org.springframework.batch.core.annotation.OnWriteError;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.support.ListItemReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
#Configuration
#EnableBatchProcessing
public class MyJob {
#Autowired
private JobBuilderFactory jobs;
#Autowired
private StepBuilderFactory steps;
#Bean
public ItemReader<Integer> itemReader() {
return new ListItemReader<>(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
}
#Bean
public ItemWriter<Integer> itemWriter() {
return items -> {
for (Integer item : items) {
if (item.equals(3)) {
throw new Exception("No 3 here!");
}
System.out.println("item = " + item);
}
};
}
#Bean
public Step step() {
return steps.get("step")
.<Integer, Integer>chunk(5)
.reader(itemReader())
.writer(itemWriter())
.faultTolerant()
.skip(Exception.class)
.skipLimit(10)
.listener(new StepExecutionListener())
.build();
}
#Bean
public Job job() {
return jobs.get("job")
.start(step())
.build();
}
public class StepExecutionListener {
#OnSkipInRead
public void onSkipInRead(Throwable t) {
System.err.println("On Skip in Read Error : " + t.getMessage());
}
#OnSkipInWrite
public void onSkipInWrite(Integer item, Throwable t) {
System.err.println("Skipped in write due to : " + t.getMessage());
}
#OnSkipInProcess
public void onSkipInProcess(Integer item, Throwable t) {
System.err.println("Skipped in process due to: " + t.getMessage());
}
#OnWriteError
public void onWriteError(Exception exception, List<? extends Integer> items) {
System.err.println("Error on write on " + items + " : " + exception.getMessage());
}}
public static void main(String[] args) throws Exception {
ApplicationContext context = new AnnotationConfigApplicationContext(MyJob.class);
JobLauncher jobLauncher = context.getBean(JobLauncher.class);
Job job = context.getBean(Job.class);
JobExecution jobExecution = jobLauncher.run(job, new JobParameters());
StepExecution stepExecution = jobExecution.getStepExecutions().iterator().next();
System.out.println("WriteSkipCount = " + stepExecution.getWriteSkipCount());
}
}
This example prints:
item = 1
item = 2
Error on write on [1, 2, 3, 4, 5] : No 3 here!
item = 1
item = 2
Error on write on [3] : No 3 here!
item = 4
Skipped in write due to : No 3 here!
item = 5
item = 6
item = 7
item = 8
item = 9
item = 10
WriteSkipCount = 1
Which means the skip listener is called when an item is skipped on write and the writeSkipCount is correct.
Hope this helps.
You can implement SkipListener interface instead of using #OnWriteError annotation.
Try that in your BatchConf:
#Bean
#StepScope
public StepExecutionListener stepExecutionListener() {
return new StepExecutionListener();
}
...
.skipLimit(1)
.listener(stepExecutionListener()
.build();

how to identify data at the websocket url in java serverendpoint

ws://host:port/cms/ocpp/CBNO7
This is my first websocket program,here the url defines "cms" is projectname "ocpp" is serverendpoint and the last one is the data changes for every client endpoint user.How to get the last data in the server endpoint.My java serverendpoint code as follows,
`import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
import javax.ws.rs.PathParam;
#ServerEndpoint("/ocpp")
public class OcppWebsocketServer {
#OnOpen
public void onOpen(Session session) throws IOException {
System.out.println(session.getId() + " has opened a connection");
try {
session.getBasicRemote().sendText("Connection Established");
} catch (IOException ex) {
ex.printStackTrace();
}
}
#OnMessage
public void onMessage(String message, Session session) {
System.out.println("Message from " + session.getId() + ": " + message);
}
#OnError
public void onError(Throwable error) {
System.out.println("error = " + error);
Logger.getLogger(OcppWebsocketServer.class.getName()).log(Level.SEVERE, null, error);
}
#OnClose
public void onClose(Session session) {
System.out.println("Session " + session.getId() + " has ended");
}
}`
how to get CBNO7 at the endpoint
You need to use the PathParam: http://docs.oracle.com/javaee/7/api/javax/websocket/server/PathParam.html
You'll end up with something like
#ServerEndpoint("/cms/ocpp/{parameter}")
public class OcppWebsocketServer{
#OnMessage
public void onMessage(#PathParam("parameter") String param, String message, Session session) {
// it'll print CBN07
System.out.println(param);
}
}
Edit
Make sure you import javax.websocket.server.PathParam and not the JAX-RS one

How To Use Spring RESTTemplate To Post Data to a Web Service

I have written a jersey client code to call a webservice.And it is working fine. Now insteade of jersey i have to use the Spring rest template to call the webservice . So please help me in converting the jersey code to spring 4.0.
Here is my jersey code.
ServiceClient.java
package com.api.Client;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import com.tcs.DataShare.dao.ConfigureLogDao;
import com.tcs.ngps.sip.modeler.utils.ProductConfiguration;
public class ServiceClient {
static final Logger LOGGER = LoggerFactory
.getLogger(ServiceClient.class);
private WebResource service;
private ClientResponse response;
private String serviceName;
private String vmAddress;
private String portNumber;
private String WAR_FILE_NAME;
public ServiceClient(String localhost, String port,
String serviceName) {
this.vmAddress = localhost;
this.portNumber = port;
this.serviceName = serviceName;
System.out.println("vm address:" + vmAddress + "port:" + portNumber);
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WAR_FILE_NAME = ProductConfiguration
.getStringValueForProductProperty("DATASHARE_SERVER_WAR_FILE_NAME");
service = client.resource(UriBuilder.fromUri(
"http://" + vmAddress + ":" + portNumber + "/" + WAR_FILE_NAME)
.build());
LOGGER.debug("WAR_FILE_NAME in the client program"+WAR_FILE_NAME);
System.out.println("service is" + service);
}
public String getServiceName() {
return serviceName;
}
public void setServiceName(String serviceName) {
this.serviceName = serviceName;
}
public String getVmAddress() {
return vmAddress;
}
public void setVmAddress(String vmAddress) {
this.vmAddress = vmAddress;
}
public String getPortNumber() {
return portNumber;
}
public void setPortNumber(String portNumber) {
this.portNumber = portNumber;
}
public InputStream zipFolder(String folderToBeZipped,String transactionId) {
LOGGER.debug("ServiceClient :: zipFolder() : Calling zipFolder Service -> folderToBeZipped: "
+ folderToBeZipped);
String header = getServiceName();
response = service.path("rest").path("DataShareService")
.path("zipFolder")
.type(MediaType.APPLICATION_JSON).header("header", header)
.post(ClientResponse.class, folderToBeZipped);
LOGGER.debug("INSIDE THE ZIP METHOD FOR CHECKING ZIP METHOD");
InputStream inputStream = response.getEntityInputStream();
LOGGER.debug("DataShareServiceClient :: zipFolder() : Calling zipFolderWithSubsequestFolder Service done");
return inputStream;
}
}
You can find it out with a simple search.
According to this tutorial from spring you can do it like this:
// Set the Content-Type header
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setContentType(new MediaType("application","json"));
HttpEntity<String> requestEntity = new HttpEntity<String>(folderToBeZipped, requestHeaders);
// Create a new RestTemplate instance
RestTemplate restTemplate = new RestTemplate();
// Add the Jackson and String message converters
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
// Make the HTTP POST request, marshaling the request to JSON, and the response to a String
ResponseEntity<InputStream> responseEntity = restTemplate.exchange(your_url, HttpMethod.POST, requestEntity, InputStream.class);
String result = responseEntity.getBody();
hope this helps.

How to call a webservice in spring from the jersey client program

I have written the client program using the jersey framework but my webservice is of different project which uses spring framework. So I want to write the webservice using spring . When I wrote it something is going wrong .The webservice is not getting called.
Here is my code
ModelerServiceClient.java is written using jersey
ModelerServiceClient.java
package com.tcs.DataShare.Client;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
//import com.tcs.srl.smart.utility.PropertyReader;
import com.tcs.ngps.sip.modeler.utils.ProductConfiguration;
public class ModelerServiceClient {
static final Logger LOGGER = LoggerFactory
.getLogger(DataShareServiceClient.class);
private WebResource service;
private ClientResponse response;
private String serviceName;
private String vmAddress;
private String portNumber;
private String WAR_FILE_NAME_DATASHARE;
public ModelerServiceClient() {
try {
serviceName = "BPIngestorAppaaS";
vmAddress = ProductConfiguration
.getStringValueForProductProperty("vmAddress");
portNumber = ProductConfiguration
.getStringValueForProductProperty("portNumber");
System.out
.println("vm address:" + vmAddress + "port:" + portNumber);
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WAR_FILE_NAME_DATASHARE = ProductConfiguration
.getStringValueForProductProperty("WAR_FILE_NAME_DATASHARE");
service = client.resource(UriBuilder.fromUri(
"http://" + vmAddress + ":" + portNumber + "/"
+ WAR_FILE_NAME_DATASHARE).build());
System.out.println("war name is: "+WAR_FILE_NAME_DATASHARE);
System.out.println("URL is: "+service);
} catch (NullPointerException nullex) {
LOGGER.error("Error occured - " + nullex.getMessage());
} catch (Exception ex) {
LOGGER.error("" + ex);
}
}
public ModelerServiceClient(String localhost, String port,
String serviceName) {
this.vmAddress = localhost;
this.portNumber = port;
this.serviceName = serviceName;
System.out.println("vm address:" + vmAddress + "port:" + portNumber);
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WAR_FILE_NAME_DATASHARE = ProductConfiguration
.getStringValueForProductProperty("WAR_FILE_NAME_DATASHARE");
service = client.resource(UriBuilder.fromUri(
"http://" + vmAddress + ":" + portNumber + "/" + WAR_FILE_NAME_DATASHARE)
.build());
LOGGER.debug("WAR_FILE_NAME in the client program"+WAR_FILE_NAME_DATASHARE);
System.out.println("In the data share constructor"+WAR_FILE_NAME_DATASHARE);
System.out.println("service is" + service);
}
public HashMap createTable(String folderToBeZipped) {
LOGGER.debug("DataShareServiceClient :: zipFolder() : Calling zipFolderWithSubsequestFolder Service -> folderToBeZipped: "
+ folderToBeZipped);
HashMap map=new HashMap();
LOGGER.debug("before webservice ");
System.out.println("in the create table method in modelerServiceClient class");
response = service.path("dataModeler").path("ModelerService")
.path("createTablesFromEntity")
.type(MediaType.APPLICATION_JSON)
.post(ClientResponse.class, folderToBeZipped);
System.out.println("After calling response,in the create table method in modelerServiceClient class");
LOGGER.debug("INSIDE THE ZIP METHOD FOR CHECKING ZIP METHOD");
LOGGER.debug("after webservice ");
// InputStream inputStream = response.getEntityInputStream();
LOGGER.debug("DataShareServiceClient :: createTable() : Calling createTable() Service done");
return map;
}
}
DataShareCentralController.java is in spring
DataShareCentralController.java
package com.tcs.ngps.sip.restservices.controllers;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import java.io.IOException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import org.apache.log4j.Logger;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.quartz.JobDataMap;
import org.quartz.JobKey;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.ee.servlet.QuartzInitializerListener;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.impl.matchers.GroupMatcher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import com.tcs.ngps.sip.model.ModelerResponse;
import com.tcs.ngps.sip.modeler.Services.DataIngestionServices;
import com.tcs.ngps.sip.modeler.constants.IngesterConstants;
import com.tcs.ngps.sip.modeler.constants.ModelerConstants;
import com.tcs.ngps.sip.modeler.enumeration.TechnologyServices;
import com.tcs.ngps.sip.modeler.ingester.CreateTableUsingEntityJson;
import com.tcs.ngps.sip.modeler.tracker.StatusActivityTracker;
import com.tcs.ngps.sip.modeler.utils.Utilities;
import com.tcs.ngps.sip.restservices.viewmodels.AnalysisInputModel;
//import com.tcs.ngps.sip.Services.CIServices;
/*
import com.tcs.ngps.sip.Services.SearchServices;
import com.tcs.ngps.sip.commonUtitlities.CommonUtilities;
import com.tcs.ngps.sip.constants.RequestConstants;
import com.tcs.ngps.sip.model.RequestModel;
import com.tcs.ngps.sip.model.ResponceModel;
*/
import com.tcs.ngps.sip.restservices.viewmodels.ResponseModel;
//#Path("/ModelerService")
#RestController
#EnableWebMvc
public class DataShareCentralController {
static Logger logger = Logger.getLogger(ModelerCentralController.class);
DataShareCentralController()
{
System.out.println("In the DataShareCentralController ");
}
// #Path("/createTablesFromEntity")
//#POST
//#Produces("application/json")
#ResponseBody
#RequestMapping(value="/ModelerService/createTablesFromEntity", method= RequestMethod.GET,produces = APPLICATION_JSON_VALUE)
public void CreateTableFromEntity(#Context HttpServletRequest requestObj,String serviceData )
{
System.out.println("done dana done");
JSONParser parser = new JSONParser();
JSONObject object = new JSONObject();
try {
System.out.println("in the controller");
JSONObject serviceJSON = (JSONObject) parser.parse(serviceData);
String datashareURL = (String) serviceJSON
.get(ModelerConstants.DATASHARE_URL);
CreateTableUsingEntityJson createTableUsingEntityJson=new CreateTableUsingEntityJson();
createTableUsingEntityJson.getData();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Please help me in resolving the issue....

Resources