Problem initiating SIP session/ getClientTransaction(request) throws NullPointerException - java

I have a small issue, I had my SIP client working, and I changed the structure of the code. I kept the creation process of the SIP objects as it was before, but now it does not work.
I keep getting:
java.lang.NullPointerException at gov.nist.javax.sip.SipProviderImpl.getNewClientTransaction(SipProviderImpl.java:285)
and there is no reference to such error in the documentation... what does it mean?
here is the instantiation code for the sip:
sipFactory.setPathName(host);
sipFactory.resetFactory();
sipStack = sipFactory.createSipStack(getProperties());
String address = Inet4Address.getLocalHost().getHostAddress();
sipFactory.createHeaderFactory();
sipFactory.createAddressFactory();
sipFactory.createMessageFactory();
udpPoint = sipStack.createListeningPoint(address, SIPPort, SIPConstants.UDP);
udpSipProvider = sipStack.createSipProvider(udpPoint);
udpSipProvider.addSipListener(this);
tcpPoint = sipStack.createListeningPoint(address, SIPPort, SIPConstants.TCP);
tcpSipProvider = sipStack.createSipProvider(tcpPoint);
tcpSipProvider.addSipListener(this);
sipStack.start();
setSessionState(SipSessionState.Connected);
Any Help please??
Adam.

WWWWWWWWWWWOOOOOOOOOOOWWWWWWWWWWWWW
If anyone would had ever guessed this, I'll eat my LapTop....
in the first project I was using the Jain-Sip 1.2
and in the new one I use the 1.2.1
BIG issue that in the 1.2, as far as I can tell, request.getMethod() returns the method of the CSeq header in case I don't use the request.setMethod(method).
While in the 1.2.1, if not setting the request.setMethod(method), the request.getMethod() method returns null.
that was my error...
now if you read this please commend or something... I'm so frustrated, I was sitting on this bugger for 4 hours now. Damn.
Adam.

Related

NPE in sun.net.www.protocol.http.HttpURLConnection.plainConnect()

I'm working on an application that runs in a JBoss 7 environment and thus is bound to use Java 7 at max (AFAIK JBoss 7 doesn't run on Java 8+ because they did some dirty tricks or used something that changed from Java 7 to 8 (source).
The problem I'm facing is this: I do a request to some remote https url which only supports TLSv1.2 and the first request is successful.
Any further request fails though with the following exception:
Caused by: java.lang.NullPointerException
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:986)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1092)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
at <our code>
<our code> looks like this:
URL url = new URL( "https://..." );
URLConnection urlConnection = url.openConnection();
urlConnection.setUseCaches( false );
urlConnection.setRequestProperty( "User-Agent", "java.net.URLConnection/" );
//Here's where we finally get the exception
OuputStream out = urlConnection.getOutputStream();
Normally an NPE isn't that big a problem, just a little debugging helps spot the error. However, since it happens in proprietary classes (sun.net. ....) I can't get the sources for those, at least not in a version which seems correct (one version looks like this at like 986: connected = true; - hardly a source for an NPE).
This happens in both Oracle JDK 1.7.0u80 and OpenJDK 7u75.
Any ideas?
Finally found the error, thanks to some help by #yole.
The sources are not exact so I can't be 100% sure about the actual cause but in our case there was a custom ProxySelector registered and the exception seems to have been thrown when calling this code which is part of plainConnect() and somewhere around line 986:
ProxySelector sel =
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<ProxySelector>() {
public ProxySelector run() {
return ProxySelector.getDefault();
}
});
As I said the sources were off because I couldn't find the exact version but looking for custom ProxySelector related code helped at lot (and as in 99.9% of the cases it was our code that caused the problem somehow).
That still doesn't explain the NPE because all versions I could find were either setting some boolen flag, comments or handling an IOException (either the catch-clause or a plain rethrow) but since removing the custom selector solved the problem I'm happy.
I hope if anyone else stumbles over a similar problem this will help save them some headaches.

How to change Jetty settings through SparkJava? / Form too Large Exception / org.eclipse.jetty.server.Request.maxFormContentSize

I'm using SparkJava 2.2 which is using Jetty 9.0.2.
I'm getting "Form too large" exception which is thrown by Jetty. I already know how to solve this problem if I was using Jetty directly:
Form too Large Exception
http://www.eclipse.org/jetty/documentation/current/setting-form-size.html
PROBLEM :
Now I need to find a way to change org.eclipse.jetty.server.Request.maxFormContentSize setting through SparkJava. Is there a way to do this?
I must note that other methods (JVM_OPTS, System.setProperty) do not work for me for some reason. I'm still getting the same exception.
Stacktrace:
[qtp1858644635-27] ERROR spark.webserver.MatcherFilter -
java.lang.IllegalStateException: Form too large 308913>200000
at org.eclipse.jetty.server.Request.extractParameters(Request.java:334)
at org.eclipse.jetty.server.Request.getParameterMap(Request.java:765)
at javax.servlet.ServletRequestWrapper.getParameterMap(ServletRequestWrapper.java:193)
at spark.QueryParamsMap.<init>(QueryParamsMap.java:59)
at spark.Request.initQueryMap(Request.java:364)
at spark.Request.queryMap(Request.java:349)
at spark.webserver.RequestWrapper.queryMap(RequestWrapper.java:213)
at com.xyz.analytics.webservice.RequestTools.getRequestQueryMap(RequestTools.java:27)
at com.xyz.analytics.webservice.RequestTools.getMandrillQueryParams(RequestTools.java:22)
at com.xyz.analytics.webservice.Endpoints.lambda$initiateEndpointsAndExceptionHandlers$2(Endpoints.java:61)
at com.xyz.analytics.webservice.Endpoints$$Lambda$3/1485697819.handle(Unknown Source)
at spark.SparkBase$1.handle(SparkBase.java:311)
at spark.webserver.MatcherFilter.doFilter(MatcherFilter.java:159)
at spark.webserver.JettyHandler.doHandle(JettyHandler.java:60)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:179)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:451)
at org.eclipse.jetty.server.HttpChannel.run(HttpChannel.java:252)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:266)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:240)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:596)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:527)
at java.lang.Thread.run(Thread.java:745)
Edit:
I must note that other methods (JVM_OPTS, System.setProperty) do not work for me.
Well, debugger doesn't even stop at any breakpoint set within org.eclipse.jetty.server.handlerContextHandler... Plus when it stops at org.eclipse.jetty.server.Request breakpoints, _context property is null. Seems that SparkJava is handling it differently. Dead end.
Request does one more thing before setting maxFormContentSize = 200000;. It checks _channel.getServer().getAttribute("org.eclipse.jetty.server.Request.maxFormContentSize").
Except Server's attribute collection is empty... And I don't see any way to add any attribute. Jetty Server is created by SparkBase.init() which calls SparkServer.ignite().
But it doesn't help us much. It's not easy to "break in" to make our own adjustments. It seems pretty hopeless.
Not possible with Spark 2.2
The creation of the ServerConnector is hardcoded in the SparkServer, you cannot change those values after the fact, they have to be passed into the ServerConnector before server start.
Would recommend filing a bug with Spark to make that configurable.
https://github.com/perwendel/spark/issues
Good news everyone :)
In Spark 2.6 (released April 2017) embedded Jetty is fully configurable!
Release notes: http://sparkjava.com/news#spark-26-released
See the original future request for more details here: https://github.com/perwendel/spark/issues/314
and related pull request here:
https://github.com/perwendel/spark/pull/813
NOTE that it is also possible to run Spark on another web server instead of the embedded Jetty server:
http://sparkjava.com/documentation#other-web-server
Well, having access to the server object, you can always do something like:
server.setAttribute("org.eclipse.jetty.server.Request.maxFormContentSize", 1024 * 1024);
Hope this helps!

Bad Request trying to call getMedia() on DocsService

When calling getMedia() on DocsService for some document I got next message:
Bad Request
We have encountered an error, which we will investigate immediately. Sorry for the inconvenience.
This happens already 10 days, how this one could be fixed ?
Thanks.
What happens if you retry?
The Google infrastructure regularly throws 500 errors which succeed after a retry. Make sure you do an exponential backoff.

Handling java errors in Flex

I am new bie to flex. We are using flex,java,blazeds to develop our application. So we are successfully connected to blazeds but it is showing one error when we are trying to execute the application.the error is:
(mx.rpc::Fault)#0
content = (null)
errorID = 0
faultCode = "Server.Processing"
faultDetail = (null)
faultString = "java.lang.NullPointerException : null"
message = "faultCode:Server.Processing
faultString:'java.lang.NullPointerException : null'
faultDetail:'null'"
name = "Error"
rootCause = (Object)#1
cause = (null)
localizedMessage = (null)
message = (null)
If anyone has idea about this issue.Please help me.I am trying to solve the issue.But i didnt get the perfect solution.
Thanks in Advance,
Rakhi
The Error you got in Flex says that there was an uncaught NullPointerException in your java code.
You should examine the processing code of the actual request (debug / encapsulate it in try-catch), to see where the NPE is thrown, and handle it, otherwise, instead of the response object, this exception is returned to the flex application.
You can also surround with try-catch the request/response processing code in your flex application -in case you don't want to deal with it on server side-, and show a popup/alert message about it.
But it would be nicer if you'd wrap that NullPointerException on server side to a custom Exception, so you could handle it more precisely.
I wrote an article about handling the Java errors in Flex, you can find it here. It aims to cover all the cases (webservices, amf, spring integration).

Error implementing the Thrift API

I'm implementing the Thrift Remote Procedure call framework in Java. I set up thrift and generated my skeleton code without a lot of issues, but now that I'm actually using the API methods, I get strange errors.
Here are the errors I get:
Exception in thread "main" org.apache.thrift.transport.TTransportException: Cannot write to null outputStream
at org.apache.thrift.transport.TIOStreamTransport.write(TIOStreamTransport.java:142)
at org.apache.thrift.protocol.TBinaryProtocol.writeI32(TBinaryProtocol.java:163)
at org.apache.thrift.protocol.TBinaryProtocol.writeMessageBegin(TBinaryProtocol.java:91)
at SimonSays$Client.send_registerClient(SimonSays.java:102)
at SimonSays$Client.registerClient(SimonSays.java:96)
at simon.main(testClass.java:16)
I don't think I'm not making any mistakes, but just to make sure, here's the code that's leading to the errors:
TProtocol prot = new TBinaryProtocol(new TSocket("http://thriftpuzzle.facebook.com",9030));
SimonSays.Client client = new SimonSays.Client(prot);
client.registerClient("userEmailAddress#gmail.com");
The error is said to be generated from the client.registerClient() call, but that is a call to the code generated by Thrift, which makes me feel that I'm doing something wrong in setting up the connection itself.
The part about making a TProtocol instance I included myself, and it's likely that that's where the problem lies.
I was hoping that someone would have more of an idea about what's going wrong that I do.
Please let me know if more information or clarification is needed.
Edit: I found the TProtocol instantiation statement from the Cassandra Wiki
You need to call the open() method on your TSocket instance in order for it to connect and obtain the input/output streams it needs.
Source: TSocket.java

Categories