One Star

[resolved] java.lang.RuntimeException: Login failed!

Hello,
I am trying to run a job in java generated by TalenD. The job its a tFileInputDelimited, tMap, tSalesForceOutput.
The job reads the CSV then maps it and uploads the results to SalesForce.
I have no problem to run this in Talend(correct login etc) but when i export the .jar in my java project i get an error.. I have been hitting a wall since 2 weeks and i can't solve the issue..
The problem is related with the context variables. I have 4 context variables(user, pass, token and path) and i can't access Sales Force as it returns "login failed" error;
also i can't pass the path to .jar for the upload..
I will paste the whole error.
java.io.FileNotFoundException: C:\Archivos de programa\Apache Software Foundation\Tomcat 7.0\webapps\factura\account_activities_201312.csv (El sistema no puede encontrar la ruta especificada)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at org.apache.commons.fileupload.disk.DiskFileItem.write(DiskFileItem.java:394)
at com.src.csvreader.escribircsv(csvreader.java:49)
at com.src.TalenD_SFServlet.doGet(TalenD_SFServlet.java:33)
at com.src.TalenD_SFServlet.doPost(TalenD_SFServlet.java:72)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception in component tSalesforceOutput_1
java.lang.RuntimeException: Login failed! Please check the username,password and endpoint
at facturasflexibles.prueba_factura_0_1.Prueba_factura.tFileInputDelimited_1Process(Prueba_factura.java:1226)
at facturasflexibles.prueba_factura_0_1.Prueba_factura.runJobInTOS(Prueba_factura.java:2498)
at facturasflexibles.prueba_factura_0_1.Prueba_factura.runJob(Prueba_factura.java:2378)
at com.src.TalenD_SFServlet.doGet(TalenD_SFServlet.java:66)
at com.src.TalenD_SFServlet.doPost(TalenD_SFServlet.java:72)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

I will put my code too:
public void doGet(HttpServletRequest req, HttpServletResponse resp){
Prueba_factura pf = new Prueba_factura();
try{
String fieldname ="";
String fieldvalue = "";
String user ="";
String path= "";
String token = "";
String pass ="";
csvreader.escribircsv(req);
List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(req);
for (FileItem item : items) {
if (item.isFormField()) {
// Process regular form field (input type="text|radio|checkbox|etc", select, etc).
fieldname= item.getFieldName();
fieldvalue = item.getString();
System.out.println("El parametro " + fieldname +" tiene el valor " + fieldvalue);
if(fieldname.equals("usuario")){
user=fieldvalue;
}else if(fieldname.equals("contrasena")){
pass=fieldvalue;
}else if(fieldname.equals("token")){
token=fieldvalue;
}else if(fieldname.equals("factura")){
path=item.getName();
}

} else {
// Process form file field (input type="file").
fieldname = item.getFieldName();
if(fieldname.equals("usuario")){
user=fieldvalue;
}else if(fieldname.equals("contrasena")){
pass=fieldvalue;
}else if(fieldname.equals("token")){
token=fieldvalue;
}else if(fieldname.equals("factura")){
path=item.getName();
}
}
}
String[] variables = {"--context_param Path='C:\\Archivos de programa\\Apache Software Foundation\\Tomcat 7.0\\webapps\\factura\\'"+path+"'","--context_param Usuario="+user,"--context_param Pass="+pass,"--context_param Token="+token};
pf.runJob(variables);
}catch(Exception e){
e.printStackTrace();
}
}

(In other class i have the csvwriter i will put it if you need).
I'm really desperate.
I am waiting for your reply,thanks in advance!!
Edit: i have a tomcat server in my server and other in my eclipse for debug
Regards, Víctor
1 ACCEPTED SOLUTION

Accepted Solutions
One Star

Re: [resolved] java.lang.RuntimeException: Login failed!

Hey nichafner! I solved this problem with this code:

Prueba_factura pf = new Prueba_factura();
//(where Prueba_factura is my talend job)
//context variables
try{
String user = "";
String path= "";
String token = "";
String pass = "";
File file= null;
File destino=new File("");
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(1024*1024);
factory.setRepository(destino);
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(1024*1024);
List /* FileItem */items = upload.parseRequest(req);
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
String name = item.getFieldName();
if (item.isFormField()) {
try{
if(name.equals("contrasena")){
pass=item.getString();
}else if(name.equals("usuario")){
user=item.getString();
}else if(name.equals("token")){
token=item.getString();
}else if(name.equals("factura")){
path=item.getName();
}
}catch(Exception e){
e.printStackTrace();
}
} else {
try{
if(name.equals("factura")){
path=item.getName();
file=new File(item.getName());
item.write(new File(destino,file.getName()));
}
}catch(ItemSkippedException e){
e.printStackTrace();
}
}
}
String aux = "";
String[] variables = {"--context_param Path="+path,"--context_param Usuario="+user,"--context_param Pass="+pass,"--context_param Token="+token};

I hope this code can help you
Best,víctor

EDIT: factura is my input type file;
4 REPLIES
One Star

Re: [resolved] java.lang.RuntimeException: Login failed!

Hi Victor,
Your question is not clear, you are using context variables so while exporting the job you have to select "export dependencies" option and also select "apply to children" option. Then only your context will be exported along with your job. if you are using many subjobs in your job better to use context group.

Thanks,
Bhanu.
One Star

Re: [resolved] java.lang.RuntimeException: Login failed!

Hello Bhanu, thanks for your fast reply.
I did the export as you were saying in your post but the problem continues.
I will try to modify the src code, but i think its should be easier.
Thanks and regards
One Star

Re: [resolved] java.lang.RuntimeException: Login failed!

Hi,
I have the same problem with several other components ,tFTP, tSCP and tSSH. It seems to me that there is a pattern here.
But the wierd thing is, the jobs that contained those components worked perfectly fine on talend 5.3.0 with the jre 6. So I think that this error is poped up by the JRE/JDK 7.
I've try to lauch talend with -vm and deleting every other JRE in >> but nothing worked out.
any idea folk?
FYI i'm on talend Open Studio for DI 5.4.1
One Star

Re: [resolved] java.lang.RuntimeException: Login failed!

Hey nichafner! I solved this problem with this code:

Prueba_factura pf = new Prueba_factura();
//(where Prueba_factura is my talend job)
//context variables
try{
String user = "";
String path= "";
String token = "";
String pass = "";
File file= null;
File destino=new File("");
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(1024*1024);
factory.setRepository(destino);
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(1024*1024);
List /* FileItem */items = upload.parseRequest(req);
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
String name = item.getFieldName();
if (item.isFormField()) {
try{
if(name.equals("contrasena")){
pass=item.getString();
}else if(name.equals("usuario")){
user=item.getString();
}else if(name.equals("token")){
token=item.getString();
}else if(name.equals("factura")){
path=item.getName();
}
}catch(Exception e){
e.printStackTrace();
}
} else {
try{
if(name.equals("factura")){
path=item.getName();
file=new File(item.getName());
item.write(new File(destino,file.getName()));
}
}catch(ItemSkippedException e){
e.printStackTrace();
}
}
}
String aux = "";
String[] variables = {"--context_param Path="+path,"--context_param Usuario="+user,"--context_param Pass="+pass,"--context_param Token="+token};

I hope this code can help you
Best,víctor

EDIT: factura is my input type file;