abstractaction.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 1,076 行 · 第 1/3 页
JAVA
1,076 行
_bodyInputs++; _bodyOutputs++; } bodyList.add(pMarshal); _bodyArguments.put(localName, pMarshal); } } _attachmentArgs = new ParameterMarshal[attachmentList.size()]; attachmentList.toArray(_attachmentArgs); _headerArgs = new ParameterMarshal[headerList.size()]; headerList.toArray(_headerArgs); _bodyArgs = new ParameterMarshal[bodyList.size()]; bodyList.toArray(_bodyArgs); // // Return type // if (! Void.TYPE.equals(method.getReturnType())) { if (_isOneway) throw new WebServiceException(L.l("Method {0} annotated with @Oneway, but has non-void return", method.getName())); Property property = _jaxbContext.createProperty(method.getGenericReturnType()); WebResult webResult = method.getAnnotation(WebResult.class); if (webResult == null && eiMethod != null) webResult = eiMethod.getAnnotation(WebResult.class); if (webResult != null) { _headerReturn = webResult.header(); String localName = webResult.name(); if ("".equals(localName)) localName = "return"; if ("".equals(webResult.targetNamespace())) _resultName = new QName(localName); else _resultName = new QName(webResult.targetNamespace(), localName); } else { _headerReturn = false; _resultName = new QName("return"); // XXX namespace? } _returnMarshal = ParameterMarshal.create(0, property, _resultName, WebParam.Mode.OUT, marshaller, unmarshaller); _bodyOutputs++; if (_headerReturn) _headerOutputs++; } else { _headerReturn = false; _returnMarshal = null; } // // Exceptions // Class[] exceptions = method.getExceptionTypes(); for (Class exception : exceptions) { QName faultName = new QName(targetNamespace, exception.getSimpleName(), TARGET_NAMESPACE_PREFIX); // XXX check for generated exception classes versus raw exceptions // i.e. things like getFaultInfo() Property property = jaxbContext.createProperty(exception); ParameterMarshal marshal = ParameterMarshal.create(0, property, faultName, WebParam.Mode.OUT, marshaller, unmarshaller); _faults.put(exception, marshal); _faultNames.put(faultName, marshal); } } public static AbstractAction createAction(Method method, JAXBContextImpl jaxbContext, String targetNamespace, WSDLDefinitions wsdl, Marshaller marshaller, Unmarshaller unmarshaller) throws JAXBException, WebServiceException { // There are three valid modes in JAX-WS: // // 1. Document wrapped -- all the parameters and return values // are encapsulated in a single encoded object (i.e. the document). // This is selected by // SOAPBinding.style() == DOCUMENT // SOAPBinding.use() == LITERAL // SOAPBinding.parameterStyle() == WRAPPED // // 2. Document bare -- the method must have at most one input and // one output parameter. No wrapper objects are created. // This is selected by // SOAPBinding.style() == DOCUMENT // SOAPBinding.use() == LITERAL // SOAPBinding.parameterStyle() == BARE // // 3. RPC style -- parameters and return values are mapped to // wsdl:parts. This is selected by: // SOAPBinding.style() == RPC // SOAPBinding.use() == LITERAL // SOAPBinding.parameterStyle() == WRAPPED // // It seems that "use" is never ENCODED in JAX-WS and is not allowed // by WS-I, so we don't allow it either. // // Check for the SOAPBinding annotation... // look at the declaring class and method first Class cl = method.getDeclaringClass(); Method eiMethod = null; SOAPBinding soapBinding = (SOAPBinding) cl.getAnnotation(SOAPBinding.class); if (method.isAnnotationPresent(SOAPBinding.class)) soapBinding = method.getAnnotation(SOAPBinding.class); if (soapBinding == null) { // Then look at the endpoint interface, if available WebService webService = (WebService) cl.getAnnotation(WebService.class); if (webService != null) { if (! "".equals(webService.endpointInterface())) { try { ClassLoader loader = cl.getClassLoader(); Class endpointInterface = loader.loadClass(webService.endpointInterface()); soapBinding = (SOAPBinding) endpointInterface.getAnnotation(SOAPBinding.class); eiMethod = endpointInterface.getMethod(method.getName(), method.getParameterTypes()); if (eiMethod.isAnnotationPresent(SOAPBinding.class)) soapBinding = eiMethod.getAnnotation(SOAPBinding.class); } catch (ClassNotFoundException e) { throw new WebServiceException(L.l("Endpoint interface {0} not found", webService.endpointInterface()), e); } catch (NoSuchMethodException e) { // We don't care if the method isn't defined in the interface } } } } // Document wrapped is the default for methods w/o a @SOAPBinding if (soapBinding == null) return new DocumentWrappedAction(method, eiMethod, jaxbContext, targetNamespace, wsdl, marshaller, unmarshaller); if (soapBinding.use() == SOAPBinding.Use.ENCODED) throw new UnsupportedOperationException(L.l("SOAP encoded style is not supported by JAX-WS")); if (soapBinding.style() == SOAPBinding.Style.DOCUMENT) { if (soapBinding.parameterStyle() == SOAPBinding.ParameterStyle.WRAPPED) return new DocumentWrappedAction(method, eiMethod, jaxbContext, targetNamespace, wsdl, marshaller, unmarshaller); else { return new DocumentBareAction(method, eiMethod, jaxbContext, targetNamespace, wsdl, marshaller, unmarshaller); } } else { if (soapBinding.parameterStyle() != SOAPBinding.ParameterStyle.WRAPPED) throw new UnsupportedOperationException(L.l("SOAP RPC bare style not supported")); return new RpcAction(method, eiMethod, jaxbContext, targetNamespace, wsdl, marshaller, unmarshaller); } } protected boolean isAttachment(WebParam webParam) { return webParam.name().startsWith("attach"); } /** * Client-side invocation. */ public Object invoke(String url, Object[] args, HandlerChainInvoker handlerChain) throws IOException, XMLStreamException, MalformedURLException, JAXBException, Throwable { XMLStreamReader in = null; URL urlObject = new URL(url); URLConnection connection = urlObject.openConnection(); // XXX HTTPS if (! (connection instanceof HttpURLConnection)) return null; HttpURLConnection httpConnection = (HttpURLConnection) connection; try { // // Send the request // httpConnection.setRequestMethod("POST"); httpConnection.setDoInput(true); httpConnection.setDoOutput(true); // XXX: Does this change for multipart/attachments? httpConnection.setRequestProperty("Content-type", "text/xml"); OutputStream httpOut = null; XMLStreamWriter out = null; DOMResult dom = null; UUID uuid = UUID.randomUUID(); if (_attachmentInputs > 0) { // note that we have to add the request property (header) before // we get the output stream httpConnection.addRequestProperty("Content-Type", "multipart/related; " + "type=\"text/xml\"; " + "boundary=\"uuid:" + uuid + "\""); httpOut = httpConnection.getOutputStream(); PrintWriter writer = new PrintWriter(httpOut); writer.print("--uuid:" + uuid + "\r\n"); writer.print("Content-Type: text/xml\r\n"); writer.print("\r\n"); writer.flush(); } else httpOut = httpConnection.getOutputStream(); if (handlerChain != null) { dom = new DOMResult(); out = getXMLOutputFactory().createXMLStreamWriter(dom); } else { out = getXMLOutputFactory().createXMLStreamWriter(httpOut); } writeRequest(out, args); out.flush(); if (_attachmentInputs > 0) { httpOut.write("\r\n".getBytes()); writeAttachments(httpOut, uuid, args); } if (handlerChain != null) { Source source = new DOMSource(dom.getNode()); if (! handlerChain.invokeClientOutbound(source, httpOut)) { source = handlerChain.getSource(); in = _xmlInputFactory.createXMLStreamReader(source); return readResponse(in, args); } } // // Parse the response // httpConnection.getResponseCode(); InputStream is = httpConnection.getInputStream(); if (handlerChain != null) is = handlerChain.invokeClientInbound(httpConnection); String contentType = httpConnection.getHeaderField("Content-Type"); if (contentType != null && contentType.startsWith("multipart/related")) { String[] tokens = contentType.split(";"); String boundary = null; for (int i = 0; i < tokens.length; i++) { int start = tokens[i].indexOf("boundary="); if (start >= 0) { boundary = tokens[i].substring(start + "boundary=".length() + 1, tokens[i].lastIndexOf('"')); break; } } if (boundary == null) return null; // XXX throw something about malformed response } in = _xmlInputFactory.createXMLStreamReader(is); if (httpConnection.getResponseCode() != 200) return null; // XXX more meaningful error if (_isOneway) return null; return readResponse(in, args); } finally { if (httpConnection != null) httpConnection.disconnect(); } } protected void writeRequest(XMLStreamWriter out, Object []args) throws IOException, XMLStreamException, JAXBException { out.writeStartDocument("UTF-8", "1.0"); out.writeStartElement(Skeleton.SOAP_ENVELOPE_PREFIX, "Envelope", Skeleton.SOAP_ENVELOPE); out.writeNamespace(Skeleton.SOAP_ENVELOPE_PREFIX, Skeleton.SOAP_ENVELOPE); out.writeStartElement(Skeleton.SOAP_ENVELOPE_PREFIX, "Header", Skeleton.SOAP_ENVELOPE); for (ParameterMarshal marshal : _headerArguments.values()) marshal.serializeCall(out, args); out.writeEndElement(); // Header out.writeStartElement(Skeleton.SOAP_ENVELOPE_PREFIX, "Body", Skeleton.SOAP_ENVELOPE); writeMethodInvocation(out, args); out.writeEndElement(); // Body out.writeEndElement(); // Envelope } protected void writeAttachments(OutputStream out, UUID uuid, Object[] args) throws IOException { PrintWriter writer = new PrintWriter(out);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?