Source Code Cross Referenced for TCPServer.java in  » Web-Services-AXIS2 » kernal » org » apache » axis2 » transport » tcp » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Services AXIS2 » kernal » org.apache.axis2.transport.tcp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements. See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership. The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License. You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied. See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         */
019:
020:        package org.apache.axis2.transport.tcp;
021:
022:        import org.apache.axis2.AxisFault;
023:        import org.apache.axis2.Constants;
024:        import org.apache.axis2.addressing.EndpointReference;
025:        import org.apache.axis2.context.ConfigurationContext;
026:        import org.apache.axis2.context.ConfigurationContextFactory;
027:        import org.apache.axis2.context.MessageContext;
028:        import org.apache.axis2.context.SessionContext;
029:        import org.apache.axis2.description.Parameter;
030:        import org.apache.axis2.description.TransportInDescription;
031:        import org.apache.axis2.engine.ListenerManager;
032:        import org.apache.axis2.i18n.Messages;
033:        import org.apache.axis2.transport.TransportListener;
034:        import org.apache.axis2.transport.http.server.HttpUtils;
035:        import org.apache.commons.logging.Log;
036:        import org.apache.commons.logging.LogFactory;
037:
038:        import java.io.File;
039:        import java.io.IOException;
040:        import java.net.ServerSocket;
041:        import java.net.Socket;
042:        import java.net.SocketException;
043:
044:        /**
045:         * Class TCPServer
046:         */
047:        public class TCPServer implements  Runnable, TransportListener {
048:            private int port = 8000;
049:            private boolean started = false;
050:            private static final Log log = LogFactory.getLog(TCPServer.class);
051:            private ConfigurationContext configContext;
052:            private ServerSocket serversocket;
053:            private String hostAddress = null;
054:            private String contextPath;
055:
056:            public TCPServer() {
057:            }
058:
059:            public TCPServer(int port, ConfigurationContext configContext)
060:                    throws AxisFault {
061:                try {
062:                    this .configContext = configContext;
063:                    serversocket = new ServerSocket(port);
064:
065:                    ListenerManager listenerManager = configContext
066:                            .getListenerManager();
067:                    TransportInDescription trsIn = new TransportInDescription(
068:                            Constants.TRANSPORT_TCP);
069:                    trsIn.setReceiver(this );
070:                    if (listenerManager == null) {
071:                        listenerManager = new ListenerManager();
072:                        listenerManager.init(configContext);
073:                    }
074:                    listenerManager.addListener(trsIn, true);
075:                    contextPath = configContext.getServiceContextPath();
076:
077:                } catch (IOException e1) {
078:                    throw AxisFault.makeFault(e1);
079:                }
080:            }
081:
082:            public TCPServer(int port, String dir) throws AxisFault {
083:                this (port, ConfigurationContextFactory
084:                        .createConfigurationContextFromFileSystem(dir, null));
085:            }
086:
087:            public void init(ConfigurationContext axisConf,
088:                    TransportInDescription transprtIn) throws AxisFault {
089:                this .configContext = axisConf;
090:
091:                Parameter param = transprtIn.getParameter(PARAM_PORT);
092:
093:                if (param != null) {
094:                    this .port = Integer.parseInt((String) param.getValue());
095:                }
096:                param = transprtIn.getParameter(HOST_ADDRESS);
097:                if (param != null) {
098:                    hostAddress = ((String) param.getValue()).trim();
099:                }
100:                contextPath = configContext.getServiceContextPath();
101:            }
102:
103:            public static void main(String[] args) throws AxisFault,
104:                    NumberFormatException {
105:                if (args.length != 2) {
106:                    System.out.println("TCPServer repositoryLocation port");
107:                } else {
108:                    File repository = new File(args[0]);
109:
110:                    if (!repository.exists()) {
111:                        System.out
112:                                .print("Repository file does not exists .. initializing repository");
113:                    }
114:
115:                    TCPServer tcpServer = new TCPServer(Integer
116:                            .parseInt(args[1]), repository.getAbsolutePath());
117:
118:                    System.out.println("[Axis2] Using the Repository "
119:                            + repository.getAbsolutePath());
120:                    System.out
121:                            .println("[Axis2] Starting the TCP Server on port "
122:                                    + args[1]);
123:                    tcpServer.start();
124:                    Runtime.getRuntime().addShutdownHook(new Thread(tcpServer));
125:                }
126:            }
127:
128:            public void run() {
129:                while (started) {
130:                    Socket socket = null;
131:
132:                    try {
133:                        socket = serversocket.accept();
134:                    } catch (java.io.InterruptedIOException iie) {
135:                    } catch (Exception e) {
136:                        log.debug(e);
137:
138:                        break;
139:                    }
140:
141:                    if (socket != null) {
142:                        configContext.getThreadPool().execute(
143:                                new TCPWorker(configContext, socket));
144:                    }
145:                }
146:            }
147:
148:            public synchronized void start() throws AxisFault {
149:                if (serversocket == null) {
150:                    serversocket = openSocket(port);
151:                }
152:                started = true;
153:                this .configContext.getThreadPool().execute(this );
154:            }
155:
156:            /**
157:             * Controls the number of server sockets kept open.
158:             */
159:            public ServerSocket openSocket(int port) throws AxisFault {
160:                for (int i = 0; i < 5; i++) {
161:                    try {
162:                        return new ServerSocket(port + i);
163:                    } catch (IOException e) {
164:                        // What I'm gonna do here. Try again.
165:                    }
166:                }
167:
168:                throw new AxisFault(Messages.getMessage("failedToOpenSocket"));
169:            }
170:
171:            /*
172:             *  (non-Javadoc)
173:             * @see org.apache.axis2.transport.TransportListener#stop()
174:             */
175:            public void stop() throws AxisFault {
176:                try {
177:                    this .serversocket.close();
178:                    started = false;
179:                } catch (IOException e) {
180:                    throw AxisFault.makeFault(e);
181:                }
182:            }
183:
184:            public ConfigurationContext getConfigurationContext() {
185:                return this .configContext;
186:            }
187:
188:            /**
189:             * I fthe hostAddress parameter is present in axis2.xml then the EPR will be
190:             * created by taking the hostAddres into account
191:             * (non-Javadoc)
192:             *
193:             * @see org.apache.axis2.transport.TransportListener#getEPRForService(String, String)
194:             */
195:            public EndpointReference getEPRForService(String serviceName,
196:                    String ip) throws AxisFault {
197:                EndpointReference[] epRsForService = getEPRsForService(
198:                        serviceName, ip);
199:                return epRsForService != null ? epRsForService[0] : null;
200:            }
201:
202:            public EndpointReference[] getEPRsForService(String serviceName,
203:                    String ip) throws AxisFault {
204:                //if host address is present
205:                if (hostAddress != null) {
206:                    if (serversocket != null) {
207:                        // todo this has to fix
208:                        return new EndpointReference[] { new EndpointReference(
209:                                hostAddress + "/" + contextPath + serviceName) };
210:                    } else {
211:                        log
212:                                .debug("Unable to generate EPR for the transport tcp");
213:                        return null;
214:                    }
215:                }
216:                if (ip == null) {
217:                    try {
218:                        ip = HttpUtils.getIpAddress(configContext
219:                                .getAxisConfiguration());
220:                    } catch (SocketException e) {
221:                        throw AxisFault.makeFault(e);
222:                    }
223:                }
224:                if (serversocket != null) {
225:                    // todo this has to fix
226:                    return new EndpointReference[] { new EndpointReference(
227:                            "tcp://" + ip + ":" + (serversocket.getLocalPort())
228:                                    + "/" + contextPath + "/" + serviceName) };
229:                } else {
230:                    log.debug("Unable to generate EPR for the transport tcp");
231:                    return null;
232:                }
233:            }
234:
235:            public SessionContext getSessionContext(
236:                    MessageContext messageContext) {
237:                return null;
238:            }
239:
240:            public void destroy() {
241:                this.configContext = null;
242:            }
243:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.