clientwrapper.java
来自「提供ESB 应用mule源代码 提供ESB 应用mule源代码」· Java 代码 · 共 471 行 · 第 1/2 页
JAVA
471 行
} } protected void createClientFromClass(Bus bus, String clientClassName) throws Exception { // TODO: Specify WSDL String wsdlLocation = (String) endpoint.getProperty(CxfConstants.WSDL_LOCATION); Class<?> clientCls = ClassLoaderUtils.loadClass(clientClassName, getClass()); Service s = null; if (wsdlLocation != null) { Constructor<?> cons = clientCls.getConstructor(URL.class, QName.class); ResourceManager rr = bus.getExtension(ResourceManager.class); URL url = rr.resolveResource(wsdlLocation, URL.class); if (url == null) { URIResolver res = new URIResolver(wsdlLocation); if (!res.isResolved()) { throw new CreateException(CxfMessages.wsdlNotFound(wsdlLocation), this); } url = res.getURL(); } WebServiceClient clientAnn = clientCls.getAnnotation(WebServiceClient.class); QName svcName = new QName(clientAnn.targetNamespace(), clientAnn.name()); s = (Service) cons.newInstance(url, svcName); } else { s = (Service) clientCls.newInstance(); } String port = (String) endpoint.getProperty(CxfConstants.CLIENT_PORT); if (port == null) { throw new CreateException(CxfMessages.mustSpecifyPort(), this); } clientProxy = null; if (port != null) { for (Method m : clientCls.getMethods()) { WebEndpoint we = m.getAnnotation(WebEndpoint.class); if (we != null && we.name().equals(port) && m.getParameterTypes().length == 0) { clientProxy = (BindingProvider) m.invoke(s, new Object[0]); break; } } } if (clientProxy == null) { throw new CreateException(CxfMessages.portNotFound(port), this); } EndpointURI uri = endpoint.getEndpointURI(); if (uri.getUser() != null) { clientProxy.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, uri.getUser()); } if (uri.getPassword() != null) { clientProxy.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, uri.getPassword()); } clientProxy.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, uri.getAddress()); client = ClientProxy.getClient(clientProxy); defaultMethod = findMethod(clientCls); defaultMethodName = getDefaultMethodName(); } private String getDefaultMethodName() { EndpointURI endpointUri = endpoint.getEndpointURI(); String m = (String) endpointUri.getParams().get(MuleProperties.MULE_METHOD_PROPERTY); if (m == null) { m = (String) endpoint.getProperties().get(MuleProperties.MULE_METHOD_PROPERTY); } return m; } protected void createClientFromLocalServer(final Bus bus) throws Exception { String uri = endpoint.getEndpointURI().toString(); int idx = uri.indexOf('?'); if (idx != -1) { uri = uri.substring(0, idx); } EndpointInfo ei = new EndpointInfo(); ei.setAddress(uri); DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class); DestinationFactory df = dfm.getDestinationFactoryForUri(uri); if (df == null) { throw new Exception("Could not find a destination factory for uri " + uri); } Destination dest = df.getDestination(ei); MessageObserver mo = dest.getMessageObserver(); if (mo instanceof ChainInitiationObserver) { ChainInitiationObserver cMo = (ChainInitiationObserver) mo; Endpoint cxfEP = cMo.getEndpoint(); client = new ClientImpl(bus, cxfEP); } else { throw new Exception("Could not create client! No Server was found directly on the endpoint: " + uri); } } protected void addMuleInterceptors() { client.getInInterceptors().add(new MuleHeadersInInterceptor()); client.getInFaultInterceptors().add(new MuleHeadersInInterceptor()); client.getOutInterceptors().add(new MuleHeadersOutInterceptor()); client.getOutFaultInterceptors().add(new MuleHeadersOutInterceptor()); client.getOutInterceptors().add(new MuleProtocolHeadersOutInterceptor()); client.getOutFaultInterceptors().add(new MuleProtocolHeadersOutInterceptor()); } protected String getMethodOrOperationName(MuleEvent event) throws DispatchException { // @TODO: Which of these *really* matter? String method = (String) event.getMessage().getProperty(MuleProperties.MULE_METHOD_PROPERTY); if (method == null) { method = (String) event.getMessage().getProperty(CxfConstants.OPERATION); } if (method == null) { method = defaultMethodName; } if (method == null && proxy) { return "invoke"; } if (method == null) { throw new DispatchException(SoapMessages.cannotInvokeCallWithoutOperation(), event.getMessage(), event.getEndpoint()); } return method; } public void setEndpoint(ImmutableEndpoint endpoint) { this.endpoint = endpoint; } public void setBus(Bus bus) { this.bus = bus; } public boolean isClientProxyAvailable() { return clientProxy != null; } public BindingOperationInfo getOperation(MuleEvent event) throws Exception { String opName = getMethodOrOperationName(event); if (opName == null) { opName = defaultMethodName; } return getOperation(opName); } public Method getMethod(MuleEvent event) throws Exception { Method method = defaultMethod; if (method == null) { String opName = (String) event.getMessage().getProperty(CxfConstants.OPERATION); if (opName != null) { method = getMethodFromOperation(opName); } if (method == null) { opName = (String) endpoint.getProperty(CxfConstants.OPERATION); if (opName != null) { method = getMethodFromOperation(opName); } } if (method == null) { opName = defaultMethodName; if (opName != null) { method = getMethodFromOperation(opName); } } } if (method == null) { throw new DispatchException(CxfMessages.noOperationWasFoundOrSpecified(), event.getMessage(), endpoint); } return method; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?