FedEx Sun One server does not allow POST
Hello,
I am attempting to communicate with FedEx's Direct XML Track. They use a Sun One Server v. 6.1 w/ SSL. When I do a POST with my XML document, I get back a 504, Method Not Allowed. Have communicated with FedEx technical support to no avail. Have downloaded server 6.1 and installed, trying to reverse-problem solve. Cannot see anywhere in the server where POSTs might be set to prohibited. The FedEx documentation specifically says to use a POST, which of course makes sense. Has anyone successfully used FedEx XML Direct, and/or could supply me with a hint as to why this might be happening? Also, am URL-encoding the reuest. Here's the code:
public class FedexHTTPS {
static final int HTTPS_PORT = 443;
public static String enc = "encoding='UTF-8'";
public static String subRequest = "<?xml version = '1.0' encoding = 'UTF-8'?><RequestHeader><AccountNumber>xxxxxxxxx</AccountNumb er></RequestHeader><Contact><PersonName>name </PersonName><CompanyName>Ubercom</CompanyName><Department >ActiveIdentity</Department><PhoneNumber>xxxx</PhoneNumber> <E-MailAddress>anyname@uber.com</E-MailAddress></Contact><A ddress><Line1>12 main st</Line1><Line2/><City>Leesburg</City><StateOrProvi nceCode>VA</StateOrProvinceCode><PostalCode>20111</PostalCode& gt;<CountryCode>US</CountryCode></Address></FDXSubscription Request>>";
public static String address = "gatewaybeta.fedex.com";
public static void main(String argv[]) throws Exception {
String encData=null;
try {
encData = URLEncoder.encode(subRequest,"UTF-8");
} catch (Exception ex){
System.out.println("Exception: " + ex.getMessage());
}
//System.out.println(encData);
int length = encData.length();
// Get a Socket factory
SocketFactory factory = SSLSocketFactory.getDefault();
// Get Socket from factory
Socket socket = factory.createSocket(address, HTTPS_PORT);
/*BufferedWriter out = new BufferedWriter(new
OutputStreamWriter(socket.getOutputStream())); */
BufferedReader in = new BufferedReader(
new InputStreamReader(socket.getInputStream()));
OutputStream out = socket.getOutputStream();
String xmlEnc = "application/x-www-form-urlencoded";
String msg = "GET / HTTP/1.0\r\nContent-Length: " + length
+ "\r\nContent-Type: image/gif"
+ "\r\nReferer: www.EDS.com"
+ "\r\nHost: SSLserver.fedex.com"
+ "\r\nAccept-Encoding: image/jpeg"
+ "\r\nAccept: application/x-www-form-urlencoded, image/gif,image/jpeg,image pjpeg, text/plain,text/html/,*/*"
+ "\r\n\r\n" ;
out.write(msg.getBytes());
out.flush();
String line;
StringBuffer sb = new StringBuffer();
while((line = in.readLine()) != null) {
sb.append(line);
}
out.close();
in.close();
System.out.println(sb.toString());
}
}
[3005 byte] By [
dglhkea] at [2007-11-27 11:15:52]

# 1
Maybe I'm missing something obvious, but I don't see where your code is doing a POST.
I also don't see where you pass the data to the FedEx server. I do see a GET of /, but not POST of encData.
You sure you're sending things right?
# 2
My apologies. I was changing code in desperation to get something to work. Here is the correct code fragment:
BufferedReader in = new BufferedReader(
new InputStreamReader(socket.getInputStream()));
OutputStream out = socket.getOutputStream();
String xmlEnc = "application/x-www-form-urlencoded";
String msg = "POST / HTTP/1.0\r\nContent-Length: " + length
+ "\r\nContent-Type: application/x-www-form-urlencoded"
+ "\r\nReferer: www.EDS.com"
+ "\r\nHost: SSLserver.fedex.com"
+ "\r\nAccept-Encoding: image/jpeg, application/x-www-form-urlencoded"
+ "\r\nAccept: application/x-www-form-urlencoded, image/gif,image/jpeg,image pjpeg, text/plain,text/html/,*/*"
+ "\r\n\r\n" + encData;
out.write(msg.getBytes());
out.flush();
# 3
Hi
Quick observation is that your xml isnt well formed.
I dont know if you need to have a trailing \n at the end of your request, I tend to avoid writing raw http connections these days.
Personally, I'd suggest something like the Jakarta Commons Httpclient (dont know if thats a neddy no-no on this forum!! :)
Takes all of the mystery about creating http requests and also has useful features around connection timeouts etc.
see a little code sample
String instr="<myxml/";
PostMethod post = new PostMethod("http://myhost");
post.setRequestEntity(new StringRequestEntity(instr, "text/xml", "UTF-8"));
post.setRequestHeader("Connection", "close");
HttpClientParams params = new HttpClientParams();
params.setSoTimeout(1000); // 1 sec timeout
SimpleHttpConnectionManager manager = new SimpleHttpConnectionManager();
HttpConnectionManagerParams conparams = new HttpConnectionManagerParams();
conparams.setSoTimeout(1000);
conparams.setConnectionTimeout(1000);
manager.setParams(conparams);
HttpClient httpclient = new HttpClient(params,manager);
int code = httpclient.executeMethod(post);
String restr = new String(post.getResponseBody(),"UTF-8");
Might look like a lot, but they've put a good deal of work into handling chunked responses, authentication (including pre-emptive auth), ssl, certs etc.
We use it in a production capacity and are very happy with it.>
# 4
I cleaned up the XML (thanks) and re-did using jakarta - still get the 504 Not Allowed....
public class FedexPost {
public static String subRequest = "<?xml version="1.0" encoding="UTF-8"?><FDXSubscriptionRequest><RequestHeader><AccountNumber>1111111111</AccountNumber></RequestHeader><Contact><PersonName>name</PersonName><CompanyName>EDS</CompanyName><Department>ActiveIdentity</Department><PhoneNumber>7037773333</PhoneNumber><E-MailAddress>my.name@any.com</E-MailAddress></Contact><Address><Line1>10 Main St</Line1><Line2/><City>Anytown</City><StateOrProvinceCode>VA</StateOrProvinceCode><PostalCode>20175</PostalCode><CountryCode>US</CountryCode></Address></FDXSubscriptionRequest>";
public FedexPost() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String encData=null;
try {
encData = URLEncoder.encode(subRequest,"UTF-8");
} catch (Exception ex){
System.out.println("Exception: " + ex.getMessage());
}
// TODO code application logic here
HttpClient httpclient = new HttpClient();
PostMethod httpsPost = new PostMethod("https://gatewaybeta.fedex.com/");
httpsPost.setRequestHeader("Connection", "close");
try {
httpsPost.setRequestEntity(new StringRequestEntity(encData, "application/x-www-form-urlencoded", "UTF-8"));
httpclient.executeMethod(httpsPost);
System.out.print(httpsPost.getStatusLine());
System.out.println(httpsPost.getResponseBodyAsString());
}
catch (IOException ex) {
System.out.println(ex.getMessage());
}
finally {
httpsPost.releaseConnection();
}
}
}
# 5
504 is gateway timeout and 405 is method not allowed which one are you getting? Are you sure that everybody has appropriate rights to post data?
Can you send the same POST request using telnet ? (calculate length of xml and put in place of xxx)
$telnet hostname port
POST / HTTP/1.0
Content-type: txt/xml
Connection: close
Content-Length: xxx
Referer: www.EDS.com"
Host: SSLserver.fedex.com"
Accept-Encoding: image/jpeg, application/x-www-form-urlencoded
Accept: application/x-www-form-urlencoded, image/gif,image/jpeg,image pjpeg, text/plain,text/html/,*/*
<?xml version="1.0" encoding="UTF-8"?>
<FDXSubscriptionRequest>
<RequestHeader>
<AccountNumber>1111111111</AccountNumber>
</RequestHeader>
<Contact>
<PersonName>name</PersonName>
<CompanyName>EDS</CompanyName>
<Department>ActiveIdentity</Department>
<PhoneNumber>7037773333</PhoneNumber>
<E-MailAddress>my.name@any.com</E-MailAddress>
</Contact>
<Address>
<Line1>10 Main St</Line1>
<Line2/>
<City>Anytown</City>
<StateOrProvinceCode>VA</StateOrProvinceCode>
<PostalCode>20175</PostalCode>
<CountryCode>US</CountryCode>
</Address>
</FDXSubscriptionRequest>
mva at 2007-7-29 14:15:49 >

# 6
Sorry - yes, it is a 405 -- getting "HTTP/1.1 405 Method Not Allowed<HTML><HEAD><TITLE>Method Not Allowed</TITLE></HEAD>
<BODY><H1>Method Not Allowed</H1"
I have properly registerd with FedEx and have proper credentials, should be working. The server is SSL-secured, so in order to use telnet, will have to get some package that handles SSL. Any recomendations of open-source or trial packages?
thanks...>
# 7
I don't know the answer to that question. I just use browser or telnet !!!
You can take a backup of your server installation directory disable ssl and see if it works for a normal server and try a POST then enable it again so we can rule out configuration issues.
You can run server at log-level "finest" to see if there is anything in error logs.
If you remember tell us what changes you had made to the server after installation and how OR you can post configuration files (magnus.conf, server.xml, obj.conf,web.xml etc. whatever you have changed) we can see what's wrong.
mva at 2007-7-29 14:15:49 >

# 8
Thank you. It got lost in the trail further up, but I'm trying to connect to a Fedex server not under my control... All I can get from them is "POST should work"Tried using telnet from IE, using "telnet://gatewaybeta.fedex.com:443" did not work - have you had success connecting to servers with SSL with telnet?
# 9
Just a quick question. Where you are calling SSLserver.fedex.com is that literally the name of the server you want to call? I thought you were trying to call gatewaybeta.fedex.com.