📄 client.java
字号:
if (serviceClass != null) { ep.getBinding().getService().getServiceInfo().setServiceClass(serviceClass); } setService(ep.getBinding().getService()); } public Endpoint findEndpoint(String binding, Collection services) { for (Iterator itr = services.iterator(); itr.hasNext();) { Service service = (Service) itr.next(); for (Iterator eitr = service.getEndpoints().iterator(); eitr.hasNext();) { Endpoint ep = (Endpoint) eitr.next(); if (ep.getBinding().getBindingId().equals(binding)) { return ep; } } } return null; } private Binding findBinding(Transport transport, Service service) { String[] ids = transport.getSupportedBindings(); for (int i = 0; i < ids.length; i++) { Binding b = service.getBinding(ids[i]); if (b != null) { return b; } } return findSoapBinding(service); // throw new IllegalStateException("Couldn't find an appropriate binding for the selected transport."); } private AbstractSoapBinding findSoapBinding(Service service) { for (Iterator itr = service.getBindings().iterator(); itr.hasNext();) { Object o = itr.next(); if (o instanceof AbstractSoapBinding) { return (AbstractSoapBinding) o; } } return null; } public Object[] invoke(OperationInfo op, Object[] params) throws Exception { Invocation call = new Invocation(this); try { invocations.add(call); return call.invoke(op, params); } finally { invocations.remove(call); } } public Object[] invoke(String name, XMLStreamReader reader) throws Exception { Invocation call = new Invocation(this); OperationInfo op = service.getServiceInfo().getOperation(name); if (op == null) throw new XFireRuntimeException("Could not find operation with name " + name); try { invocations.add(call); return call.invoke(op, reader); } finally { invocations.remove(call); } } public Object[] invoke(String name, Object[] params) throws Exception { OperationInfo op = service.getServiceInfo().getOperation(name); if (op == null) throw new XFireRuntimeException("Could not find operation with name " + name); return invoke(op, params); } public void onReceive(MessageContext context, InMessage msg) { if (log.isDebugEnabled()) log.debug("Received message to " + msg.getUri()); if (context.getExchange() == null) { new MessageExchange(context); } MessageExchange exchange = context.getExchange(); if (exchange == null) { exchange = new MessageExchange(context); } if (exchange.getOperation() != null && SoapConstants.MEP_IN.equals(exchange.getOperation().getMEP())) return; exchange.setInMessage(msg); context.setCurrentMessage(msg); context.setService(service); try { //the Client object in the context is not necessary "this" (client.onReceive()) // we need to invoke the handlers from the client in the context not "this" // was creating issues when used in multi-threaded Client contextClient = context.getClient(); HandlerPipeline inPipe = new HandlerPipeline(contextClient.getXFire().getInPhases()); inPipe.addHandlers(contextClient.getInHandlers()); inPipe.addHandlers(contextClient.getTransport().getInHandlers()); context.setInPipeline(inPipe); inPipe.invoke(context); } catch (Exception e1) { XFireFault fault = XFireFault.createFault(e1); AbstractMessage faultMsg = context.getExchange().getFaultMessage(); faultMsg.setBody(fault); context.setCurrentMessage(faultMsg); HandlerPipeline inPipe = new HandlerPipeline(getXFire().getInPhases()); inPipe.addHandlers(getFaultHandlers()); inPipe.addHandlers(getTransport().getFaultHandlers()); context.setInPipeline(inPipe); try { inPipe.invoke(context); } catch (Exception e) { if (e instanceof XFireRuntimeException) throw (XFireRuntimeException) e; throw new XFireRuntimeException("Could not receive fault.", e); } } } public Channel getOutChannel() { if (outChannel != null) return outChannel; try { String uri = getEndpointUri(); if (uri == null) outChannel = getTransport().createChannel(); else outChannel = getTransport().createChannel(uri); } catch (Exception e) { throw new XFireRuntimeException("Couldn't open channel.", e); } outChannel.setEndpoint(this); return outChannel; } public void close() { if (outChannel != null) outChannel.close(); } public Transport getTransport() { return transport; } public void setTransport(Transport transport) { this.transport = transport; } public Service getService() { return service; } public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } public String getEndpointUri() { return endpointUri; } public void setEndpointUri(String endpointUri) { this.endpointUri = endpointUri; } public int getTimeout() { return timeout; } public void setTimeout(int timeout) { this.timeout = timeout; } public XFire getXFire() { return xfire; } public void setXFire(XFire xfire) { this.xfire = xfire; } /** * Return the underlying Client instance for a client Proxy. * * @see XFireProxy * @see XFireProxyFactory * @param service * @return */ public static Client getInstance(Object service) { Object proxy = Proxy.getInvocationHandler(service); if( proxy == null || !(proxy instanceof XFireProxy) ){ throw new IllegalArgumentException("Argument is not an XFireProxy"); } return ((XFireProxy)proxy ).getClient(); } Binding getBinding() { return binding; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -