• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

USPS Web Service

 
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Has anybody successfully written a WS client that access the USPS Web Service?

The service is cool in principle, but there isn't much documentation.

http://www.usps.com/webtools/address.htm

Look forward to any replies.

Thanks.

-- Mike
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A couple of years ago I implemented both the automatic generation of shipment files (that interfaces with the Worldship program, though, not the WS), and the automatic retrieval of delivery statuses via the WS. I did get started by the Java examples that are online, but the service may have changed since (although I doubt it). Do you have any particular questions?
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,

Thanks for writing back.

Yes, I have a couple questions.

I'm trying to get started with the address verification API.

The USPS requires that you verify you can connect to their site before they will switch you to the "production" server.

I'm not sure, from the doucumentation how to actually do this initial connection. I do have an account, but it's not clear to me if "verification" means I just need to pack up some URL line with parameters and send it to them with my ID embedded or if I need to write some code.

Then, I couldn't find any Java examples of how to package up a SOAP request, ship it off and how to unpack it when it returns.

I bet it's pretty simple; I'm just having trouble getting started.

Any help or suggestions would be greatly appreciated. <s>

Thanks again.

-- Mike
 
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
D'oh! I read your initial post a bit too quickly - what I was accessing was UPS, not USPS, about which I have no clue. Sorry about that.
 
Ranch Hand
Posts: 2108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mike,

I looked at http://www.usps.com/webtools/_pdf/Address-Information.pdf.

It looks like the client will send an xml as an html parameter. It doesnt use soap.

For that reason, maybe you can test right now, by pasting the below at your browser url input, and press enter:

http://SERVERNAME/ShippingAPITest.dll?API=Verify&XML=<AddressValidateRequest%20USERID="xxxxxxx"%20PASSWORD="xxxxxxx"><Address ID="0"><Address1></Address1>
<Address2>6406 Ivy Lane</Address2><City>Greenbelt</City><State>MD</State>
<Zip5></Zip5><Zip4></Zip4></Address></AddressValidateRequest>

I got this from the documentation I mentioned above.

Replace the SERVERNAME, xxxxxxx and xxxxxxx for the approriate value(server, user, password). And input the address details that you want.

In addition, the entire xml string must be url-encoded. This is quite expected, as it is an html url parameter. For this one, I am not familiar with url encoding; I see spaces in the sample above so you might need to manually url-encode it now before sending it.

Other than that, I think you can test it now.

That pdf seems to give enough details, but is implemented in microsoft technology. So instead of the microsoft dom codes, you might use java. As I have mentioned, it looks like it is pure xml, no soap.

The user and password are exposed, so I think you will have some additional stuff in production, like https.
 
Jesus Angeles
Ranch Hand
Posts: 2108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you start coding in java, you will need a java implementation of dom, to build the xml. (like those you use in coding in book Beginning Java WEb Services. The book also has sample codes on parsing using dom, which you can imitate in processing the xml reply)

And then send the html request, along with the html parameters required, like the API parameter (e.g. API=Verify), and the XML(the xml you built)

I am not familiar how to send the html request via java code; maybe via java http connection classes. Also, that class might have methods to encode the url for you.
[ January 08, 2006: Message edited by: Jesus Angeles ]
 
Jesus Angeles
Ranch Hand
Posts: 2108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I were you, I try run in using microsoft first, as they have given runnable sample codes. You just cut and paste from that pdf.

After that, you can convert to java codes.
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.

I got the Java Web Services book at your suggestion, but was disappointed that the very first example I downloaded from their site didn't work. I tried with two different versions of xerces.

I supposed I'd really use JDOM in practice anyway. <s>

Thanks for your other suggestions.

-- Mike
 
Jesus Angeles
Ranch Hand
Posts: 2108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I saw your posts.

I did the chapter 2 handsons last week. And I wouldnt have been able to run the first one without your posts. The null trick did it. But all the other codes in the chapter went flawlessly.

This chapter 2 has codes that both build xml via dom, and parse an xml using dom(to process it).
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cool, thanks.

Based on your success, I'll press on with the book <s>

Are there any cool (& useful) Web Services you use that there's Java code for? I haven't looked that far into the book yet so there may be code there.

Thanks again!!!

-- Mike
 
Greenhorn
Posts: 10
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike London wrote:Has anybody successfully written a WS client that access the USPS Web Service?

The service is cool in principle, but there isn't much documentation.

http://www.usps.com/webtools/address.htm

Look forward to any replies.

Thanks.

-- Mike



This is an old post I'm replying to but info is kind of sparse even now for Java and USPS web tools. Today I got the zip code lookup API working in Java. I used Groovy for the XML part. Here is the Groovy part for putting an address into the required XML form
The user ID is obtained at the USPS web site https://www.usps.com/business/webtools.htm ... Once you register you get access to their test server.



Here is the Groovy code for parsing the XML back into fields

 
Life just hasn't been the same since the volcano erupted and now the air is full of tiny ads.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic