⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test1.java

📁 对于cmpp3.0 开发有一定的帮助,请大家下载下来进行研究.
💻 JAVA
字号:
package com.zhanghao.provision;import java.net.*;import java.io.*;import java.util.*;import java.util.*;import javax.xml.soap.*;import com.zhanghao.common.util.Base64;public class Test1 extends Thread{  public ServerSocket serverSocket;  public int port = 8088;  public Test1() {  }  public void run(){    try{      serverSocket = new ServerSocket(port);      System.out.println("Start....");      while(true){        Socket socket = serverSocket.accept();        service(socket);      }    }    catch(Exception ex){      ex.printStackTrace();    }  }  public void service(Socket socket){    try{      long a = System.currentTimeMillis();      System.out.println(socket.getLocalAddress().getHostAddress());      DataInputStream inputStream = new DataInputStream(socket.getInputStream());      DataOutputStream outputStream = new DataOutputStream(socket.getOutputStream());      String str = inputStream.readLine();      String strTemp = "";      System.out.println(str);      strTemp = strTemp+str;      int iLength = 0;      while(!str.equals("")){        str = inputStream.readLine();        System.out.println(str);        if(str.startsWith("Content-Length:")){          iLength = Integer.parseInt(str.substring(str.indexOf(" ")).trim());        }      }      byte[] bb = new byte[iLength];      inputStream.readFully(bb,0,iLength);      java.io.ByteArrayInputStream binput = new ByteArrayInputStream(bb);      javax.xml.transform.stream.StreamSource          streamSource = new javax.xml.transform.stream.StreamSource(binput);//      javax.xml.soap.SOAPConnectionFactory connFactory =//          SOAPConnectionFactory.newInstance();////      javax.xml.soap.SOAPConnection conn = connFactory.createConnection();      javax.xml.soap.MessageFactory messageFactory =          MessageFactory.newInstance();      javax.xml.soap.SOAPMessage message = messageFactory.createMessage();      javax.xml.soap.SOAPPart soapPart = message.getSOAPPart();      javax.xml.soap.SOAPEnvelope soapEnvelop = soapPart.getEnvelope();      javax.xml.soap.SOAPBody soapBody = soapEnvelop.getBody();      System.out.println("streamSource....");      soapPart.setContent(streamSource);      ByteArrayOutputStream byteArrayOutStream = new ByteArrayOutputStream();      DataOutputStream dataOutStream = new DataOutputStream(byteArrayOutStream);      SyncOrderRelationReqBean syncOrderbean =          new SyncOrderRelationReqBean(message);      SyncOrderRelationRespBean syncOrderRespBean =          new SyncOrderRelationRespBean(syncOrderbean);      syncOrderRespBean.respXML.writeTo(dataOutStream);      //syncOrderRespBean.respXML.writeTo();      System.out.println(new String(byteArrayOutStream.toByteArray()));      System.out.println(          Base64.decodeBase64(syncOrderbean.FeatureStr));      outputStream.write("HTTP/1.1 200 OK\r\n".getBytes());      outputStream.write("Server: Provision HTTP/1.0\r\n".getBytes());      outputStream.write(String.valueOf(String.valueOf( (new StringBuffer("Date: ")).          append( (new Date()).toString()).append("\r\n"))).getBytes());      outputStream.write(String.valueOf(String.valueOf( (new StringBuffer(          "Content-Type: ")).append("text/xml").append(          "\r\n"))).getBytes());      byte outb[] = byteArrayOutStream.toByteArray();      System.out.println(outb.length);      outputStream.write(String.valueOf(String.valueOf( (new StringBuffer(          "Content-Length: ")).append(outb.length).append("\r\n"))).                getBytes());      outputStream.write("\r\n".getBytes());      outputStream.write(outb);      System.out.println((System.currentTimeMillis() - a )+"毫秒");    }    catch(Exception ex){      ex.printStackTrace();    }    finally{      try{        if(socket!=null){          socket.close();        }//        if(serverSocket!=null){//          serverSocket.close();//        }      }      catch(Exception ex){}    }  }  private static final int fillchar = '=';  private static final String cvt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"      + "abcdefghijklmnopqrstuvwxyz"      + "0123456789+/";  /**   * Decodes a base64 String.   *   * @param data a base64 encoded String to decode.   * @return the decoded String.   */  public static String decodeBase64(String data) {    return decodeBase64(data.getBytes());  }  /**   * Decodes a base64 aray of bytes.   *   * @param data a base64 encode byte array to decode.   * @return the decoded String.   */  public static String decodeBase64(byte[] data) {    int c, c1;    int len = data.length;    StringBuffer ret = new StringBuffer( (len * 3) / 4);    for (int i = 0; i < len; ++i) {      c = cvt.indexOf(data[i]);      ++i;      c1 = cvt.indexOf(data[i]);      c = ( (c << 2) | ( (c1 >> 4) & 0x3));      ret.append( (char) c);      if (++i < len) {        c = data[i];        if (fillchar == c)          break;        c = cvt.indexOf( (char) c);        c1 = ( (c1 << 4) & 0xf0) | ( (c >> 2) & 0xf);        ret.append( (char) c1);      }      if (++i < len) {        c1 = data[i];        if (fillchar == c1)          break;        c1 = cvt.indexOf( (char) c1);        c = ( (c << 6) & 0xc0) | c1;        ret.append( (char) c);      }    }    return ret.toString();  }  public static void main(String args[]) throws Exception{    new Test1().start();  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -