abstractaction.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 1,076 行 · 第 1/3 页

JAVA
1,076
字号
    for (int i = 0; i < _attachmentArgs.length; i++)      _attachmentArgs[i].serializeCall(writer, out, uuid, args);  }  abstract protected void writeMethodInvocation(XMLStreamWriter out,                                                 Object []args)    throws IOException, XMLStreamException, JAXBException;  abstract protected Object readResponse(XMLStreamReader in, Object []args)    throws IOException, XMLStreamException, JAXBException, Throwable;  /**   * Invokes the request for a call.   */  public int invoke(Object service, XMLStreamReader header,                    XMLStreamReader in, XMLStreamWriter out,                    List<Attachment> attachments)    throws IOException, XMLStreamException, Throwable  {    // We're starting out at the point in the input stream where the     // method name is listed (with the arguments as children) and the     // point in the output stream where the results are to be written.        Object[] args = readMethodInvocation(header, in);    readAttachments(attachments, args);    Object value = null;    try {      value = _method.invoke(service, args);    }     catch (IllegalAccessException e) {      throw new Throwable(e);    }     catch (IllegalArgumentException e) {      throw new Throwable(e);    }    catch (InvocationTargetException e) {      writeFault(out, e.getCause());      return 500;    }    if (! _isOneway) {      if (_headerOutputs > 0) {        out.writeStartElement(SOAP_ENVELOPE_PREFIX, "Header", SOAP_ENVELOPE);        if (_returnMarshal != null && _headerReturn)          _returnMarshal.serializeReply(out, value);        for (int i = 0; i < _headerArgs.length; i++)          _headerArgs[i].serializeReply(out, args);        out.writeEndElement(); // Header      }    }    // services/1318: We always need a body even if it is oneway    out.writeStartElement(SOAP_ENVELOPE_PREFIX, "Body", SOAP_ENVELOPE);    if (! _isOneway)      writeResponse(out, value, args);    out.writeEndElement(); // Body    return 200;  }  protected void readHeaders(XMLStreamReader header, Object[] args)    throws IOException, XMLStreamException, JAXBException  {    for (int i = 0; i < _headerArgs.length; i++)      _headerArgs[i].prepareArgument(args);    if (header != null) {      header.nextTag();      while (header.getEventType() == header.START_ELEMENT) {        ParameterMarshal arg = _headerArguments.get(header.getLocalName());        if (arg == null) {          if (log.isLoggable(Level.FINER))            log.finer(L.l("Unknown header argument: {0}", header.getName()));          // skip this subtree          int depth = 1;          while (depth > 0) {            switch (header.nextTag()) {              case XMLStreamReader.START_ELEMENT:                depth++;                break;              case XMLStreamReader.END_ELEMENT:                depth--;                break;            }          }        }        else {          arg.deserializeCall(header, args);        }      }    }  }  protected void readAttachments(List<Attachment> attachments, Object[] args)    throws IOException, XMLStreamException, JAXBException  {    for (int i = 0; i < _attachmentArgs.length; i++) {      if (_attachmentArgs[i] instanceof OutParameterMarshal)        continue;      _attachmentArgs[i].prepareArgument(args);      if (attachments != null) {        if (i < attachments.size())          _attachmentArgs[i].deserializeCall(attachments.get(i), args);                else          log.fine(L.l("Received unexpected attachment"));      }    }  }  // reads the method invocation and returns the arguments  abstract protected Object[] readMethodInvocation(XMLStreamReader header,                                                   XMLStreamReader in)    throws IOException, XMLStreamException, JAXBException;  abstract protected void writeResponse(XMLStreamWriter out,                                         Object value, Object[] args)    throws IOException, XMLStreamException, JAXBException;  protected void writeFault(XMLStreamWriter out, Throwable fault)    throws IOException, XMLStreamException, JAXBException  {    out.writeStartElement(SOAP_ENVELOPE_PREFIX, "Body", SOAP_ENVELOPE);    out.writeStartElement(Skeleton.SOAP_ENVELOPE_PREFIX,                           "Fault",                           Skeleton.SOAP_ENVELOPE);    out.writeStartElement("faultcode");    out.writeCharacters(Skeleton.SOAP_ENVELOPE_PREFIX + ":Server");    out.writeEndElement(); // faultcode    //    // Marshal this exception as a fault.    //     // faults must have exactly the same class as declared on the method,    // otherwise we emit an internal server error.    // XXX This may not be behavior required by the standard and we may     // be able to improve here by casting as a superclass.    ParameterMarshal faultMarshal = _faults.get(fault.getClass());    if (faultMarshal == null) {      out.writeStartElement("faultstring");      out.writeCharacters(L.l("Internal server error"));      out.writeEndElement(); // faultstring    }    else {      out.writeStartElement("faultstring");      out.writeCharacters(fault.getMessage());      out.writeEndElement(); // faultstring      out.writeStartElement("detail");      faultMarshal.serializeReply(out, fault);      out.writeEndElement(); // detail     }    out.writeEndElement(); // Fault    out.writeEndElement(); // Body  }  protected Throwable readFault(XMLStreamReader in)    throws IOException, XMLStreamException, JAXBException, SOAPException  {    Throwable fault = null;    String message = null;    String actor = null;    SOAPFault soapFault = createSOAPFault();    while (in.nextTag() == XMLStreamReader.START_ELEMENT) {      if ("faultcode".equals(in.getLocalName())) {        if (in.next() == XMLStreamReader.CHARACTERS) {          String code = in.getText();          int colon = code.indexOf(':');          if (colon >= 0)            code = code.substring(colon + 1);          if ("Server".equalsIgnoreCase(code)) {            // XXX Do anything with this?          }          else if ("Client".equalsIgnoreCase(code)) {            // XXX Do anything with this?          }          else if ("VersionMismatch".equalsIgnoreCase(code)) {            // XXX Do anything with this?          }          else if ("MustUnderstand".equalsIgnoreCase(code)) {            // XXX Do anything with this?          }          soapFault.setFaultCode(code);        }        while (in.nextTag() != XMLStreamReader.END_ELEMENT) {}      }      else if ("faultstring".equals(in.getLocalName())) {        if (in.next() == XMLStreamReader.CHARACTERS)          message = in.getText();        soapFault.setFaultString(message);        while (in.nextTag() != XMLStreamReader.END_ELEMENT) {}      }      else if ("faultactor".equals(in.getLocalName())) {        if (in.next() == XMLStreamReader.CHARACTERS)          actor = in.getText();        soapFault.setFaultActor(actor);        while (in.nextTag() != XMLStreamReader.END_ELEMENT) {}      }      else if ("detail".equals(in.getLocalName())) {        if (in.nextTag() == XMLStreamReader.START_ELEMENT) {          ParameterMarshal faultMarshal = _faultNames.get(in.getName());          if (faultMarshal != null)            fault = (Exception) faultMarshal.deserializeReply(in, fault);        }      }    }    if (fault == null)      fault = new SOAPFaultException(soapFault);    return fault;  }  public boolean hasHeaderInput()  {    return false;  }  public int getArity()  {    return _arity;  }  public String getInputName()  {    return _inputName;  }  public static String getWebMethodName(Method method)  {    String methodName = _methodNames.get(method);    if (methodName == null) {      Method eiMethod = getEIMethod(method);      methodName = getWebMethodName(method, eiMethod);      _methodNames.put(method, methodName);    }    return methodName;  }  public static String getWebMethodName(Method method, Method eiMethod)  {    String name = method.getName();    WebMethod webMethod = method.getAnnotation(WebMethod.class);    if (webMethod == null && eiMethod != null)      webMethod = eiMethod.getAnnotation(WebMethod.class);    if (webMethod != null && ! "".equals(webMethod.operationName()))      name = webMethod.operationName();        return name;  }  public static String getPortName(Method method, Method eiMethod)  {    Class cl = method.getDeclaringClass();    WebService webService = (WebService) cl.getAnnotation(WebService.class);    if (webService == null && eiMethod != null) {      cl = eiMethod.getDeclaringClass();      webService = (WebService) cl.getAnnotation(WebService.class);    }    if (webService != null && ! "".equals(webService.portName()))      return webService.portName();        return null;  }  public static String getSOAPAction(Method method, Method eiMethod)  {    String action = "";    WebMethod webMethod = method.getAnnotation(WebMethod.class);    if (webMethod == null && eiMethod != null)      webMethod = eiMethod.getAnnotation(WebMethod.class);    if (webMethod != null)      action = webMethod.action();        return action;  }  public static Method getEIMethod(Method method)  {    try {      Class cl = method.getDeclaringClass();      WebService webService = (WebService) cl.getAnnotation(WebService.class);      if (webService != null) {        if (! "".equals(webService.endpointInterface())) {          ClassLoader loader = cl.getClassLoader();          Class endpointInterface =             loader.loadClass(webService.endpointInterface());          return endpointInterface.getMethod(method.getName(),                                              method.getParameterTypes());        }      }    }    catch (ClassNotFoundException e) {    }    catch (NoSuchMethodException e) {    }    return null;  }  public abstract void writeWSDLMessages(XMLStreamWriter out,                                          String soapNamespaceURI)    throws XMLStreamException;  public abstract void writeSchema(XMLStreamWriter out,                                    String namespace,                                   JAXBContextImpl context)    throws XMLStreamException, WebServiceException;    public abstract void writeWSDLBindingOperation(XMLStreamWriter out,                                                  String soapNamespaceURI)    throws XMLStreamException;  public abstract void writeWSDLOperation(XMLStreamWriter out,                                           String soapNamespaceURI)    throws XMLStreamException;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?