I am trying to import csv file to xml file
i see apache has feature to do
from(in)
.to(out)
.split(body().tokenize("\n")).streaming()
.unmarshal().csv();
but i have a "cannot resolve method 'from(java.lang.String)' error
when I try to import then i cannot find any packages for camel
this one works:
import org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat;
what is the package to use "from" from org.apache.camel.???
this is my file:
import org.apache.camel.Exchange;
import org.apache.camel.dataformat.bindy.BindyAbstractDataFormat;
import org.apache.camel.dataformat.bindy.BindyAbstractFactory;
import org.apache.camel.dataformat.bindy.BindyFixedLengthFactory;
import org.apache.camel.dataformat.bindy.FormatFactory;
import org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat;
import org.apache.camel.dataformat.bindy.util.ConverterUtils;
import org.apache.camel.spi.DataFormat;
import org.apache.camel.util.IOHelper;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
public class Csvtoxml {
public static void convert(String in, String out) throws Exception {
DataFormat bindy = new BindyCsvDataFormat(Model.class);
from("myCsvFile.csv")
.to("myXmlFile.xml")
.split(body().tokenize("\n")).streaming()
.unmarshal().csv();
}
}
It is not imported from anywhere. In order to use it this way you have to inherit your class from org.apache.camel.builder.RouteBuilder
Related
I am stuck on an error I keep getting, I have isolated the area the error has developed but cant figure out the cause.
package guiProject;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.File;
import java.util.Scanner;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.IOException;
import java.nio.file.Paths;
import java.nio.file.Path;
import java.nio.file.Files;
import java.util.List;
import java.util.stream.Collectors;
import java.awt.EventQueue;
import javax.swing.JFrame;
import java.awt.CardLayout;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTree;
public class mainWindow {
// imports and class definition are before this point
private Path adminList =
Paths.get("src/guiProject/AdminList.txt").toAbsolutePath();
try {
List<String> admins = Files.lines(adminList).collect(Collectors.toList());
} catch (IOException e) {
}
// rest of code
The error is occurring at the end of the line that defines adminList. Any help is appreciated.
Put your code inside a method - say pullAdminList . Moreover private access of adminList works just fine, because, again your methods - member of class, can access it:
public List<String> pullAdminList()
{
List<String> admins;
try
{
admins = Files.lines(adminList).collect(Collectors.toList());
}
catch (IOException e) {
}
return admins;
}
Hi I am trying to test logging into bookmyshow.
Firstly I am reading data from excel sheet to write in username and password but while executing I am getting error that
Error: Main method not found in class Test_Pack1.Bookmyshow, please
define the main method as: public static void main(String[] args)
or a JavaFX application class must extend
javafx.application.Application.
I am providing written program code as well.please look into this and correct me if I am wrong thank you.
package Test_Pack1;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
public class Bookmyshow {
//public static void main()
{
System.setProperty("webdriver.chrome.driver",
"G:\\Selenium_Test\\lib\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://in.bookmyshow.com/hyderabad?wzrk_source=Google&wzrk_medium=CPC_Branded&wzrk_campaign=Book_My_Show_Search|RLSA&gclid=CjwKEAiAu6DBBRDDr6-e_6698E0SJACvuxnyBrs85Juwsx_cWiHXrPnS0eKFhZoQmo_nCYgopyDSIxoCGCHw_wcB");
driver.manage().window().maximize();
driver.findElement((By.className("email-input")));
// driver.findElement(By.id("FirstName"));
driver.findElement(By.xpath(".//*[#id='iUserName']")).notifyAll();
}
public static void main(String[] args) throws IOException
{
FileInputStream istream=new FileInputStream("G:\\Selenium_Test\\hari.xlsx");
XSSFWorkbook wrkbook=new XSSFWorkbook(istream);
XSSFSheet sheet1=wrkbook.getSheet("Sheet1");
XSSFRow row=null;
XSSFCell cell=null;
HashMap<String, String> dataHmap = new HashMap<String, String>();
String PropertyName,value;
int lastRowNumber=sheet1.getLastRowNum();
}
}
The way you have commented earlier section is not correct.
First of all, your code which needs to be invoked as a starting point should be included in main method.You can invoke multiple methods in turn from inside main method. I have tried to change your code bit and it should work. Let me know if you face any issue further
package com.automation.servicenow.config;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
public class Bookmyshow {
public static void main(String[] args) throws IOException {
System.setProperty("webdriver.chrome.driver",
"G:\\Selenium_Test\\lib\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://in.bookmyshow.com/hyderabad?wzrk_source=Google&wzrk_medium=CPC_Branded&wzrk_campaign=Book_My_Show_Search|RLSA&gclid=CjwKEAiAu6DBBRDDr6-e_6698E0SJACvuxnyBrs85Juwsx_cWiHXrPnS0eKFhZoQmo_nCYgopyDSIxoCGCHw_wcB");
driver.manage().window().maximize();
driver.findElement((By.className("email-input")));
// driver.findElement(By.id("FirstName"));
driver.findElement(By.xpath(".//*[#id='iUserName']")).notifyAll();
FileInputStream istream=new FileInputStream("G:\\Selenium_Test\\hari.xlsx");
XSSFWorkbook wrkbook=new XSSFWorkbook(istream);
XSSFSheet sheet1=wrkbook.getSheet("Sheet1");
XSSFRow row=null;
XSSFCell cell=null;
HashMap<String, String> dataHmap = new HashMap<String, String>();
String PropertyName,value;
int lastRowNumber=sheet1.getLastRowNum();
}
}
I am trying edit my soap header using my java code before running the request. I am not using handler or jax-rs. I saw WsdlUtils but am not able figure how to use this in my code. please someone help me in this
Here's my code;
package soap.impl;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.xmlbeans.XmlException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.eviware.soapui.SoapUI;
import com.eviware.soapui.StandaloneSoapUICore;
import com.eviware.soapui.config.impl.TestStepConfigImpl;
import com.eviware.soapui.impl.wsdl.WsdlHeaderPart;
import com.eviware.soapui.impl.wsdl.WsdlProject;
import com.eviware.soapui.impl.wsdl.WsdlTestSuite;
import com.eviware.soapui.impl.wsdl.submit.filters.SoapHeadersRequestFilter;
import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlUtils;
import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlUtils.SoapHeader;
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner;
import com.eviware.soapui.model.TestPropertyHolder;
import com.eviware.soapui.model.iface.MessageExchange;
import com.eviware.soapui.model.propertyexpansion.PropertyExpansionUtils;
import com.eviware.soapui.model.support.PropertiesMap;
import com.eviware.soapui.model.support.TestPropertyUtils;
import com.eviware.soapui.model.testsuite.TestCase;
import com.eviware.soapui.model.testsuite.TestProperty;
import com.eviware.soapui.model.testsuite.TestRunner;
import com.eviware.soapui.model.testsuite.TestStepResult;
import com.eviware.soapui.model.testsuite.TestRunner.Status;
import com.eviware.soapui.model.testsuite.TestSuite;
import com.eviware.soapui.support.SoapUIException;
import com.eviware.soapui.support.types.StringToObjectMap;
import com.eviware.soapui.support.types.StringToStringsMap;
public class RunTestImpl{
static Logger logger = LoggerFactory.getLogger(RunTestImpl.class);
public static void main(String[] args) throws XmlException, IOException, SoapUIException {
logger.info("Into the Class for running test cases");
String suiteName = "";
String reportStr = "";
InputData input=new InputData();
TestPropertyHolder holder = PropertyExpansionUtils.getGlobalProperties();
String testCaseName="";
holder.setPropertyValue("CRK", "CRK987909000000000075");
// variables for getting duration
WsdlTestCaseRunner runner = null;
List<TestSuite> suiteList = new ArrayList<TestSuite>();
List<TestCase> caseList = new ArrayList<TestCase>();
SoapUI.setSoapUICore(new StandaloneSoapUICore(true));
// specified soapUI project
WsdlProject project1 = new WsdlProject("D://my-project.xml");
WsdlTestSuite testSuite1= project1.getTestSuiteByName("my TestSuite");
WsdlTestCase testCase1= testSuite1.getTestCaseByName("myTestCase");
suiteList.add(testSuite1);
runner= testCase1.run(new StringToObjectMap(), false);
List<TestStepResult> list= runner.getResults();
StringToStringsMap headers1=null;
for (TestStepResult testStepResult : list) {
testStepResult).getRequestContent();
byte[] rawReq=((MessageExchange)testStepResult).getRawRequestData();
headers1 = ((MessageExchange)testStepResult).getRequestHeaders();
String response = ((MessageExchange)testStepResult).getResponseContent();
StringBuilder build=new StringBuilder();
for (byte b : rawReq) {
build.append((char)b);
}
System.out.println("build "+build.toString());
}
for (Map.Entry<String,List< String>> entry : headers1.entrySet()) {
System.out.println("key"+entry.getKey());
for (String string:entry.getValue()) {
System.out.println("value "+string);
}
}
// }
// string of the results
System.out.println(reportStr);
}
}
I am trying to run a map/reducer in java using eclipse. Below are my codes
Driver code:
package com.hadoop.training.criccount;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Set;
import javax.lang.model.SourceVersion;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import com.hadoop.training.hadooputility.HadoopUtility;
public class CricClickDriver extends Configured implements Tool{
public int run (String args[]) throws Exception
{
Configuration config =HadoopUtility.INSTANCE.pseudomode();
Job job = new Job(config, "No of clicks by location");
job.setJarByClass(CricClickDriver.class);
job.setInputFormatClass(TextInputFormat.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(LongWritable.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(LongWritable.class);
job.setMapperClass(CricClickMapper.class);
job.setReducerClass(CricClickReducer.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
int exitcode = job.waitForCompletion(true)? 0:1;
return exitcode;
}
}
Mapper Code:
package com.hadoop.training.criccount;
import java.io.IOException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
#SuppressWarnings("unused")
public class CricClickMapper extends Mapper<LongWritable, Text,Text, LongWritable>{
public void CricketClick(LongWritable key, Text value, Context output) throws IOException, InterruptedException
{
String Line= value.toString();
String part[]=Line.split(" ");
if(part[0].contains("BAN"))
{
output.write(new Text(part[1]),new LongWritable(Long.parseLong(part[2])));
}
}
}
Reducer Code:
package com.hadoop.training.criccount;
import java.io.IOException;
import java.util.Iterator;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
public class CricClickReducer extends Reducer<Text, LongWritable, Text, LongWritable>{
public void reduce(Text key, Iterable<LongWritable> value, Context output) throws IOException, InterruptedException
{
int sum=0;
for(LongWritable val:value){
sum +=val.get();
}
output.write(key, new LongWritable(sum));
}
}
I am getting following error:
Type mismatch in key from map
I tried to debug but not able to find the rootcause. Need a help on it.
Your Mapper class definition does not look like the one mentioned in the documentation.
public class Mapper<KEYIN,VALUEIN,KEYOUT,VALUEOUT>
or is it that it is not visible in the code you posted here ?
I am attempting to download a .db file from my organization's website within an Android application and have encountered difficulties. It says the download is unsuccessful.
Here is the code that handles the download:
package midamcorp.com.burgerkingapp;
import android.app.DownloadManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.widget.Toast;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
public class downloadReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context c, Intent i) {
File localDBFile = new File(c.getFilesDir(), "bk.db");
try {
DownloadManager manager = (DownloadManager) c.getSystemService(Context.DOWNLOAD_SERVICE);
Uri uriTest = Uri.parse("http://www.midamcorp.com/bk.db");
DownloadManager.Request request = new DownloadManager.Request(uriTest);
if (localDBFile.exists()) {
localDBFile.delete();
}
manager.enqueue(request);
// }
}
catch(Exception ex) {
Log.e("Error", ex.getMessage());
}
}
}
Furthermore, when I navigate to this file in my browser, I receive a 404 error; however, I know the path is correct. I have a feeling it has to do with the file extension (.db). How can I fix this?
Thanks!
Furthermore, when I navigate to this file in my browser, I receive a 404 error; however, I know the path is correct
It is not correct, because you are getting 404. URL is invalid or for any other reasons you are not able to reach it, and so is DownloadManager