1 16 package org.apache.axis2.util; 17 18 import org.apache.axis2.Constants; 19 import org.apache.axis2.description.*; 20 import org.apache.axis2.engine.AxisConfiguration; 21 import org.apache.axis2.engine.AxisFault; 22 import org.apache.axis2.engine.Handler; 23 import org.apache.axis2.engine.MessageReceiver; 24 import org.apache.axis2.phaseresolver.PhaseException; 25 import org.apache.axis2.phaseresolver.PhaseResolver; 26 import org.apache.axis2.receivers.AbstractMessageReceiver; 27 import org.apache.axis2.receivers.RawXMLINOutMessageReceiver; 28 import org.apache.wsdl.WSDLService; 29 30 import javax.xml.namespace.QName ; 31 32 public class Utils { 33 34 public static void addHandler(Flow flow, Handler handler, String phaseName) { 35 HandlerDescription handlerDesc = new HandlerDescription(); 36 PhaseRule rule = new PhaseRule(phaseName); 37 handlerDesc.setRules(rule); 38 handler.init(handlerDesc); 39 handlerDesc.setHandler(handler); 40 flow.addHandler(handlerDesc); 41 } 42 43 56 75 public static ServiceDescription createSimpleService( 76 QName serviceName, 77 MessageReceiver messageReceiver, 78 String className, 79 QName opName) { 80 ServiceDescription service = new ServiceDescription(serviceName); 81 service.setClassLoader(Thread.currentThread().getContextClassLoader()); 82 service.addParameter(new ParameterImpl(AbstractMessageReceiver.SERVICE_CLASS, className)); 83 84 OperationDescription axisOp = new OperationDescription(opName); 85 axisOp.setMessageReciever(messageReceiver); 86 axisOp.setStyle(WSDLService.STYLE_RPC); 87 service.addOperation(axisOp); 88 return service; 89 } 90 91 100 public static ServiceDescription createSimpleService( 101 QName serviceName, 102 String className, 103 QName opName) { 104 return createSimpleService( 105 serviceName, 106 new RawXMLINOutMessageReceiver(), 107 className, 108 opName); 109 } 110 111 public static void resolvePhases(AxisConfiguration axisconfig, ServiceDescription serviceDesc) 120 throws AxisFault, PhaseException { 121 PhaseResolver pr = new PhaseResolver(axisconfig, serviceDesc); 122 pr.buildchains(); 123 } 124 125 public static String getParameterValue(Parameter param) { 126 if (param == null) { 127 return null; 128 } else { 129 return (String ) param.getValue(); 130 } 131 } 132 133 134 135 public static String [] parseRequestURLForServiceAndOperation(String filePart) { 136 String [] values = new String [2]; 137 138 int index = filePart.lastIndexOf(Constants.REQUEST_URL_PREFIX); 139 String serviceStr = null; 140 if (-1 != index) { 141 serviceStr = filePart.substring(index + Constants.REQUEST_URL_PREFIX.length() + 1); 142 if ((index = serviceStr.indexOf('/')) > 0) { 143 values[0] = serviceStr.substring(0, index); 144 int lastIndex = serviceStr.indexOf('?'); 145 if(lastIndex >= 0){ 146 values[1] = serviceStr.substring(index + 1,lastIndex); 147 }else{ 148 values[1] = serviceStr.substring(index + 1); 149 } 150 } else { 151 values[0] = serviceStr; 152 } 153 } 154 return values; 155 } 156 157 } 158 | Popular Tags |