예제 #1
0
 /**
  * This method will check whether the text can be optimizable using IS_BINARY flag. If that is set
  * then we try to get the data handler.
  *
  * @param omContainer
  * @param textType
  * @return omNode
  */
 private OMNode createOMText(OMContainer omContainer, int textType) {
   if (dataHandlerReader != null && dataHandlerReader.isBinary()) {
     Object dataHandlerObject;
     if (dataHandlerReader.isDeferred()) {
       dataHandlerObject = dataHandlerReader.getDataHandlerProvider();
     } else {
       try {
         dataHandlerObject = dataHandlerReader.getDataHandler();
       } catch (XMLStreamException ex) {
         throw new OMException(ex);
       }
     }
     OMText text = omfactory.createOMText(dataHandlerObject, dataHandlerReader.isOptimized());
     String contentID = dataHandlerReader.getContentID();
     if (contentID != null) {
       text.setContentID(contentID);
     }
     omContainer.addChild(text);
     return text;
   } else {
     // Some parsers (like Woodstox) parse text nodes lazily and may throw a
     // RuntimeException in getText()
     String text;
     try {
       text = parser.getText();
     } catch (RuntimeException ex) {
       parserException = ex;
       throw ex;
     }
     return omfactory.createOMText(omContainer, text, textType);
   }
 }
예제 #2
0
  public void addSobjects(
      String strOperation,
      String strParamName,
      MessageContext synCtx,
      SynapseLog synLog,
      String strExternalId) {
    SOAPEnvelope envelope = synCtx.getEnvelope();
    OMFactory fac = OMAbstractFactory.getOMFactory();
    SOAPBody body = envelope.getBody();
    Iterator<OMElement> bodyChildElements = body.getChildrenWithLocalName(strOperation);
    if (bodyChildElements.hasNext()) {
      try {
        OMElement bodyElement = bodyChildElements.next();
        if (strExternalId != null) {
          OMNamespace omNs = fac.createOMNamespace("urn:partner.soap.sforce.com", "urn");
          OMElement value = fac.createOMElement("externalIDFieldName", omNs);
          value.addChild(fac.createOMText(strExternalId));
          bodyElement.addChild(value);
        }
        String strSobject = (String) ConnectorUtils.lookupTemplateParamater(synCtx, strParamName);
        OMElement sObjects = AXIOMUtil.stringToOM(strSobject);
        Iterator<OMElement> sObject = sObjects.getChildElements();
        String strType =
            sObjects.getAttributeValue(new QName(SalesforceUtil.SALESFORCE_CREATE_SOBJECTTYPE));
        OMElement tmpElement = null;
        OMNamespace omNsurn = fac.createOMNamespace("urn:partner.soap.sforce.com", "urn");
        OMNamespace omNsurn1 = fac.createOMNamespace("urn:sobject.partner.soap.sforce.com", "urn1");
        // Loops sObject
        while (sObject.hasNext()) {
          OMElement currentElement = sObject.next();
          OMElement newElement = fac.createOMElement("sObjects", omNsurn);
          // Add Object type
          if (strType != null) {
            tmpElement = fac.createOMElement("type", omNsurn1);
            tmpElement.addChild(fac.createOMText(strType));
            newElement.addChild(tmpElement);
          }
          // Add the fields
          Iterator<OMElement> sObjectFields = currentElement.getChildElements();
          while (sObjectFields.hasNext()) {
            OMElement sObjectField = sObjectFields.next();
            tmpElement = fac.createOMElement(sObjectField.getLocalName(), omNsurn1);
            tmpElement.addChild(fac.createOMText(sObjectField.getText()));
            newElement.addChild(tmpElement);
          }

          bodyElement.addChild(newElement);
        }
      } catch (Exception e) {
        synLog.error("Saleforce adaptor - error injecting sObjects to payload : " + e);
      }
    }
  }
  public OMElement getCEPPublisher(OMElement request) throws XMLStreamException {
    request.build();
    request.detach();

    OMElement tenantId =
        request.getFirstChildWithName(
            new QName(
                ManagerServiceConstants.NAMESPACE, ManagerServiceConstants.ELEMENT_TENANT_ID));
    OMElement executionPlan =
        request.getFirstChildWithName(
            new QName(
                ManagerServiceConstants.NAMESPACE, ManagerServiceConstants.ELEMENT_EXEC_PLAN));
    OMElement requesterIp =
        request.getFirstChildWithName(
            new QName(
                ManagerServiceConstants.NAMESPACE, ManagerServiceConstants.ELEMENT_REQUESTER_IP));
    String key = getKey(executionPlan.getText(), tenantId.getText());
    log.info("CEP Publisher requested for  " + key);

    Set<Endpoint> endpointSet = cepPublishers.get(key);
    Endpoint selectedEndpoint = selectEndpoint(endpointSet, requesterIp.getText());
    OMElement response =
        factory.createOMElement(
            ManagerServiceConstants.ELEMENT_CEP_PUBLISHER_RESPONSE, OMNamespace);
    if (selectedEndpoint != null) {
      OMElement hostNameElement =
          factory.createOMElement(ManagerServiceConstants.ELEMENT_HOST_NAME, OMNamespace);
      OMElement portElement =
          factory.createOMElement(ManagerServiceConstants.ELEMENT_PORT, OMNamespace);

      OMText hostNameText = factory.createOMText(hostNameElement, selectedEndpoint.getHostName());
      OMText portText =
          factory.createOMText(portElement, Integer.toString(selectedEndpoint.getPort()));

      hostNameElement.addChild(hostNameText);
      portElement.addChild(portText);
      response.addChild(hostNameElement);
      response.addChild(portElement);
      log.info(
          "Returning CEP Publisher:"
              + selectedEndpoint.getHostName()
              + ":"
              + selectedEndpoint.getPort());
    } else {
      log.warn("No CEP publishers registered " + key);
    }

    return response;
  }
예제 #4
0
 public void addIds(
     String strOperation, String strParamName, MessageContext synCtx, SynapseLog synLog) {
   SOAPEnvelope envelope = synCtx.getEnvelope();
   OMFactory fac = OMAbstractFactory.getOMFactory();
   SOAPBody body = envelope.getBody();
   Iterator<OMElement> bodyChildElements = body.getChildrenWithLocalName(strOperation);
   if (bodyChildElements.hasNext()) {
     try {
       OMElement bodyElement = bodyChildElements.next();
       Iterator<OMElement> cElements = bodyElement.getChildElements();
       if (cElements != null && cElements.hasNext()) {
         cElements.next();
       }
       String strSobject = (String) ConnectorUtils.lookupTemplateParamater(synCtx, strParamName);
       OMElement sObjects = AXIOMUtil.stringToOM(strSobject);
       Iterator<OMElement> sObject = sObjects.getChildElements();
       OMNamespace omNsurn = fac.createOMNamespace("urn:partner.soap.sforce.com", "urn");
       // Loops sObject
       while (sObject.hasNext()) {
         OMElement currentElement = sObject.next();
         OMElement newElement = fac.createOMElement("ids", omNsurn);
         // Add the fields
         newElement.addChild(fac.createOMText(currentElement.getText()));
         bodyElement.addChild(newElement);
       }
     } catch (Exception e) {
       synLog.error("Saleforce adaptor - error injecting sObjects to payload : " + e);
     }
   }
 }
  public void sendUsingMTOM(String fileName, String targetEPR) throws IOException {
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMNamespace ns = factory.createOMNamespace("http://services.samples", "m0");
    OMElement payload = factory.createOMElement("uploadFileUsingMTOM", ns);
    OMElement request = factory.createOMElement("request", ns);
    OMElement image = factory.createOMElement("image", ns);

    FileDataSource fileDataSource = new FileDataSource(new File(fileName));
    DataHandler dataHandler = new DataHandler(fileDataSource);
    OMText textData = factory.createOMText(dataHandler, true);
    image.addChild(textData);
    request.addChild(image);
    payload.addChild(request);

    ServiceClient serviceClient = new ServiceClient();
    Options options = new Options();
    options.setTo(new EndpointReference(targetEPR));
    options.setAction("urn:uploadFileUsingMTOM");
    options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
    options.setCallTransportCleanup(true);
    serviceClient.setOptions(options);
    OMElement response = serviceClient.sendReceive(payload);
    Assert.assertTrue(
        response
            .toString()
            .contains(
                "<m:testMTOM xmlns:m=\"http://services.samples/xsd\">"
                    + "<m:test1>testMTOM</m:test1></m:testMTOM>"));
  }
예제 #6
0
  private static boolean JARServiceTest() {
    boolean JARServiceStatus = false;
    OMElement result;
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://ws.apache.org/axis2", "ns1");
    OMElement payload = fac.createOMElement("echo", omNs);
    OMElement value = fac.createOMElement("args0", omNs);
    value.addChild(fac.createOMText(value, "Hello-World"));
    payload.addChild(value);

    ServiceClient serviceclient;
    try {
      serviceclient = new ServiceClient();
      Options opts = new Options();

      opts.setTo(new EndpointReference(HTTP_APPSERVER_STRATOSLIVE_URL + "/SimpleJarService"));
      opts.setAction("echo");
      // bypass http protocol exception
      opts.setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED, Boolean.FALSE);

      serviceclient.setOptions(opts);

      result = serviceclient.sendReceive(payload);

      if ((result.toString().indexOf("Hello-World")) > 0) {
        JARServiceStatus = true;
      }
      assertTrue("Jar service invocation failed", JARServiceStatus);

    } catch (AxisFault axisFault) {
      log.error("Jar service invocation failed:" + axisFault.getMessage());
      fail("Jar service invocation failed:" + axisFault.getMessage());
    }
    return JARServiceStatus;
  }
예제 #7
0
 private static OMElement createPayLoad() {
   OMFactory fac = OMAbstractFactory.getOMFactory();
   OMNamespace omNs = fac.createOMNamespace("http://service.carbon.wso2.org", "ns1");
   OMElement method = fac.createOMElement("echoString", omNs);
   OMElement value = fac.createOMElement("s", omNs);
   value.addChild(fac.createOMText(value, "Hello World"));
   method.addChild(value);
   return method;
 }
예제 #8
0
  private OMElement createStandardSimpleRequest(String symbol) {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://services.samples", "ns");
    OMElement method = fac.createOMElement("getSimpleQuote", omNs);
    OMElement value1 = fac.createOMElement("symbol", omNs);

    value1.addChild(fac.createOMText(method, symbol));
    method.addChild(value1);

    return method;
  }
예제 #9
0
  private OMElement getPayload() {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://services.samples", "ns");
    OMElement method = fac.createOMElement("getQuote", omNs);
    OMElement value1 = fac.createOMElement("request", omNs);
    OMElement value2 = fac.createOMElement("symbol", omNs);

    value2.addChild(fac.createOMText(value1, "Secured"));
    value1.addChild(value2);
    method.addChild(value1);

    return method;
  }
예제 #10
0
  private OMElement createMultipleQuoteRequest(String symbol, int iterations) {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://services.samples", "ns");
    OMElement method = fac.createOMElement("getQuote", omNs);

    for (int i = 0; i < iterations; i++) {
      OMElement value1 = fac.createOMElement("request", omNs);
      OMElement value2 = fac.createOMElement("symbol", omNs);
      value2.addChild(fac.createOMText(value1, symbol));
      value1.addChild(value2);
      method.addChild(value1);
    }
    return method;
  }
예제 #11
0
  private static OMElement getPayload() {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://service.esb.wso2.org", "ns");
    OMElement method = fac.createOMElement("add", omNs);
    OMElement value1 = fac.createOMElement("x", omNs);
    OMElement value2 = fac.createOMElement("y", omNs);

    value1.addChild(fac.createOMText(value1, "10"));
    value2.addChild(fac.createOMText(value2, "10"));
    method.addChild(value1);
    method.addChild(value2);

    return method;
  }
예제 #12
0
  /** @param args */
  public void sendMedicamento() {
    IWebServiceStub service = null;
    ResultSendMedicamento result = new ResultSendMedicamento();
    try {

      System.out.println("Inicio: " + new Timestamp(System.currentTimeMillis()));
      service = new IWebServiceStub("https://trazabilidad.pami.org.ar:9050/trazamed.WebService");
      // service = new
      // IWebServiceServiceStub("https://trazabilidad.pami.org.ar:9050/trazamed.WebService");

      ServiceClient serviceClient = service._getServiceClient();

      OMFactory omFactory = OMAbstractFactory.getOMFactory();

      OMElement security =
          omFactory.createOMElement(
              new QName(
                  "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
                  "Security",
                  "wsse"),
              null);

      OMNamespace omNs =
          omFactory.createOMNamespace(
              "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
              "wsu");
      OMElement userNameToken = omFactory.createOMElement("UsernameToken", omNs);

      OMElement userName = omFactory.createOMElement("Username", omNs);
      userName.addChild(omFactory.createOMText("testwservice"));

      OMElement password = omFactory.createOMElement("Password", omNs);
      password.addChild(omFactory.createOMText("testwservicepsw"));

      userNameToken.addChild(userName);
      userNameToken.addChild(password);

      security.addChild(userNameToken);
      serviceClient.addHeader(security);

      serviceClient.getOptions().setTimeOutInMilliSeconds(1000000);

      // serviceClient.setOptions(o);

      String error = null;
      GetTransaccionesNoConfirmadasE ge = new GetTransaccionesNoConfirmadasE();
      GetTransaccionesNoConfirmadas g = new GetTransaccionesNoConfirmadas();
      g.setArg0("DROGUERIAORIEN");
      g.setArg1("ORIEN1152");

      g.setArg6("07795312001427");
      // g.setArg18("8137306466");
      ge.setGetTransaccionesNoConfirmadas(g);

      GetTransaccionesNoConfirmadasResponseE geR = new GetTransaccionesNoConfirmadasResponseE();

      System.out.println(
          "Voy a llmar a getTransaccionesNoConfirmadas "
              + new Timestamp(System.currentTimeMillis()));
      geR = service.getTransaccionesNoConfirmadas(ge);
      System.out.println(
          geR.getGetTransaccionesNoConfirmadasResponse().get_return().getList().length);
      System.out.println(
          "Llame a getTransaccionesNoConfirmadas " + new Timestamp(System.currentTimeMillis()));
      if (geR.getGetTransaccionesNoConfirmadasResponse().get_return().getErrores() != null) {
        WebServiceError[] wseArray =
            geR.getGetTransaccionesNoConfirmadasResponse().get_return().getErrores();
        for (WebServiceError wse : wseArray) {
          System.out.println(wse.get_d_error());
          error = wse.get_d_error();
        }
      }
      String idTransac = "";
      if (error == null
          && geR.getGetTransaccionesNoConfirmadasResponse().get_return().getList() != null) {
        for (TransaccionPlainWS t :
            geR.getGetTransaccionesNoConfirmadasResponse().get_return().getList()) {
          idTransac = t.get_id_transaccion();
        }
      }

      try {
        Long id_transac = Long.parseLong(idTransac);
        ConfirmacionTransaccionDTO[] series = new ConfirmacionTransaccionDTO[1];
        ConfirmacionTransaccionDTO serie = new ConfirmacionTransaccionDTO();
        serie.setP_ids_transac(id_transac);
        serie.setF_operacion(
            DateUtil.getFormatedSTDDate(new Timestamp(System.currentTimeMillis())));
        series[0] = serie;
        SendConfirmaTransaccE ge_ = new SendConfirmaTransaccE();
        SendConfirmaTransacc g_ = new SendConfirmaTransacc();
        g_.setArg0("ENTRERIOS205");
        g_.setArg1("ORIEN2012");
        g_.setArg2(series);
        ge_.setSendConfirmaTransacc(g_);

        System.out.println(
            "Voy a llmar a sendConfirmaTransacc " + new Timestamp(System.currentTimeMillis()));
        SendConfirmaTransaccResponseE result_confirm = service.sendConfirmaTransacc(ge_);
        System.out.println(
            "llame a sendConfirmaTransacc " + new Timestamp(System.currentTimeMillis()));
        String id_transac_ = "";
        if (result_confirm.getSendConfirmaTransaccResponse().get_return().getErrores() != null
            && result_confirm.getSendConfirmaTransaccResponse().get_return().getErrores().length
                > 0) {
          WebServiceError[] wseArray =
              result_confirm.getSendConfirmaTransaccResponse().get_return().getErrores();
          for (WebServiceError wse : wseArray) {
            result.setExito(false);
            result.setErrores(wse.get_d_error());
          }

        } else {
          id_transac_ =
              result_confirm
                  .getSendConfirmaTransaccResponse()
                  .get_return()
                  .getId_transac_asociada();
          result.setExito(true);
          result.setErrores("OK");
          result.setTransacNr(id_transac_);
        }

      } catch (Exception e) {
        result.setExito(false);
        result.setErrores("No se pudo obtener el id_transac_global");
      }

    } catch (AxisFault e1) {
      result.setExito(false);
      result.setErrores("No se pudo obtener el id_transac_global");
      e1.printStackTrace();
    } catch (RemoteException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      result.setExito(false);
      result.setErrores("No se pudo obtener el id_transac_global");
    }
    System.out.println(result.getErrores());
    System.out.println(result.getTransacNr());
    System.out.println("Fin: " + new Timestamp(System.currentTimeMillis()));
  }