Hello Guys,
I want to connect Aras Innovator 12 With my Java web Application is not work. when I try connect Aras Innovator 11 with my Java web Application is work. I am using same code in case of Aras Innovator 11 and 12 . Why I am getting Strange behavior . I do not know.
Please help me . code is below and Exception is below.
httpConnection: Exception :======java.io.IOException: Server returned HTTP response code: 401 for URL: win-8dg8qc6q2gp:80/.../InnovatorServer.aspx
import java.io.IOException;
import javax.servlet.ServletException;
//import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.nio.charset.Charset;
import java.io.ByteArrayInputStream;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.MimeHeaders;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPMessage;
import org.w3c.dom.NodeList;
/**
* Servlet implementation class ArasInnovatorLogin
*/
//@WebServlet("/ArasInnovatorLogin")
public class ArasInnovatorLogin extends HttpServlet {
private static final long serialVersionUID = 1L;
String ErrString="",invalideDb="",ErrorUi="";
java.io.BufferedReader in;
String database="",userName="",innovatorServer="",request="",password="";
NodeList list=null;
boolean isSuccess = false; NodeList returnList;NodeList innerResultList;
/**
* @see HttpServlet#HttpServlet()
*/
public ArasInnovatorLogin() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//response.getWriter().append("Served at: ").append(request.getContextPath());
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
try{
Vector getItem=null;
ErrString="<SOAP-ENV:Envelope xmlns:SOAP-ENV='schemas.xmlsoap.org/.../'><SOAP-ENV:Body><SOAP-ENV:Fault xmlns:af='www.aras.com/.../faultcode><faultstring><![CDATA[Authentication failed for admin]]></faultstring><detail><af:legacy_detail><![CDATA[Authentication failed for admin]]></af:legacy_detail><af:exception message='Authentication failed for admin' type='Aras.Server.Core.InnovatorServerException' /></detail></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>";
invalideDb="<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>";
ErrorUi="<SOAP-ENV:Envelope xmlns:SOAP-ENV='schemas.xmlsoap.org/.../'><SOAP-ENV:Body><SOAP-ENV:Fault xmlns:af='www.aras.com/.../af:legacy_detail><af:exception message='formation' type='Aras.Server.Core.InnovatorServerException' /></detail></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>";
this.innovatorServer ="">win-8dg8qc6q2gp:80/.../InnovatorServer.aspx";
this.database ="Netradyne";
this.userName =request.getParameter("UserName");
this.password =request.getParameter("password");
response.getWriter().println("userName:" +userName);
response.getWriter().println("password:" +password);
this.request = "<AML>"
+"<Item type='User' action='get' select='user_name,password'>"+
"</Item>"+
"</AML>";
String formation="Authentication failed for"+" "+this.password;
String nameSpace = "">http://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/.../encoding'>"
"<SOAP-ENV:Body>"+
"<"+remoteMethod+" xmlns:m='"+nameSpace+"'>" + this.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();
//response.getWriter().println(messageBytes);
// 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",this.userName);
httpConnection.setRequestProperty("AUTHPASSWORD", MD5(this.password));
httpConnection.setRequestProperty("DATABASE",this.database);
httpConnection.setDoInput(true);
httpConnection.setDoOutput(true);
// Write and send the SOAP message
java.io.OutputStream out = httpConnection.getOutputStream();
response.getWriter().println("httpConnection:" +out);
out.write(messageBytes);
out.close();
// Read server response
in = new java.io.BufferedReader(new java.io.InputStreamReader(httpConnection.getInputStream()));
String inputLine; String erroS="";
while ((inputLine = in.readLine()) != null) {
erroS=inputLine;
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage(new MimeHeaders(),new ByteArrayInputStream(inputLine.getBytes(Charset.forName("UTF-8"))));
SOAPBody body = message.getSOAPBody();
NodeList returnList = body.getElementsByTagName("Item");
isSuccess = false;
response.getWriter().println(in.readLine());
for (int k = 0; k < returnList.getLength(); k++) {
NodeList innerResultList = returnList.item(k).getChildNodes();
response.getWriter().println("innerResultList.getLength()="+innerResultList.getLength());
for (int l= 0; l < innerResultList.getLength(); l++) {
isSuccess=true;
String or="'";
char nr='"';
String Nr=String.valueOf(nr);
//erroS.replaceAll(or,Nr);
//response.getWriter().println(erroS.replaceAll(Nr,or));
//response.getWriter().println(ErrorUi.replaceAll("formation",formation));
int flag=1,Flag=0;
if( ErrString.equals(erroS.replaceAll(Nr,or)))
{
flag=0;
Flag=1;
response.getWriter().println(password+" is not valide Password");
}
if(invalideDb.equals(erroS.replaceAll(Nr,or)))
{
flag=0;
response.getWriter().println("Authantication is fail for the Selected DataBase"+" "+""+database);
}
if(ErrorUi.replaceAll("formation",formation).equals(erroS.replaceAll(Nr,or)))
{
flag=0;
if(Flag!=1)
response.getWriter().println(userName+" "+" is not valide user");
}
if(flag==1)
{
}
// getItem=new Vector();
if (isSuccess) {
list = body.getElementsByTagName("Item");
response.getWriter().println("isSuccess==="+isSuccess);
}
}
}
}
}
catch (Exception e) {
// TODO Auto-generated catch block
response.getWriter().println("Exception :======"+e);
e.printStackTrace();
}
doGet(request, response);
}
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);
}
}
Thanks in Advance