/**
   * Invokes the bussiness logic invocation on the service implementation class
   *
   * @param msgContext the incoming message context
   * @param newmsgContext the response message context
   * @throws AxisFault on invalid method (wrong signature) or behaviour (return null)
   */
  public void invokeBusinessLogic(MessageContext msgContext, MessageContext newmsgContext)
      throws AxisFault {
    try {

      // get the implementation class for the Web Service
      Object obj = getTheImplementationObject(msgContext);

      // find the WebService method
      Class implClass = obj.getClass();

      AxisOperation opDesc = msgContext.getAxisOperation();
      Method method = findOperation(opDesc, implClass);

      if (method == null) {
        throw new AxisFault(
            Messages.getMessage("methodDoesNotExistInOut", opDesc.getName().toString()));
      }

      OMElement result =
          (OMElement)
              method.invoke(
                  obj, new Object[] {msgContext.getEnvelope().getBody().getFirstElement()});
      SOAPFactory fac = getSOAPFactory(msgContext);
      SOAPEnvelope envelope = fac.getDefaultEnvelope();

      if (result != null) {
        envelope.getBody().addChild(result);
      }

      newmsgContext.setEnvelope(envelope);
    } catch (Exception e) {
      throw AxisFault.makeFault(e);
    }
  }
Exemplo n.º 2
0
  public static String sendSOAP(
      EndpointReference soapEPR, String requestString, String action, String operation)
      throws Exception {

    ServiceClient sender = PmServiceClient.getServiceClient();
    OperationClient operationClient = sender.createClient(ServiceClient.ANON_OUT_IN_OP);

    // creating message context
    MessageContext outMsgCtx = new MessageContext();
    // assigning message context's option object into instance variable
    Options opts = outMsgCtx.getOptions();
    // setting properties into option
    log.debug(soapEPR);
    opts.setTo(soapEPR);
    opts.setAction(action);
    opts.setTimeOutInMilliSeconds(180000);

    log.debug(requestString);

    SOAPEnvelope envelope = null;

    try {
      SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
      envelope = fac.getDefaultEnvelope();
      OMNamespace omNs =
          fac.createOMNamespace(
              "http://rpdr.partners.org/", //$NON-NLS-1$
              "rpdr"); //$NON-NLS-1$

      // creating the SOAP payload
      OMElement method = fac.createOMElement(operation, omNs);
      OMElement value = fac.createOMElement("RequestXmlString", omNs); // $NON-NLS-1$
      value.setText(requestString);
      method.addChild(value);
      envelope.getBody().addChild(method);
    } catch (FactoryConfigurationError e) {
      log.error(e.getMessage());
      throw new Exception(e);
    }

    outMsgCtx.setEnvelope(envelope);

    operationClient.addMessageContext(outMsgCtx);
    operationClient.execute(true);

    MessageContext inMsgtCtx = operationClient.getMessageContext("In"); // $NON-NLS-1$
    SOAPEnvelope responseEnv = inMsgtCtx.getEnvelope();

    OMElement soapResponse = responseEnv.getBody().getFirstElement();
    //		System.out.println("Sresponse: "+ soapResponse.toString());
    OMElement soapResult = soapResponse.getFirstElement();
    //		System.out.println("Sresult: "+ soapResult.toString());

    String i2b2Response = soapResult.getText();
    log.debug(i2b2Response);

    return i2b2Response;
  }
Exemplo n.º 3
0
  public static MessageContext sendUsingSwA(String fileName, String targetEPR) throws IOException {

    Options options = new Options();
    options.setTo(new EndpointReference(targetEPR));
    options.setAction("urn:uploadFileUsingSwA");
    options.setProperty(Constants.Configuration.ENABLE_SWA, Constants.VALUE_TRUE);

    ServiceClient sender = new ServiceClient();
    sender.setOptions(options);
    OperationClient mepClient = sender.createClient(ServiceClient.ANON_OUT_IN_OP);

    MessageContext mc = new MessageContext();

    System.out.println("Sending file : " + fileName + " as SwA");
    FileDataSource fileDataSource = new FileDataSource(new File(fileName));
    DataHandler dataHandler = new DataHandler(fileDataSource);
    String attachmentID = mc.addAttachment(dataHandler);

    SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
    SOAPEnvelope env = factory.getDefaultEnvelope();
    OMNamespace ns = factory.createOMNamespace("http://services.samples/xsd", "m0");
    OMElement payload = factory.createOMElement("uploadFileUsingSwA", ns);
    OMElement request = factory.createOMElement("request", ns);
    OMElement imageId = factory.createOMElement("imageId", ns);
    imageId.setText(attachmentID);
    request.addChild(imageId);
    payload.addChild(request);
    env.getBody().addChild(payload);
    mc.setEnvelope(env);

    mepClient.addMessageContext(mc);
    mepClient.execute(true);
    MessageContext response = mepClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);

    SOAPBody body = response.getEnvelope().getBody();
    String imageContentId =
        body.getFirstChildWithName(
                new QName("http://services.samples/xsd", "uploadFileUsingSwAResponse"))
            .getFirstChildWithName(new QName("http://services.samples/xsd", "response"))
            .getFirstChildWithName(new QName("http://services.samples/xsd", "imageId"))
            .getText();

    Attachments attachment = response.getAttachmentMap();
    dataHandler = attachment.getDataHandler(imageContentId);
    File tempFile = File.createTempFile("swa-", ".gif");
    FileOutputStream fos = new FileOutputStream(tempFile);
    dataHandler.writeTo(fos);
    fos.flush();
    fos.close();

    System.out.println("Saved response to file : " + tempFile.getAbsolutePath());

    return response;
  }
Exemplo n.º 4
0
  public static void transferFile(File file, String destinationFile) throws Exception {

    Options options = new Options();
    options.setTo(targetEPR);
    options.setProperty(Constants.Configuration.ENABLE_SWA, Constants.VALUE_TRUE);
    options.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
    // Increase the time out when sending large attachments
    options.setTimeOutInMilliSeconds(10000);
    options.setTo(targetEPR);
    options.setAction("urn:uploadFile");

    // assume the use runs this sample at
    // <axis2home>/samples/soapwithattachments/ dir
    ConfigurationContext configContext =
        ConfigurationContextFactory.createConfigurationContextFromFileSystem(
            "../../repository", null);

    ServiceClient sender = new ServiceClient(configContext, null);
    sender.setOptions(options);
    OperationClient mepClient = sender.createClient(ServiceClient.ANON_OUT_IN_OP);

    MessageContext mc = new MessageContext();
    FileDataSource fileDataSource = new FileDataSource(file);

    // Create a dataHandler using the fileDataSource. Any implementation of
    // javax.activation.DataSource interface can fit here.
    DataHandler dataHandler = new DataHandler(fileDataSource);
    String attachmentID = mc.addAttachment(dataHandler);

    SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
    SOAPEnvelope env = fac.getDefaultEnvelope();
    OMNamespace omNs = fac.createOMNamespace("http://service.soapwithattachments.sample", "swa");
    OMElement uploadFile = fac.createOMElement("uploadFile", omNs);
    OMElement nameEle = fac.createOMElement("name", omNs);
    nameEle.setText(destinationFile);
    OMElement idEle = fac.createOMElement("attchmentID", omNs);
    idEle.setText(attachmentID);
    uploadFile.addChild(nameEle);
    uploadFile.addChild(idEle);
    env.getBody().addChild(uploadFile);
    mc.setEnvelope(env);

    mepClient.addMessageContext(mc);
    mepClient.execute(true);
    MessageContext response = mepClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
    SOAPBody body = response.getEnvelope().getBody();
    OMElement element =
        body.getFirstElement()
            .getFirstChildWithName(
                new QName("http://service.soapwithattachments.sample", "return"));
    System.out.println(element.getText());
  }
  private org.apache.axiom.soap.SOAPEnvelope toEnvelope(
      org.apache.axiom.soap.SOAPFactory factory,
      com.pa.GetEmp param,
      boolean optimizeContent,
      javax.xml.namespace.QName methodQName)
      throws org.apache.axis2.AxisFault {

    try {

      org.apache.axiom.soap.SOAPEnvelope emptyEnvelope = factory.getDefaultEnvelope();
      emptyEnvelope.getBody().addChild(param.getOMElement(com.pa.GetEmp.MY_QNAME, factory));
      return emptyEnvelope;
    } catch (org.apache.axis2.databinding.ADBException e) {
      throw org.apache.axis2.AxisFault.makeFault(e);
    }
  }
  private org.apache.axiom.soap.SOAPEnvelope toEnvelope(
      org.apache.axiom.soap.SOAPFactory factory,
      org.example.www.site.GetSiteResponse param,
      boolean optimizeContent)
      throws org.apache.axis2.AxisFault {
    try {
      org.apache.axiom.soap.SOAPEnvelope emptyEnvelope = factory.getDefaultEnvelope();

      emptyEnvelope
          .getBody()
          .addChild(param.getOMElement(org.example.www.site.GetSiteResponse.MY_QNAME, factory));

      return emptyEnvelope;
    } catch (org.apache.axis2.databinding.ADBException e) {
      throw org.apache.axis2.AxisFault.makeFault(e);
    }
  }
Exemplo n.º 7
0
  private org.apache.axiom.soap.SOAPEnvelope toEnvelope(
      final org.apache.axiom.soap.SOAPFactory factory,
      final CadConsultaCadastro2Stub.NfeDadosMsg param,
      final boolean optimizeContent,
      final javax.xml.namespace.QName methodQName)
      throws org.apache.axis2.AxisFault {

    try {

      final org.apache.axiom.soap.SOAPEnvelope emptyEnvelope = factory.getDefaultEnvelope();
      emptyEnvelope
          .getBody()
          .addChild(param.getOMElement(CadConsultaCadastro2Stub.NfeDadosMsg.MY_QNAME, factory));
      return emptyEnvelope;
    } catch (final org.apache.axis2.databinding.ADBException e) {
      throw org.apache.axis2.AxisFault.makeFault(e);
    }
  }
  private org.apache.axiom.soap.SOAPEnvelope toEnvelope(
      org.apache.axiom.soap.SOAPFactory factory,
      gsn.webservice.standard.RegisterQueryResponse param,
      boolean optimizeContent)
      throws org.apache.axis2.AxisFault {
    try {
      org.apache.axiom.soap.SOAPEnvelope emptyEnvelope = factory.getDefaultEnvelope();

      emptyEnvelope
          .getBody()
          .addChild(
              param.getOMElement(gsn.webservice.standard.RegisterQueryResponse.MY_QNAME, factory));

      return emptyEnvelope;
    } catch (org.apache.axis2.databinding.ADBException e) {
      throw org.apache.axis2.AxisFault.makeFault(e);
    }
  }
Exemplo n.º 9
0
 public OMElement processDocument(InputStream inputStream, String s, MessageContext messageContext)
     throws AxisFault {
   messageContext.setProperty(JsonConstant.IS_JSON_STREAM, true);
   JsonReader jsonReader;
   String charSetEncoding = null;
   try {
     charSetEncoding =
         (String) messageContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
     jsonReader = new JsonReader(new InputStreamReader(inputStream, charSetEncoding));
     GsonXMLStreamReader gsonXMLStreamReader = new GsonXMLStreamReader(jsonReader);
     messageContext.setProperty(JsonConstant.GSON_XML_STREAM_READER, gsonXMLStreamReader);
     // dummy envelop
     SOAPFactory soapFactory = OMAbstractFactory.getSOAP11Factory();
     return soapFactory.getDefaultEnvelope();
   } catch (UnsupportedEncodingException e) {
     throw new AxisFault(
         charSetEncoding + " encoding is may not supported by json inputStream ", e);
   }
 }
  private org.apache.axiom.soap.SOAPEnvelope toEnvelope(
      org.apache.axiom.soap.SOAPFactory factory,
      org.wso2.carbon.billing.mgt.services.AddPaymentResponse param,
      boolean optimizeContent,
      javax.xml.namespace.QName methodQName)
      throws org.apache.axis2.AxisFault {
    try {
      org.apache.axiom.soap.SOAPEnvelope emptyEnvelope = factory.getDefaultEnvelope();

      emptyEnvelope
          .getBody()
          .addChild(
              param.getOMElement(
                  org.wso2.carbon.billing.mgt.services.AddPaymentResponse.MY_QNAME, factory));

      return emptyEnvelope;
    } catch (org.apache.axis2.databinding.ADBException e) {
      throw org.apache.axis2.AxisFault.makeFault(e);
    }
  }
Exemplo n.º 11
0
  public void createSoapRequest(MessageContext msgCtx, Element message, Operation op)
      throws AxisFault {
    if (op == null) {
      throw new NullPointerException("Null operation");
    }
    // The message can be null if the input message has no part
    if (op.getInput().getMessage().getParts().size() > 0 && message == null) {
      throw new NullPointerException("Null message.");
    }
    if (msgCtx == null) {
      throw new NullPointerException("Null msgCtx");
    }

    BindingOperation bop = binding.getBindingOperation(op.getName(), null, null);

    if (bop == null) {
      throw new OdeFault("BindingOperation not found.");
    }

    BindingInput bi = bop.getBindingInput();
    if (bi == null) {
      throw new OdeFault("BindingInput not found.");
    }

    SOAPEnvelope soapEnv = msgCtx.getEnvelope();
    if (soapEnv == null) {
      soapEnv = soapFactory.getDefaultEnvelope();
      msgCtx.setEnvelope(soapEnv);
    }

    //        createSoapHeaders(soapEnv, getSOAPHeaders(bi), op.getInput().getMessage(), message);

    SOAPBody soapBody = getSOAPBody(bi);
    if (soapBody != null) {
      org.apache.axiom.soap.SOAPBody sb =
          soapEnv.getBody() == null ? soapFactory.createSOAPBody(soapEnv) : soapEnv.getBody();
      createSoapBody(sb, soapBody, op.getInput().getMessage(), message, op.getName());
    }
  }
Exemplo n.º 12
0
  public static void testConnect(
      String strOperation, String strParamName, AbstractConnector connector) throws AxisFault {

    org.apache.axis2.context.MessageContext axis2Ctx =
        new org.apache.axis2.context.MessageContext();
    SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
    org.apache.axiom.soap.SOAPEnvelope envelope = fac.getDefaultEnvelope();
    axis2Ctx.setEnvelope(envelope);
    Collection<String> collection = new java.util.ArrayList<String>();
    collection.add(strParamName);
    testCtx.setProperty(
        TEST_TEMPLATE + ":" + strParamName,
        new Value(
            "<sfdc:sObjects xmlns:sfdc='sfdc' type='Account'><sfdc:sObject><sfdc:Name>name01</sfdc:Name></sfdc:sObject></sfdc:sObjects>"));
    TemplateContext context = new TemplateContext(TEST_TEMPLATE, collection);
    Stack<TemplateContext> stack = new Stack<TemplateContext>();
    stack.add(context);
    context.setupParams(testCtx);

    testCtx.setProperty(SynapseConstants.SYNAPSE__FUNCTION__STACK, stack);
    try {
      connector.connect(testCtx);
    } catch (Exception e) {
      assertTrue(false);
    }

    Iterator<OMElement> iIteratorElements =
        testCtx.getEnvelope().getBody().getChildrenWithLocalName(strOperation);
    OMElement element = iIteratorElements.next();
    iIteratorElements = element.getChildren();
    if (iIteratorElements.hasNext()) {
      assertTrue(true);
    } else {
      assertTrue(false);
    }
  }
 /** get the default envelope */
 private org.apache.axiom.soap.SOAPEnvelope toEnvelope(org.apache.axiom.soap.SOAPFactory factory) {
   return factory.getDefaultEnvelope();
 }