aspose file tools*
The moose likes Java in General and the fly likes Deprecated function authscheme().  Need Help to resolve this issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Deprecated function authscheme().  Need Help to resolve this issue" Watch "Deprecated function authscheme().  Need Help to resolve this issue" New topic
Author

Deprecated function authscheme(). Need Help to resolve this issue

Abhishek Shirodkar
Greenhorn

Joined: May 08, 2009
Posts: 26

Hi,
I have the following statement in which the function authenticate() is shown as deprecated.



The variables "method" and "uriString" i am creating is shown below:



The above usage seems to be deprecated and it is insisted to use the following format of the authenticate function as mentioned in javadocs.



Now, how do i make the method (of type String) and uriString (of type String) appear as the second parameter in the appropriate usage of the authenticate function in my code. What do i write as the correction? Please assist.

Thanks in advance.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39576
    
  27
What kind of object is "authscheme"? The javadocs of most -maybe all- deprecated methods and classes will tell you which other methods or classes should be used instead.


Ping & DNS - updated with new look and Ping home screen widget
Abhishek Shirodkar
Greenhorn

Joined: May 08, 2009
Posts: 26

Hi,
authscheme is declared the following way. It is of type AuthScheme as you can see in the text below:
AuthScheme authscheme = new DigestScheme();

It is using the following import statements:

import org.apache.commons.httpclient.auth.AuthScheme;
import org.apache.commons.httpclient.auth.AuthenticationException;
import org.apache.commons.httpclient.auth.DigestScheme;
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39576
    
  27
So you're talking about this: http://www.docjar.org/docs/api/org/apache/commons/httpclient/auth/DigestScheme.html

As you can see, the javadocs say to use "authenticate(Credentials, HttpMethod)" instead. So you need to figure out a way to construct an HttpMethod object from the information you have. The most likely candidates would be GetMethod and PostMethod (POST even likelier that GET - you wouldn't want login credentials in the URL), both of which have a constructor that takes the uri -which you have- as parameter. That looks promising.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19556
    
  16

Have you checked the API?

Depending on the method, you create an instance of an implementation of HttpMethod. For instance, for the "GET" method you create a GetMethod instance: new GetMethod(uriString). There are similar classes with matching constructors for the other 6 HTTP methods: POST, HEAD, OPTIONS, TRACE, PUT, DELETE.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Krishna Komarpant
Greenhorn

Joined: Aug 07, 2009
Posts: 15
I had a similar issue.. tried creating the method variable and the uriString variable typecast to HttpMethod variable. but the statements seem to be erronous. Even i would like to know the solution to this problem that would make me complete by project.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39576
    
  27
tried creating the method variable and the uriString variable typecast to HttpMethod variable. but the statements seem to be erronous.

What, exactly, did you try? The approach outlined by Rob and myself seems pretty straight-forward.
Krishna Komarpant
Greenhorn

Joined: Aug 07, 2009
Posts: 15
Hi Ulf Dittmer,
Let me summarize the code statements involved...
I imported the following class:

Yes, i am trying to get some idea by what Rob and you have suggested. I will get back if I get it going.
The following is the entire AuthenticationHelper.java file in which the code changes are to be done. can you please take a look at this file.

Abhishek Shirodkar
Greenhorn

Joined: May 08, 2009
Posts: 26
I got an idea that i have tomake the HttpMethod parameter be a combination of String type variables - "method" and "uriString".

i created a new class using:

Is this right? If not can you please writea snippet to tell me what exactly i should do?

Thanks in advance.

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19556
    
  16

What's wrong with actually using the classes Ulf and I mentioned?
Abhishek Shirodkar
Greenhorn

Joined: May 08, 2009
Posts: 26
Rob Prime wrote:Have you checked the API?

Depending on the method, you create an instance of an implementation of HttpMethod. For instance, for the "GET" method you create a GetMethod instance: new GetMethod(uriString). There are similar classes with matching constructors for the other 6 HTTP methods: POST, HEAD, OPTIONS, TRACE, PUT, DELETE.


As per your suggestion i did the following:



i get the following output:


init:
deps-jar:
compile:
run:
Reading Data From File VoipSettings.ini....:
createSipStack gov.nist.javax.sip.SipStackImpl@94948a
Sending Probe 10.0.2.58 5060
Line Event: LINE_REGISTERING, LINE_NORMAL
processResponseAuthorization()
0 [Thread-7] DEBUG org.apache.commons.httpclient.auth.DigestScheme - enter DigestScheme.createCnonce()
Received response not waited on:
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 10.0.2.58:5060;rport=5060;branch=z9hG4bK8015468bfd6153e2b6657aa0d0c0afce;received=10.0.2.58
From: <sip:50@10.0.2.59>;tag=1a61c22b
To: <sip:50@10.0.2.59>
Call-ID: 02f60dab94f86694548d29f04ca317ba@10.0.2.58
CSeq: 1 REGISTER
User-Agent: Asterisk PBX
Allow: INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,SUBSCRIBE,NOTIFY
Supported: replaces
Contact: <sip:50@10.0.2.59>
Content-Length: 0


47 [Thread-7] DEBUG org.apache.commons.httpclient.auth.DigestScheme - enter DigestScheme.encode(byte[])
94 [Thread-7] DEBUG org.apache.commons.httpclient.params.DefaultHttpParams - Set parameter http.useragent = Jakarta Commons-HttpClient/3.1-rc1
94 [Thread-7] DEBUG org.apache.commons.httpclient.params.DefaultHttpParams - Set parameter http.protocol.version = HTTP/1.1
94 [Thread-7] DEBUG org.apache.commons.httpclient.params.DefaultHttpParams - Set parameter http.connection-manager.class = class org.apache.commons.httpclient.SimpleHttpConnectionManager
94 [Thread-7] DEBUG org.apache.commons.httpclient.params.DefaultHttpParams - Set parameter http.protocol.cookie-policy = default
94 [Thread-7] DEBUG org.apache.commons.httpclient.params.DefaultHttpParams - Set parameter http.protocol.element-charset = US-ASCII
94 [Thread-7] DEBUG org.apache.commons.httpclient.params.DefaultHttpParams - Set parameter http.protocol.content-charset = ISO-8859-1
109 [Thread-7] DEBUG org.apache.commons.httpclient.params.DefaultHttpParams - Set parameter http.method.retry-handler = org.apache.commons.httpclient.DefaultHttpMethodRetryHandler@f11404
Exception in thread "Thread-7" java.lang.NoClassDefFoundError: org/apache/commons/codec/DecoderException
at org.apache.commons.httpclient.HttpMethodBase.<init>(HttpMethodBase.java:220)
109 [Thread-7] DEBUG org.apache.commons.httpclient.params.DefaultHttpParams - Set parameter http.dateparser.patterns = [EEE, dd MMM yyyy HH:mm:ss zzz, EEEE, dd-MMM-yy HH:mm:ss zzz, EEE MMM d HH:mm:ss yyyy, EEE, dd-MMM-yyyy HH:mm:ss z, EEE, dd-MMM-yyyy HH-mm-ss z, EEE, dd MMM yy HH:mm:ss z, EEE dd-MMM-yyyy HH:mm:ss z, EEE dd MMM yyyy HH:mm:ss z, EEE dd-MMM-yyyy HH-mm-ss z, EEE dd-MMM-yy HH:mm:ss z, EEE dd MMM yy HH:mm:ss z, EEE,dd-MMM-yy HH:mm:ss z, EEE,dd-MMM-yyyy HH:mm:ss z, EEE, dd-MM-yyyy HH:mm:ss z]
at org.apache.commons.httpclient.methods.GetMethod.<init>(GetMethod.java:89)
at com.sipresponse.voipcallmgr.internal.util.AuthenticationHelper.processResponseAuthorization(AuthenticationHelper.java:115)
at com.sipresponse.voipcallmgr.internal.actions.RegisterAction.run(RegisterAction.java:103)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.codec.DecoderException
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
... 4 more
CallManager destroyed.
BUILD SUCCESSFUL (total time: 33 seconds)


Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19556
    
  16

You're missing the Apache Commons Codec library.
Krishna Komarpant
Greenhorn

Joined: Aug 07, 2009
Posts: 15
Rob Prime wrote:What's wrong with actually using the classes Ulf and I mentioned?

Alright, i wrote this...
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19556
    
  16

REGISTER is not a supported method for web servers. Like I said before, the seven that are are GET, POST, HEAD, TRACE, OPTIONS, PUT and DELETE.

However, if you still need it (because it's a special web server that does support it), extend HttpMethodBase:
You may want to extend GetMethod or PostMethod instead if you want REGISTER to act like one of those.
Krishna Komarpant
Greenhorn

Joined: Aug 07, 2009
Posts: 15

I did the following with my code: seems to work out to some extent, but there is one Exception that is generated:

I get the following output....
init:
deps-jar:
compile:
run:
Reading Data From File VoipSettings.ini....:
createSipStack gov.nist.javax.sip.SipStackImpl@94948a
Sending Probe 10.0.2.58 5060
Line Event: LINE_REGISTERING, LINE_NORMAL
processResponseAuthorization()
Received response not waited on:
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 10.0.2.58:5060;rport=5060;branch=z9hG4bKc35c0d59d3f4bf6cc99c65cda8856399;received=10.0.2.58
From: <sip:50@10.0.2.59>;tag=740083d7
To: <sip:50@10.0.2.59>
Call-ID: 98440ac88c2ca5de38ee82975a279788@10.0.2.58
CSeq: 1 REGISTER
User-Agent: Asterisk PBX
Allow: INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,SUBSCRIBE,NOTIFY
Supported: replaces
Contact: <sip:50@10.0.2.59>
Content-Length: 0
0 [Thread-7] DEBUG org.apache.commons.httpclient.auth.DigestScheme - enter DigestScheme.createCnonce()
16 [Thread-7] DEBUG org.apache.commons.httpclient.auth.DigestScheme - enter DigestScheme.encode(byte[])
63 [Thread-7] DEBUG org.apache.commons.httpclient.params.DefaultHttpParams - Set parameter http.useragent = Jakarta Commons-HttpClient/3.1-rc1
63 [Thread-7] DEBUG org.apache.commons.httpclient.params.DefaultHttpParams - Set parameter http.protocol.version = HTTP/1.1
63 [Thread-7] DEBUG org.apache.commons.httpclient.params.DefaultHttpParams - Set parameter http.connection-manager.class = class org.apache.commons.httpclient.SimpleHttpConnectionManager
63 [Thread-7] DEBUG org.apache.commons.httpclient.params.DefaultHttpParams - Set parameter http.protocol.cookie-policy = default
63 [Thread-7] DEBUG org.apache.commons.httpclient.params.DefaultHttpParams - Set parameter http.protocol.element-charset = US-ASCII
63 [Thread-7] DEBUG org.apache.commons.httpclient.params.DefaultHttpParams - Set parameter http.protocol.content-charset = ISO-8859-1
63 [Thread-7] DEBUG org.apache.commons.httpclient.params.DefaultHttpParams - Set parameter http.method.retry-handler = org.apache.commons.httpclient.DefaultHttpMethodRetryHandler@f11404

Exception in thread "Thread-7" java.lang.IllegalStateException: unsupported protocol: 'sip'
at org.apache.commons.httpclient.protocol.Protocol.lazyRegisterProtocol(Protocol.java:149)
63 [Thread-7] DEBUG org.apache.commons.httpclient.params.DefaultHttpParams - Set parameter http.dateparser.patterns = [EEE, dd MMM yyyy HH:mm:ss zzz, EEEE, dd-MMM-yy HH:mm:ss zzz, EEE MMM d HH:mm:ss yyyy, EEE, dd-MMM-yyyy HH:mm:ss z, EEE, dd-MMM-yyyy HH-mm-ss z, EEE, dd MMM yy HH:mm:ss z, EEE dd-MMM-yyyy HH:mm:ss z, EEE dd MMM yyyy HH:mm:ss z, EEE dd-MMM-yyyy HH-mm-ss z, EEE dd-MMM-yy HH:mm:ss z, EEE dd MMM yy HH:mm:ss z, EEE,dd-MMM-yy HH:mm:ss z, EEE,dd-MMM-yyyy HH:mm:ss z, EEE, dd-MM-yyyy HH:mm:ss z]
at org.apache.commons.httpclient.protocol.Protocol.getProtocol(Protocol.java:117)
at org.apache.commons.httpclient.HttpHost.<init>(HttpHost.java:107)
at org.apache.commons.httpclient.HttpMethodBase.setURI(HttpMethodBase.java:280)
at org.apache.commons.httpclient.HttpMethodBase.<init>(HttpMethodBase.java:220)
at org.apache.commons.httpclient.methods.GetMethod.<init>(GetMethod.java:89)
at com.sipresponse.voipcallmgr.internal.util.AuthenticationHelper.processResponseAuthorization(AuthenticationHelper.java:115)
at com.sipresponse.voipcallmgr.internal.actions.RegisterAction.run(RegisterAction.java:103)
CallManager destroyed.

BUILD SUCCESSFUL (total time: 33 seconds)

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19556
    
  16

The SIP protocol isn't known by default. You'll need to create an instance of Protocol, then register it using Protocol.registerProtocol.
Krishna Komarpant
Greenhorn

Joined: Aug 07, 2009
Posts: 15
Hello Everyone,
It took me a little long to get back, apologies for that. I was busy with my code.
Yes RobThat would have surely helped me.
I tried it, but after debugging I came to the conclusion that there are serious issues with the Proxy Authentication that is being used. I had to completely break the code and get all the code included in the classes within the same file where the proxy authentication was being called.
i used a JAVA DECOMPILER to get the java source code of the java library class files.

It is also observed that the Asterix System has been to complicated to understand, I switched to a 3CX system, with this and some more massive code changes done i was able to make my First Call.


Thanks a lot to Rob Prime and Ulf Dittmer and others for all the help provided, I have learnt a lot of new things on this issue.

Regards,
Krishna.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Deprecated function authscheme(). Need Help to resolve this issue
 
Similar Threads
phone listener is not working properly
How to Detect a File not Found
login issues with AOL program
JAXWS client SOAP manipulation
overriding JDBCRealm