Jagathees - Thursday, April 28, 2016 7:57 AM:
I am trying to connect aras and excecute the follwing SOAP request in Java.
<SOAP-ENV:Envelope xmlns:SOAP-ENV="schemas.xmlsoap.org/.../"><SOAP-ENV:Body><ApplyItem><Item type="Part" levels="0" action="get" id="9D661AD2C3E74F0694E4E8B8AAB39D0A"></Item></ApplyItem></SOAP-ENV:Body></SOAP-ENV:Envelope>
my JAVA code is
try {
URL u = new URL("localhost/InnovatorServer");
URLConnection uc = u.openConnection();
HttpURLConnection connection = (HttpURLConnection) uc;
String boundary = "-------------------------BRdnIy5hBONlyI";
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", " Content-Type: application/soap+xml;charset=UTF-8;action="www.aras.com/ApplyItem"");
OutputStream os = connection.getOutputStream();
String content = "--"+boundary +" Content-Disposition: form-data; name="SOAPACTION"; Content-Type: text/plain ApplyItem ";
os.write(content.getBytes());
content = "--"+boundary +" Content-Disposition: form-data; name="AUTHUSER"; Content-Type: text/plain admin ";
os.write(content.getBytes());
content = "--"+boundary +" Content-Disposition: form-data; name="AUTHPASSWORD"; Content-Type: text/plain 607920b64fe136f9ab2389e371852af2 ";
os.write(content.getBytes());
content = "--"+boundary +" Content-Disposition: form-data; name="DATABASE"; Content-Type: text/plain InnovatorSolutions ";
os.write(content.getBytes());
content = "--"+boundary +" Content-Disposition: form-data; name="XMLDATA"; Content-Type: text/plain ";
content += "<SOAP-ENV:Envelope xmlns:SOAP-ENV='schemas.xmlsoap.org/.../'>";
content += " <SOAP-ENV:Body>";
content += " <ApplyItem>";
content += " <Item type='Part' levels='0' action='get' id='9D661AD2C3E74F0694E4E8B8AAB39D0A'>";
content += " </Item>";
content += " </ApplyItem>";
content += " </SOAP-ENV:Body>";
content += "</SOAP-ENV:Envelope> ";
String sdc = " Content-Type: application/soap+xml;charset=UTF-8;action="www.aras.com/ApplyItem"";
os.write(content.getBytes());
os.flush();
os.close();
System.out.println(content);
InputStream in = connection.getInputStream();
int c;
while ((c = in.read()) != -1) System.out.write(c);
in.close();
}
catch (IOException e) {
e.printStackTrace();
System.err.println(e);
}
But above code is not working. how to execute this SOAP request in JAVA
Jagathees - Thursday, April 28, 2016 8:07 AM:
I am getting
java.io.IOException: Server returned HTTP response code: 405 for URL: localhost/InnovatorServer
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
RobMcAveney - Thursday, April 28, 2016 8:30 AM:
Try:
URL u = new URL("localhost/.../InnovatorServer.aspx";");
Jagathees - Thursday, April 28, 2016 9:13 AM:
Getting Database is not avaliable error in SOAP Response.
<SOAP-ENV:Envelope xmlns:SOAP-ENV="schemas.xmlsoap.org/.../"><SOAP-ENV:Body><SOAP-ENV:Fault xmlns:af="www.aras.com/.../faultcode><faultstring><![CDATA[The Database is not available.]]></faultstring><detail><af:legacy_detail><![CDATA[The Database is not available.]]></af:legacy_detail><af:exception message="The Database is not available." type="Aras.Server.Core.InnovatorServerException" /></detail></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Enve
InnovatorServerConfig.XML
<DB-Connection id="InnovatorSolutions" database="InnovatorSolutions" server="(local)MYSQLSERVER" uid="innovator" pwd=""/>
RobMcAveney - Thursday, April 28, 2016 10:50 AM:
Are you able to log in with other clients (web client, nash, etc.)?
Jagathees - Thursday, April 28, 2016 11:27 AM:
Yes . I am able to do login with other clients
RobMcAveney - Thursday, April 28, 2016 11:51 AM:
I don't see anything obviously wrong with your code that would produce this error. The error generally means that the database definition exists in InnovatorServerConfig.xml, but the server cannot access it due to a connectivity or credential issue.
Camarillo - Thursday, May 5, 2016 5:13 AM:
I am trying something similar, and I receive exactly the same errors shown by Jagathees. I have seen that for VB or C there is the IOM.dll with the method IomFactory.CreateHttpServerConnection which manages the connexion to the Server. Actually it is the one used by AML Studio, and it connects without any problem with my server. Is there any similar for JAVA?
Thanks!
RobMcAveney - Thursday, May 5, 2016 8:33 AM:
I found another version of a simple Java client. Try the following:
public class sendArasRequest {
public static void main(String[] args) throws Exception{
String innovatorServer = "localhost/.../InnovatorServer.aspx";
String database = "InnovatorSolutions";
String userName = "admin";
String password = "innovator";
String request = "<AML><Item type='Sequence' action='get' select='name' page='1' pagesize='5'/></AML>";
String nameSpace = "www.aras-corp.com/";
String remoteMethod = "ApplyAML";
String characterEncoding = "UTF-8";
String SOAPmessage = "<SOAP-ENV:Envelope xmlns:SOAP-ENV='schemas.xmlsoap.org/.../' encodingStyle='schemas.xmlsoap.org/.../'><SOAP-ENV:Body><" remoteMethod " xmlns:m='"+nameSpace+"'>" + request + "</"+remoteMethod+"></SOAP-ENV:Body></SOAP-ENV:Envelope>";
// Create new URL object and HttpURLConnection object
java.net.URL url = new java.net.URL(innovatorServer);
java.net.HttpURLConnection httpConnection = (java.net.HttpURLConnection) url.openConnection();
// Convert the message to a byte array
byte[] messageBytes = SOAPmessage.getBytes();
// Set headers
httpConnection.setRequestProperty("Content-Length", String.valueOf(messageBytes.length));
httpConnection.setRequestProperty("Content-Type","text/xml; charset=" + characterEncoding + """);
httpConnection.setRequestProperty("SOAPAction", remoteMethod);
httpConnection.setRequestMethod("POST");
httpConnection.setRequestProperty("AUTHUSER", userName);
httpConnection.setRequestProperty("AUTHPASSWORD", MD5(password));
httpConnection.setRequestProperty("DATABASE", database);
httpConnection.setDoInput(true);
httpConnection.setDoOutput(true);
// Write and send the SOAP message
java.io.OutputStream out = httpConnection.getOutputStream();
out.write(messageBytes);
out.close();
// Read server response
java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(httpConnection.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
}
}
public static String MD5(String s) throws Exception{
java.security.MessageDigest m = java.security.MessageDigest.getInstance("MD5");
m.update(s.getBytes(),0,s.length());
return new java.math.BigInteger(1,m.digest()).toString(16);
}
}
Jagathees - Thursday, May 5, 2016 9:26 AM:
The above code works for me if I am pointing Aras Url to my Server. If I am trying to Connect to Local machine getting below error.
<SOAP-ENV:Envelope xmlns:SOAP-ENV="schemas.xmlsoap.org/.../"><SOAP-ENV:Body><SOAP-ENV:Fault xmlns:af="www.aras.com/.../faultcode><faultstring><![CDATA[The Database is not available.]]></faultstring><detail><af:legacy_detail><![CDATA[The Database is not available.]]></af:legacy_detail><af:exception message="The Database is not available." type="Aras.Server.Core.InnovatorServerException" /></detail></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
When I connect to server,I got response in 1 or 2 sec. But in local it's took more than 5 mins to get the above response.
Camarillo - Thursday, May 5, 2016 12:30 PM:
With this new version it works wonderful.
Thank you so much, Rob McAveney!
Jagathees - Thursday, May 5, 2016 9:37 AM:
Above code working only in Testserver . I have tested with Local,Development it is not working. Is there anything specifically need to configure for this SOAP in Aras?
RobMcAveney - Thursday, May 5, 2016 9:51 AM:
I don't understand your question. Are you saying you have 3 separate installations and the code only works with one of them?
Jagathees - Thursday, May 5, 2016 10:04 AM:
for My code not working in All installations.But what you shared that code works only in Testserver. In Local & Development servers not working.
Is there any Separate configuration has to do for SOAP in ARAS?
RobMcAveney - Thursday, May 5, 2016 10:18 AM:
No, there is no separate configuration. There must be something different between your servers, but there's no way to figure out what that is with the information you are providing.