Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/SimpleMailListener.java URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/SimpleMailListener.java?view=diff&rev=529306&r1=529305&r2=529306 ============================================================================== --- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/SimpleMailListener.java (original) +++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/SimpleMailListener.java Mon Apr 16 09:15:48 2007 @@ -91,21 +91,21 @@ public SimpleMailListener() { } + /** + * This constructor will be used in when Mail simulate the request/response + * + * @param messageQueue + */ + public SimpleMailListener(LinkedBlockingQueue messageQueue) { + this.messageQueue = messageQueue; + } + public void init(ConfigurationContext configurationContext, TransportInDescription transportIn) throws AxisFault { this.configurationContext = configurationContext; ArrayList mailParameters = transportIn.getParameters(); - replyTo = Utils.getParameterValue( - transportIn.getParameter(org.apache.axis2.transport.mail.Constants.RAPLY_TO)); - Parameter listenerWaitIntervalParam = transportIn - .getParameter(org.apache.axis2.transport.mail.Constants.LISTENER_INTERVAL); - if (listenerWaitIntervalParam != null) { - listenerWaitInterval = - Integer.parseInt(Utils.getParameterValue(listenerWaitIntervalParam)); - } - String password = ""; String host = ""; String protocol = ""; @@ -117,8 +117,9 @@ String paramKey = param.getName(); String paramValue = Utils.getParameterValue(param); if (paramKey == null || paramValue == null) { - throw new AxisFault(Messages.getMessage("canNotBeNull", - "Parameter name and value")); + String error = Messages.getMessage("canNotBeNull", "Parameter name and value"); + log.error(error); + throw new AxisFault(error); } pop3Properties.setProperty(paramKey, paramValue); @@ -138,11 +139,21 @@ port = paramValue; } + //Transport specific + if (paramKey.equals(org.apache.axis2.transport.mail.Constants.REPLY_TO)) { + replyTo = paramValue; + } + if (paramKey.equals(org.apache.axis2.transport.mail.Constants.LISTENER_INTERVAL)) { + listenerWaitInterval = Integer.parseInt(paramValue); + } + } if (password.length() == 0 || user.length() == 0 || host.length() == 0 || protocol.length() == 0) { - throw new AxisFault( - "One or more of Password, User, Host and Protocol are null or empty"); + String error = SimpleMailListener.class.getName() + + " one or more of Password, User, Host and Protocol are null or empty"; + log.error(error); + throw new AxisFault(error); } if (port.length() == 0) { @@ -158,10 +169,52 @@ } + public void initFromRuntime(Properties properties, MessageContext msgContext) throws AxisFault { + + this.configurationContext = msgContext.getConfigurationContext(); + + String password = ""; + String host = ""; + String protocol = ""; + String port = ""; + URLName urlName; + + pop3Properties.clear(); + pop3Properties.putAll(properties); + + user = properties.getProperty(org.apache.axis2.transport.mail.Constants.POP3_USER); + password = properties.getProperty(org.apache.axis2.transport.mail.Constants.POP3_PASSWORD); + host = properties.getProperty(org.apache.axis2.transport.mail.Constants.POP3_HOST); + protocol = properties.getProperty(org.apache.axis2.transport.mail.Constants.STORE_PROTOCOL); + port = properties.getProperty(org.apache.axis2.transport.mail.Constants.POP3_PORT); + replyTo = properties.getProperty(org.apache.axis2.transport.mail.Constants.REPLY_TO); + String value = + properties.getProperty(org.apache.axis2.transport.mail.Constants.LISTENER_INTERVAL); + if (value != null) { + listenerWaitInterval = Integer.parseInt(value); + } + + if (password.length() == 0 || user.length() == 0 || host.length() == 0 || + protocol.length() == 0) { + String error = SimpleMailListener.class.getName() + " one or more of Password, User," + + " Host and Protocol are null or empty" + "in runtime settings"; + log.error(error); + throw new AxisFault(error); + } + + if (port == null) { + urlName = new URLName(protocol, host, -1, "", user, password); + } else { + urlName = new URLName(protocol, host, Integer.parseInt(port), "", user, password); + } + + receiver = new EmailReceiver(); + receiver.setPop3Properties(pop3Properties); + receiver.setUrlName(urlName); + } + /** * Server process. - * @param args command line args - * @throws AxisFault if a problem occurs */ public static void main(String args[]) throws AxisFault { if (args.length < 2) { @@ -271,9 +324,11 @@ msgContext.setIncomingTransportName(org.apache.axis2.Constants.TRANSPORT_MAIL); MailBasedOutTransportInfo transportInfo = new MailBasedOutTransportInfo(); - if (msg.getFrom() != null && msg.getFrom().length > 0) { - EndpointReference fromEPR = new EndpointReference((msg.getFrom()[0]).toString()); - msgContext.setFrom(fromEPR); + Address[] mimefroms = msg.getFrom(); + if (mimefroms != null && mimefroms.length > 0) { + EndpointReference fromEPR = new EndpointReference( + org.apache.axis2.transport.mail.Constants.MAILTO + ":" + + msg.getFrom()[0].toString()); transportInfo.setFrom(fromEPR); } @@ -282,6 +337,11 @@ if (smtpMessageId != null) { transportInfo.setInReplyTo(smtpMessageId); } + String inReplyTo = + getMailHeader(msg, org.apache.axis2.transport.mail.Constants.IN_REPLY_TO); + if (inReplyTo != null) { + transportInfo.setInReplyTo(inReplyTo); + } msgContext.setProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO, transportInfo); buildSOAPEnvelope(msg, msgContext); @@ -353,7 +413,6 @@ } } -/* Commented since this is never used...? private String getMailHeader(MimeMessage msg, String headerName) throws AxisFault { try { String values[] = msg.getHeader(headerName); @@ -367,7 +426,6 @@ throw AxisFault.makeFault(e); } } -*/ private String getMailHeaderFromPart(Part part, String headerName) throws AxisFault { try { @@ -422,9 +480,14 @@ } public EndpointReference[] getEPRsForService(String serviceName, String ip) throws AxisFault { - return new EndpointReference[]{new EndpointReference(Constants.TRANSPORT_MAIL + ":" + - replyTo + "?" + configurationContext - .getServiceContextPath() + "/" + serviceName)}; + return new EndpointReference[]{ + new EndpointReference(Constants.TRANSPORT_MAIL + ":" + replyTo + "?" + + configurationContext.getServiceContextPath() + "/" + + serviceName), + new EndpointReference(Constants.TRANSPORT_MAIL + ":" + replyTo + "?" + + org.apache.axis2.transport.mail.Constants.X_SERVICE_PATH + "=" + + configurationContext.getServiceContextPath() + "/" + + serviceName)}; } @@ -434,5 +497,9 @@ public void destroy() { this.configurationContext = null; + } + + public LinkedBlockingQueue getLinkedBlockingQueue() { + return messageQueue; } }
Added: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/SynchronousMailListener.java URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/SynchronousMailListener.java?view=auto&rev=529306 ============================================================================== --- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/SynchronousMailListener.java (added) +++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/SynchronousMailListener.java Mon Apr 16 09:15:48 2007 @@ -0,0 +1,108 @@ +/* + * 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; + +import edu.emory.mathcs.backport.java.util.concurrent.LinkedBlockingQueue; +import org.apache.axis2.AxisFault; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.description.TransportInDescription; +import org.apache.axis2.wsdl.WSDLConstants; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.Properties; +/* + * + */ + +public class SynchronousMailListener { + + private static Log log = LogFactory.getLog(SynchronousMailListener.class); + + private long timeoutInMilliseconds = -1; + + public SynchronousMailListener(long timeoutInMilliseconds) { + this.timeoutInMilliseconds = timeoutInMilliseconds; + } + + + public void sendReceive(final MessageContext msgContext, final String msgId) throws AxisFault { + /** + * This will be bloked invocation + */ + SimpleMailListener listener = new SimpleMailListener(new LinkedBlockingQueue()) { + public void start() throws AxisFault { + long timeStatus; + LinkedBlockingQueue queue = getLinkedBlockingQueue(); + while (true) { + long startTime = System.currentTimeMillis(); + try { + MessageContext msgCtx = (MessageContext) queue.take(); + MailBasedOutTransportInfo transportInfo = (MailBasedOutTransportInfo) msgCtx + .getProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO); + if (transportInfo.getInReplyTo() == null) { + String error = EMailSender.class.getName() +" Coudn't simulate request/response without In-Reply-To Mail header"; + log.error(error); + throw new AxisFault(error); + } + if (transportInfo.getInReplyTo().equals(msgId)) { + msgContext.getOperationContext() + .getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE) + .setEnvelope(msgCtx.getEnvelope()); + log.info(SynchronousMailListener.class.getName() + " found the required message."); + break; + } + + } catch (InterruptedException e) { + log.warn(e); + throw AxisFault.makeFault(e); + } + long endTime = System.currentTimeMillis(); + timeStatus = endTime - startTime; + if (timeoutInMilliseconds != -1 && timeStatus > timeoutInMilliseconds) { + /*TODO What should be the best default value for timeoutInMilliseconds ?*/ + /*log.info(SynchronousMailListener.class.getName() + " timeout"); + break;*/ + } + + } + + + } + }; + + TransportInDescription transportIn = msgContext.getConfigurationContext() + .getAxisConfiguration().getTransportIn(org.apache.axis2.Constants.TRANSPORT_MAIL); + + Object obj = msgContext.getProperty(Constants.MAIL_POP3); + if (obj != null) { + listener.initFromRuntime((Properties)obj,msgContext); + } else { + listener.init(msgContext.getConfigurationContext(), transportIn); + } + msgContext.getConfigurationContext().getThreadPool().execute(listener); + listener.start(); + + } + + public long getTimeoutInMilliseconds() { + return timeoutInMilliseconds; + } + + public void setTimeoutInMilliseconds(long timeoutInMilliseconds) { + this.timeoutInMilliseconds = timeoutInMilliseconds; + } +} Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/Counter.java URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/Counter.java?view=diff&rev=529306&r1=529305&r2=529306 ============================================================================== --- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/Counter.java (original) +++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/Counter.java Mon Apr 16 09:15:48 2007 @@ -22,44 +22,9 @@ // Counter uses java.util.concurrent.atomic.AtomicLong if present, // else falls back to the backport version public class Counter { - private static Class clazz; - private static Method method; - private Object counter; + private long value = 0L; - static { - try { - clazz = Class.forName("java.util.concurrent.atomic.AtomicLong"); - } catch (ClassNotFoundException e) { - try { - clazz = Class.forName("edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicLong"); - } catch (ClassNotFoundException e1) { - throw new RuntimeException(e1); - } - } - try { - method = clazz.getMethod("incrementAndGet", new Class[]{}); - } catch (NoSuchMethodException e) { - throw new RuntimeException(e); - } - } - - public Counter() { - try { - counter = clazz.newInstance(); - } catch (InstantiationException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } - } - - public final synchronized long incrementAndGet() { - try { - return ((Long) method.invoke(counter, new Object[]{})).longValue(); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } catch (InvocationTargetException e) { - throw new RuntimeException(e); - } + public synchronized long incrementAndGet() { + return ++value; } } Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/WSDLSerializationUtil.java URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/WSDLSerializationUtil.java?view=diff&rev=529306&r1=529305&r2=529306 ============================================================================== --- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/WSDLSerializationUtil.java (original) +++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/WSDLSerializationUtil.java Mon Apr 16 09:15:48 2007 @@ -28,6 +28,7 @@ import org.apache.axis2.wsdl.HTTPHeaderMessage; import org.apache.axis2.namespace.Constants; import org.apache.axis2.AxisFault; +import org.apache.axis2.addressing.AddressingConstants; import org.apache.axiom.om.OMElement; import org.apache.axiom.om.OMFactory; import org.apache.axiom.om.OMNamespace; @@ -174,6 +175,7 @@ WSDL2Constants.URI_WSDL2_SOAP)); binding.addAttribute(fac.createOMAttribute(WSDL2Constants.ATTRIBUTE_VERSION, wsoap, WSDL2Constants.SOAP_VERSION_1_1)); + generateDefaultSOAPBindingOperations(axisService, fac, binding, tns, wsoap); return binding; } @@ -198,6 +200,7 @@ WSDL2Constants.URI_WSDL2_SOAP)); binding.addAttribute(fac.createOMAttribute(WSDL2Constants.ATTRIBUTE_VERSION, wsoap, WSDL2Constants.SOAP_VERSION_1_2)); + generateDefaultSOAPBindingOperations(axisService, fac, binding, tns, wsoap); return binding; } @@ -234,6 +237,20 @@ return binding; } + private static void generateDefaultSOAPBindingOperations(AxisService axisService, OMFactory omFactory, OMElement binding, OMNamespace tns, OMNamespace wsoap) { + Iterator iterator = axisService.getChildren(); + while (iterator.hasNext()) { + AxisOperation axisOperation = (AxisOperation) iterator.next(); + OMElement opElement = omFactory.createOMElement(WSDL2Constants.OPERATION_LOCAL_NAME, null); + binding.addChild(opElement); + String name = axisOperation.getName().getLocalPart(); + opElement.addAttribute(omFactory.createOMAttribute(WSDL2Constants.ATTRIBUTE_REF, null, + tns.getPrefix() + ":" + name)); + opElement.addAttribute(omFactory.createOMAttribute(WSDL2Constants.ATTRIBUTE_ACTION, wsoap, + axisOperation.getInputAction())); + } + } + /** * Generates a default service element * @param omFactory - The OMFactory @@ -298,10 +315,12 @@ /** * Adds the namespaces to the given OMElement + * * @param descriptionElement - The OMElement that the namespaces should be added to * @param nameSpaceMap - The namespaceMap */ public static void populateNamespaces(OMElement descriptionElement, Map nameSpaceMap) { + if (nameSpaceMap != null) { Iterator keys = nameSpaceMap.keySet().iterator(); while (keys.hasNext()) { String key = (String) keys.next(); @@ -310,6 +329,46 @@ } else { descriptionElement.declareNamespace((String) nameSpaceMap.get(key), key); } + } + } + } + + public static void addWSAWActionAttribute(OMElement element, String action) { + if (action == null || action.length() == 0) { + return; + } + OMNamespace namespace = element.declareNamespace( + AddressingConstants.Final.WSAW_NAMESPACE, "wsaw"); + element.addAttribute("Action", action, namespace); + } + + public static void addExtensionElement(OMFactory fac, OMElement element, + String name, String att1Name, String att1Value, + OMNamespace soapNameSpace) { + OMElement extElement = fac.createOMElement(name, soapNameSpace); + element.addChild(extElement); + extElement.addAttribute(att1Name, att1Value, null); + } + + public static void addWSAddressingToBinding(String addressingFlag, OMFactory omFactory, OMElement bindingElement) { + // Add WS-Addressing UsingAddressing element if appropriate + // SHOULD be on the binding element per the specification + if (addressingFlag.equals( + AddressingConstants.ADDRESSING_OPTIONAL)) { + OMNamespace wsawNamespace = omFactory.createOMNamespace( + AddressingConstants.Final.WSAW_NAMESPACE, "wsaw"); + WSDLSerializationUtil.addExtensionElement(omFactory, bindingElement, + AddressingConstants.USING_ADDRESSING, + "required", "true", + wsawNamespace); + } else if (addressingFlag.equals( + AddressingConstants.ADDRESSING_REQUIRED)) { + OMNamespace wsawNamespace = omFactory.createOMNamespace( + AddressingConstants.Final.WSAW_NAMESPACE, "wsaw"); + WSDLSerializationUtil.addExtensionElement(omFactory, bindingElement, + AddressingConstants.USING_ADDRESSING, + "required", "true", + wsawNamespace); } } } Modified: webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/transport/http/util/URLTemplatingUtilTest.java URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/transport/http/util/URLTemplatingUtilTest.java?view=diff&rev=529306&r1=529305&r2=529306 ============================================================================== --- webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/transport/http/util/URLTemplatingUtilTest.java (original) +++ webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/transport/http/util/URLTemplatingUtilTest.java Mon Apr 16 09:15:48 2007 @@ -52,7 +52,8 @@ public void testGetTemplatedURL() throws AxisFault, MalformedURLException { URL testURL = - new URL("http://locahost:8080/paramOne/{FirstName}?test=1&lastName={LastName}"); + new URL("http://locahost:8080/paramOne"); + messageContext.setProperty(WSDL2Constants.ATTR_WHTTP_LOCATION, "{FirstName}?test=1&lastName={LastName}"); URL modifiedURL = URLTemplatingUtil.getTemplatedURL(testURL, messageContext, true); System.out.println("original = " + testURL); @@ -65,6 +66,7 @@ public void testAppendParametersToURL() throws MalformedURLException, AxisFault { URL testURL = new URL("http://locahost:8080/paramOne"); + messageContext.setProperty(WSDL2Constants.ATTR_WHTTP_LOCATION, null); URL modifiedURL = URLTemplatingUtil.appendQueryParameters(messageContext,testURL); System.out.println("original = " + testURL); @@ -76,6 +78,7 @@ public void testQueryParameterSeperator() throws MalformedURLException, AxisFault { URL testURL = new URL("http://locahost:8080/paramOne"); + messageContext.setProperty(WSDL2Constants.ATTR_WHTTP_LOCATION, null); messageContext.setProperty(WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR,";"); URL modifiedURL = URLTemplatingUtil.appendQueryParameters(messageContext,testURL); @@ -86,24 +89,11 @@ assertEquals(modifiedURL.toString(), expectedURL); } - public void testIgnoreUncitedTrue() throws MalformedURLException, AxisFault { - - URL testURL = new URL("http://locahost:8080/paramOne/Foo?test=1"); - messageContext.setProperty(WSDL2Constants.ATTR_WHTTP_IGNORE_UNCITED,"true"); - URL modifiedURL = URLTemplatingUtil.appendQueryParameters(messageContext,testURL); - - System.out.println("original = " + testURL); - System.out.println("modifiedURL = " + modifiedURL); - - String expectedURL = "http://locahost:8080/paramOne/Foo?test=1"; - assertEquals(modifiedURL.toString(), expectedURL); - - } - public void testIgnoreUncitedFalse() throws MalformedURLException, AxisFault { URL testURL = new URL("http://locahost:8080/paramOne/Foo?test=1"); messageContext.setProperty(WSDL2Constants.ATTR_WHTTP_IGNORE_UNCITED,"false"); + messageContext.setProperty(WSDL2Constants.ATTR_WHTTP_LOCATION, null); URL modifiedURL = URLTemplatingUtil.appendQueryParameters(messageContext,testURL); System.out.println("original = " + testURL); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
