1 16 17 package org.apache.axis.transport.local; 18 19 import org.apache.axis.AxisFault; 20 import org.apache.axis.Constants; 21 import org.apache.axis.Message; 22 import org.apache.axis.MessageContext; 23 import org.apache.axis.attachments.Attachments; 24 import org.apache.axis.components.logger.LogFactory; 25 import org.apache.axis.handlers.BasicHandler; 26 import org.apache.axis.message.SOAPEnvelope; 27 import org.apache.axis.message.SOAPFault; 28 import org.apache.axis.server.AxisServer; 29 import org.apache.axis.utils.Messages; 30 import org.apache.commons.logging.Log; 31 32 import java.net.URL ; 33 34 39 public class LocalSender extends BasicHandler { 40 protected static Log log = 41 LogFactory.getLog(LocalSender.class.getName()); 42 43 private volatile AxisServer server; 44 45 48 public synchronized void init() { 49 this.server= new AxisServer(); 50 } 51 52 public void invoke(MessageContext clientContext) throws AxisFault { 53 if (log.isDebugEnabled()) { 54 log.debug("Enter: LocalSender::invoke"); 55 } 56 57 AxisServer targetServer = 58 (AxisServer)clientContext.getProperty(LocalTransport.LOCAL_SERVER); 59 60 if (log.isDebugEnabled()) { 61 log.debug(Messages.getMessage("usingServer00", 62 "LocalSender", "" + targetServer)); 63 } 64 65 if (targetServer == null) { 66 if (server == null) init(); 69 targetServer = server; 70 } 71 72 MessageContext serverContext = new MessageContext(targetServer); 74 75 78 80 Message clientRequest = clientContext.getRequestMessage(); 81 82 String msgStr = clientRequest.getSOAPPartAsString(); 83 84 if (log.isDebugEnabled()) { 85 log.debug(Messages.getMessage("sendingXML00", "LocalSender")); 86 log.debug(msgStr); 87 } 88 89 Message serverRequest = new Message(msgStr); 90 91 Attachments serverAttachments = serverRequest.getAttachmentsImpl(); 92 Attachments clientAttachments = clientRequest.getAttachmentsImpl(); 93 94 if (null != clientAttachments && null != serverAttachments) { 95 serverAttachments.setAttachmentParts(clientAttachments.getAttachments()); 96 } 97 98 serverContext.setRequestMessage(serverRequest); 99 100 102 serverContext.setTransportName("local"); 103 104 String user = clientContext.getUsername(); 106 if (user != null) { 107 serverContext.setUsername(user); 108 String pass = clientContext.getPassword(); 109 if (pass != null) 110 serverContext.setPassword(pass); 111 } 112 113 String transURL = clientContext.getStrProp(MessageContext.TRANS_URL); 115 if (transURL != null) { 116 try { 117 URL url = new URL (transURL); 118 String file = url.getFile(); 119 if (file.length()>0 && file.charAt(0)=='/') { 120 file = file.substring(1); 121 } 122 serverContext.setProperty(Constants.MC_REALPATH, file); 123 serverContext.setProperty(MessageContext.TRANS_URL, 124 "local:///" + file); 125 serverContext.setTargetService(file); 127 } catch (Exception e) { 128 throw AxisFault.makeFault(e); 129 } 130 } 131 132 String remoteService = clientContext.getStrProp(LocalTransport.REMOTE_SERVICE); 136 if (remoteService != null) 137 serverContext.setTargetService(remoteService); 138 139 try { 141 targetServer.invoke(serverContext); 142 } catch (AxisFault fault) { 143 Message respMsg = serverContext.getResponseMessage(); 144 if (respMsg == null) { 145 respMsg = new Message(fault); 146 serverContext.setResponseMessage(respMsg); 147 } else { 148 SOAPFault faultEl = new SOAPFault(fault); 149 SOAPEnvelope env = respMsg.getSOAPEnvelope(); 150 env.clearBody(); 151 env.addBodyElement(faultEl); 152 } 153 } 154 155 clientContext.setResponseMessage(serverContext.getResponseMessage()); 158 clientContext.getResponseMessage().getSOAPPartAsString(); 159 160 if (log.isDebugEnabled()) { 161 log.debug("Exit: LocalSender::invoke"); 162 } 163 } 164 } 165 | Popular Tags |