Mockito : mock() calls real method - java

I am new to Mockito, I am using it along with JUnit4 in Eclipse.
I am trying to mock my method as follows:
CartLine line = mock(CartLine.class);
Then I get: FileNotFoundException caused by the call of the supposedly mocked method, as shown in the stacktrace below. How is this the expected behaviour? I am using Mockito precisely to avoid using the whole environment.
Stack Trace:
java.io.FileNotFoundException: cart.properties (file not found)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at com.mycompany.cart.util.ResourceFactory.getFileInputStream(ResourceFactory.java:119)
at com.mycompany.cart.util.ResourceFactory.getProperties(ResourceFactory.java:295)
at com.mycompany.cart.CartSettings.tryLoadSettings(CartSettings.java:215)
at com.mycompany.cart.CartSettings.<init>(CartSettings.java:72)
at com.mycompany.cart.CartSettings.<clinit>(CartSettings.java:60)
at com.mycompany.cart.CartLine.<clinit>(CartLine.java:59)
at sun.reflect.GeneratedSerializationConstructorAccessor4.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.newInstance(SunReflectionFactoryInstantiator.java:40)
at org.objenesis.ObjenesisBase.newInstance(ObjenesisBase.java:59)
at org.mockito.internal.creation.jmock.ClassImposterizer.createProxy(ClassImposterizer.java:128)
at org.mockito.internal.creation.jmock.ClassImposterizer.imposterise(ClassImposterizer.java:63)
at org.mockito.internal.creation.jmock.ClassImposterizer.imposterise(ClassImposterizer.java:56)
at org.mockito.internal.creation.CglibMockMaker.createMock(CglibMockMaker.java:23)
at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:26)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:51)
at org.mockito.Mockito.mock(Mockito.java:1243)
at org.mockito.Mockito.mock(Mockito.java:1120)
at com.redacted.ml.TestConfToJasper.mockCartLine(TestConfToJasper.java:173)
at com.redacted.ml.TestConfToJasper.mockCartLines(TestConfToJasper.java:131)
at com.redacted.ml.TestConfToJasper.testBuildUCSElement(TestConfToJasper.java:75)
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 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.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
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.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
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:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
1249 [main] WARN com.redacted.cart.util.ResourceFactory - Can not find property file: cart.properties
1249 [main] FATAL com.redacted.cart.CartSettings - Can not load cart properties!
Edit: Here is the full test code:
private static final CartLine mockCartLine(LineType type) {
CartLine line = mock(CartLine.class);
when(line.getLineType()).thenReturn(type);
return line;
}
called by:
private static final CartLine[] mockCartLines() {
CartLine[] lines = new CartLine[10];
int i=0;
lines[i++] = mockCartLine(LineType.FO);
[...]
return lines;
}
called by:
#Test
public void testBuildUCSElement() {
ConfToJasper ctj = new ConfToJasper(confML);
CartController controller = mock(CartController.class);
CartDataObject dataObject = mock(CartDataObject.class);
CartLine[] lines = mockCartLines();
[...]
}
(I am not the creator of this code)

it seems to me that you have some kind of static initializer in your CartLine which tried to open file stream.
I will strong suggest you cleanup your code to make it unit-test friendly by removing such kind of static initializer logic. (It is usually more appropriate to make it instance method instead)
Or you may have a dummy `cart.properties1 in your testing resources so that your CartLine can read that.
Or you may consider using PowerMock to see if it help to avoid such problem (I doubt anyway...)

Related

SWTBot Could not find node with text: Dynamic Web Project

I am using the SWTBot recorder to test a very simple feature. I just want to create a Dynamic Web Project and then delete it. But it won't even create the project. Why is it blowing up here?
Here is the code that the recorder generated:
#RunWith(SWTBotJunit4ClassRunner.class)
public class TestSwtBot {
private static SWTWorkbenchBot bot = new SWTWorkbenchBot();
#Test
public void test() {
bot.menu("File").menu("New").menu("Other...").click();
bot.tree().getTreeItem("Web").getNode("Dynamic Web Project").select();
bot.textWithLabel("Project na&me:").setText("TestDynamicProject");
bot.button("Next >").click();
bot.button("Next >").click();
bot.checkBox("Generate web.xml deployment descriptor").click();
bot.button("Finish").click();
bot.button("No").click();
bot.checkBox("Delete project contents on disk (cannot be undone)").click();
bot.button("OK").click();
}
So it is blowing up on this line:
bot.tree().getTreeItem("Web").getNode("Dynamic Web Project").select();
And here is the stacktrace:
org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException: Could not find node with text: Dynamic Web Project
at org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem.getNodes(SWTBotTreeItem.java:338)
at org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem.getNode(SWTBotTreeItem.java:312)
at org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem.getNode(SWTBotTreeItem.java:350)
at com.homedepot.is.dt.eclipse.swtbot.TestSwtBot.test(TestSwtBot.java:26)
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:497)
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.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
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.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner.run(SWTBotJunit4ClassRunner.java:54)
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.swtbot.eclipse.core.RemotePluginTestRunner.main(RemotePluginTestRunner.java:64)
at org.eclipse.swtbot.eclipse.core.UITestApplication.runTests(UITestApplication.java:117)
at org.eclipse.e4.ui.internal.workbench.swt.E4Testable$1.run(E4Testable.java:73)
at java.lang.Thread.run(Thread.java:745)
You need to expand the "Web" tree item first.
bot.tree().getTreeItem("Web").expand();
bot.tree().getTreeItem("Web").getNode("Dynamic Web Project").select();
did you use Eclipse Spy to see if your calling the correct tree?, I mean, in this part of your code: bot.tree() you can call differents trees by their index, for example bot.tree(0) or bot.tree(1) maybe is looking for your node in another tree.
For more information about Eclipse spy, please see here: https://wiki.eclipse.org/SWTBot/FAQ#Can_I_get_more_details_on_a_particular_widget.3F

ExceptionInInitializerError on variable initialization

I imported a project into eclipse and added the dependenciues (Just oracle drivers and junit4). But when I try to run the project I get a ExceptionInInitializerError. I can't initialize certain variables for some reason.
I know the project is okay so I think it is a problem with the JDK.
I have tried goggling it but I didn't get any solution.
Any help would be greatly appreciated.
java.lang.ExceptionInInitializerError
at com.ats.dao.RetrievalDAO.<init>(RetrievalDAO.java:27)
at com.ats.dao.test.RetrievalDAOTest.testinsertmessage(RetrievalDAOTest.java:49)
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 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.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
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.junit.runners.ParentRunner.run(ParentRunner.java:309)
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:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Unknown Source)
at java.util.Properties.load0(Unknown Source)
at java.util.Properties.load(Unknown Source)
at com.ats.util.Config.<init>(Config.java:17)
at com.ats.retriever.DBPropertiesRetriever.<clinit>(DBPropertiesRetriever.java:11)
... 25 more
Your stacktrace is telling you what you need to know. These lines:
java.lang.ExceptionInInitializerError
at com.ats.dao.RetrievalDAO.<init>(RetrievalDAO.java:27)
at com.ats.dao.test.RetrievalDAOTest.testinsertmessage(RetrievalDAOTest.java:49)
...
... tell you that your code is hitting an error in the constructor of the RetrievalDAO class while being run by the RetrievalDAOTest (presumably a unit test). The exception is further caused by:
Caused by: java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Unknown Source)
at java.util.Properties.load0(Unknown Source)
at java.util.Properties.load(Unknown Source)
at com.ats.util.Config.<init>(Config.java:17)
at com.ats.retriever.DBPropertiesRetriever.<clinit>(DBPropertiesRetriever.java:11)
... which tells you that the actual error is caused in the initialiser of your Config class. Check what your Config class does at line 17, and why it might be passing a null to the Properties loader.

Assertion Error while performing easymock on junit

I am facing following exception while running my test case. Please help.
The code :
#Test
public void shouldSaveTypedOrder() throws Exception {
mockControl.replay();
sampleDto.setId(null);
Sample savedDto = sampleDao.save(sampleDto);
mockControl.verify();
assertThat(savedDto).isEqualTo(sampleDto);
}
Error:
java.lang.AssertionError:
Unexpected method call DataSource.getConnection():
at org.easymock.internal.MockInvocationHandler.invoke(MockInvocationHandler.java:44)
at org.easymock.internal.ObjectMethodsFilter.invoke(ObjectMethodsFilter.java:85)
at com.sun.proxy.$Proxy4.getConnection(Unknown Source)
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:280)
at org.springframework.jdbc.core.metadata.TableMetaDataProviderFactory.createMetaDataProvider(TableMetaDataProviderFactory.java:63)
at org.springframework.jdbc.core.metadata.TableMetaDataContext.processMetaData(TableMetaDataContext.java:205)
at org.springframework.jdbc.core.simple.AbstractJdbcInsert.compileInternal(AbstractJdbcInsert.java:280)
at org.springframework.jdbc.core.simple.AbstractJdbcInsert.compile(AbstractJdbcInsert.java:265)
at org.springframework.jdbc.core.simple.AbstractJdbcInsert.checkCompiled(AbstractJdbcInsert.java:316)
at org.springframework.jdbc.core.simple.AbstractJdbcInsert.doExecuteAndReturnKey(AbstractJdbcInsert.java:391)
at org.springframework.jdbc.core.simple.SimpleJdbcInsert.executeAndReturnKey(SimpleJdbcInsert.java:126)
at com.inetwork.common.dao.BaseDaoImpl.insert(BaseDaoImpl.java:121)
at com.inetwork.common.dao.notification.TypedOrderDao.save(TypedOrderDao.java:85)
at com.inetwork.common.dao.notification.TypedOrderDaoTest.shouldSaveTypedOrder(TypedOrderDaoTest.java:66)
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.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
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.junit.runners.ParentRunner.run(ParentRunner.java:309)
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:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Your DAO tries to get the connection to the DataSource in BaseDaoImpl's insert method on line 121.
com.inetwork.common.dao.BaseDaoImpl.insert(BaseDaoImpl.java:121)
You probably don't want to connect to a real database.
You will need to also somehow mock the Connection object and have the DataSource.getConnection() method return your mock.

Unit testing hadoop hdfs writings with MiniDFSCluster

I wrote a class that writes to hadoop HDFS.
I'm using hadoop jars of version 1.2.1.
I would like to test this class.
So based on blogs such as this one I wrote my code:
private void createSimulatedHdfs() {
conf = new Configuration();
// 100K blocksize
conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, 1024 * 100);
conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, 100);
conf.setInt(DFSConfigKeys.DFS_BYTES_PER_CHECKSUM_KEY, 1);
conf.setLong(DFSConfigKeys.DFS_HEARTBEAT_INTERVAL_KEY, DFS_REPLICATION_INTERVAL);
conf.setInt(DFSConfigKeys.DFS_NAMENODE_REPLICATION_INTERVAL_KEY, DFS_REPLICATION_INTERVAL);
try {
// simulated HDFS
cluster = new MiniDFSCluster(conf, DATANODE_COUNT, true, null);
cluster.waitActive();
simulatedHdfs = cluster.getFileSystem();
} catch (IOException e) {
Assert.fail("Could not create simulated HDFS " + e.getMessage());
}
}
But when running the new MiniDFSCluster running into an exception:
java.lang.AssertionError: Could not create simulated HDFS Cannot run program "du": CreateProcess error=2, The system cannot find the file specified
at org.junit.Assert.fail(Assert.java:88)
at com.taptica.hdfs.writer.HdfsWriterUTest.createSimulatedHdfs(HdfsWriterUTest.java:101)
at com.taptica.hdfs.writer.HdfsWriterUTest.initJunitModeTest(HdfsWriterUTest.java:42)
at com.taptica.hdfs.writer.HdfsWriterUTest.writeTest(HdfsWriterUTest.java:50)
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 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.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
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.junit.runners.ParentRunner.run(ParentRunner.java:309)
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:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
I did not install hadoop on my local env (and I don't intend doing so).
how can I get over this one?
For JUnit testing local file system can be used without Hadoop installation and third-party utils:
LocalFileSystem fs = FileSystem.getLocal(new Configuration());
Also take a look on MRunit, helpfull utility for MR testing: http://mrunit.apache.org/

overriding endpoint address in the JAX-WS WSDL throw InaccessibleWSDLException

I am facing an issue when trying to init a simple Jax-ws webservice,
the exception is thrown when I init the new service object: [e.g. new HelloService()]
I was trying to follow instructions on java.net on how to override endpoint address
I also found similar question on StackOverflow,
but still facing the same issue:
com.sun.xml.internal.ws.wsdl.parser.InaccessibleWSDLException: 2 counts of InaccessibleWSDLException.
java.io.FileNotFoundException: http://server-ps:8080/halloWorld/HalloWorldWebService.wsdl
java.io.FileNotFoundException: http://server-ps:8080/halloWorld/HalloWorldWebService.wsdl?wsdl
Here is the code I am using (from the java.net article)
String halloServiceUrl = "http://server-ps:8080/halloWorld/HalloWorldWebService?wsdl";
HelloService service = new HelloService(); // I get the exception here..
HelloPort proxy = service.getHelloPort();
((BindingProvider)proxy).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,alloServiceUrl);
proxy.sayHello("Hello World!");
full stack Trace:
com.sun.xml.internal.ws.wsdl.parser.InaccessibleWSDLException: 2 counts of InaccessibleWSDLException.
java.io.FileNotFoundException: http://server-ps:8080/halloWorld/HalloWorldWebService.wsdl
java.io.FileNotFoundException: http://server-ps:8080/halloWorld/HalloWorldWebService.wsdl?wsdl
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:161)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:133)
at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:254)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:217)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:165)
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:93)
at javax.xml.ws.Service.<init>(Service.java:56)
at halloWorld.services.HalloWorldWebService_v1.HalloWorldWebService.<init>(HalloWorldWebService.java:46)
at com.starOne.ps.cmmg.pkg.test.MiscTest.testhalloWorldServiceCall(MiscTest.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
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.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
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.junit.runners.ParentRunner.run(ParentRunner.java:309)
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:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
I was able to work it out.
Previously the command I used to generate the clients was:
wsimport -keep halloWorldWebService.wsdl -d output -s output -verbose
Once I added wsdllocation parameter to wsimport:
-wsdllocation http://localhost:8088/mockHWebServiceSOAP?WSDL
It is working as expected using the code:
String halloServiceUrl = "http://server-ps:8080/halloWorld/HalloWorldWebService";
HelloService service = new HelloService();
HelloPort proxy = service.getHelloPort();
((BindingProvider)proxy).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,alloServiceUrl);
proxy.sayHello("Hello World!");
Thank you!

Categories

Resources