My code to call to a port name getDUNSProfile() looks like this:
public class LookupRequestProcessor
{
protected GetCleanseMatchResponse sendRequest(Request request) throws Exception_Exception, GetDUNSProfileFault, PayloadException
{
return DNBPortUtil.getDunsService().getDUNSProfile();
}
}
And I receive an exception as below (Updated with full stacktrace)
java.lang.Error: javax.xml.ws.soap.SOAPFaultException: Error in operation:
at imx.svb.module.getdunsprofile.LookupRequestProcessor.doWork(LookupRequestProcessor.java:478)
at imx.svb.TemplateDatablockProcessor.run(TemplateDatablockProcessor.java:63)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.xml.ws.soap.SOAPFaultException: Error in operation:
at com.sun.xml.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:197)
at com.sun.xml.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:130)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:125)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:95)
at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:136)
at com.sun.proxy.$Proxy97.getDUNSProfile(Unknown Source)
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 weblogic.wsee.jaxws.spi.ClientInstanceInvocationHandler.invoke(ClientInstanceInvocationHandler.java:84)
at com.sun.proxy.$Proxy98.getDUNSProfile(Unknown Source)
at imx.svb.module.getdunsprofile.LookupRequestProcessor.sendRequest(LookupRequestProcessor.java:258)
at imx.svb.module.getdunsprofile.LookupRequestProcessor.doWork(LookupRequestProcessor.java:472)
Does this mean I called successfully to the port? Or still not reaching it? Is the message Error in operation from exception returned by the The WS server?
Chances are you have reached the Port. Referencing the documentation of the Fault and this thread on code ranch seems to suggest that a fault is being thrown from the provider of the service. In your code can you add a block to catch the Exception and get the SOAPFault being thrown when invoked. If the fault is well handled , it should ideally give you a reason / code as to why the exception is happening.
Related
please help to understand following issue:
After moving from JBoss to Wildfly 8, if some runtime exception is thrown in the bean, I excpect to receive this exception at client side, but instead I receive IO exception :
Client side:
Caused by: javax.ejb.EJBException: java.io.IOException: Channel Channel ID ddd7dcd1 (outbound) of Remoting connection 12c97f7d to localhost/127.0.0.1:80 has been closed
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:236)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:181)
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:144)
and in the server side I see this one:
14:26:00,167 ERROR [ejb3] JBAS014250: Could not write method invocation failure for method public abstract void com.allot.nms.catalog.mobile.ejb.MobileControllerInternal.replaceCatalogEntries(java.util.Collection) throws com.allot.nms.catalog.exception.CatalogException on bean named MobileControllerBean for appname NMS modulename catalog distinctname due to: java.io.IOException: JBAS014560: Could not open message outputstream for writing to Channel
at org.jboss.as.ejb3.remote.protocol.AbstractMessageHandler.writeException(AbstractMessageHandler.java:102)
at org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler.access$400(MethodInvocationMessageHandler.java:70)
at org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler$1.run(MethodInvocationMessageHandler.java:213)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
at org.jboss.threads.JBossThread.run(JBossThread.java:122)
Caused by: java.lang.InterruptedException
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1302)
at java.util.concurrent.Semaphore.acquire(Semaphore.java:312)
at org.jboss.as.ejb3.remote.protocol.versionone.ChannelAssociation.acquireChannelMessageOutputStream(ChannelAssociation.java:66)
at org.jboss.as.ejb3.remote.protocol.AbstractMessageHandler.writeException(AbstractMessageHandler.java:100)
It seems that there is some problem to handle the originally thrown exception.
Same code worked with JBoss.
Any ideas how to fix it and make the exception propagate to client?
Thanks a lot.
I have the following exception (the stacktrace):
java.lang.NullPointerException
at sun.reflect.GeneratedConstructorAccessor171.newInstance(Unknown Source) ~[?:?]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_40]
at java.lang.reflect.Constructor.newInstance(Constructor.java:422) ~[?:1.8.0_40]
at java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:598) ~[?:1.8.0_40]
at java.util.concurrent.ForkJoinTask.reportException(ForkJoinTask.java:677) ~[?:1.8.0_40]
at java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:735) ~[?:1.8.0_40]
at java.util.stream.ForEachOps$ForEachOp.evaluateParallel(ForEachOps.java:160) ~[?:1.8.0_40]
at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateParallel(ForEachOps.java:174) ~[?:1.8.0_40]
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:233) ~[?:1.8.0_40]
at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418) ~[?:1.8.0_40]
at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:583) ~[?:1.8.0_40]
at com.tradair.tnet.services.trades.TradeService.updateUnrealizedPNL(TradeService.java:173) ~[tnet.jar:5.1.1.0-SNAPSHOT]
which starts at my TradeService class here:
public void updateUnrealizedPNL(Set<Org> orgsToCaluclate, Set<Org> orgsToSendUpdate) {
orgsToCaluclate.parallelStream().forEach(o -> {
pnlService.updateMidPrices(o);
Collection<SystemTradeOrder> allLiveTradesByOrgId = tradesRepository.getAllLiveTradesByOrgId(o.getId());
updateUnrealizedPNL(o, allLiveTradesByOrgId);
});
// more code ....
So it looks like the exception is thrown inside java native code while running forEach(..) method.
I mean, the NullPointerException isn't thrown from my own code - not from my consumer function which appears as the argument in forEach(..) method.
I double checked that there is no modification to the orgsToCaluclate set when this piece of code runs.
This is the initialization of orgsToCaluclate:
Set<Org> orgsToCaluclate = getMarginOrgs();
orgsToCaluclate = orgsToCaluclate.stream()
.filter(org -> !isOrgInCloseout(org.getId())).collect(Collectors.toSet());
Any thoughts?..
We got used to say that an exception’s stack trace reflects “where it happened”, but that’s an imprecise statement. An exception’s stack trace usually reflects where its instance has been created.
When we have code of the form,
1 String s=null;
2 s.length();
The JRE will create an instance of NullPointerException when we try to dereference null for invoking the method length(), so its stack trace will report line 2.
However, when we have the following code
1 String s=null;
2 if(s == null) {
3 RuntimeException rt=new NullPointerException();
4 throw rt;
5 }
The stack trace will not report where the erroneous condition has been detected (line 2) nor where the exception has been thrown (line 4) but where the instance has been created, in line 3.
For most practical cases, these places are close enough to make no significant difference, but here, we have an extraordinary situation.
As tonakai has pointed out, the ForkJoinTask will create a new instance of an already encountered exception via Reflection, as we can see in its source code when the threads mismatch.
When it succeeds, its stack trace will precisely reflect where the new exception instance has been created, which is in some generated code performing the reflective instance creation. Of course, this successful creation can’t be distinguished from the situation when the JRE creates an exception due to an error condition when executing the same code.
But when we look closer at the source code, we see that the entire reflective creation is enclosed with a
584 try {
…
604 } catch (Exception ignore) {
605 }
block. So if the operation really failed, no exception was visible. Instead, the code had fallen over to return the original exception. This indicates that the reflective code didn’t fail, but instead we see the successfully, reflectively created NullPointerException instance returned by getThrowableException() and later on deliberately throw by ForkJoinTask to report that there was a NullPointerException in another thread during the processing.
But this code initializes the cause of the new exception to point to the original one. E.g. the following code:
import java.util.stream.IntStream;
public class Main
{
public static void main(String[] args) {
Thread main=Thread.currentThread();
IntStream.range(0, 1000).parallel().forEach(i -> {
if(Thread.currentThread()!=main)
throw new NullPointerException();
});
}
}
prints
Exception in thread "main" java.lang.NullPointerException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:598)
at java.util.concurrent.ForkJoinTask.reportException(ForkJoinTask.java:677)
at java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:735)
at java.util.stream.ForEachOps$ForEachOp.evaluateParallel(ForEachOps.java:160)
at java.util.stream.ForEachOps$ForEachOp$OfInt.evaluateParallel(ForEachOps.java:189)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:233)
at java.util.stream.IntPipeline.forEach(IntPipeline.java:404)
at java.util.stream.IntPipeline$Head.forEach(IntPipeline.java:560)
at Main.main(Main.java:7)
Caused by: java.lang.NullPointerException
at Main.lambda$main$0(Main.java:9)
at java.util.stream.ForEachOps$ForEachOp$OfInt.accept(ForEachOps.java:205)
at java.util.stream.Streams$RangeIntSpliterator.forEachRemaining(Streams.java:110)
at java.util.Spliterator$OfInt.forEachRemaining(Spliterator.java:693)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:291)
at java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:731)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
so you are still able to recognize what happened. You just have to pay attention to the cause. Since the stack trace in your question doesn’t look like the typical Throwable.printStackTrace() output, it might be the code which produced this output which ignored the cause property of the exception.
As an addendum, we can check what happens if that recreation really fails using a custom exception type:
import java.util.stream.IntStream;
public class Main
{
public static class CustomException extends RuntimeException {
public CustomException() {
System.err.println("will deliberately fail");
throw new NullPointerException();
}
private CustomException(String message) {
super(message);
}
}
public static void main(String[] args) {
Thread main=Thread.currentThread();
IntStream.range(0, 1000).parallel().forEach(i -> {
if(Thread.currentThread()!=main)
throw new CustomException("forced failure");
});
}
}
will print
will deliberately fail
Exception in thread "main" Main$CustomException: forced failure
at Main.lambda$main$0(Main.java:18)
at java.util.stream.ForEachOps$ForEachOp$OfInt.accept(ForEachOps.java:205)
at java.util.stream.Streams$RangeIntSpliterator.forEachRemaining(Streams.java:110)
at java.util.Spliterator$OfInt.forEachRemaining(Spliterator.java:693)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
at java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:291)
at java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:731)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
showing that the NullPointerException thrown during the reflective recreation via the default constructor stays unreported and the original exception from the other thread is thrown directly instead.
looking at the stacktrace it looks like there is an exception happening in your code, and it is trying to get a new instance of that exception but fails to do so because of NullPointerException, can you check your code if any of the code that is called in that foreach throws any exception and make sure
all constructors of those exceptions are correct
at java.lang.reflect.Constructor.newInstance(Constructor.java:422) ~[?:1.8.0_40]
at java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:598) ~[?:1.8.0_40]
at java.util.concurrent.ForkJoinTask.reportException(ForkJoinTask.java:677) ~[?:1.8.0_40]
at java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:735) ~[?:1.8.0_40]
I have a program which sometimes encounters the errorjava.net.SocketException. Is there a way I can have the client program execute some code if (and only if) it encounters this error in order to "deal with" the error? The full error is
java.net.SocketException: Software caused connection abort: socket write error
Here's a summary of what I have now.
public void run() {
try {
//some code that causes the SocketException
}
catch (SocketException e) {
System.out.println("I recognize the SocketException");
}
}
However despite the error it still won't print the line.
Here is the full error
java.net.SocketException: Software caused connection abort: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(Unknown Source)
at java.net.SocketOutputStream.write(Unknown Source)
at java.io.ObjectOutputStream$BlockDataOutputStream.drain(Unknown Source)
at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(Unknown Source)
at java.io.ObjectOutputStream.writeNonProxyDesc(Unknown Source)
at java.io.ObjectOutputStream.writeClassDesc(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeFatalException(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at (...).java:61)
at (...).java:164)
It depends on whether the client or the server is the one throwing the exception.
Either way, you should just be able to add a try-catch block around the code.
try {
//code
} catch (SocketException e) {
// Handle the error
}
If the server is throwing the error and you want the client to handle the situation, the client should be throwing an exception due to the loss of connection (this is what this exception looks like). Alternatively, if the server throws an error but doesn't crash, just have the server send some signal to the client that an error occurred.
Either way, with a little more information, I could give you a better resposne.
The problem is the following:
When sending a mail in webapp running on Play framework 1.2.4 exception with following stack trace can be observed in logs:
Execution exception
NullPointerException occured : null
play.exceptions.JavaExecutionException
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:231)
at Invocation.HTTP Request(Play!)
Caused by: java.lang.NullPointerException
at play.exceptions.MailException.<init>(MailException.java:27)
at play.libs.Mail.buildMessage(Mail.java:79)
at play.libs.Mail.send(Mail.java:35)
at play.mvc.Mailer.send(Mailer.java:347)
at play.mvc.Mailer.sendAndWait(Mailer.java:355)
at notifiers.Mails.forgotPassword(Mails.java:19)
at controllers.PasswordReset.requestPasswordReset(PasswordReset.java:102)
at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:548)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:502)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:478)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:473)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161)
... 1 more
The relevant part here is following:
Caused by: java.lang.NullPointerException
at play.exceptions.MailException.<init>(MailException.java:27)
which indicates that NullPointerException was thrown from constructor of play.exceptions.MailException (in 27th line). Source code of this constructor looks like the following:
public MailException(String message, Throwable cause) {
super(message, cause);
StackTraceElement element = getInterestingStrackTraceElement(cause);
if(element != null) {
ApplicationClass applicationClass = Play.classes.getApplicationClass(element.getClassName());
sourceFile = applicationClass.javaFile.relativePath(); // this line is 27th and NPE is thrown from here
source = Arrays.asList(applicationClass.javaSource.split("\n"));
line = element.getLineNumber();
}
}
So either applicationClass local variable or javaFile property is null. Could someone familiar with Play framework weird internals advise what can cause this problem?
Thanks a lot in advance
EDIT after Seb Cesbron answer
We also inspected play.libs.Mail.buildMessage(Mail.java:79) where it is clearly seen that from address is null, but after fixing that, similar exception popped up:
play.exceptions.JavaExecutionException
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:231)
at Invocation.HTTP Request(Play!)
Caused by: java.lang.NullPointerException
at play.exceptions.MailException.<init>(MailException.java:27)
at play.mvc.Mailer.send(Mailer.java:349)
at play.mvc.Mailer.sendAndWait(Mailer.java:355)
at notifiers.Mails.forgotPassword(Mails.java:19)
at controllers.PasswordReset.requestPasswordReset(PasswordReset.java:102)
at play.mvc.ActionInvoker.invokeWithContinuation(ActionInvoker.java:548)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:502)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:478)
at play.mvc.ActionInvoker.invokeControllerMethod(ActionInvoker.java:473)
at play.mvc.ActionInvoker.invoke(ActionInvoker.java:161)
And there, play.mvc.Mailer.send method contains nearly 200 lines of code enclosed in try-catch block, so it got really tricky to find out what was the problem :)
Line 79 in Mail.java refers to a throw MailException because there is no from address.
The NullPointerException in MailException seems to show that there is no file associated to your mail. Are you sure that the file Mails/forgotPassword.html (or txt) exists ?
We are calling a web service where RequestDetails is an input object and getting the following error. I've read at multiple forums that the "invalid element"-related error occurs if there is a mismatch between the field at the client and webservice sides. Can anyone shed more light on this?
55-a002-d59e5869552f|884ce533-9236-42e0-bb2c-93beeefddc38|en_GB - xyzabc|m023}
12:15:21,784 [ebContainer : 1] ERROR : oteservice.impl.m023.SendwantRequestExt: Requesting want failed. AxisFault thrown. {JQU|||||c86d4f9c-a493-4e5a-a2ce-d52bee2128b5|884ce533-9236-42e0-bb2c-93beeefddc38|en_GB - xyzabc|m023}
org.apache.axis2.AxisFault: org.xml.sax.SAXException: Invalid element in com.ABC.wm.eu.webserviceapp.ejb.ws.RequestDetails - standardField
at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:512)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:370)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:416)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)
at com.ABC.applica.v1.privateservices.orderentrytreasurymanagement.extension.wantservice.impl.m023.ws.LocalServiceStub.requestwant(LocalServiceStub.java:773)
at com.ABC.applica.v1.privateservices.orderentrytreasurymanagement.extension.wantservice.impl.m023.SendwantRequestExt.sendwantRequest(SendwantRequestExt.java:183)
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:592)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
Found out what the cause was. The field standardField was missing from the input class RequestDetails.