• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

basic http authentication

 
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello. If anybody has a minute, I need to send a post request with basic http authentication included in the header. Do i have to encode the user name/password pair? Is this roughly how I would do it?...

urlconn is an httpurlconnection...

urlconn.setRequestProperty("Authorization", "Basic " + encode(user_name +":"+ user_password));


then the seperate method to encode the username/password pair...

public static String encode (String source) {
BASE64Encoder enc = new sun.misc.BASE64Encoder();
return(enc.encode(source.getBytes()));
}


I tried this but i keep getting an http 500 response code from the server.

Thank you very much.
[ July 19, 2006: Message edited by: Tom Griffith ]
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks good to me. But 500 is a server error, while the proper response for authorization denied would be 401, so maybe something else entirely is going wrong on the server.
 
Tom Griffith
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ulf, would it throw a 500 error if it had a problem with the SOAP/xml format or the http headers i'm sending to it? Just for kicks, I changed the url to something innocuous that didn't have any service, like www.yahoo.com, and posted to it...i received a 501 error back, saying it was an unsupported request. That tells me somehow yahoo could decipher the http headers and SOAP/xml enough to know it doesn't run the service...

these are the request headers i'm setting...do you see anything obviously funny with any of this?...and even so, would it cause the server to throw a 500 response back?...

urlconn is the httpurlconnection to the service...

urlconn.setDoOutput (true);
urlconn.setDoInput (true);
urlconn.setUseCaches (false);
urlconn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
urlconn.setRequestProperty("Content-Length",String.valueOf(xmlcode.length()));
urlconn.setRequestProperty("Authorization", "Basic " + encode(user_name +":"+ user_password));
urlconn.setRequestMethod("POST");


then the hard-coded SOAP xml, for this connection test...

String xmlcode="<?xml version=\"1.0\" encoding=\"UTF-8\"?> " +
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
"<soapenv:Body>" +
"<OpenCustomer xmlns=\"\">" +
"<GeneralData xsi:type=\"ns1:ItemInfo\" xmlns:ns1=\"http://www.mystore.com/MyWebService/\">" +
"<OrderDate xsi:type=\"xsd:string\">6/2/2006</OrderDate>" +
"<ReceiptDate xsi:type=\"xsd:string\"></ReceiptDate>" +
...

thank you again.
[ July 19, 2006: Message edited by: Tom Griffith ]
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An HTTP error shouldn't be thrown by a web service (unless it's badly implemented, which is of course a possibility); it sounds more likely that the WS never gets to see the request.

Are you sure that Content-Type "text/xml" is correct for SOAP requests? This page suggests "application/soap+xml".
 
Tom Griffith
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ulf, i was able to print out the error stream..it's yelling at me..

<faultstring>no SOAPAction Header!</faultstring>

we talked about this yesterday, remember, i think at the end of this thread...when I pondered about two of the four operations not having a soap action namespace tied to them...

https://coderanch.com/t/222934/Web-Services/java/Posting-webservice

I assume these guys made the SOAPAction namespace mandatory somehow for the incoming requests...hmm, i wonder if this is possible, and if this "hunch" of mine is right...would SOAPAction be required for only the two operations that have a soap action namespace indicated in the wsdl?...then i leave the header off for the two operations that don't have a soap action namespace in the wsdl...

man, i am going to do all this with axis stubs once i can get this brute force operation working...
[ July 19, 2006: Message edited by: Tom Griffith ]
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SOAPAction is not required in general, but it may be required by this particular WS. Only way to find out is to ask the people who run it. They should be able to provide you with all the particulars of how to access the service.
 
Tom Griffith
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah, i sent them an email inquiring about this...it's now trying to parse the xml which is good...but i don't get why it's tossing a parse exception..it sez <GeneralData> needs a closing tag...and this is the xml string i hardcoded in (although i doubt this will be a problem when this works in lotus notes because i will just assign a document field containing all the xml to a String object and won't have to hardcode it)...

"<GeneralData xsi:type=\"ns1:ItemInfo\" xmlns:ns1=\"http://www.mystore.com/MyWebService/\">" +
"<OrderDate xsi:type=\"xsd:string\">6/2/2006</OrderDate>" +
"<ReceiptDate xsi:type=\"xsd:string\"></ReceiptDate>" +
...
"</GeneralData>

I can't figure out why it's thrown off by the nested tag...
 
Today's lesson is that you can't wear a jetpack AND a cape. I should have read this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic