📄 odeservice.java
字号:
try { _txManager.rollback(); } catch (Exception ex) { throw new OdeFault("Rollback failed!", ex); } } } } if (!success) { throw new OdeFault("Message was either unroutable or timed out!"); } } else { // One ways cleanup odeMex.release(); } } public boolean respondsTo(QName serviceName, QName portTypeName) { boolean result = _serviceName.equals(serviceName); result = result && _wsdlDef.getService(_serviceName).getPort(_portName).getBinding().getPortType().getQName().equals( portTypeName); return result; } /** * do not store the value so it can be dynamically updated */ private long getTimeout() { String timeout = _pconf.getEndpointProperties(_serviceRef).get(Properties.PROP_MEX_TIMEOUT); if (timeout != null) { try { return Long.parseLong(timeout); } catch (NumberFormatException e) { if(__log.isWarnEnabled()) __log.warn("Mal-formatted Property: ["+ Properties.PROP_MEX_TIMEOUT+"="+timeout+"] Default value ("+Properties.DEFAULT_MEX_TIMEOUT+") will be used"); } } return Properties.DEFAULT_MEX_TIMEOUT; } private void onResponse(MyRoleMessageExchange mex, MessageContext msgContext) throws AxisFault { switch (mex.getStatus()) { case FAULT: if (__log.isDebugEnabled()) __log.debug("Fault response message: " + mex.getFault()); SOAPFault fault = _converter.createSoapFault(mex.getFaultResponse().getMessage(), mex.getFault(), mex.getOperation()); msgContext.getEnvelope().getBody().addFault(fault); if (__log.isDebugEnabled()) __log.debug("Returning fault: " + msgContext.getEnvelope().toString()); break; case ASYNC: case RESPONSE: _converter.createSoapResponse(msgContext, mex.getResponse(), mex.getOperation()); if (__log.isDebugEnabled()) __log.debug("Response message " + msgContext.getEnvelope()); writeHeader(msgContext, mex); break; case FAILURE: throw new OdeFault("Message exchange failure"); default: throw new OdeFault("Received ODE message exchange in unexpected state: " + mex.getStatus()); } } /** * Extracts endpoint information from Axis MessageContext (taken from WSA * headers) to stuff them into ODE mesage exchange. */ private void readHeader(MessageContext msgContext, MyRoleMessageExchange odeMex) { Object otse = msgContext.getProperty("targetSessionEndpoint"); Object ocse = msgContext.getProperty("callbackSessionEndpoint"); if (otse != null) { Element serviceEpr = (Element) otse; WSAEndpoint endpoint = new WSAEndpoint(); endpoint.set(serviceEpr); // Extract the session ID for the local process. odeMex.setProperty(MessageExchange.PROPERTY_SEP_MYROLE_SESSIONID, endpoint.getSessionId()); } if (ocse != null) { Element serviceEpr = (Element) ocse; WSAEndpoint endpoint = new WSAEndpoint(); endpoint.set(serviceEpr); // Save the session id of the remote process. Also, magically // initialize the EPR // of the partner to the EPR provided. odeMex.setProperty(MessageExchange.PROPERTY_SEP_PARTNERROLE_SESSIONID, endpoint.getSessionId()); odeMex.setProperty(MessageExchange.PROPERTY_SEP_PARTNERROLE_EPR, DOMUtils.domToString(serviceEpr)); } } /** * Handle callback endpoints for the case where partner contact process * my-role which results in an "updated" my-role EPR due to session id * injection. */ private void writeHeader(MessageContext msgContext, MyRoleMessageExchange odeMex) { EndpointReference targetEPR = odeMex.getEndpointReference(); if (targetEPR == null) return; // The callback endpoint is going to be the same as the target // endpoint in this case, except that it is updated with session // information (if available). if (odeMex.getProperty(MessageExchange.PROPERTY_SEP_MYROLE_SESSIONID) != null) { _serviceRef.setSessionId(odeMex.getProperty(MessageExchange.PROPERTY_SEP_MYROLE_SESSIONID)); msgContext.setProperty("callbackSessionEndpoint", _serviceRef); } } public AxisService getAxisService() { return _axisService; } /** * Return the service-ref element that will be used to represent this * endpoint. * * @return my service endpoint */ public EndpointReference getMyServiceRef() { return _serviceRef; } /** * Get the EPR of this service from the WSDL. * * @param name service name * @param portName port name * @return XML representation of the EPR */ public static Element genEPRfromWSDL(Definition wsdlDef, QName name, String portName) { Service serviceDef = wsdlDef.getService(name); if (serviceDef != null) { Port portDef = serviceDef.getPort(portName); if (portDef != null) { Document doc = DOMUtils.newDocument(); Element service = doc.createElementNS(Namespaces.WSDL_11, "service"); service.setAttribute("name", serviceDef.getQName().getLocalPart()); service.setAttribute("targetNamespace", serviceDef.getQName().getNamespaceURI()); Element port = doc.createElementNS(Namespaces.WSDL_11, "port"); service.appendChild(port); port.setAttribute("name", portDef.getName()); port.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:bindns", portDef.getBinding().getQName() .getNamespaceURI()); port.setAttribute("bindns:binding", portDef.getName()); for (Object extElmt : portDef.getExtensibilityElements()) { if (extElmt instanceof SOAPAddress) { Element soapAddr = doc.createElementNS(Namespaces.SOAP_NS, "address"); port.appendChild(soapAddr); soapAddr.setAttribute("location", ((SOAPAddress) extElmt).getLocationURI()); } else if (extElmt instanceof HTTPAddress) { Element httpAddr = doc.createElementNS(Namespaces.HTTP_NS, "address"); port.appendChild(httpAddr); httpAddr.setAttribute("location", ((HTTPAddress) extElmt).getLocationURI()); } else { port.appendChild(doc.importNode(((UnknownExtensibilityElement) extElmt).getElement(), true)); } } return service; } } return null; } /** * Create-and-copy a service-ref element. * * @param elmt * @return wrapped element */ public static MutableEndpoint createServiceRef(Element elmt) { Document doc = DOMUtils.newDocument(); QName elQName = new QName(elmt.getNamespaceURI(), elmt.getLocalName()); // If we get a service-ref, just copy it, otherwise make a service-ref // wrapper if (!EndpointReference.SERVICE_REF_QNAME.equals(elQName)) { Element serviceref = doc.createElementNS(EndpointReference.SERVICE_REF_QNAME.getNamespaceURI(), EndpointReference.SERVICE_REF_QNAME.getLocalPart()); serviceref.appendChild(doc.importNode(elmt, true)); doc.appendChild(serviceref); } else { doc.appendChild(doc.importNode(elmt, true)); } return EndpointFactory.createEndpoint(doc.getDocumentElement()); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -