Monday, July 25, 2011

Deriving and Binding WSLD URL at runtime for ADF Application

There are scenario when developers tend to use an exposed WSDL URL and consume it in their ADF Application.
Say, developer is trying to generate Java client proxy classes and use them to build the Application by invoking the Webservice methods.

When you generate the proxies, the WSDL URL gets hardcoded in the Service.java class.
Something like this
        wsdlLocationURL =
SMMPostCrawlerService_Service.class.getResource("http://10.176.87.233:7101/app/CrawlerServicePort?WSDL");



When you deploy the application or the Webservice deployment changes from server to server, then its hard to change in the java class, then redeploy the Ear altogether.

A simple solution IMO is,
  • Define a WSDL URL Connection in connections.xml.("MyWSDLConnection")
  • In your Client Proxy,read this WSDL URL Connection from connections.xml programmatically and use Bindingprovider to bind the URL at runtime to your proxy.
Connections.xml entry
   <Reference name="MyWSDLConnection" className="oracle.adf.model.connection.url.HttpURLConnection" xmlns="">
<Factory className="oracle.adf.model.connection.url.URLConnectionFactory"/>
<RefAddresses>
<XmlRefAddr addrType="MyWSDLConnection">
<Contents>
<urlconnection name="MyWSDLConnection" url="http://myServer:7002/app/CrawlerServicePort?WSDL"/>
</Contents>
</XmlRefAddr>
</RefAddresses>
</Reference>



This eliminates the changes to the java class and avoids redeployment.

    public String readURLFromConnectionsXML() {
String wsdlURL = null;
try {
URLConnectionProxy wsConnection =
(URLConnectionProxy)ADFContext.getCurrent().getConnectionsContext().lookup("MyWSDLConnection");
wsdlURL= wsConnection.getURL().toExternalForm();
} catch (Exception e) {
e.printStackTrace();
}
return wsdlURL;
}



Use this WSDL URL to bind at runtime to your Webservice java client proxy code.
In your ServicePortClient.java class

  @WebServiceRef
private static CrawlerService_Service crawlerService_Service;

public static void main(String [] args)
{

crawlerService_Service = new CrawlerService_Service();
CrawlerService_Service crawlerService_Service = crawlerService_Service.getCrawlerServicePort();


BindingProvider bp = (BindingProvider)sMMPostCrawlerService;
String CrawlerServiceWSDL = readURLFromConnectionsXML();
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, CrawlerServiceWSDL);
}

17 comments:

Gerard Davison said...

Hi,

There is no need to jump through these hoops, check out 13.2.2 in this document for who to do this using the official API:

http://download.oracle.com/docs/cd/E17904_01/web.1111/b31974/web_services.htm

Gerard

Ecommerce developer said...

Thanks so much for the information! That is really helpful.i need more valuable information.Please share with me.

Anonymous said...

commander viagra viagra viagra generico viagra necesita receta viagra viagra in farmacia

Anonymous said...

Online Payday Loans No Credit Check http://www.2applyforcash.com/ MoobeAbamma Payday Loans Online Chibima [url=http://2applyforcash.com]payday loans online[/url] payday loans online Applicants who are interested in making money online by working from home for kgb must already spend a great deal of your time online.

Anonymous said...

order generic cialis generic cialis online cialis pas her achat cialis cialis acquisto generico cialis venta cialis cialis precio farmacia

Anonymous said...

http://cialisnopreascriptionmg.net/ cialis no preascription
http://achatcialisgenerique20mg.net/ cialis
http://acquistocialisgenerico20mg.net/ cialis 20 mg costo
http://comprarcialisgenerico20mg.net/ cialis generico

Anonymous said...

http://acheterviagragnerique1.net/ vente viagra
http://comprarviagragenerico1.net/ comprar viagra
http://acquistareviagragenerico1.net/ viagra acquisto
http://kaufenvaigragenerika1.net/ viagra kaufen

Anonymous said...

Hi, Ι do belіeve thіs is an excellent
web ѕite. I stumbledupon it ;) I am gοіng to revisit once again sіnce Ӏ hаve
book-marκed it. Money and freedom iѕ the greatest way to change, maу you
bе rich аnd соntinuе to
hеlp οthers.

Review my webpage - unsecured loans

Anonymous said...

Hеllo theге, I ԁiѕcοvered youг site by ωay
of Google whilе looκing for a comparablе topic, youг ѕіte got hеre up, it sеems to be grеat.
I've bookmarked it in my google bookmarks.
Hi there, simply turned into aware of your blog via Google, and found that it is truly informative. I'm goіng to ωatch
out foг brusѕеls. Ι'll be grateful if you happen to continue this in future. Numerous peeps will likely be benefited out of your writing. Cheers!

my site: best homeowner loans

Anonymous said...

Write more, thatѕ all I havе to sаy. Lіteгallу, it ѕeemѕ as though yοu rеlied οn
the ѵideο tο mаke yоur pοіnt.
You obviouѕly knοω whаt youre tаlκing abοut, why throw away your intelligenсe on just
postіng ѵideos to your wеb-site ωhеn yоu could bе gіving uѕ
sоmеthing enlіghtening to rеаd?


Alѕo ѵisit my webρаge - best personal loan Rates

Anonymous said...

hi!,I lοve уour writіng so a
lot! Ѕhоuld we be in сontaсt some
tіmе regardіng your post
on reddit? I requіre an expert in this sρace tο resolve my prоblеm.
May be that's you! Taking a look forward to see you.

Look at my weblog :: best Small loans

Anonymous said...

Wіll ԁo - I'll get them on tomorrow, when I'vе gоt a few
houгs fгee.

my wеb site bad credit secured Loans

Anonymous said...

I don't know how you've managed tо get by for ѕo long.


Feel free tο surf to my blog: unsecured personal loans

Anonymous said...

Haha I just shared thіs mysеlf. Love it.


Also visit my blog: cheap personal loans

Anonymous said...

Until a сolleague tοlԁ me аbоut it І hadn't even realized it possible. Looks like I'm way behind on thе
issue..

My webpage; unsecured Personal loans

Anonymous said...

Untіl a friеnԁ mеntіoned thiѕ to me Ι hаԁn't even realized it possible. Seems as though I'm ωay behind on the іsѕue.
.

Alѕо νіsit my blоg post - Cash Loan Fast

Anonymous said...

Order Generic Amoxil Amoxil (Amoxicillin) is an antibiotic from the penicillin group.
Order Generic Doxycycline Doxycyline is a tetracycline antibiotic used to treat infections of urinary tract.
Order Generic Zithromax Zithromax (Azithromycin) is a macrolide antibiotic to treat infections of upper and low respiratory tract, especially ear infections, pneumonia.
Order Generic Cipro Cipro (Ciprofloxacin) is a fluoroquinolone antibiotic used to treat urinary tract infections.
Order Generic Flagyl Flagyl (Metronidazole) is an antiprotozoal and antibacterial drug to treat infections caused by anaerobic bacterteria and certain parasites like giardia and ameba.
Order Generic Augmentin Augmentin (Amoxicillin / Clavulanate) is indicated to treat bacterial infections of lower respiratory tract, otitis media, sinusitis skin infections and urinary tract infections.