TestJS

/*
 * Created on Jun 8, 2009
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package servlets;

import java.io.BufferedReader;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author lh53491
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class ApplicationProxyServlet extends HttpServlet {
 
 public final void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
  performTask(request, response);
 } 

 /**
  * Process incoming HTTP POST requests
  * @param request Object that encapsulates the request to the servlet
  * @param response Object that encapsulates the response from the servlet
  * @exception ServletException
  * @exception IOException
  */
 public final void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
  performTask(request, response);
 } 

 private final void performTask(HttpServletRequest request, HttpServletResponse response) throws IOException{
  String endPointURL = request.getParameter("ENDPOINTURL");
  System.out.println("endPointURL:::::::::"+endPointURL);
  BufferedReader webIn = request.getReader();
  String inputLine = "";
  StringBuffer inputText = new StringBuffer();
  if((inputLine = webIn.readLine())!=null)
   inputText = inputText.append(inputLine);
  webIn.close();
  System.out.print(inputText);
  
  
  
 }
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

<

 

html

>

 

 

 

< head

>

 

 

 

< title > Axis 2 - Home </ title

>

 

 

 

< link href = "axis2-web/css/axis-style.css" rel = "stylesheet" type = "text/css"

/>

 

 

 

< script type = "text/javascript"

>

 

 

 

var req = new ActiveXObject( 'MSXML2.XMLHTTP'

);

req.onreadystatechange =

 

function()

{

if

 

(req != null && req.readyState == 4)

{

if

 

(req.status == 200)

{

 

 

alert(req.responseText);

 

 

}

}

}

 

;

 

req.open(

 

"POST", "http://localhost:9086/TestAxisClient/ApplicationProxyServlet?ENDPOINTURL='http://localhost:9086/TestAxis/services/Student'", true

);

req.send(

 

'<?xml version="1.0"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><SOAP-ENV:Body><jsx1:getName xmlns:jsx1="http://POJO">Emmy</jsx1:getName></SOAP-ENV:Body></SOAP-ENV:Envelope>'

);

req.setRequestHeader(

 

'SOAPAction','/Services/Business/CreditProcessing/Verification/Interface/Verification.serviceagent/VerificationEndpoint0/GetAttemptHistoryDetailOp'

);

req.setRequestHeader(

 

'Content-Type','text/xml'

);

 

 

</script

>

 

 

 

</ head

>

 

 

 

< body

>

 

 

 

< br

/>

 

 

 

< h1 > Welcome! </ h1

>

 

 

 

</ body

>

</

 

html>

 

 

 

  long startTime = System.currentTimeMillis();
  try {
   String newline = null;
   try {
    newline = System.getProperty("line.separator");
   } catch (Exception e) {
    newline = "/n";
   }

         Logger.printLog(Logger.DEBUG,null, "ApplicationProxyServlet | processRequest entered Start Request:"+System.currentTimeMillis(),FRAMEWORK_LOGGER);
         HttpSession _HttpSession = request.getSession(false);
   String endpointURL = request.getParameter("ENDPOINTURL");

   Logger.printLog(Logger.DEBUG,null, "ApplicationProxyServlet | processRequest entered ENDPOINTURL:"+endpointURL,FRAMEWORK_LOGGER);
   URL url = new URL(reformBWEndPointUrl(endpointURL));

         BufferedReader webIn = request.getReader();
   String inputLine ="";
   String inputRequest ="";
   while ((inputLine = webIn.readLine()) != null){
    inputRequest += inputLine;
   }
   webIn.close();

      Logger.printLog(Logger.DEBUG,null, "ApplicationProxyServlet | processRequest entered inputRequest length:"+inputRequest.length(),FRAMEWORK_LOGGER);

   Logger.printLog(Logger.DEBUG,null, "ApplicationProxyServlet | processRequest entered Incomming Request:"+inputRequest,FRAMEWORK_LOGGER);

   UserSecurityContext userContext = getUserSecurityContext(_HttpSession);

 


   // This is for Soap Header Manipulation
   String soapHeader = getSoapHeader(_HttpSession.getId(),userContext);
   inputRequest = attachSoapHeaderToEnvelope(inputRequest,soapHeader);

   logProxyDetails(userContext,inputRequest);


   HttpURLConnection conn = (HttpURLConnection) url.openConnection();
   conn.setRequestMethod("POST");
   conn.setAllowUserInteraction(false);
   conn.setDoOutput(true);


   for (Enumeration enu = request.getHeaderNames(); enu.hasMoreElements();) {
    String pName = (String) enu.nextElement();
    String pValu = request.getHeader(pName);
    if (!pName.toUpperCase().startsWith("HOST")) {
     conn.setRequestProperty(pName, pValu);


    } else {
     conn.setRequestProperty(pName, url.getHost() + ":"
       + url.getPort());
    }
   }

   Logger.printLog(Logger.DEBUG,null, "ApplicationProxyServlet | processRequest entered BW Start Request:"+System.currentTimeMillis(),FRAMEWORK_LOGGER);

   OutputStream rawOutStream = conn.getOutputStream();
   PrintStream pw = new PrintStream(rawOutStream,false,"UTF-8");
   pw.print(inputRequest);
   pw.flush();
   pw.close();


   InputStream rawInStream;
   try {
       rawInStream = conn.getInputStream();
   } catch(IOException e) {
       Logger.printLog(Logger.ERROR,null,"ApplicationProxyServlet | processRequest BW IO Exception, code:"
               + conn.getResponseCode() + " message:" + conn.getResponseMessage(),FRAMEWORK_LOGGER);
       rawInStream = conn.getErrorStream();
   }

   Logger.printLog(Logger.DEBUG,null, "ApplicationProxyServlet | processRequest entered BW End:"+System.currentTimeMillis(),FRAMEWORK_LOGGER);

         Reader rdrInputUTF = new InputStreamReader(rawInStream, "UTF-8");

   BufferedReader rdr = new BufferedReader(rdrInputUTF);
   String line = "";
   String sbOutPut = "";
   while ((line = rdr.readLine()) != null) {
    sbOutPut += line;
   }
   rdr.close();

   response.setStatus(conn.getResponseCode());
   response.setCharacterEncoding("UTF-8");
   response.setContentType(conn.getContentType());

   PrintStream out = new PrintStream(response.getOutputStream(),false,"UTF-8");
   out.print(sbOutPut.toString());
   Logger.printLog(Logger.DEBUG,null, "ApplicationProxyServlet | processRequest entered sbOutPut length:"+sbOutPut.length(),FRAMEWORK_LOGGER);
   out.flush();
   out.close();
   sbOutPut = null;

   Logger.printLog(Logger.DEBUG,null, "ApplicationProxyServlet | processRequest TOTAL Request time (in ms): for <<Service>>"+endpointURL+"<</Service>> <<Time taken>>"+(System.currentTimeMillis() - startTime)+"<</Time Taken>>",FRAMEWORK_LOGGER);
  } catch (MalformedURLException e) {
   Logger.printLog(Logger.ERROR,null, "ApplicationProxyServlet | processRequest MalformedURLException:"+e.getMessage(),FRAMEWORK_LOGGER);
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (ProtocolException e) {
   // TODO Auto-generated catch block
   Logger.printLog(Logger.ERROR,null, "ApplicationProxyServlet | processRequest ProtocolException:"+e.getMessage(),FRAMEWORK_LOGGER);
   e.printStackTrace();
  } catch (Exception e) {
   // TODO Auto-generated catch block
   Logger.printLog(Logger.ERROR,null, "ApplicationProxyServlet | processRequest GeneralException:"+e.getMessage(),FRAMEWORK_LOGGER);
   e.printStackTrace();
  }

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值