?? cwspsession.java~3~
字號:
tempHeader.setHeader("User-Agent",agent); if(headers==null) { pdu.setHeaders(tempHeader); } else { pdu.setHeaders(headers); } // prepare WTP Service Primitive CWTPEvent initPacket = new CWTPEvent(pdu.toByteArray(), CWTPEvent.TR_INVOKE_REQ); // construct transaction with initPacket if(linkgate==1) { wtp = socket.tr_invoke(this, initPacket, false, IWTPTransaction.CLASS_TYPE_2); setState(STATE_CONNECTING); } else { setState(STATE_CONNECTED); } } } /** * S-Disconnect.req * @return S-Disconnect.ind */ public synchronized void s_disconnect() { if (state == STATE_CONNECTING) { wtp.abort(ABORT_DISCONNECT); abortAllMethods(ABORT_DISCONNECT); s_disconnect_ind(ABORT_USERREQ); setState(STATE_NULL); } else if (state == STATE_CONNECTED) { abortAllMethods(ABORT_DISCONNECT); abortAllPushes(ABORT_DISCONNECT); CWSPDisconnect pdu = new CWSPDisconnect(session_id); CWTPEvent initPacket = new CWTPEvent(pdu.toByteArray(), CWTPEvent.TR_INVOKE_REQ); wtp = socket.tr_invoke(this, initPacket, false, IWTPTransaction.CLASS_TYPE_0); s_disconnect_ind(ABORT_USERREQ); setState(STATE_NULL); } else if (state == STATE_SUSPENDED) { s_disconnect_ind(ABORT_USERREQ); setState(STATE_NULL); } else if (state == STATE_RESUMING) { wtp.abort(); abortAllMethods(ABORT_DISCONNECT); s_disconnect_ind(ABORT_USERREQ); setState(STATE_NULL); } } /** * S-Suspend.req * @return S-Suspend.ind */ public synchronized boolean s_suspend() { if (state == STATE_CONNECTED) { abortAllMethods(ABORT_SUSPEND); abortAllPushes(ABORT_SUSPEND); CWSPSuspend pdu = new CWSPSuspend(this.session_id); CWTPEvent initPacket = new CWTPEvent(pdu.toByteArray(), CWTPEvent.TR_INVOKE_REQ); wtp = socket.tr_invoke(this, initPacket, false, IWTPTransaction.CLASS_TYPE_0); s_disconnect_ind(ABORT_USERREQ); setState(STATE_SUSPENDED); return true; } else if (state == STATE_RESUMING) { wtp.abort(ABORT_SUSPEND); abortAllMethods(ABORT_SUSPEND); CWSPSuspend pdu = new CWSPSuspend(this.session_id); CWTPEvent initPacket = new CWTPEvent(pdu.toByteArray(), CWTPEvent.TR_INVOKE_REQ); wtp = socket.tr_invoke(this, initPacket, false, IWTPTransaction.CLASS_TYPE_0); s_disconnect_ind(ABORT_USERREQ); setState(STATE_NULL); return true; } return false; } /** * S-Resume.req */ public synchronized void s_resume() throws SocketException { if (state == STATE_CONNECTED) { abortAllMethods(ABORT_USERREQ); abortAllPushes(ABORT_USERREQ); // bind session to the new peer address quadruplet socket.close(); socket = new CWTPSocket(socket.getRemoteAddress(), socket.getRemotePort(), this); CWSPResume pdu = new CWSPResume(session_id); CWTPEvent initPacket = new CWTPEvent(pdu.toByteArray(), CWTPEvent.TR_INVOKE_REQ); wtp = socket.tr_invoke(this, initPacket, false, IWTPTransaction.CLASS_TYPE_2); setState(STATE_RESUMING); } else if (state == STATE_SUSPENDED) { CWSPResume pdu = new CWSPResume(session_id); CWTPEvent initPacket = new CWTPEvent(pdu.toByteArray(), CWTPEvent.TR_INVOKE_REQ); wtp = socket.tr_invoke(this, initPacket, false, IWTPTransaction.CLASS_TYPE_2); setState(STATE_RESUMING); } } /** * Use this method to construct a POST-MethodInvoke.req. * This method uses <code>methodInvoke(CWSPPDU pdu)</code> * to send the constructed WSP-POST-PDU. * * @param data The data to be POSTed * @param contentType The MIME-ContentType of the data to be POSTed */ public synchronized CWSPMethodManager s_post(byte[] data, String contentType, String uri) { /** @todo hier m黶sen die Nachrichten aufgeteilt werden !!!! */ CWSPPost pdu = new CWSPPost(data, contentType, uri); return s_methodInvoke(pdu); } /** * Use this method to construct a POST-MethodInvoke.req. * This method uses <code>methodInvoke(CWSPPDU pdu)</code> * to send the constructed WSP-POST-PDU. * * @param headers The headers defined for the request * @param data The data to be POSTed * @param contentType The MIME-ContentType of the data to be POSTed * @param uri the target URI to post to */ public synchronized CWSPMethodManager s_post(CWSPHeaders headers, byte[] data, String contentType, String uri) { /** @todo hier m黶sen die Nachrichten aufgeteilt werden !!!! */ CWSPPost pdu = new CWSPPost(data, contentType, uri); pdu.setHeaders(headers); return s_methodInvoke(pdu); } /** * Use this method to construct a GET-MethodInvoke.req. * This method uses <code>methodInvoke(CWSPPDU pdu)</code> * to send the constructed WSP-GET-PDU. * * @param uri The Unfied Resource Identifier of the resource to GET */ public synchronized CWSPMethodManager s_get(String uri) { CWSPGet pdu = new CWSPGet(uri); return s_methodInvoke(pdu); } /** * Use this method to construct a GET-MethodInvoke.req. * This method uses <code>methodInvoke(CWSPPDU pdu)</code> * to send the constructed WSP-GET-PDU. * * @param headers The headers that are defined for the request * @param uri The Unfied Resource Identifier of the resource to GET */ public synchronized CWSPMethodManager s_get(CWSPHeaders headers, String uri) { CWSPGet pdu = new CWSPGet(uri); pdu.setHeaders(headers); return s_methodInvoke(pdu); } /** * S-MethodInvoke.req * To construct a POST- or GET-Request please use * <code>get(String uri)</code> or * <code>post(byte[] data, String contentType)</code> * instead of this method. * * @param pdu The GET- or POST-PDU to be sent. */ public synchronized CWSPMethodManager s_methodInvoke(CWSPPDU pdu) { if ( (state != STATE_NULL) && (state != STATE_SUSPENDED)) { CWSPMethodManager m = null; synchronized (methods) { m = new CWSPMethodManager(pdu, this, upperlayer); methods.add(m); } return m; } else { return null; } } public void removeMethod(CWSPMethodManager m) { synchronized (methods) { methods.remove(m); } } // s-methodInvokeData implemented in CWTPMethodManager // s-methodResult implemented in CWTPMethodManager // s-methodResultData implemented in CWTPMethodManager // s-methodAbort.req implemented in CWTPMethodManager // S-confirmedPush.res implemented in CWSPPushManager // s_pushAbort.req implemented in CWSPPushManager // s_push.req not implemented in client private synchronized void s_connect_cnf() { logger.debug("s-connect.ind"); upperlayer.s_connect_cnf(); } private synchronized void s_suspend_ind(short reason) { logger.debug("s-suspend.ind"); isSuspended = true; suspendCode = reason; upperlayer.s_suspend_ind(reason); } private synchronized void s_resume_cnf() { logger.debug("s-resume.ind"); isSuspended = false; suspendCode = 0; upperlayer.s_resume_cnf(); } private synchronized void s_disconnect_ind(short reason) { logger.debug("s-disconnect.ind"); isDisconnected = true; disconnectCode = reason; upperlayer.s_disconnect_ind(reason); socket.close(); } private synchronized void s_disconnect_ind(InetAddress[] redirectInfo) { logger.debug("s-disconnect.ind - redirected"); isDisconnected = true; upperlayer.s_disconnect_ind(redirectInfo); socket.close(); } private synchronized void s_disconnect_ind(CWSPSocketAddress[] redirectInfo) { logger.debug("s-disconnect.ind - redirected"); isDisconnected = true; if (version == 2) { ( (IWSPUpperLayer2) upperlayer).s_disconnect_ind(redirectInfo); } else { InetAddress[] redirectInfo2 = new InetAddress[redirectInfo.length]; for (int i = 0; i < redirectInfo.length; i++) { redirectInfo2[i] = redirectInfo[i].getAddress(); } upperlayer.s_disconnect_ind(redirectInfo2); } socket.close(); } ////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////// implementing IWTPUpperLayer - TR-*.* /** * process all TR-*.ind and TR-*.cnf service primitives except TR-Abort * (call tr-abort(short abortReason) to indicate a Abort by TR). * @param p The WTP Service primitive */ public synchronized void tr_process(CWTPEvent p) { try { CWSPPDU pdu = null; if ( (p.getUserData() != null) && (p.getUserData().length != 0)) { pdu = CWSPPDU.getPDU(p.getUserData()); } if (logger.isDebugEnabled()) { logger.debug("tr_process(CWTPEvent p)"+CWTPEvent.types[p.getType()] + " in " + states[state]); } switch (p.getType()) { case 0x01: //--------------------------------------------- TR-INVOKE.IND switch (state) { case STATE_CONNECTING: if ( (p.getTransaction().getClassType() == IWTPTransaction.CLASS_TYPE_1) && (pdu.getType() == CWSPPDU.PDU_TYPE_CONFIRMEDPUSH)) { p.getTransaction().abort(ABORT_PROTOERR); } break; case STATE_CONNECTED: if ( (p.getTransaction().getClassType() == IWTPTransaction.CLASS_TYPE_0) && (pdu.getType() == CWSPPDU.PDU_TYPE_DISCONNECT)) { abortAllMethods(ABORT_DISCONNECT); abortAllPushes(ABORT_DISCONNECT); s_disconnect_ind(ABORT_DISCONNECT); setState(STATE_NULL); } else if ( (p.getTransaction().getClassType() == IWTPTransaction.CLASS_TYPE_0) && (pdu.getType() == CWSPPDU.PDU_TYPE_PUSH)) { /** @todo s_push_ind() */ }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -