I'm working under a AS400 system using Java 1.4.2, to get an XML but when I do the request using getOutputStream() I got an IOException and the message only returns the domain of the provider.
Here a part of my code:
try {
url = new URL("https://test.example.it/27/xml/"); //Example URL...
} catch(MalformedURLException exMAL) {
return exMAL.getMessage();
}
//Set parameters
LinkedHashMap params = new LinkedHashMap();
params.put("id", id);
params.put("password", password);
...
params.put("description", description);
String data = "";
Set set = params.entrySet();
Iterator i = set.iterator();
//Create URL of parameters
while(i.hasNext()){
if(data != ""){
data += "&";
}
Map.Entry me = (Map.Entry)i.next();
data += me.getKey() + "=" + me.getValue();
}
try {
//Create connection
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
//Do request
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); //Error here
wr.write(data);
wr.flush();
//Get resource
InputStream is = conn.getInputStream();
outputData = readAll(is);
} catch (IOException ioEx) {
return "ERROR IOException: " + ioEx.getMessage();
}
And the message error is "ERROR IOException: test.example.it".
I tested my code in a computer with Windows XP, Netbeans 4.1, Java 1.4.2 Build 19 (the same in the AS400) and I get the XML without problems.
I can compile my code into the AS400 but when I run the class in QSHELL or using a RPG Program i get the error.
Somebody knows what else I have to do or why I get this error?
Thanks!
EDIT:
Its a POST method, and actually I included setDoInput and setDoOutput in the code.
Now printing the exception I get this:
java.net.UnknownHostException: test.example.it
ERROR IOException: test.example.it
EDIT:
Looks like nslookup doesn't resolve the domain but after that I retry using the IP and now I have this error...
java.net.SocketException: The value specified for the argument is not correct.
ERROR IOException: The value specified for the argument is not correct.
I think it would be a problem with AS400 security, probably should I add this domain in a list or edit a system value?
EDIT:
Using TCPCFG and then option 10, in this table of hosts I don't have the domain test.example.it, I suppose that I need to add this domain and IP, isn't it?
EDIT:
The version is V6R1M0. I added the IPs (Option 10. Work with TCP/IP host table entries) and now the AS400 resolve the domain but now I have a new problem.
java.net.ConnectException: A remote host refused an attempted connect operation.
In the option 12 I have *SAME in all the options. For option 1 the following:
Internet Subnet Line Line Opt Address Mask Description Type 127.0.0.1 255.0.0.0 *LOOPBACK *NONE 151.208.xxx.xx 255.255.255.0 ETHLINE *ELAN
I found in a group this: "Is the 8080 port on the 400. Is the 400 setup to accept 8080 traffic via SSL".
How can I able the 400 to accept traffic?
Finally I resolve my problem, adding the IP and Domain in the host table (as I mentioned in a edit) but here is another problem.
The provider gave me one IP for requests and two more IPs for responses, an I added the three IPs with the same domain in the host table. I deleted two of three IPs and then I tried using only the IP for request and it worked!
Now the problem is that the request via Java is too slow! but that's another topic. Thank you very much for all.