You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by di...@apache.org on 2005/12/16 18:18:08 UTC
svn commit: r357187 [24/25] - in
/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2: ./
addressing/ client/ client/async/ context/ deployment/ deployment/listener/
deployment/repository/util/ deployment/scheduler/ deployment/util/
descript...
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/SMTPServer.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/SMTPServer.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/SMTPServer.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/SMTPServer.java Fri Dec 16 09:13:57 2005
@@ -1,18 +1,19 @@
/*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
package org.apache.axis2.transport.mail.server;
@@ -26,31 +27,25 @@
import java.net.Socket;
public class SMTPServer extends Thread {
- private Storage st;
-
- private ConfigurationContext configurationContext;
private Log log = LogFactory.getLog(getClass());
-
- private int port;
-
private boolean actAsMailet = false;
- private ServerSocket ss;
private boolean running = false;
+ private ConfigurationContext configurationContext;
+ private int port;
+ private ServerSocket ss;
+ private Storage st;
- public SMTPServer(
- Storage st,
- ConfigurationContext configurationContext,
- int port) {
+ public SMTPServer(Storage st, int port) {
this.st = st;
- this.configurationContext = configurationContext;
this.port = port;
- actAsMailet = true;
+ actAsMailet = false;
}
- public SMTPServer(Storage st, int port) {
+ public SMTPServer(Storage st, ConfigurationContext configurationContext, int port) {
this.st = st;
+ this.configurationContext = configurationContext;
this.port = port;
- actAsMailet = false;
+ actAsMailet = true;
}
public void run() {
@@ -58,7 +53,6 @@
}
public void runServer() {
-
try {
synchronized (this) {
running = true;
@@ -71,16 +65,18 @@
while (running) {
try {
- //wait for a client
+
+ // wait for a client
Socket socket = ss.accept();
SMTPWorker thread = null;
- if (actAsMailet)
+
+ if (actAsMailet) {
thread = new SMTPWorker(socket, st, configurationContext);
- else {
+ } else {
thread = new SMTPWorker(socket, st);
}
- thread.start();
+ thread.start();
} catch (IOException ex) {
if (running) {
log.info(ex.getMessage());
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/SMTPWorker.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/SMTPWorker.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/SMTPWorker.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/SMTPWorker.java Fri Dec 16 09:13:57 2005
@@ -1,18 +1,19 @@
/*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
package org.apache.axis2.transport.mail.server;
@@ -36,130 +37,78 @@
import java.util.Properties;
public class SMTPWorker extends Thread {
-
private BufferedReader reader = null;
-
private BufferedWriter writer = null;
-
- private boolean actAsMailet = false;
-
- private ArrayList receivers = new ArrayList();
-
+ private boolean transmitionEnd = false;
+ private String temp = "";
private Storage st = null;
-
boolean runThread = true;
-
+ private ArrayList receivers = new ArrayList();
private MimeMessage mail = null;
-
- private ConfigurationContext configurationContext = null;
-
- private String temp = "";
-
+ private Log log = LogFactory.getLog(getClass());
private boolean dataWriting = false;
-
- private boolean transmitionEnd = false;
-
+ private ConfigurationContext configurationContext = null;
private boolean bodyData = false;
- private Log log = LogFactory.getLog(getClass());
-
- public SMTPWorker(Socket socket, Storage st,
- ConfigurationContext configurationContext) {
- doWork(socket, st, configurationContext);
- }
+ private boolean actAsMailet = false;
public SMTPWorker(Socket socket, Storage st) {
doWork(socket, st, null);
}
- private void doWork(Socket socket, Storage st,
- ConfigurationContext configurationContext) {
+ public SMTPWorker(Socket socket, Storage st, ConfigurationContext configurationContext) {
+ doWork(socket, st, configurationContext);
+ }
+
+ private void doWork(Socket socket, Storage st, ConfigurationContext configurationContext) {
try {
this.st = st;
+
if (configurationContext == null) {
actAsMailet = false;
} else {
this.configurationContext = configurationContext;
actAsMailet = true;
}
- //get the streams from the socket and save in instance variables.
- reader = new BufferedReader(new InputStreamReader(socket
- .getInputStream()));
- writer = new BufferedWriter(new OutputStreamWriter(socket
- .getOutputStream()));
+
+ // get the streams from the socket and save in instance variables.
+ reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+ writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
} catch (IOException ex) {
log.info(ex.getMessage());
}
}
- //running the thread
- public void run() {
- try {
- //do initial transmission.
- initializeClient();
-
- //analyze all the inputs from client and work accordingly.
- while (runThread) {
- String input = null;
-
- //get client input
- input = reader.readLine();
-
- String retString = processInput(input);
-
- if (MailSrvConstants.COMMAND_EXIT.equals(retString)) {
- exitWorker();
- } else {
- if (retString != null) {
- send(retString); //Send the reply
- }
- if (mail != null && transmitionEnd) {
- exitWorker();
- }
- }
- }
- for (int idx = 0; idx < receivers.size(); idx++) {
- try {
- MailSorter mSort = null;
- if (actAsMailet) {
- mSort = new MailSorter(this.st,
- this.configurationContext);
- } else {
- mSort = new MailSorter(this.st, null);
- }
- mSort.sort((String) receivers.get(idx), new MimeMessage(
- mail));
- } catch (MessagingException e1) {
- log.info(e1.getMessage());
- //e1.printStackTrace();
- }
- }
- //
-
- } catch (IOException e) {
- log.info("ERROR: CLIENT CLOSED THE SOCKET");
- }
+ // transmission is over. setting to exit
+ private void exitWorker() throws IOException {
+ reader.close();
+ writer.close();
+ runThread = false;
}
- private void send(String s) throws IOException {
- writer.write(s);
- writer.newLine();
- writer.flush();
+ // initializing the client by sending the initial message.
+ private void initializeClient() throws IOException {
+ if (writer != null) {
+ send("220 SMTP Server IS UP");
+ }
}
private String processInput(String input) {
- byte[] CR_LF = new byte[] { 0x0D, 0x0A };
- if (input == null)
+ byte[] CR_LF = new byte[]{0x0D, 0x0A};
+
+ if (input == null) {
return MailSrvConstants.COMMAND_UNKNOWN;
- if (mail != null && transmitionEnd)
+ }
+
+ if ((mail != null) && transmitionEnd) {
return MailSrvConstants.COMMAND_TRANSMISSION_END;
+ }
if (input.startsWith("MAIL")) {
- mail = new MimeMessage(Session.getInstance(new Properties(),
- new Authenticator() {
- protected PasswordAuthentication getPasswordAuthentication() {
- return null;
- }
- }));
+ mail = new MimeMessage(Session.getInstance(new Properties(), new Authenticator() {
+ protected PasswordAuthentication getPasswordAuthentication() {
+ return null;
+ }
+ }));
int start = input.indexOf("<") + 1;
int end;
@@ -173,40 +122,45 @@
String from = input.substring(start, end);
- if (from != null && !from.trim().equals("")) {
- //TODO this is an ugly hack to get the from address in. There
+ if ((from != null) && !from.trim().equals("")) {
+
+ // TODO this is an ugly hack to get the from address in. There
// should be a better way to do this.
MailAddress mailFrom[] = new MailAddress[1];
+
mailFrom[0] = new MailAddress(from);
+
try {
mail.addFrom(mailFrom);
} catch (MessagingException e) {
log.info(e.getMessage());
+
// TODO Auto-generated catch block
}
}
return MailSrvConstants.MAIL_OK;
-
}
+
if (input.startsWith("HELO")) {
return MailSrvConstants.HELO_REPLY;
-
} else if (input.startsWith("RCPT")) {
-
String domain = MailSrvConstants.SERVER_DOMAIN;
- //System.out.println("RCPT:" + input);
- //temp += input + "\n"; TODO Check this
+
+ // System.out.println("RCPT:" + input);
+ // temp += input + "\n"; TODO Check this
int start = input.indexOf("<") + 1;
int end;
if (start <= 0) {
start = input.indexOf("TO:") + 3;
+
/*
* if(!input.endsWith(domain)){ System.out.println("ERROR: wrong
* donmain name"); return MailSrvConstants.RCPT_ERROR; }
*/
} else {
+
/*
* if(!input.endsWith(domain + ">")){ System.out.println("ERROR:
* wrong donmain name"); return MailSrvConstants.RCPT_ERROR; }
@@ -214,34 +168,37 @@
}
end = input.indexOf(">");
+
String toStr = input.substring(start, end);
try {
- mail.addRecipient(Message.RecipientType.TO, new MailAddress(
- toStr));
+ mail.addRecipient(Message.RecipientType.TO, new MailAddress(toStr));
receivers.add(toStr);
} catch (MessagingException e) {
log.info(e.getMessage());
+
// TODO Auto-generated catch block
}
- return MailSrvConstants.RCPT_OK;
+ return MailSrvConstants.RCPT_OK;
} else if (input.equalsIgnoreCase("DATA")) {
dataWriting = true;
- return MailSrvConstants.DATA_START_SUCCESS;
+ return MailSrvConstants.DATA_START_SUCCESS;
} else if (input.equalsIgnoreCase("QUIT")) {
dataWriting = true;
transmitionEnd = true;
- return MailSrvConstants.COMMAND_TRANSMISSION_END;
+ return MailSrvConstants.COMMAND_TRANSMISSION_END;
} else if (input.equals(".")) {
dataWriting = false;
+
return MailSrvConstants.DATA_END_SUCCESS;
} else if (input.equals("") && !bodyData) {
bodyData = true;
+
return null;
- } else if (mail != null && dataWriting) {
+ } else if ((mail != null) && dataWriting) {
try {
if (bodyData) {
temp += input;
@@ -251,27 +208,72 @@
}
} catch (MessagingException e) {
log.info(e.getMessage());
+
// TODO Auto-generated catch block
}
- return null;
+ return null;
} else {
return MailSrvConstants.COMMAND_UNKNOWN;
}
-
}
- //transmission is over. setting to exit
- private void exitWorker() throws IOException {
- reader.close();
- writer.close();
- runThread = false;
- }
+ // running the thread
+ public void run() {
+ try {
- //initializing the client by sending the initial message.
- private void initializeClient() throws IOException {
- if (writer != null) {
- send("220 SMTP Server IS UP");
+ // do initial transmission.
+ initializeClient();
+
+ // analyze all the inputs from client and work accordingly.
+ while (runThread) {
+ String input = null;
+
+ // get client input
+ input = reader.readLine();
+
+ String retString = processInput(input);
+
+ if (MailSrvConstants.COMMAND_EXIT.equals(retString)) {
+ exitWorker();
+ } else {
+ if (retString != null) {
+ send(retString); // Send the reply
+ }
+
+ if ((mail != null) && transmitionEnd) {
+ exitWorker();
+ }
+ }
+ }
+
+ for (int idx = 0; idx < receivers.size(); idx++) {
+ try {
+ MailSorter mSort = null;
+
+ if (actAsMailet) {
+ mSort = new MailSorter(this.st, this.configurationContext);
+ } else {
+ mSort = new MailSorter(this.st, null);
+ }
+
+ mSort.sort((String) receivers.get(idx), new MimeMessage(mail));
+ } catch (MessagingException e1) {
+ log.info(e1.getMessage());
+
+ // e1.printStackTrace();
+ }
+ }
+
+ //
+ } catch (IOException e) {
+ log.info("ERROR: CLIENT CLOSED THE SOCKET");
}
+ }
+
+ private void send(String s) throws IOException {
+ writer.write(s);
+ writer.newLine();
+ writer.flush();
}
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/Storage.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/Storage.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/Storage.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/mail/server/Storage.java Fri Dec 16 09:13:57 2005
@@ -1,24 +1,21 @@
/*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
-package org.apache.axis2.transport.mail.server;
-/**
- * Inmemory storage to used to store the mails.
- */
+package org.apache.axis2.transport.mail.server;
import javax.mail.internet.MimeMessage;
import java.util.ArrayList;
@@ -26,29 +23,31 @@
public class Storage {
private ArrayList mails = new ArrayList();
-
private Hashtable users = new Hashtable();
-
public Storage() {
}
public void addMail(String user, MimeMessage mail) {
ArrayList curMailBox = null;
+
if (users.containsKey(user)) {
curMailBox = (ArrayList) users.get(user);
} else {
curMailBox = new ArrayList();
users.put(user, curMailBox);
}
+
curMailBox.add(mail);
}
public ArrayList popUserMails(String user) {
- ArrayList usrMailBox = new ArrayList(); // This will return a emty list when the user has no mails or no mail box.
+ ArrayList usrMailBox = new ArrayList(); // This will return a emty list when the user has no mails or no mail box.
+
if (users.containsKey(user)) {
usrMailBox = (ArrayList) users.get(user);
}
+
return usrMailBox;
}
-}
\ No newline at end of file
+}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/tcp/TCPServer.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/tcp/TCPServer.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/tcp/TCPServer.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/tcp/TCPServer.java Fri Dec 16 09:13:57 2005
@@ -1,18 +1,19 @@
/*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
package org.apache.axis2.transport.tcp;
@@ -39,20 +40,28 @@
*/
public class TCPServer extends TransportListener implements Runnable {
private int port = 8000;
- private ServerSocket serversocket;
private boolean started = false;
- private ConfigurationContext configContext;
-
protected Log log = LogFactory.getLog(SimpleHTTPServer.class.getName());
+ private ConfigurationContext configContext;
+ private ServerSocket serversocket;
public TCPServer() {
}
+ public TCPServer(int port, ConfigurationContext configContext) throws AxisFault {
+ try {
+ this.configContext = configContext;
+ serversocket = new ServerSocket(port);
+ } catch (IOException e1) {
+ throw new AxisFault(e1);
+ }
+ }
+
public TCPServer(int port, String dir) throws AxisFault {
try {
ConfigurationContextFactory erfac = new ConfigurationContextFactory();
- this.configContext = erfac.buildConfigurationContext(
- dir);
+
+ this.configContext = erfac.buildConfigurationContext(dir);
Thread.sleep(3000);
serversocket = new ServerSocket(port);
} catch (DeploymentException e1) {
@@ -64,52 +73,67 @@
}
}
- public TCPServer(int port, ConfigurationContext configContext) throws AxisFault {
- try {
- this.configContext = configContext;
- serversocket = new ServerSocket(port);
- } catch (IOException e1) {
- throw new AxisFault(e1);
+ public void init(ConfigurationContext axisConf, TransportInDescription transprtIn)
+ throws AxisFault {
+ this.configContext = axisConf;
+
+ Parameter param = transprtIn.getParameter(PARAM_PORT);
+
+ if (param != null) {
+ int port = Integer.parseInt((String) param.getValue());
+ }
+ }
+
+ public static void main(String[] args) throws AxisFault, NumberFormatException {
+ if (args.length != 2) {
+ System.out.println("TCPServer repositoryLocation port");
+ } else {
+ File repository = new File(args[0]);
+
+ if (!repository.exists()) {
+ System.out.print("Repository file does not exists .. initializing repository");
+ }
+
+ TCPServer tcpServer = new TCPServer(Integer.parseInt(args[1]),
+ repository.getAbsolutePath());
+
+ System.out.println("[Axis2] Using the Repository " + repository.getAbsolutePath());
+ System.out.println("[Axis2] Starting the TCP Server on port " + args[1]);
+ tcpServer.start();
}
}
public void run() {
while (started) {
Socket socket = null;
+
try {
socket = serversocket.accept();
} catch (java.io.InterruptedIOException iie) {
- } catch (Exception e) {
+ }
+ catch (Exception e) {
log.debug(e);
+
break;
}
+
if (socket != null) {
- configContext.getThreadPool().execute(
- new TCPWorker(configContext, socket));
+ configContext.getThreadPool().execute(new TCPWorker(configContext, socket));
}
}
-
}
public synchronized void start() throws AxisFault {
if (serversocket == null) {
serversocket = ListenerManager.openSocket(port);
}
+
started = true;
this.configContext.getThreadPool().execute(this);
}
- /* (non-Javadoc)
- * @see org.apache.axis2.transport.TransportListener#replyToEPR(java.lang.String)
- */
- public EndpointReference getReplyToEPR(String serviceName) throws AxisFault {
- //todo this has to fix
- return new EndpointReference("tcp://127.0.0.1:" + (serversocket.getLocalPort()) +
- "/axis/services/" +
- serviceName);
- }
-
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
* @see org.apache.axis2.transport.TransportListener#stop()
*/
public void stop() throws AxisFault {
@@ -121,39 +145,18 @@
}
}
- public void init(ConfigurationContext axisConf,
- TransportInDescription transprtIn)
- throws AxisFault {
- this.configContext = axisConf;
- Parameter param = transprtIn.getParameter(PARAM_PORT);
- if (param != null) {
- int port = Integer.parseInt((String) param.getValue());
- }
- }
-
- public ConfigurationContext getConfigurationContext() {
+ public ConfigurationContext getConfigurationContext() {
return this.configContext;
}
- public static void main(String[] args) throws AxisFault,
- NumberFormatException {
- if (args.length != 2) {
- System.out.println("TCPServer repositoryLocation port");
- } else {
- File repository = new File(args[0]);
- if (!repository.exists()) {
- System.out.print(
- "Repository file does not exists .. initializing repository");
- }
- TCPServer tcpServer = new TCPServer(Integer.parseInt(args[1]),
- repository.getAbsolutePath());
- System.out.println(
- "[Axis2] Using the Repository " +
- repository.getAbsolutePath());
- System.out.println(
- "[Axis2] Starting the TCP Server on port " + args[1]);
- tcpServer.start();
- }
- }
+ /*
+ * (non-Javadoc)
+ * @see org.apache.axis2.transport.TransportListener#replyToEPR(java.lang.String)
+ */
+ public EndpointReference getReplyToEPR(String serviceName) throws AxisFault {
+ // todo this has to fix
+ return new EndpointReference("tcp://127.0.0.1:" + (serversocket.getLocalPort())
+ + "/axis/services/" + serviceName);
+ }
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/tcp/TCPTransportSender.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/tcp/TCPTransportSender.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/tcp/TCPTransportSender.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/tcp/TCPTransportSender.java Fri Dec 16 09:13:57 2005
@@ -1,18 +1,19 @@
/*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
package org.apache.axis2.transport.tcp;
@@ -32,60 +33,55 @@
import java.net.Socket;
import java.net.SocketAddress;
-
public class TCPTransportSender extends AbstractTransportSender {
+
/**
* Field out
*/
protected Writer out;
+ private ByteArrayOutputStream outputStream;
/**
* Field socket
*/
private Socket socket;
- private ByteArrayOutputStream outputStream;
- /**
- * Method writeTransportHeaders
- *
- * @param out
- * @param url
- * @param msgContext
- * @throws IOException
- */
- protected void writeTransportHeaders(Writer out,
- URL url,
- MessageContext msgContext,
- int contentLength)
- throws IOException {
- //TCP no headers :)
+ public void cleanUp(MessageContext msgContext) throws AxisFault {
+ try {
+ if (socket != null) {
+ socket.close();
+ socket = null;
+ }
+ } catch (IOException e) {
+ }
}
- public void finalizeSendWithOutputStreamFromIncomingConnection(
- MessageContext msgContext, OutputStream out) {
+ public void finalizeSendWithOutputStreamFromIncomingConnection(MessageContext msgContext,
+ OutputStream out) {
}
- public void finalizeSendWithToAddress(MessageContext msgContext,
- OutputStream out) throws AxisFault {
+ public void finalizeSendWithToAddress(MessageContext msgContext, OutputStream out)
+ throws AxisFault {
try {
socket.shutdownOutput();
- msgContext.setProperty(MessageContext.TRANSPORT_IN,
- socket.getInputStream());
+ msgContext.setProperty(MessageContext.TRANSPORT_IN, socket.getInputStream());
} catch (IOException e) {
throw new AxisFault(e);
}
}
- protected OutputStream openTheConnection(EndpointReference toURL,
- MessageContext msgContext) throws AxisFault {
+ protected OutputStream openTheConnection(EndpointReference toURL, MessageContext msgContext)
+ throws AxisFault {
if (toURL != null) {
try {
URL url = new URL(toURL.getAddress());
- SocketAddress add =
- new InetSocketAddress(url.getHost(),
- url.getPort() == -1 ? 80 : url.getPort());
+ SocketAddress add = new InetSocketAddress(url.getHost(), (url.getPort() == -1)
+ ? 80
+ : url.getPort());
+
socket = new Socket();
socket.connect(add);
+
return socket.getOutputStream();
} catch (MalformedURLException e) {
throw new AxisFault(e.getMessage(), e);
@@ -93,32 +89,32 @@
throw new AxisFault(e.getMessage(), e);
}
} else {
- throw new AxisFault(Messages.getMessage("canNotBeNull","Can not Be Null"));
+ throw new AxisFault(Messages.getMessage("canNotBeNull", "Can not Be Null"));
}
}
- public OutputStream startSendWithOutputStreamFromIncomingConnection(
- MessageContext msgContext,
- OutputStream out)
+ public OutputStream startSendWithOutputStreamFromIncomingConnection(MessageContext msgContext,
+ OutputStream out)
throws AxisFault {
return out;
}
- public OutputStream startSendWithToAddress(MessageContext msgContext,
- OutputStream out) {
+ public OutputStream startSendWithToAddress(MessageContext msgContext, OutputStream out) {
return out;
}
- public void cleanUp(MessageContext msgContext) throws AxisFault {
- try {
- if (socket != null) {
- socket.close();
- socket = null;
- }
-
- } catch (IOException e) {
- }
+ /**
+ * Method writeTransportHeaders
+ *
+ * @param out
+ * @param url
+ * @param msgContext
+ * @throws IOException
+ */
+ protected void writeTransportHeaders(Writer out, URL url, MessageContext msgContext,
+ int contentLength)
+ throws IOException {
+ // TCP no headers :)
}
-
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/tcp/TCPWorker.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/tcp/TCPWorker.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/tcp/TCPWorker.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/transport/tcp/TCPWorker.java Fri Dec 16 09:13:57 2005
@@ -1,18 +1,19 @@
/*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
package org.apache.axis2.transport.tcp;
@@ -39,8 +40,9 @@
import java.io.OutputStream;
import java.io.Reader;
import java.net.Socket;
+
/**
- * This Class is the work hoarse of the TCP request, this process the incomming SOAP Message.
+ * This Class is the work hoarse of the TCP request, this process the incomming SOAP Message.
*/
public class TCPWorker implements Runnable {
protected Log log = LogFactory.getLog(getClass().getName());
@@ -54,48 +56,56 @@
public void run() {
MessageContext msgContext = null;
+
try {
AxisEngine engine = new AxisEngine(configurationContext);
AxisConfiguration axisConf = configurationContext.getAxisConfiguration();
-
TransportOutDescription transportOut =
- axisConf.getTransportOut(new QName(Constants.TRANSPORT_TCP));
+ axisConf.getTransportOut(new QName(Constants.TRANSPORT_TCP));
TransportInDescription transportIn =
- axisConf.getTransportIn(new QName(Constants.TRANSPORT_TCP));
- if (transportOut != null && transportIn != null) {
- //create the Message Context and fill in the values
+ axisConf.getTransportIn(new QName(Constants.TRANSPORT_TCP));
+
+ if ((transportOut != null) && (transportIn != null)) {
+
+ // create the Message Context and fill in the values
msgContext = new MessageContext(configurationContext, transportIn, transportOut);
msgContext.setServerSide(true);
+
OutputStream out = socket.getOutputStream();
+
msgContext.setProperty(MessageContext.TRANSPORT_OUT, out);
- //create the SOAP Envelope
+ // create the SOAP Envelope
Reader in = new InputStreamReader(socket.getInputStream());
XMLStreamReader xmlreader = XMLInputFactory.newInstance().createXMLStreamReader(in);
StAXBuilder builder = new StAXSOAPModelBuilder(xmlreader, null);
SOAPEnvelope envelope = (SOAPEnvelope) builder.getDocumentElement();
+
msgContext.setEnvelope(envelope);
+
if (envelope.getBody().hasFault()) {
engine.receiveFault(msgContext);
} else {
engine.receive(msgContext);
}
} else {
- throw new AxisFault(Messages.getMessage("unknownTransport",Constants.TRANSPORT_TCP));
+ throw new AxisFault(Messages.getMessage("unknownTransport",
+ Constants.TRANSPORT_TCP));
}
-
} catch (Throwable e) {
try {
AxisEngine engine = new AxisEngine(configurationContext);
+
if (msgContext != null) {
msgContext.setProperty(MessageContext.TRANSPORT_OUT, socket.getOutputStream());
+
MessageContext faultContext = engine.createFaultMessageContext(msgContext, e);
+
engine.sendFault(faultContext);
}
} catch (Exception e1) {
log.error(e);
}
-
} finally {
if (socket != null) {
try {
@@ -104,7 +114,5 @@
}
}
}
-
}
-
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/CallbackReceiver.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/CallbackReceiver.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/CallbackReceiver.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/CallbackReceiver.java Fri Dec 16 09:13:57 2005
@@ -10,15 +10,12 @@
import java.util.HashMap;
/**
- * This is a MessageReceiver which is used on the client side to accept the
+ * This is a MessageReceiver which is used on the client side to accept the
* messages (response) that come to the client. This correlates the incoming message to
- * the related messages and makes a call to the appropriate callback.
+ * the related messages and makes a call to the appropriate callback.
*/
-
public class CallbackReceiver implements MessageReceiver {
-
public static String SERVICE_NAME = "ClientService";
-
private HashMap callbackStore;
public CallbackReceiver() {
@@ -30,20 +27,16 @@
}
public void receive(MessageContext messgeCtx) throws AxisFault {
- RelatesTo relatesTO = messgeCtx.getMessageInformationHeaders()
- .getRelatesTo();
-
+ RelatesTo relatesTO = messgeCtx.getMessageInformationHeaders().getRelatesTo();
String messageID = relatesTO.getValue();
Callback callback = (Callback) callbackStore.get(messageID);
AsyncResult result = new AsyncResult(messgeCtx);
+
if (callback != null) {
callback.onComplete(result);
callback.setComplete(true);
} else {
- throw new AxisFault(
- "The Callback realtes to MessageID " + messageID +
- " is not found");
+ throw new AxisFault("The Callback realtes to MessageID " + messageID + " is not found");
}
}
-
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/HostConfiguration.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/HostConfiguration.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/HostConfiguration.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/HostConfiguration.java Fri Dec 16 09:13:57 2005
@@ -1,4 +1,5 @@
package org.apache.axis2.util;
+
/*
* Copyright 2004,2005 The Apache Software Foundation.
*
@@ -18,10 +19,9 @@
*
*/
-
//to keep infor getting from axis2.xml
-public class HostConfiguration {
+public class HostConfiguration {
private String ip;
private int port;
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/OptionsParser.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/OptionsParser.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/OptionsParser.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/OptionsParser.java Fri Dec 16 09:13:57 2005
@@ -1,20 +1,21 @@
/*
- * Copyright 2001-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright 2001-2004 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
-package org.apache.axis2.util ;
+package org.apache.axis2.util;
/**
* General purpose command line options parser.
@@ -29,31 +30,103 @@
import java.util.Vector;
public class OptionsParser {
- protected static Log log =
- LogFactory.getLog(OptionsParser.class.getName());
-
+ protected static Log log = LogFactory.getLog(OptionsParser.class.getName());
String args[] = null;
Vector usedArgs = null;
- //////////////////////////////////////////////////////////////////////////
+ // ////////////////////////////////////////////////////////////////////////
// SOASS (Start of Axis Specific Stuff)
-
// EOASS
- //////////////////////////////////////////////////////////////////////////
+ // ////////////////////////////////////////////////////////////////////////
/**
* Constructor - just pass in the <b>args</b> from the command line.
*/
public OptionsParser(String _args[]) throws MalformedURLException {
if (_args == null) {
- _args = new String []{};
+ _args = new String[]{};
}
+
args = _args;
usedArgs = null;
-
getUser();
getPassword();
}
+
+ public String getPassword() {
+ return (isValueSet('w'));
+ }
+
+ /**
+ * This returns an array of unused args - these are the non-option
+ * args from the command line.
+ */
+ public String[] getRemainingArgs() {
+ ArrayList al = null;
+ int loop;
+
+ for (loop = 0; loop < args.length; loop++) {
+ if ((args[loop] == null) || (args[loop].length() == 0)) {
+ continue;
+ }
+
+ if (args[loop].charAt(0) == '-') {
+ continue;
+ }
+
+ if (al == null) {
+ al = new ArrayList();
+ }
+
+ al.add((String) args[loop]);
+ }
+
+ if (al == null) {
+ return (null);
+ }
+
+ String a[] = new String[al.size()];
+
+ for (loop = 0; loop < al.size(); loop++) {
+ a[loop] = (String) al.get(loop);
+ }
+
+ return (a);
+ }
+
+ /**
+ * This just returns a string with the unprocessed flags - mainly
+ * for error reporting - so you can report the unknown flags.
+ */
+ public String getRemainingFlags() {
+ StringBuffer sb = null;
+ int loop;
+
+ for (loop = 0; loop < args.length; loop++) {
+ if ((args[loop] == null) || (args[loop].length() == 0)) {
+ continue;
+ }
+
+ if (args[loop].charAt(0) != '-') {
+ continue;
+ }
+
+ if (sb == null) {
+ sb = new StringBuffer();
+ }
+
+ sb.append(args[loop].substring(1));
+ }
+
+ return ((sb == null)
+ ? null
+ : sb.toString());
+ }
+
+ public String getUser() {
+ return (isValueSet('u'));
+ }
+
/**
* Returns an int specifying the number of times that the flag was
* specified on the command line. Once this flag is looked for you
@@ -65,26 +138,46 @@
int loop;
int i;
- for (loop = 0; usedArgs != null && loop < usedArgs.size(); loop++) {
+ for (loop = 0; (usedArgs != null) && (loop < usedArgs.size()); loop++) {
String arg = (String) usedArgs.elementAt(loop);
- if (arg.charAt(0) != '-') continue;
- for (i = 0; i < arg.length(); i++)
- if (arg.charAt(i) == optChar) value++;
+
+ if (arg.charAt(0) != '-') {
+ continue;
+ }
+
+ for (i = 0; i < arg.length(); i++) {
+ if (arg.charAt(i) == optChar) {
+ value++;
+ }
+ }
}
for (loop = 0; loop < args.length; loop++) {
- if (args[loop] == null || args[loop].length() == 0) continue;
- if (args[loop].charAt(0) != '-') continue;
- while (args[loop] != null &&
- (i = args[loop].indexOf(optChar)) != -1) {
+ if ((args[loop] == null) || (args[loop].length() == 0)) {
+ continue;
+ }
+
+ if (args[loop].charAt(0) != '-') {
+ continue;
+ }
+
+ while ((args[loop] != null) && (i = args[loop].indexOf(optChar)) != -1) {
args[loop] = args[loop].substring(0, i) + args[loop].substring(i + 1);
- if (args[loop].length() == 1)
+
+ if (args[loop].length() == 1) {
args[loop] = null;
+ }
+
value++;
- if (usedArgs == null) usedArgs = new Vector();
+
+ if (usedArgs == null) {
+ usedArgs = new Vector();
+ }
+
usedArgs.add("-" + optChar);
}
}
+
return (value);
}
@@ -104,96 +197,80 @@
int loop;
int i;
- for (loop = 0; usedArgs != null && loop < usedArgs.size(); loop++) {
+ for (loop = 0; (usedArgs != null) && (loop < usedArgs.size()); loop++) {
String arg = (String) usedArgs.elementAt(loop);
- if (arg.charAt(0) != '-' || arg.charAt(1) != optChar)
+
+ if ((arg.charAt(0) != '-') || (arg.charAt(1) != optChar)) {
continue;
+ }
+
value = arg.substring(2);
- if (loop + 1 < usedArgs.size())
+
+ if (loop + 1 < usedArgs.size()) {
value = (String) usedArgs.elementAt(++loop);
+ }
}
for (loop = 0; loop < args.length; loop++) {
- if (args[loop] == null || args[loop].length() == 0) continue;
- if (args[loop].charAt(0) != '-') continue;
+ if ((args[loop] == null) || (args[loop].length() == 0)) {
+ continue;
+ }
+
+ if (args[loop].charAt(0) != '-') {
+ continue;
+ }
+
i = args[loop].indexOf(optChar);
- if (i != 1) continue;
+
+ if (i != 1) {
+ continue;
+ }
+
if (i != args[loop].length() - 1) {
- // Not at end of arg, so use rest of arg as value
+
+ // Not at end of arg, so use rest of arg as value
value = args[loop].substring(i + 1);
args[loop] = args[loop].substring(0, i);
} else {
+
// Remove the char from the current arg
args[loop] = args[loop].substring(0, i);
// Nothing after char so use next arg
- if (loop + 1 < args.length && args[loop + 1] != null) {
+ if ((loop + 1 < args.length) && (args[loop + 1] != null)) {
+
// Next arg is there and non-null
if (args[loop + 1].charAt(0) != '-') {
value = args[loop + 1];
args[loop + 1] = null;
}
} else {
+
// Next is null or not there - do nothing
// value = null ;
}
}
- if (args[loop].length() == 1)
+
+ if (args[loop].length() == 1) {
args[loop] = null;
+ }
+
// For now, keep looping to get that last on there
- // break ;
+ // break ;
}
- if (value != null) {
- if (usedArgs == null) usedArgs = new Vector();
- usedArgs.add("-" + optChar);
- if (value.length() > 0) usedArgs.add(value);
- }
- return (value);
- }
-
- /**
- * This just returns a string with the unprocessed flags - mainly
- * for error reporting - so you can report the unknown flags.
- */
- public String getRemainingFlags() {
- StringBuffer sb = null;
- int loop;
- for (loop = 0; loop < args.length; loop++) {
- if (args[loop] == null || args[loop].length() == 0) continue;
- if (args[loop].charAt(0) != '-') continue;
- if (sb == null) sb = new StringBuffer();
- sb.append(args[loop].substring(1));
- }
- return (sb == null ? null : sb.toString());
- }
+ if (value != null) {
+ if (usedArgs == null) {
+ usedArgs = new Vector();
+ }
- /**
- * This returns an array of unused args - these are the non-option
- * args from the command line.
- */
- public String[] getRemainingArgs() {
- ArrayList al = null;
- int loop;
+ usedArgs.add("-" + optChar);
- for (loop = 0; loop < args.length; loop++) {
- if (args[loop] == null || args[loop].length() == 0) continue;
- if (args[loop].charAt(0) == '-') continue;
- if (al == null) al = new ArrayList();
- al.add((String) args[loop]);
+ if (value.length() > 0) {
+ usedArgs.add(value);
+ }
}
- if (al == null) return (null);
- String a[] = new String[ al.size() ];
- for (loop = 0; loop < al.size(); loop++)
- a[loop] = (String) al.get(loop);
- return (a);
- }
- public String getUser() {
- return (isValueSet('u'));
- }
-
- public String getPassword() {
- return (isValueSet('w'));
+ return (value);
}
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/StreamWrapper.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/StreamWrapper.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/StreamWrapper.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/StreamWrapper.java Fri Dec 16 09:13:57 2005
@@ -1,18 +1,19 @@
/*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
package org.apache.axis2.util;
@@ -23,12 +24,10 @@
import javax.xml.stream.XMLStreamReader;
public class StreamWrapper implements XMLStreamReader {
-
- private XMLStreamReader realReader = null;
private static final int STATE_SWITCHED = 0;
private static final int STATE_INIT = 1;
private static final int STATE_SWITHC_AT_NEXT = 2;
-
+ private XMLStreamReader realReader = null;
private int state = STATE_INIT;
private int prevState = state;
@@ -36,19 +35,19 @@
if (realReader == null) {
throw new UnsupportedOperationException("Reader cannot be null");
}
+
this.realReader = realReader;
}
- public Object getProperty(String s) throws IllegalArgumentException {
+ public void close() throws XMLStreamException {
if (prevState != STATE_INIT) {
- return realReader.getProperty(s);
+ realReader.close();
} else {
- throw new IllegalArgumentException();
+ throw new XMLStreamException();
}
}
public int next() throws XMLStreamException {
-
prevState = state;
if (state == STATE_SWITCHED) {
@@ -56,95 +55,97 @@
} else if (state == STATE_INIT) {
if (realReader.getEventType() == START_DOCUMENT) {
state = STATE_SWITCHED;
+
return realReader.getEventType();
} else {
state = STATE_SWITHC_AT_NEXT;
+
return START_DOCUMENT;
}
} else if (state == STATE_SWITHC_AT_NEXT) {
state = STATE_SWITCHED;
+
return realReader.getEventType();
} else {
throw new UnsupportedOperationException();
}
-
}
- public void require(int i, String s, String s1) throws XMLStreamException {
+ public int nextTag() throws XMLStreamException {
if (prevState != STATE_INIT) {
- realReader.require(i, s, s1);
+ return realReader.nextTag();
+ } else {
+ throw new XMLStreamException();
}
}
- public String getElementText() throws XMLStreamException {
+ public void require(int i, String s, String s1) throws XMLStreamException {
if (prevState != STATE_INIT) {
- return realReader.getElementText();
- } else {
- throw new XMLStreamException();
+ realReader.require(i, s, s1);
}
}
- public int nextTag() throws XMLStreamException {
+ public boolean standaloneSet() {
if (prevState != STATE_INIT) {
- return realReader.nextTag();
+ return realReader.standaloneSet();
} else {
- throw new XMLStreamException();
+ return false;
}
}
- public boolean hasNext() throws XMLStreamException {
+ public int getAttributeCount() {
if (prevState != STATE_INIT) {
- return realReader.hasNext();
+ return realReader.getAttributeCount();
} else {
- return true;
+ return 0;
}
}
- public void close() throws XMLStreamException {
+ public String getAttributeLocalName(int i) {
if (prevState != STATE_INIT) {
- realReader.close();
+ return realReader.getAttributeLocalName(i);
} else {
- throw new XMLStreamException();
+ return null;
}
}
- public String getNamespaceURI(String s) {
+ public QName getAttributeName(int i) {
if (prevState != STATE_INIT) {
- return realReader.getNamespaceURI(s);
+ return realReader.getAttributeName(i);
} else {
return null;
}
}
- public boolean isStartElement() {
+ public String getAttributeNamespace(int i) {
if (prevState != STATE_INIT) {
- return realReader.isStartElement();
+ return realReader.getAttributeNamespace(i);
} else {
- return false;
+ return null;
}
}
- public boolean isEndElement() {
+ public String getAttributePrefix(int i) {
if (prevState != STATE_INIT) {
- return realReader.isEndElement();
+ return realReader.getAttributePrefix(i);
} else {
- return false;
+ return null;
}
}
- public boolean isCharacters() {
+ public String getAttributeType(int i) {
if (prevState != STATE_INIT) {
- return realReader.isCharacters();
+ return realReader.getAttributeType(i);
} else {
- return false;
+ return null;
}
}
- public boolean isWhiteSpace() {
+ public String getAttributeValue(int i) {
if (prevState != STATE_INIT) {
- return realReader.isWhiteSpace();
+ return realReader.getAttributeValue(i);
} else {
- return false;
+ return null;
}
}
@@ -156,67 +157,67 @@
}
}
- public int getAttributeCount() {
+ public String getCharacterEncodingScheme() {
if (prevState != STATE_INIT) {
- return realReader.getAttributeCount();
+ return realReader.getCharacterEncodingScheme();
} else {
- return 0;
+ return null;
}
}
- public QName getAttributeName(int i) {
+ public String getElementText() throws XMLStreamException {
if (prevState != STATE_INIT) {
- return realReader.getAttributeName(i);
+ return realReader.getElementText();
} else {
- return null;
+ throw new XMLStreamException();
}
}
- public String getAttributeNamespace(int i) {
+ public String getEncoding() {
if (prevState != STATE_INIT) {
- return realReader.getAttributeNamespace(i);
+ return realReader.getEncoding();
} else {
return null;
}
}
- public String getAttributeLocalName(int i) {
- if (prevState != STATE_INIT) {
- return realReader.getAttributeLocalName(i);
+ public int getEventType() {
+ if (prevState == STATE_INIT) {
+ return START_DOCUMENT;
} else {
- return null;
+ return realReader.getEventType();
}
}
- public String getAttributePrefix(int i) {
+ public String getLocalName() {
if (prevState != STATE_INIT) {
- return realReader.getAttributePrefix(i);
+ return realReader.getLocalName();
} else {
return null;
}
}
- public String getAttributeType(int i) {
+ public Location getLocation() {
if (prevState != STATE_INIT) {
- return realReader.getAttributeType(i);
+ return realReader.getLocation();
} else {
return null;
}
}
- public String getAttributeValue(int i) {
+ public QName getName() {
if (prevState != STATE_INIT) {
- return realReader.getAttributeValue(i);
+ return realReader.getName();
} else {
return null;
}
}
- public boolean isAttributeSpecified(int i) {
+ public NamespaceContext getNamespaceContext() {
if (prevState != STATE_INIT) {
- return realReader.isAttributeSpecified(i);
+ return realReader.getNamespaceContext();
} else {
- return false;
+ return null;
}
}
@@ -236,105 +237,105 @@
}
}
- public String getNamespaceURI(int i) {
+ public String getNamespaceURI() {
if (prevState != STATE_INIT) {
- return realReader.getNamespaceURI(i);
+ return realReader.getNamespaceURI();
} else {
return null;
}
}
- public NamespaceContext getNamespaceContext() {
+ public String getNamespaceURI(int i) {
if (prevState != STATE_INIT) {
- return realReader.getNamespaceContext();
+ return realReader.getNamespaceURI(i);
} else {
return null;
}
}
- public int getEventType() {
- if (prevState == STATE_INIT) {
- return START_DOCUMENT;
+ public String getNamespaceURI(String s) {
+ if (prevState != STATE_INIT) {
+ return realReader.getNamespaceURI(s);
} else {
- return realReader.getEventType();
+ return null;
}
}
- public String getText() {
+ public String getPIData() {
if (prevState != STATE_INIT) {
- return realReader.getText();
+ return realReader.getPIData();
} else {
return null;
}
}
- public char[] getTextCharacters() {
+ public String getPITarget() {
if (prevState != STATE_INIT) {
- return realReader.getTextCharacters();
+ return realReader.getPITarget();
} else {
- return new char[0];
+ return null;
}
}
- public int getTextCharacters(int i, char[] chars, int i1, int i2) throws XMLStreamException {
+ public String getPrefix() {
if (prevState != STATE_INIT) {
- return realReader.getTextCharacters(i, chars, i1, i2);
+ return realReader.getPrefix();
} else {
- return 0;
+ return null;
}
}
- public int getTextStart() {
+ public Object getProperty(String s) throws IllegalArgumentException {
if (prevState != STATE_INIT) {
- return realReader.getTextStart();
+ return realReader.getProperty(s);
} else {
- return 0;
+ throw new IllegalArgumentException();
}
}
- public int getTextLength() {
+ public String getText() {
if (prevState != STATE_INIT) {
- return realReader.getTextStart();
+ return realReader.getText();
} else {
- return 0;
+ return null;
}
}
- public String getEncoding() {
+ public char[] getTextCharacters() {
if (prevState != STATE_INIT) {
- return realReader.getEncoding();
+ return realReader.getTextCharacters();
} else {
- return null;
+ return new char[0];
}
}
- public boolean hasText() {
+ public int getTextCharacters(int i, char[] chars, int i1, int i2) throws XMLStreamException {
if (prevState != STATE_INIT) {
- return realReader.hasText();
+ return realReader.getTextCharacters(i, chars, i1, i2);
} else {
- return false;
+ return 0;
}
}
- public Location getLocation() {
+ public int getTextLength() {
if (prevState != STATE_INIT) {
- return realReader.getLocation();
+ return realReader.getTextStart();
} else {
- return null;
+ return 0;
}
}
- public QName getName() {
+ public int getTextStart() {
if (prevState != STATE_INIT) {
- return realReader.getName();
+ return realReader.getTextStart();
} else {
- return null;
+ return 0;
}
}
- public String getLocalName() {
+ public String getVersion() {
if (prevState != STATE_INIT) {
- return realReader.getLocalName();
+ return realReader.getVersion();
} else {
return null;
}
@@ -348,67 +349,67 @@
}
}
- public String getNamespaceURI() {
+ public boolean hasNext() throws XMLStreamException {
if (prevState != STATE_INIT) {
- return realReader.getNamespaceURI();
+ return realReader.hasNext();
} else {
- return null;
+ return true;
}
}
- public String getPrefix() {
+ public boolean hasText() {
if (prevState != STATE_INIT) {
- return realReader.getPrefix();
+ return realReader.hasText();
} else {
- return null;
+ return false;
}
}
- public String getVersion() {
+ public boolean isAttributeSpecified(int i) {
if (prevState != STATE_INIT) {
- return realReader.getVersion();
+ return realReader.isAttributeSpecified(i);
} else {
- return null;
+ return false;
}
}
- public boolean isStandalone() {
+ public boolean isCharacters() {
if (prevState != STATE_INIT) {
- return realReader.isStandalone();
+ return realReader.isCharacters();
} else {
return false;
}
}
- public boolean standaloneSet() {
+ public boolean isEndElement() {
if (prevState != STATE_INIT) {
- return realReader.standaloneSet();
+ return realReader.isEndElement();
} else {
return false;
}
}
- public String getCharacterEncodingScheme() {
+ public boolean isStandalone() {
if (prevState != STATE_INIT) {
- return realReader.getCharacterEncodingScheme();
+ return realReader.isStandalone();
} else {
- return null;
+ return false;
}
}
- public String getPITarget() {
+ public boolean isStartElement() {
if (prevState != STATE_INIT) {
- return realReader.getPITarget();
+ return realReader.isStartElement();
} else {
- return null;
+ return false;
}
}
- public String getPIData() {
+ public boolean isWhiteSpace() {
if (prevState != STATE_INIT) {
- return realReader.getPIData();
+ return realReader.isWhiteSpace();
} else {
- return null;
+ return false;
}
}
}
Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/URL.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/URL.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/URL.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/URL.java Fri Dec 16 09:13:57 2005
@@ -1,41 +1,48 @@
/*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
package org.apache.axis2.util;
public class URL {
- private String protocol;
- private String host;
private int port = -1;
private String fileName;
+ private String host;
+ private String protocol;
public URL(String url) {
int start = 0;
int end = 0;
+
end = url.indexOf("://");
+
if (end > 0) {
protocol = url.substring(0, end);
start = end + 3;
}
end = url.indexOf('/', start);
+
if (end > 0) {
String hostAndPort = url.substring(start, end);
+
fileName = url.substring(end);
+
int index = hostAndPort.indexOf(':');
+
if (index > 0) {
host = hostAndPort.substring(0, index);
port = Integer.parseInt(hostAndPort.substring(index + 1));
@@ -45,8 +52,6 @@
} else {
host = url;
}
-
-
}
/**
@@ -76,5 +81,4 @@
public String getProtocol() {
return protocol;
}
-
}