You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Murali Krishnan <cm...@yahoo.com> on 2007/10/11 18:29:37 UTC
how to add basic auth header to soap request
Hi all,
I'm trying to add a Basic Auth header to the outgoing soap request, but I'm not seeing it in the list of headers. This is the code I'm using. Is there something wrong?
ServiceClient client = new ServiceClient();
Options options = new Options();
HttpTransportProperties.Authenticator basicAuth = new HttpTransportProperties.Authenticator();
basicAuth.setUsername("xxxxxxx");
basicAuth.setPassword("xxxxxxx");
options.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, basicAuth);
options.setAction("urn:echo");
options.setTo(new EndpointReference(args[0]));
client.setOptions(options);
OMElement response = client.sendReceive(getPayload("Dummy"));
System.out.println(response);
Outgoing SOAP request: (captured with tcpmon)
====================
POST /web/wss11/services/Services_EchoWSD HTTP/1.1
Content-Type: text/xml; charset=UTF-8
SOAPAction: "urn:echo"
User-Agent: Axis2
Host: 127.0.0.1:5050
Transfer-Encoding: chunked
f0
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Body>
<input>Dummy</input>
</ns1:echo>
</soapenv:Body>
</soapenv:Envelope>0
____________________________________________________________________________________
Take the Internet to Go: Yahoo!Go puts the Internet in your pocket: mail, news, photos & more.
http://mobile.yahoo.com/go?refer=1GNXIC
Re: how to add basic auth header to soap request
Posted by Giao <gq...@yahoo.com>.
Try this.
....
HttpTransportProperties.Authenticator basicAuth = new
HttpTransportProperties.Authenticator();
List<String> auth = new ArrayList<String>();
basicAuth.setAuthSchemes(auth);
auth.add(HttpTransportProperties.Authenticator.BASIC);
basicAuth.setPreemptiveAuthentication(true);
options.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE,
basicAuth);
...
It works for me.
Giao Nguyen
--- Murali Krishnan <cm...@yahoo.com> wrote:
> Hi all,
> I'm trying to add a Basic Auth header to the
> outgoing soap request, but I'm not seeing it in the
> list of headers. This is the code I'm using. Is
> there something wrong?
>
> ServiceClient client = new ServiceClient();
> Options options = new Options();
>
> HttpTransportProperties.Authenticator
> basicAuth = new
> HttpTransportProperties.Authenticator();
> basicAuth.setUsername("xxxxxxx");
> basicAuth.setPassword("xxxxxxx");
>
>
options.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE,
> basicAuth);
>
> options.setAction("urn:echo");
> options.setTo(new
> EndpointReference(args[0]));
>
> client.setOptions(options);
>
> OMElement response =
> client.sendReceive(getPayload("Dummy"));
>
> System.out.println(response);
>
>
> Outgoing SOAP request: (captured with tcpmon)
> ====================
> POST /web/wss11/services/Services_EchoWSD HTTP/1.1
> Content-Type: text/xml; charset=UTF-8
> SOAPAction: "urn:echo"
> User-Agent: Axis2
> Host: 127.0.0.1:5050
> Transfer-Encoding: chunked
>
> f0
> <?xml version='1.0' encoding='UTF-8'?>
>
> <soapenv:Body>
>
> <input>Dummy</input>
> </ns1:echo>
> </soapenv:Body>
> </soapenv:Envelope>0
>
>
>
>
>
>
____________________________________________________________________________________
> Take the Internet to Go: Yahoo!Go puts the Internet
> in your pocket: mail, news, photos & more.
> http://mobile.yahoo.com/go?refer=1GNXIC
____________________________________________________________________________________
Catch up on fall's hot new shows on Yahoo! TV. Watch previews, get listings, and more!
http://tv.yahoo.com/collections/3658
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org
Re: how to add basic auth header to soap request
Posted by Giao <gq...@yahoo.com>.
Forgot. You need Java 1.5 or higher.
Try this.
....
HttpTransportProperties.Authenticator basicAuth = new
HttpTransportProperties.Authenticator();
List<String> auth = new ArrayList<String>();
basicAuth.setAuthSchemes(auth);
auth.add(HttpTransportProperties.Authenticator.BASIC);
basicAuth.setPreemptiveAuthentication(true);
basicAuth.setUsername("USER");
basicAuth.setPassword("PASSWORD");
options.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE,
basicAuth);
...
It works for me.
Giao Nguyen
--- Murali Krishnan <cm...@yahoo.com> wrote:
> Hi all,
> I'm trying to add a Basic Auth header to the
> outgoing soap request, but I'm not seeing it in the
> list of headers. This is the code I'm using. Is
> there something wrong?
>
> ServiceClient client = new ServiceClient();
> Options options = new Options();
>
> HttpTransportProperties.Authenticator
> basicAuth = new
> HttpTransportProperties.Authenticator();
> basicAuth.setUsername("xxxxxxx");
> basicAuth.setPassword("xxxxxxx");
>
>
options.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE,
> basicAuth);
>
> options.setAction("urn:echo");
> options.setTo(new
> EndpointReference(args[0]));
>
> client.setOptions(options);
>
> OMElement response =
> client.sendReceive(getPayload("Dummy"));
>
> System.out.println(response);
>
>
> Outgoing SOAP request: (captured with tcpmon)
> ====================
> POST /web/wss11/services/Services_EchoWSD HTTP/1.1
> Content-Type: text/xml; charset=UTF-8
> SOAPAction: "urn:echo"
> User-Agent: Axis2
> Host: 127.0.0.1:5050
> Transfer-Encoding: chunked
>
> f0
> <?xml version='1.0' encoding='UTF-8'?>
>
> <soapenv:Body>
>
> <input>Dummy</input>
> </ns1:echo>
> </soapenv:Body>
> </soapenv:Envelope>0
>
>
>
>
>
>
____________________________________________________________________________________
> Take the Internet to Go: Yahoo!Go puts the Internet
> in your pocket: mail, news, photos & more.
> http://mobile.yahoo.com/go?refer=1GNXIC
____________________________________________________________________________________
Be a better Globetrotter. Get better travel answers from someone who knows. Yahoo! Answers - Check it out.
http://answers.yahoo.com/dir/?link=list&sid=396545469
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org