SparkHadoopWriter Failing with NPE at UserProvider - apache-spark

I am using Spark to write data to Hbase, I can read data just fine but write is failing with following exception. I found similar issue that got resolved by adding *site.xml and hbase JARs. But it is not working for me. I am trying to read data from a table write data to another table. i can read data just fine but getting exception while writing.
JavaPairRDD<ImmutableBytesWritable, Put> tablePuts = hBaseRDD.mapToPair(new PairFunction<Tuple2<ImmutableBytesWritable, Result>, ImmutableBytesWritable, Put>() {
#Override
public Tuple2<ImmutableBytesWritable, Put> call(Tuple2<ImmutableBytesWritable, Result> results) throws Exception {
byte[] accountId = results._2().getValue(Bytes.toBytes(COLFAMILY), Bytes.toBytes("accountId"));
String rowKey = new String(results._2().getRow();
String accountId2 = (Bytes.toString(accountId));
String prefix = getMd5Hash(rowKey);
String newrowKey = prefix + rowKey;
Put put = new Put( Bytes.toBytes(newrowKey) );
put.addColumn(Bytes.toBytes("def"), Bytes.toBytes("accountId"), accountId);
}
});
Job newAPIJobConfiguration = Job.getInstance(conf);
newAPIJobConfiguration.getConfiguration().set(TableOutputFormat.OUTPUT_TABLE, OUT_TABLE_NAME);
newAPIJobConfiguration.setOutputFormatClass(org.apache.hadoop.hbase.mapreduce.TableOutputFormat.class);
newAPIJobConfiguration.setOutputKeyClass(org.apache.hadoop.hbase.io.ImmutableBytesWritable.class);
newAPIJobConfiguration.setOutputValueClass(org.apache.hadoop.io.Writable.class);
tablePuts.saveAsNewAPIHadoopDataset(newAPIJobConfiguration.getConfiguration());
Exception in thread "main" java.lang.NullPointerException
at org.apache.hadoop.hbase.security.UserProvider.instantiate(UserProvider.java:123)
at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:214)
at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:119)
at org.apache.hadoop.hbase.mapreduce.TableOutputFormat.checkOutputSpecs(TableOutputFormat.java:177)
at org.apache.spark.internal.io.HadoopMapReduceWriteConfigUtil.assertConf(SparkHadoopWriter.scala:387)
at org.apache.spark.internal.io.SparkHadoopWriter$.write(SparkHadoopWriter.scala:71)
at org.apache.spark.rdd.PairRDDFunctions$$anonfun$saveAsNewAPIHadoopDataset$1.apply$mcV$sp(PairRDDFunctions.scala:1083)
at org.apache.spark.rdd.PairRDDFunctions$$anonfun$saveAsNewAPIHadoopDataset$1.apply(PairRDDFunctions.scala:1081)
at org.apache.spark.rdd.PairRDDFunctions$$anonfun$saveAsNewAPIHadoopDataset$1.apply(PairRDDFunctions.scala:1081)
at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:151)
at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:112)
at org.apache.spark.rdd.RDD.withScope(RDD.scala:363)
at org.apache.spark.rdd.PairRDDFunctions.saveAsNewAPIHadoopDataset(PairRDDFunctions.scala:1081)
at org.apache.spark.api.java.JavaPairRDD.saveAsNewAPIHadoopDataset(JavaPairRDD.scala:831)
at com.voicebase.etl.s3tohbase.HbaseScan2.main(HbaseScan2.java:148)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.spark.deploy.JavaMainApplication.start(SparkApplication.scala:52)
at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:879)
at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:197)
at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:227)
at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:136)
at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)

Related

Can not read excel file in javafx when it converted to JAR

I am using Apache POI for reading excel file (in xls and xlsx format).
It runs fine in IDE (I am using IntelliJ), but when I make the project to JAR, it can't read the excel file. I tried by giving full path of excel file, but not working.
File name spelling is right, file is not protected or read only format. Everything is good until I run JAR.
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: org/apache/poi/hssf/usermodel/HSSFWorkbook
at TakeInput.Take(TakeInput.java:25)
at MainGUI.main(MainGUI.java:53)
... 11 more
Caused by: java.lang.ClassNotFoundException: org.apache.poi.hssf.usermodel.HSSFWorkbook
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 13 more
Exception running application MainGUI
Here is my TakeInput Class:
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import java.io.*;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;
public class TakeInput {
public void Take() throws Exception{
System.out.println("Inside TakeInput class..");
File f = new File("courses.xls");
FileInputStream fs = new FileInputStream(f);
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);
int CSECourseCounter=0;
for(int i=0;i<=sheet.getLastRowNum();i++){
String tempCode = sheet.getRow(i).getCell(0).getStringCellValue();
StringTokenizer tok = new StringTokenizer(tempCode);
String codeTok=tok.nextToken();
if(codeTok.equals("CSE") || codeTok.equals("CSI")) {
CSECourseCounter++;
}
}
CourseInfo[] courses = new CourseInfo[CSECourseCounter];
for(int i=0;i<CSECourseCounter;i++)
courses[i]=new CourseInfo();
System.out.println(sheet.getLastRowNum());
for(int i=0,j=0;i<=sheet.getLastRowNum();i++){
String tempCode = sheet.getRow(i).getCell(0).getStringCellValue();
StringTokenizer tok = new StringTokenizer(tempCode);
String codeTok=tok.nextToken();
if(codeTok.equals("CSE") || codeTok.equals("CSI")) {
courses[j].code = sheet.getRow(i).getCell(0).getStringCellValue();
courses[j].title = sheet.getRow(i).getCell(1).getStringCellValue();
courses[j].section = sheet.getRow(i).getCell(2).getStringCellValue();
courses[j].day = sheet.getRow(i).getCell(4).getStringCellValue();
courses[j].time = sheet.getRow(i).getCell(5).getStringCellValue();
//courses[i].room = sheet.getRow(i).getCell(6).getNumericCellValue();
//System.out.println(courses[j].code);
j++;
//CSECourseCounter++;
}
}
Arrays.sort(courses, new Comparator<CourseInfo>() {
#Override
public int compare(CourseInfo o1, CourseInfo o2) {
return o1.title.compareTo(o2.title);
}
});
System.out.println("CSE courses = "+CSECourseCounter);
for(int i=0;i<CSECourseCounter;i++){
courses[i].setCampus();
courses[i].setLabCLassAndTimeSlot();
courses[i].setDay();
}
//***************************** CourseInfo to a linked list ******************
for(int i=0;i<courses.length;i++){
CourseToLinkedList temp = AddSearchCourse.searchCourse(courses[i].code);
if(temp==null) {
AddSearchCourse.addCourse(courses[i].title,courses[i].code,courses[i].islabClass);
CourseToLinkedList temp1 = AddSearchCourse.searchCourse(courses[i].code);
temp1.addSections(courses[i].code,courses[i].title,courses[i].section,courses[i].day,courses[i].time,
courses[i].timeStart,courses[i].timeEnd,courses[i].room,
courses[i].faculty,courses[i].credit,courses[i].assigned,
courses[i].campus,courses[i].dept,courses[i].islabClass,
courses[i].timeSlot,courses[i].labTimeSlot,courses[i].day1,courses[i].day2
);
}
else{
CourseToLinkedList temp1 = AddSearchCourse.searchCourse(courses[i].code);
temp1.addSections(courses[i].code,courses[i].title,courses[i].section,courses[i].day,courses[i].time,
courses[i].timeStart,courses[i].timeEnd,courses[i].room,
courses[i].faculty,courses[i].credit,courses[i].assigned,
courses[i].campus,courses[i].dept,courses[i].islabClass,
courses[i].timeSlot,courses[i].labTimeSlot,courses[i].day1,courses[i].day2
);
}
}
System.out.println("outside try catch..");
}
}
I put a copy of this excel file which is in the project folder to that folder where JAR file situated. No problem with location.
As I can see the logs, this issue may happen because of dependency jars for your code. try to add the jar(may be 'jakarta-poi-version.jar') having class 'HSSFWorkbook' into your class path and then try to run it again.

Mockito on android throwing lang exception

I am learning the MVP architecture that google uses in their android codelabs. I have set up a simple example. Two input fields and a "+" button to show the addition result. The view is the main activity and I have a presenter that calls a service to add the two input values. The view passes itself to the presenter in the onCreate method and keeps a reference of the presenter as well.
View Interface:
public interface MainView {
String getFirstInput();
void showFirstInputError(int resId);
String getSecondInput();
void showSecondInputError(int resId);
void setResultText(int result);
}
Presenter method that is called when the button is pressed:
public void onResultClicked(){
String firstInput = view.getFirstInput();
String secondInput = view.getSecondInput();
if(firstInput.isEmpty()) {
view.showFirstInputError(R.string.num_input_error);
return;
}
if(secondInput.isEmpty()) {
view.showSecondInputError(R.string.num_input_error);
return;
}
Service service = new Service();
int result = service.add(Integer.getInteger(firstInput),
Integer.getInteger(secondInput));
view.setResultText(result);
}
Test:
#Test
public void shouldPopulateResultWhenButtonIsClicked() throws Exception {
when(view.getFirstInput()).thenReturn("3");
when(view.getSecondInput()).thenReturn("3");
when(service.add(3,3)).thenReturn(6);
presenter.onResultClicked();
verify(service).add(3,3);
verify(view).setResultText(6);
}
I get an error on the line the service is trying to add the two inputs.
presenter.onResultClicked();
int result = service.add(Integer.getInteger(firstInput),
Integer.getInteger(secondInput));
Can somebody please help. Thanks.
java.lang.NullPointerException
at com.example.ulidder.tdd_mvp_simple.MainPresenter.onResultClicked(MainPresenter.java:29)
at com.example.ulidder.tdd_mvp_simple.MainPresenterTest.shouldPopulateResultWhenButtonIsClicked(MainPresenterTest.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
It doesn't have anything to do with Android, Mockito or MVP, you're running a jUnit test, it's pure Java.
It's just a NullPointerException, nothing else. Go to line 29 of MainPresenter.java, add a breakpoint and launch the test in debug mode to see which method call is made on a null reference. Extract variables from chained calls if necessary.
I suspect that service.add(...) returns an java.lang.Integer and you're assigning it to an int. If it returns null, the unboxing will get you a NullPointerException at this line. Try assigning the return value to an Integer and debug the value. It may be null.
See this post for more information about unboxing of null values.
Hope this helps.

real method invoke mock method but not work

i spy a object to test a method
List<HighWay> mockedList = mock(List.class);
request = Mockito.spy(new HighWayRequest());
Mockito.doReturn(mockedList).when(request).getHighWays();
request.updateNewHighWay(repository);
the updateNewHighWay method invoke getHighWays method which i want to return list,
and real method of request is like that
public void updateNewHighWay(HighWayRepository repository) {
List<HighWay> total = getHighWays();
List<HighWay> willSave = new ArrayList<HighWay>();
for (HighWay highWay : total) {
if (!repository.exists(highWay.getId())) {
willSave.add(highWay);
repository.save(highWay);
}
}
while (total.size() == willSave.size()) {
total = getHighWays();
willSave = new ArrayList<HighWay>();
for (HighWay highWay : total) {
if (!repository.exists(highWay.getId())) {
willSave.add(highWay);
repository.save(highWay);
}
}
}
}
public List<HighWay> getHighWays() {
// TODO Auto-generated method stub
return null;
}
but the reality it throws nullexception.
java.lang.NullPointerException at
chinahighway.HighWayRequest.updateNewHighWay(HighWayRequest.java:206)
at chinahighway.HttpTest.testpageinsert(HttpTest.java:269) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606) at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at
org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:73)
at
org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:82)
at
org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:73)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:217)
at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:83)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at
org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at
org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at
org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at
org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:68)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:163)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
why the doReturn not work? how to let getHighWays method return my wanted list?
plz help me thanks very much!

Gridgain serialization exception

I am trying out gridgain for the first time and facing some issues with serialization. While trying to use GridClosure to project jobs on different nodes I get marshaling exception . On debugging, It seems the failure is always for Apache log4j Logger object. Its difficult for me to avoid loggers and wanted to understand if this is a known issue or someway I can remedy this. I have requireSerializable set to false for my grid config.
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.gridgain.grid.marshaller.optimized.GridOptimizedObjectOutputStream.writeSerializable(GridOptimizedObjectOutputStream.java:292)
... 45 more
Caused by: java.io.IOException: java.lang.reflect.InvocationTargetException
at org.gridgain.grid.marshaller.optimized.GridOptimizedObjectOutputStream.writeSerializable(GridOptimizedObjectOutputStream.java:295)
at org.gridgain.grid.marshaller.optimized.GridOptimizedClassDescriptor.write(GridOptimizedClassDescriptor.java:849)
at org.gridgain.grid.marshaller.optimized.GridOptimizedObjectOutputStream.writeObject0(GridOptimizedObjectOutputStream.java:198)
at org.gridgain.grid.marshaller.optimized.GridOptimizedObjectOutputStream.writeObjectOverride(GridOptimizedObjectOutputStream.java:129)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:342)
at java.util.Hashtable.writeObject(Hashtable.java:988)
... 50 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.gridgain.grid.marshaller.optimized.GridOptimizedObjectOutputStream.writeSerializable(GridOptimizedObjectOutputStream.java:292)
... 55 more
Caused by: java.lang.NullPointerException
at org.gridgain.grid.marshaller.optimized.GridOptimizedObjectOutputStream$PutFieldImpl.value(GridOptimizedObjectOutputStream.java:1003)
at org.gridgain.grid.marshaller.optimized.GridOptimizedObjectOutputStream$PutFieldImpl.put(GridOptimizedObjectOutputStream.java:965)
at java.util.Vector.writeObject(Vector.java:1068)
... 60 more
Can you make Log4J object static so it does not affect serialization? If not, GridGain allows you to inject logger resource into pretty much anything, including closures. You can configure GridLogger as GridLog4jLogger in GridConfiguration.
Here is an example:
GridRunnable run = new GridRunnable() {
// Can be any logger, including GridLog4jLogger.
#GridLoggerResource
GridLogger log;
#Override public void run() {
log.info("Hello");
// Do some logic.
}
}
or
// Can be any logger, including GridLog4jLogger
final GridLogger log = grid.log();
GridRunnable run = new GridRunnable() {
#Override public void run() {
log.info("Hello");
// Do some logic.
}
}
For more information, refer to Resource Injection page in GridGain documentation.

SMB connection with java

Hi i have created a test program to connect with SMB protocol. My motive is to create a test.txt file on a shared location like String path="smb://192.168.143.134/rtf2xml/"+sharedFolder+"/test.txt";
But when I try to run my program (below is the code sample)
import java.io.IOException;
import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbFile;
import jcifs.smb.SmbFileOutputStream;
public class Test {
/**
* #param args
* #throws IOException
*/
public static void main(String[] args) throws IOException {
String user = "abc";
String pass ="123456";
String sharedFolder="INPUT";
String path="smb://192.168.143.134/rtf2xml/"+sharedFolder+"/test.txt";
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("192.168.143.134",user, pass);
SmbFile smbFile = new SmbFile(path, auth);
smbFile.createNewFile();
SmbFileOutputStream smbfos = new SmbFileOutputStream(smbFile);
smbfos.write("testing....and writing to a file".getBytes());
System.out.println("completed ...nice !");
}
}
It is throwing exception
Exception in thread "main" jcifs.smb.SmbException: Failed to negotiate
jcifs.smb.SmbException: Timeout trying to open socket
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at jcifs.netbios.NbtSocket.<init>(NbtSocket.java:59)
at jcifs.smb.SmbTransport.run(SmbTransport.java:342)
at java.lang.Thread.run(Unknown Source)
at jcifs.smb.SmbTransport.start(SmbTransport.java:315)
at jcifs.smb.SmbTransport.negotiate0(SmbTransport.java:865)
at jcifs.smb.SmbTransport.negotiate(SmbTransport.java:941)
at jcifs.smb.SmbTree.treeConnect(SmbTree.java:119)
at jcifs.smb.SmbFile.connect(SmbFile.java:827)
at jcifs.smb.SmbFile.connect0(SmbFile.java:797)
at jcifs.smb.SmbFile.open0(SmbFile.java:852)
at jcifs.smb.SmbFile.createNewFile(SmbFile.java:2265)
at Test.main(Test.java:22)
at jcifs.smb.SmbTransport.negotiate(SmbTransport.java:947)
at jcifs.smb.SmbTree.treeConnect(SmbTree.java:119)
at jcifs.smb.SmbFile.connect(SmbFile.java:827)
at jcifs.smb.SmbFile.connect0(SmbFile.java:797)
at jcifs.smb.SmbFile.open0(SmbFile.java:852)
at jcifs.smb.SmbFile.createNewFile(SmbFile.java:2265)
at Test.main(Test.java:22)
How to get rid of this?
But l think you have to make sure that the destination server(192.168.143.134) is up and alive.
you can write it the following way, since the IP in included in the smb link.
public static void main(String[] args) throws IOException {
String user = "abc";
String pass ="123456";
String sharedFolder="INPUT";
String path="smb://192.168.143.134/rtf2xml/"+sharedFolder+"/test.txt";
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("",user, pass);//note here
SmbFile smbFile = new SmbFile(path, auth);
smbFile.createNewFile();
SmbFileOutputStream smbfos = new SmbFileOutputStream(smbFile);
smbfos.write("testing....and writing to a file".getBytes());
System.out.println("completed ...nice !");
}
....

Resources