Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Axis Basic Autentication

843833Nov 19 2007
Hello,

I have created an Axis webServices, that must send an HTTP request, with in header "Basic" authentication.
How Can I do?

This is my code:
//sUrl="http://81.174.52.34:7800/thor/pratica/Service.asmx";
java.net.URL url = new java.net.URL(sUrl);
PraticaSoapStub binding = (PraticaSoapStub) new PraticaLocator().getpraticaSoap(url);

MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage message = messageFactory.createMessage();

SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();

String username = "eminds";
String password = "emindspass";

String authorization = new sun.misc.BASE64Encoder().encode((username+":"+password).getBytes());
javax.xml.soap.MimeHeaders hd = message.getMimeHeaders();
hd.addHeader("Authorization", "Basic " + authorization);

// start: setting SOAP headers - optional, comment out if not needed
// Create and populate the header
SOAPHeader header = message.getSOAPHeader();
if (header == null)
header = envelope.addHeader();

SOAPHeaderElement he = header.addHeaderElement(envelope.createName("foo", "ns1", "http://localhost/SOAPHeader"));
he.setMustUnderstand(false);
he.setValue("bar");

// binding.setHeader((org.apache.axis.message.SOAPHeaderElement)he);
binding.setHeader (new PraticaLocator().getServiceName().getNamespaceURI(), "SOAPHeaderElement", he);
binding.setMaintainSession(true);
res = binding.login(reqLogin);

But I have errorfrom webservice, somthing like this: "error of Authorization"!!

How Can I do?

Thanks,
FRancesco
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 17 2007
Added on Nov 19 2007
0 comments
203 views