Getting IllegalStateException while calling restTemplate.exchange() - java

Getting the java.lang.IllegalStateException while trying to read the data from json file using RestTemplate.exchange(). Tried many ways, but no success. Any suggestion would be appreciate.
Code:
ResponseEntity<GetCustomerResponse> customerResponse = restTemplate.exchange("J:\Backup\FILWORKSPACE\tapp100997_accountopeningservice\target\classes\testdata\CustomerEnquiryApiResponse.json",HttpMethod.POST, request, GetCustomerResponse.class);
Exception :
java.lang.IllegalStateException: Could not create URI object: Illegal character in opaque part at index 2: J:\Backup\FILWORKSPACE\tapp100997_accountopeningservice\target\classes\testdata\CustomerEnquiryApiResponse.json
at org.springframework.web.util.DefaultUriTemplateHandler.createUri(DefaultUriTemplateHandler.java:168)
at org.springframework.web.util.DefaultUriTemplateHandler.expandInternal(DefaultUriTemplateHandler.java:105)
at org.springframework.web.util.AbstractUriTemplateHandler.expand(AbstractUriTemplateHandler.java:106)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:612)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:531)
at com.fidintl.bs.accountopening.rulengine.rules.CustomerRule.getCustomerDetails(CustomerRule.java:169)
at com.fidintl.bs.accountopening.rulengine.rules.CustomerRule.execute(CustomerRule.java:55)
at com.fidintl.bs.accountopening.rulengine.rules.CustomerRuleTest.testCustomerEligibilityWithBlankData(CustomerRuleTest.java:122)
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: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.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
Caused by: java.net.URISyntaxException: Illegal character in opaque part at index 2: J:\Backup\FILWORKSPACE\tapp100997_accountopeningservice\target\classes\testdata\CustomerEnquiryApiResponse.json
at java.net.URI$Parser.fail(URI.java:2848)
at java.net.URI$Parser.checkChars(URI.java:3021)
at java.net.URI$Parser.parse(URI.java:3058)
at java.net.URI.<init>(URI.java:588)
at org.springframework.web.util.DefaultUriTemplateHandler.createUri(DefaultUriTemplateHandler.java:165)
... 33 more
Json file Data :
{"success":true,"errors":[],"customerDetails":[{"customerReference":{"type":"PARTY_REFERENCE_NUMBER","identifier":"500008713684"},"success":true,"errors":[],"customers":[{"customerType":"INDIVIDUAL_INVESTOR","individualClientDetails":{"personalDetails":{"personName":{"title":"Miss","initials":null,"firstName":"User","lastName":"Payroll","fullName":"Miss User Payroll","printName":"Miss User Payroll"},"dateOfBirth":"1970-12-01","dateOfDeath":null,"gender":"UNKNOWN","maritalStatus":"UNKNOWN","townOfBirth":null,"countryOfBirth":"GB","nationalityDetails":[{"countryCode":"GB","primaryNationalityFlag":null,"reportingNationalityFlag":"Y","reportingDetails":{"nationalIdType":"TAX_IDENTIFIER","nationalId":"AB109999D"}},{"countryCode":"GB","primaryNationalityFlag":"Y","reportingNationalityFlag":null,"reportingDetails":null}],"countriesOfResidence":[{"countryCode":"GB","countryName":"UNITED KINGDOM","primaryCountryOfResidence":"Y"}],"age":"48","niNoIssuedFlag":"Y","anticipatedRetirementAge":null},"crownEmployeeFlag":"N","planParticipantDetails":null,"employerDetails":null,"occupation":null},"institutionalClientDetails":null,"partyReferenceNumber":"500008713684","alternativeReferences":[{"identifierType":"SONATA_CLIENT_ID","identifier":"100668431"},{"identifierType":"INVESTOR_REFERENCE_NUMBER","identifier":"1004664408"}],"lifeCycleStatus":"INVESTOR","inceptionDate":"2019-03-19","dormancyDate":null,"directAdvisedIndicator":"DIRECT_AND_ADVISED","lostContactFlag":"N","probateFlag":"N","courtOfProtectionFlag":"N","languagePreference":"ENG","postalAddresses":[{"contactRole":"CORRESPONDENCE_ADDRESS","nonStructuredAddressDetails":{"line1":"30 Benedict Drive","line2":null,"line3":"FELTHAM","line4":null},"structuredAddressDetails":null,"overrideAddress":"N","administrativeArea":null,"postalTown":"FELTHAM","postalCode":"TW14 8JL","region":"UK","countryCode":"GB","setBy":"500008713684","status":"ACTIVE","validity":{"lastValidatedDate":null,"validFrom":"2019-03-19 18:05:07.000+0000","validTo":null},"countryName":"UNITED KINGDOM"},{"contactRole":"REGISTERED_ADDRESS","nonStructuredAddressDetails":{"line1":"30 Benedict Drive","line2":null,"line3":"FELTHAM","line4":null},"structuredAddressDetails":null,"overrideAddress":"N","administrativeArea":null,"postalTown":"FELTHAM","postalCode":"TW14 8JL","region":"UK","countryCode":"GB","setBy":"500008713684","status":"ACTIVE","validity":{"lastValidatedDate":null,"validFrom":"2019-03-19 18:05:07.000+0000","validTo":null},"countryName":"UNITED KINGDOM"}],"classifications":[{"classificationScheme":"FATCA_US","classificationCode":"INUS05","classificationDescription":"Non US Status"},{"classificationScheme":"OFFICE_CODE","classificationCode":"OAKH","classificationDescription":"FIL Investments International"},{"classificationScheme":"MIFID","classificationCode":"RE","classificationDescription":"Retail"},{"classificationScheme":"GFAS_CUSTOMER_TYPE","classificationCode":"P","classificationDescription":"Private Individual"}],"externalIdentifiers":[{"identifierName":"TAX_IDENTIFICATION_NUMBER","value":"AB109999D","country":"GB","tinNotIssued":"NOT_CONFIRMED"},{"identifierName":"NATIONAL_INSURANCE_NUMBER","value":"AB109999D","country":"GB","tinNotIssued":null}],"salutations":null,"documentDeliveryPreferenceDetails":{"documentDeliveryPreferences":[{"documentType":"COT","deliveryMethod":"POST_AND_ONLINE"},{"documentType":"SAV","deliveryMethod":"POST_AND_ONLINE"},{"documentType":"PLC","deliveryMethod":"POST_AND_ONLINE"},{"documentType":"RRL","deliveryMethod":"POST_AND_ONLINE"},{"documentType":"WPL","deliveryMethod":"POST_AND_ONLINE"},{"documentType":"DTL","deliveryMethod":"POST_AND_ONLINE"},{"documentType":"ITR","deliveryMethod":"POST_AND_ONLINE"},{"documentType":"WL","deliveryMethod":"POST_AND_ONLINE"},{"documentType":"MLC","deliveryMethod":"POST_AND_ONLINE"}],"emailNotificationFlag":"N"},"electronicAddresses":null,"telephones":null,"partyAssociations":null,"amlStatusDetails":null,"bankAccountDetails":null,"w8BenDetails":null,"reportingCurrency":null,"associatedFILEmployee":null,"employmentStatus":null,"marketingSource":null,"partyGenericVariables":{"genericVariables":[{"name":"PLATFORM","values":["SONATA"]},{"name":"PDP_CONSENT","values":["YES"]}]},"restrictions":null,"roleToFIL":null,"marketingPreferences":[],"applicationTerms":[{"applicationTermsAndCondition":{"applicationName":"ISA Declaration","applicationVersion":"1.0","applicationTermsAndConditionsVersion":"2.0","dateAccepted":"2015-03-12 00:00:00.000+0000","applicationType":"DOCUMENT"}},{"applicationTermsAndCondition":{"applicationName":"Doing Business with Fidelity","applicationVersion":"1.0","applicationTermsAndConditionsVersion":"2.0","dateAccepted":"2015-03-12 00:00:00.000+0000","applicationType":"DOCUMENT"}},{"applicationTermsAndCondition":{"applicationName":"Payroll ISA","applicationVersion":"1.0","applicationTermsAndConditionsVersion":"2.0","dateAccepted":"2015-03-12 00:00:00.000+0000","applicationType":"DOCUMENT"}},{"applicationTermsAndCondition":{"applicationName":"Fidelity's Privacy Policy","applicationVersion":"1.0","applicationTermsAndConditionsVersion":"2.0","dateAccepted":"2015-03-12 00:00:00.000+0000","applicationType":"DOCUMENT"}},{"applicationTermsAndCondition":{"applicationName":"US Person","applicationVersion":"1.0","applicationTermsAndConditionsVersion":"2.0","dateAccepted":"2015-03-12 00:00:00.000+0000","applicationType":"DOCUMENT"}},{"applicationTermsAndCondition":{"applicationName":"Client Terms","applicationVersion":"1.0","applicationTermsAndConditionsVersion":"2.0","dateAccepted":"2015-03-12 00:00:00.000+0000","applicationType":"DOCUMENT"}},{"applicationTermsAndCondition":{"applicationName":"Online Terms","applicationVersion":"1.0","applicationTermsAndConditionsVersion":"2.0","dateAccepted":"2015-03-12 00:00:00.000+0000","applicationType":"DOCUMENT"}}],"createdBy":null,"assignedTo":null,"updatedBy":null,"auditDetails":null,"standingPreferences":null,"literaturePreferences":null,"documentDeliveryPreferences":null,"pensionDetails":null,"migration":null,"pensionPlatform":null,"clientRegionDetails":null}]}]}

From docs https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/client/RestTemplate.html#exchange-java.lang.String-org.springframework.http.HttpMethod-org.springframework.http.HttpEntity-java.lang.Class-java.lang.Object...-,
Execute the HTTP method to the given URI template, writing the given request entity to the request, and returns the response as ResponseEntity.
You need to use valid hhtp url.

Related

Unit testing of BCryptPasswordEncoder hashed password

In spring 5, I am using BCryptPasswordEncoder for password hashing. My code looks like below
#Autowired
private BCryptPasswordEncoder passwordEncoder;
and I am checking my code for password equals like
String hashedPassword = userRepository.findById(101L).orElse(null).getPassword();
assertEquals(passwordEncoder.encode("myPassword"), hashedPassword);
The testcase is getting failed. Does anyone have idea how to check 'assertEquals' for 'BCryptPasswordEncoder'?
Stackstrace:
org.junit.ComparisonFailure: expected:<$2[a$10$EulgXiN/bEwjJZc2IqRgoOyTcJWNZp0STtgY0fZv9XSIWigMHiBN2]> but was:<$2[y$12$Q3BUtijkUb.HdXsYbS9rCuaCcQE0/VdU2YC.N18uZB7jZ4/r0DSzO]>
at org.junit.Assert.assertEquals(Assert.java:115)
at org.junit.Assert.assertEquals(Assert.java:144)
at com.home.practice.MessageControllerTest.hello(MessageControllerTest.java:172)
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.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.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:73)
at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:83)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
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.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
BCryptPasswordEncoder#encode isn't deterministic. A hash will include a random salt, so your hashedPassword and the subsequent passwordEncoder.encode won't match*.
Firstly, you probably shouldn't test the class itself. spring-security has BCryptPasswordEncoderTests.java. To allow testing your use of it, use NoOpPasswordEncoder, or a similar mock.
If you really want to test BCryptPasswordEncoder, you could change your code to use a provided SecureRandom, and then mock that, so you can control the output of encode in your tests.
* BCRYPT_SALT_LEN is 16 bytes, so there's a non-zero possibility that two calls use the same salt.
The user you are getting from your repository has a different password. See the org.junit.ComparisonFailure message.
passwordEncoder.encode("myPassword") returns $2[a$10$EulgXiN/bEwjJZc2IqRgoOyTcJWNZp0STtgY0fZv9XSIWigMHiBN2]
while your user has $2[y$12$Q3BUtijkUb.HdXsYbS9rCuaCcQE0/VdU2YC.N18uZB7jZ4/r0DSzO]

Java XSLT transform csv to XML

Despite lots of thread on this topic, it still doesn't help here....
Is there a working example to illustrate the csv to xml transformation using xslt?
I'm using XSLT 2.0 to convert CSV to XML format
THe source csv file and xslt are all taken from the thread above:
#Test
public void testXSLT() throws IOException, TransformerException
{
Source inputText = new StreamSource(this.getClass().getClassLoader().getResourceAsStream(inputFile));
Source xslt = new StreamSource(this.getClass().getClassLoader().getResourceAsStream(xsltTemplate));
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer(xslt);
transformer.transform(inputText, new StreamResult(new File(outputFile)));
}
But still it says:
ERROR: 'Could not compile stylesheet'
FATAL ERROR: 'Error checking type of the expression 'funcall(unparsed-text-available, [parameter-ref(csv-uri/reference), parameter-ref(csv-encoding/reference)])'.'
:Error checking type of the expression 'funcall(unparsed-text-available, [parameter-ref(csv-uri/reference), parameter-ref(csv-encoding/reference)])'.
javax.xml.transform.TransformerConfigurationException: Error checking type of the expression 'funcall(unparsed-text-available, [parameter-ref(csv-uri/reference), parameter-ref(csv-encoding/reference)])'.
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:1018)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:791)
at com.ihsmarkit.product.dtccpvin.csv2xmlFXOutrightTest.testXSLT(csv2xmlFXOutrightTest.java:48)
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.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.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:73)
at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:83)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
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.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: Error checking type of the expression 'funcall(unparsed-text-available, [parameter-ref(csv-uri/reference), parameter-ref(csv-encoding/reference)])'.
at com.sun.org.apache.xalan.internal.xsltc.compiler.FunctionCall.typeCheckStandard(FunctionCall.java:461)
at com.sun.org.apache.xalan.internal.xsltc.compiler.FunctionCall.typeCheck(FunctionCall.java:370)
at com.sun.org.apache.xalan.internal.xsltc.compiler.When.typeCheck(When.java:88)
at com.sun.org.apache.xalan.internal.xsltc.compiler.SyntaxTreeNode.typeCheckContents(SyntaxTreeNode.java:484)
at com.sun.org.apache.xalan.internal.xsltc.compiler.Instruction.typeCheck(Instruction.java:41)
at com.sun.org.apache.xalan.internal.xsltc.compiler.SyntaxTreeNode.typeCheckContents(SyntaxTreeNode.java:484)
at com.sun.org.apache.xalan.internal.xsltc.compiler.LiteralElement.typeCheck(LiteralElement.java:198)
at com.sun.org.apache.xalan.internal.xsltc.compiler.SyntaxTreeNode.typeCheckContents(SyntaxTreeNode.java:484)
at com.sun.org.apache.xalan.internal.xsltc.compiler.Template.typeCheck(Template.java:291)
at com.sun.org.apache.xalan.internal.xsltc.compiler.SyntaxTreeNode.typeCheckContents(SyntaxTreeNode.java:484)
at com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet.typeCheck(Stylesheet.java:654)
at com.sun.org.apache.xalan.internal.xsltc.compiler.Parser.createAST(Parser.java:412)
at com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:483)
at com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:568)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:977)
... 32 more
---------
Error checking type of the expression 'funcall(unparsed-text-available, [parameter-ref(csv-uri/reference), parameter-ref(csv-encoding/reference)])'.
at com.sun.org.apache.xalan.internal.xsltc.compiler.FunctionCall.typeCheckStandard(FunctionCall.java:461)
at com.sun.org.apache.xalan.internal.xsltc.compiler.FunctionCall.typeCheck(FunctionCall.java:370)
at com.sun.org.apache.xalan.internal.xsltc.compiler.When.typeCheck(When.java:88)
at com.sun.org.apache.xalan.internal.xsltc.compiler.SyntaxTreeNode.typeCheckContents(SyntaxTreeNode.java:484)
at com.sun.org.apache.xalan.internal.xsltc.compiler.Instruction.typeCheck(Instruction.java:41)
at com.sun.org.apache.xalan.internal.xsltc.compiler.SyntaxTreeNode.typeCheckContents(SyntaxTreeNode.java:484)
at com.sun.org.apache.xalan.internal.xsltc.compiler.LiteralElement.typeCheck(LiteralElement.java:198)
at com.sun.org.apache.xalan.internal.xsltc.compiler.SyntaxTreeNode.typeCheckContents(SyntaxTreeNode.java:484)
at com.sun.org.apache.xalan.internal.xsltc.compiler.Template.typeCheck(Template.java:291)
at com.sun.org.apache.xalan.internal.xsltc.compiler.SyntaxTreeNode.typeCheckContents(SyntaxTreeNode.java:484)
at com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet.typeCheck(Stylesheet.java:654)
at com.sun.org.apache.xalan.internal.xsltc.compiler.Parser.createAST(Parser.java:412)
at com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:483)
at com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:568)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:977)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:791)
at com.ihsmarkit.product.dtccpvin.csv2xmlFXOutrightTest.testXSLT(csv2xmlFXOutrightTest.java:48)
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.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.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:73)
at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:83)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
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.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
XSLT 2 is not supported by the Xalan XSLT processor you are trying to use, you will need to switch the Saxon 9 (available in the open source HE edition on Sourceforge and Maven). Furthermore the API you use it meant for XSLT 1 with an XML input source, if you want to use that API you would need to pass in a dummy XML input. In the linked example, the CSV file location is supposed to be passed in as the parameter csv-uri. As an alternative, you can use Saxon 9's native s9api (http://saxonica.com/html/documentation/using-xsl/embedding/s9api-transformation.html) and simply start the transformation with the named template, in that case you don't need a dummy XML input.

RxJava 2 doesn't tell the error line

It seems to me that RxJava doesn't give good exception tracing.
One example is this which I got from Eclipse when running my unit test. It is not clear which code using the map function.
Is there any special trick to increase the tracing ability? Or is this considered as a bug?
2017-02-28 19:12:44/SGT INFO c.bt.nmdb.ndac.adapter.Bnmpv5Adapter : Current time stamp - Tue Dec 23 23:56:00 SGT 2014
2017-02-28 19:12:45/SGT TRACE c.bt.nmdb.ndac.adapter.Bnmpv5Adapter : #findAndSendDeviceCredentials()
io.reactivex.exceptions.OnErrorNotImplementedException: The mapper function returned a null value.
at io.reactivex.internal.functions.Functions$14.accept(Functions.java:229)
at io.reactivex.internal.functions.Functions$14.accept(Functions.java:226)
at io.reactivex.internal.subscribers.LambdaSubscriber.onError(LambdaSubscriber.java:75)
at io.reactivex.internal.operators.flowable.FlowableDoOnEach$DoOnEachSubscriber.onError(FlowableDoOnEach.java:109)
at io.reactivex.internal.subscribers.BasicFuseableSubscriber.onError(BasicFuseableSubscriber.java:100)
at io.reactivex.internal.subscribers.BasicFuseableSubscriber.fail(BasicFuseableSubscriber.java:110)
at io.reactivex.internal.operators.flowable.FlowableMap$MapSubscriber.onNext(FlowableMap.java:65)
at io.reactivex.internal.operators.flowable.FlowableFromArray$ArraySubscription.fastPath(FlowableFromArray.java:134)
at io.reactivex.internal.operators.flowable.FlowableFromArray$BaseArraySubscription.request(FlowableFromArray.java:87)
at io.reactivex.internal.subscribers.BasicFuseableSubscriber.request(BasicFuseableSubscriber.java:152)
at io.reactivex.internal.subscribers.BasicFuseableSubscriber.request(BasicFuseableSubscriber.java:152)
at io.reactivex.internal.subscribers.LambdaSubscriber.request(LambdaSubscriber.java:110)
at io.reactivex.internal.operators.flowable.FlowableInternalHelper$RequestMax.accept(FlowableInternalHelper.java:244)
at io.reactivex.internal.operators.flowable.FlowableInternalHelper$RequestMax.accept(FlowableInternalHelper.java:240)
at io.reactivex.internal.subscribers.LambdaSubscriber.onSubscribe(LambdaSubscriber.java:48)
at io.reactivex.internal.subscribers.BasicFuseableSubscriber.onSubscribe(BasicFuseableSubscriber.java:66)
at io.reactivex.internal.subscribers.BasicFuseableSubscriber.onSubscribe(BasicFuseableSubscriber.java:66)
at io.reactivex.internal.operators.flowable.FlowableFromArray.subscribeActual(FlowableFromArray.java:37)
at io.reactivex.Flowable.subscribe(Flowable.java:12901)
at io.reactivex.internal.operators.flowable.FlowableMap.subscribeActual(FlowableMap.java:37)
at io.reactivex.Flowable.subscribe(Flowable.java:12901)
at io.reactivex.internal.operators.flowable.FlowableDoOnEach.subscribeActual(FlowableDoOnEach.java:48)
at io.reactivex.Flowable.subscribe(Flowable.java:12901)
at io.reactivex.Flowable.subscribe(Flowable.java:12886)
at io.reactivex.Flowable.subscribe(Flowable.java:12746)
at michsan.adapter.Bnmpv5Adapter_On_FindAndSendDeviceCredentials_TestCase.shouldFindDeviceCredentialsAndBuildResponses(Bnmpv5Adapter_On_FindAndSendDeviceCredentials_TestCase.java:71)
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: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.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
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)
Caused by: java.lang.NullPointerException: The mapper function returned a null value.
at io.reactivex.internal.functions.ObjectHelper.requireNonNull(ObjectHelper.java:39)
at io.reactivex.internal.operators.flowable.FlowableMap$MapSubscriber.onNext(FlowableMap.java:63)
... 43 more
Exception in thread "main" io.reactivex.exceptions.OnErrorNotImplementedException: The mapper function returned a null value.
at io.reactivex.internal.functions.Functions$14.accept(Functions.java:229)
at io.reactivex.internal.functions.Functions$14.accept(Functions.java:226)
at io.reactivex.internal.subscribers.LambdaSubscriber.onError(LambdaSubscriber.java:75)
at io.reactivex.internal.operators.flowable.FlowableDoOnEach$DoOnEachSubscriber.onError(FlowableDoOnEach.java:109)
at io.reactivex.internal.subscribers.BasicFuseableSubscriber.onError(BasicFuseableSubscriber.java:100)
at io.reactivex.internal.subscribers.BasicFuseableSubscriber.fail(BasicFuseableSubscriber.java:110)
at io.reactivex.internal.operators.flowable.FlowableMap$MapSubscriber.onNext(FlowableMap.java:65)
at io.reactivex.internal.operators.flowable.FlowableFromArray$ArraySubscription.fastPath(FlowableFromArray.java:134)
at io.reactivex.internal.operators.flowable.FlowableFromArray$BaseArraySubscription.request(FlowableFromArray.java:87)
at io.reactivex.internal.subscribers.BasicFuseableSubscriber.request(BasicFuseableSubscriber.java:152)
at io.reactivex.internal.subscribers.BasicFuseableSubscriber.request(BasicFuseableSubscriber.java:152)
at io.reactivex.internal.subscribers.LambdaSubscriber.request(LambdaSubscriber.java:110)
at io.reactivex.internal.operators.flowable.FlowableInternalHelper$RequestMax.accept(FlowableInternalHelper.java:244)
at io.reactivex.internal.operators.flowable.FlowableInternalHelper$RequestMax.accept(FlowableInternalHelper.java:240)
at io.reactivex.internal.subscribers.LambdaSubscriber.onSubscribe(LambdaSubscriber.java:48)
at io.reactivex.internal.subscribers.BasicFuseableSubscriber.onSubscribe(BasicFuseableSubscriber.java:66)
at io.reactivex.internal.subscribers.BasicFuseableSubscriber.onSubscribe(BasicFuseableSubscriber.java:66)
at io.reactivex.internal.operators.flowable.FlowableFromArray.subscribeActual(FlowableFromArray.java:37)
at io.reactivex.Flowable.subscribe(Flowable.java:12901)
at io.reactivex.internal.operators.flowable.FlowableMap.subscribeActual(FlowableMap.java:37)
at io.reactivex.Flowable.subscribe(Flowable.java:12901)
at io.reactivex.internal.operators.flowable.FlowableDoOnEach.subscribeActual(FlowableDoOnEach.java:48)
at io.reactivex.Flowable.subscribe(Flowable.java:12901)
at io.reactivex.Flowable.subscribe(Flowable.java:12886)
at io.reactivex.Flowable.subscribe(Flowable.java:12746)
at michsan.adapter.Bnmpv5Adapter_On_FindAndSendDeviceCredentials_TestCase.shouldFindDeviceCredentialsAndBuildResponses(Bnmpv5Adapter_On_FindAndSendDeviceCredentials_TestCase.java:71)
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: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.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
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)
Caused by: java.lang.NullPointerException: The mapper function returned a null value.
at io.reactivex.internal.functions.ObjectHelper.requireNonNull(ObjectHelper.java:39)
at io.reactivex.internal.operators.flowable.FlowableMap$MapSubscriber.onNext(FlowableMap.java:63)
... 43 more
Building up on akarnokd's answer, you want to use RxJavaPlugins to add a hook for each Flowable, Observable,... For instance, as akarnokd does in his RxJava2Extensions library with Flowables:
RxJavaPlugins.setOnFlowableAssembly(new Function<Flowable, Flowable>() {
#Override
public Flowable apply(Flowable f) throws Exception {
// Play with the Stack, collect info
return new FlowableOnAssembly(f);
}
});
This way, you can collect info (the stack, for instance) in that FlowableOnAssembly. At this point, if you can capture crashes, you can already access that info you added (stacktrace, and whatever else you put into FlowableOnAssembly).
For easier debugging, even in remote devices, you can set a DefaultUncaughtExceptionHandler to capture any crash and print the info you collected in FlowableOnAssembly, for instance:
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
#Override
public void uncaughtException(Thread t, Throwable e) {
if (e instanceOf FlowableOnAssembly) {
// Print the info you captured
}
}
};
This mechanism will be intercepting everything RxJava2 does, so you probably want to put/remove enable/disable it easily. You can go use a small library I wrote for this purpose in:
RxJava2Debug
RxJava2Debug will create a nice simple StackTrace for you. Optionally, it will also filter it so the first entry of the root cause points to your code (this way services like Crashlytics can collate different errors for you).

java.sql.SQLException: Method not supported on using HikariCP with Hive JDBC

I am using MySQL as meta store for hive.
In my JDBC code, I replaced
DriverManager.getConnection(connectionUri, username, password);
to
HikariDataSource ds = new HikariDataSource();
ds.setJdbcUrl(connectionUri);
ds.setUsername(username);
ds.setPassword(password);
return ds.getConnection();
I got following exception:
com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: Method not supported
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:514)
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:107)
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:94)
at com.impetus.idw.data.connector.utils.JDBCUtil.getJdbcConnection(JDBCUtil.java:173)
at com.impetus.idw.data.connector.utils.JDBCUtil.checkTableExistence(JDBCUtil.java:66)
at com.impetus.idw.data.connector.datasource.HiveTable.exists(HiveTable.java:146)
at com.impetus.idw.data.connector.tools.hive.HiveToHiveCopyBaseTest.testMetadata(HiveToHiveCopyBaseTest.java:25)
at com.impetus.idw.data.connector.tools.hive.LocalToLocalTest.testHive(LocalToLocalTest.java:19)
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.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.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
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)
Caused by: java.sql.SQLException: Method not supported
at org.apache.hive.jdbc.HiveConnection.setReadOnly(HiveConnection.java:1271)
at com.zaxxer.hikari.pool.PoolBase.setupConnection(PoolBase.java:372)
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:346)
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:508)
... 31 more
Does HikariCP supports Hive JDBC?
Is there any way to avoid call to org.apache.hive.jdbc.HiveConnection.setReadOnly method?
Use latest (> 2.0.0) hive driver. See issue resolved in hive.

Iterating through large ResultSets closes my JTDS connection

I'm writing code whose purpose is to read all records from two not-so-small tables. Table A has about 500k records and 25 columns, and Table B has a little under 200k records and 143 columns.
The tables are located on two separate SQL Server 2008 databases and I have no trouble establishing a connection to them. I use jtds-1.3.1.jar as my JDBC Driver. The problem is that I always get an exception before I can read all their records, and the exception varies between
java.sql.SQLException: I/O Error: socket closed
and
java.sql.SQLException: I/O Error: Stream 2 attempting to read when no request has been sent
These exceptions always happen after reading about 69k records from Table A or 12.5k records from Table B.
My connection String is:
jdbc:jtds:sqlserver://host:port;databaseName=XXX;user=XXX;password=XXX;useCursors=true;charset=ISO-8859-1
My code:
Statement st = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
st.setFetchDirection(ResultSet.FETCH_FORWARD);
st.setFetchSize(100);
ResultSet rs = st.executeQuery("SELECT * FROM TABLE A");
int counter = 0;
while (rs.next()) {
counter++;
if (counter % 2000 == 0) {
System.out.println(counter + " records.");
}
}
The first exception:
java.sql.SQLException: I/O Error: socket closed
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2481)
at net.sourceforge.jtds.jdbc.TdsCore.getNextRow(TdsCore.java:805)
at net.sourceforge.jtds.jdbc.MSCursorResultSet.processOutput(MSCursorResultSet.java:959)
at net.sourceforge.jtds.jdbc.MSCursorResultSet.cursorFetch(MSCursorResultSet.java:719)
at net.sourceforge.jtds.jdbc.MSCursorResultSet.next(MSCursorResultSet.java:1137)
at com.mycompany.client.MyCopyTest.testSelectFromTable2(MyCopyTest.java:97)
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.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.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)
Caused by: java.net.SocketException: socket closed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:152)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at java.io.DataInputStream.readFully(DataInputStream.java:195)
at java.io.DataInputStream.readFully(DataInputStream.java:169)
at net.sourceforge.jtds.jdbc.SharedSocket.readPacket(SharedSocket.java:850)
at net.sourceforge.jtds.jdbc.SharedSocket.getNetPacket(SharedSocket.java:731)
at net.sourceforge.jtds.jdbc.ResponseStream.getPacket(ResponseStream.java:477)
at net.sourceforge.jtds.jdbc.ResponseStream.read(ResponseStream.java:114)
at net.sourceforge.jtds.jdbc.ResponseStream.readShort(ResponseStream.java:319)
at net.sourceforge.jtds.jdbc.TdsData.readData(TdsData.java:959)
at net.sourceforge.jtds.jdbc.TdsCore.tdsRowToken(TdsCore.java:3175)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2433)
... 28 more
The second exception:
java.sql.SQLException: I/O Error: Stream 2 attempting to read when no request has been sent
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2481)
at net.sourceforge.jtds.jdbc.TdsCore.getNextRow(TdsCore.java:805)
at net.sourceforge.jtds.jdbc.MSCursorResultSet.processOutput(MSCursorResultSet.java:959)
at net.sourceforge.jtds.jdbc.MSCursorResultSet.cursorFetch(MSCursorResultSet.java:719)
at net.sourceforge.jtds.jdbc.MSCursorResultSet.next(MSCursorResultSet.java:1137)
at com.mycompany.client.MyCopyTest.testSelectFromTable2(MyCopyTest.java:96)
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.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.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)
Caused by: java.io.IOException: Stream 2 attempting to read when no request has been sent
at net.sourceforge.jtds.jdbc.SharedSocket.getNetPacket(SharedSocket.java:724)
at net.sourceforge.jtds.jdbc.ResponseStream.getPacket(ResponseStream.java:477)
at net.sourceforge.jtds.jdbc.ResponseStream.read(ResponseStream.java:146)
at net.sourceforge.jtds.jdbc.ResponseStream.readString(ResponseStream.java:301)
at net.sourceforge.jtds.jdbc.ResponseStream.readNonUnicodeString(ResponseStream.java:285)
at net.sourceforge.jtds.jdbc.TdsData.readData(TdsData.java:961)
at net.sourceforge.jtds.jdbc.TdsCore.tdsRowToken(TdsCore.java:3175)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2433)
... 28 more
I've searched a lot but only found questions regarding authentication issues or invalid data that the driver couldn't parse, which I believe it's not the case here. Is there anything obvious I'm missing?
Any inputs will be highly appreciated.

Categories

Resources