private void serializeRuntimeException() throws WebServiceException {
    try {
      MessageFactory factory = _soapContext.getMessageFactory();
      SOAPMessage message = factory.createMessage();

      QName faultcode =
          new QName(
              message.getSOAPBody().getNamespaceURI(), "Server", message.getSOAPBody().getPrefix());

      message.getSOAPBody().addFault(faultcode, _runtimeException.getMessage());

      _soapContext.setMessage(message);
      _source = _soapContext.getMessage().getSOAPPart().getContent();
    } catch (SOAPException se) {
      throw new WebServiceException(se);
    }
  }
Ejemplo n.º 2
0
  public Node extractResponseNode(SOAPMessage response) throws SOAPException {

    Node responseNode;

    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    try {
      response.writeTo(outStream);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
    //		logger.LogBetfairDebugEntry("SOAP Response: " + outStream.toString());

    if (response.getSOAPBody().hasFault()) {
      responseNode = response.getSOAPBody().getFault();
    } else if (response.getSOAPBody().getFirstChild() == null) { // Response type is void
      responseNode = response.getSOAPBody();
    } else {
      // extract the body
      SOAPBody respBody = response.getSOAPBody();
      // First child should be the service name object
      Node serviceResponseNode = respBody.getFirstChild();

      // second child
      responseNode = serviceResponseNode.getFirstChild();
    }

    return responseNode;
  }
  @Test
  public void testSWA() throws Exception {
    SOAPFactory soapFac = SOAPFactory.newInstance();
    MessageFactory msgFac = MessageFactory.newInstance();
    SOAPConnectionFactory conFac = SOAPConnectionFactory.newInstance();
    SOAPMessage msg = msgFac.createMessage();

    QName sayHi = new QName("http://apache.org/hello_world_rpclit", "sayHiWAttach");
    msg.getSOAPBody().addChildElement(soapFac.createElement(sayHi));
    AttachmentPart ap1 = msg.createAttachmentPart();
    ap1.setContent("Attachment content", "text/plain");
    msg.addAttachmentPart(ap1);
    AttachmentPart ap2 = msg.createAttachmentPart();
    ap2.setContent("Attachment content - Part 2", "text/plain");
    msg.addAttachmentPart(ap2);
    msg.saveChanges();

    SOAPConnection con = conFac.createConnection();
    URL endpoint =
        new URL("http://localhost:9008/SOAPServiceProviderRPCLit/SoapPortProviderRPCLit1");
    SOAPMessage response = con.call(msg, endpoint);
    QName sayHiResp = new QName("http://apache.org/hello_world_rpclit", "sayHiResponse");
    assertNotNull(response.getSOAPBody().getChildElements(sayHiResp));
    assertEquals(2, response.countAttachments());
  }
Ejemplo n.º 4
0
  public SOAPMessage invoke(SOAPMessage request) {
    SOAPBody requestBody;
    try {
      requestBody = request.getSOAPBody();
      if (requestBody.getElementName().getLocalName().equals("Body")) {
        MessageFactory mf = MessageFactory.newInstance();
        SOAPFactory sf = SOAPFactory.newInstance();

        SOAPMessage response = mf.createMessage();
        SOAPBody respBody = response.getSOAPBody();
        Name bodyName;
        if (requestBody
            .getFirstChild()
            .getNextSibling()
            .getLocalName()
            .equals("getTomorrowForecast")) {
          bodyName = sf.createName("getTomorrowForecastResponse");
        } else if (requestBody.getFirstChild().getNextSibling().getLocalName().equals("invoke")) {
          bodyName = sf.createName("invokeResponse");
        } else {
          throw new SOAPException(
              "No operation named 'getTomorrowForecast' or 'invoke' was found !");
        }
        respBody.addBodyElement(bodyName);
        SOAPElement respContent = respBody.addChildElement("return");
        respContent.setValue(soapResponse);
        response.saveChanges();
        return response;
      }
    } catch (SOAPException soapEx) {
      logger.error("An error occurs !", soapEx);
    }
    return null;
  }
Ejemplo n.º 5
0
  private void doTestSoapConnection(boolean disableChunking) throws Exception {
    SOAPFactory soapFac = SOAPFactory.newInstance();
    MessageFactory msgFac = MessageFactory.newInstance();
    SOAPConnectionFactory conFac = SOAPConnectionFactory.newInstance();
    SOAPMessage msg = msgFac.createMessage();

    if (disableChunking) {
      // this is the custom header checked by ServiceImpl
      msg.getMimeHeaders().addHeader("Transfer-Encoding-Disabled", "true");
      // this is a hint to SOAPConnection that the chunked encoding is not needed
      msg.getMimeHeaders().addHeader("Transfer-Encoding", "disabled");
    }

    QName sayHi = new QName("http://www.jboss.org/jbossws/saaj", "sayHello");
    msg.getSOAPBody().addChildElement(soapFac.createElement(sayHi));
    AttachmentPart ap1 = msg.createAttachmentPart();

    char[] content = new char[16 * 1024];
    Arrays.fill(content, 'A');

    ap1.setContent(new String(content), "text/plain");
    msg.addAttachmentPart(ap1);

    AttachmentPart ap2 = msg.createAttachmentPart();
    ap2.setContent("Attachment content - Part 2", "text/plain");
    msg.addAttachmentPart(ap2);
    msg.saveChanges();

    SOAPConnection con = conFac.createConnection();

    final String serviceURL = baseURL.toString();

    URL endpoint = new URL(serviceURL);
    SOAPMessage response = con.call(msg, endpoint);
    QName sayHiResp = new QName("http://www.jboss.org/jbossws/saaj", "sayHelloResponse");

    Iterator<?> sayHiRespIterator = response.getSOAPBody().getChildElements(sayHiResp);
    SOAPElement soapElement = (SOAPElement) sayHiRespIterator.next();
    assertNotNull(soapElement);

    assertEquals(2, response.countAttachments());

    String[] values = response.getMimeHeaders().getHeader("Transfer-Encoding-Disabled");
    if (disableChunking) {
      // this means that the ServiceImpl executed the code branch verifying
      // that chunking was disabled
      assertNotNull(values);
      assertTrue(values.length == 1);
    } else {
      assertNull(values);
    }
  }
    @Override
    protected Soap createMessage(byte[] rawXml, SOAPMessage soap, String charset) throws Exception {
      if (soap.getSOAPHeader() != null) {
        SoapHeader header = unmarshalHeader(SoapHeader.class, soap.getSOAPHeader());
        if (header.getCentralService() != null) {
          if (header.getService() != null) {
            throw new CodedException(
                X_MALFORMED_SOAP,
                "Message header must contain either service id" + " or central service id");
          }

          ServiceId serviceId = GlobalConf.getServiceId(header.getCentralService());
          header.setService(serviceId);

          SOAPEnvelope envelope = soap.getSOAPPart().getEnvelope();
          envelope.removeChild(soap.getSOAPHeader());

          Node soapBody = envelope.removeChild(soap.getSOAPBody());
          envelope.removeContents(); // removes newlines etc.

          Marshaller marshaller =
              JaxbUtils.createMarshaller(SoapHeader.class, new SoapNamespacePrefixMapper());
          marshaller.marshal(header, envelope);

          envelope.appendChild(soapBody);

          byte[] newRawXml = SoapUtils.getBytes(soap);
          return super.createMessage(newRawXml, soap, charset);
        }
      }
      return super.createMessage(rawXml, soap, charset);
    }
Ejemplo n.º 7
0
  public void testWriteOutput_saaj_rpc() throws Exception {
    SOAPMessage soapMessage = writeRpcOutput();

    // soap body
    SOAPBody bodyElem = soapMessage.getSOAPBody();
    // operation wrapper
    SOAPElement operationElem =
        SoapUtil.getElement(bodyElem, BpelConstants.NS_EXAMPLES, "opResponse");

    // simple part
    SOAPElement intPart = SoapUtil.getElement(operationElem, "intPart");
    // value
    assertEquals("2020", intPart.getValue());

    // complex part
    SOAPElement complexPart = SoapUtil.getElement(operationElem, "complexPart");
    // attributes
    assertEquals("hi", complexPart.getAttribute("attributeOne"));
    assertEquals("ho", complexPart.getAttribute("attributeTwo"));
    // child elements
    SOAPElement one = SoapUtil.getElement(complexPart, "urn:uriOne", "elementOne");
    assertEquals("ram", one.getValue());
    SOAPElement two = SoapUtil.getElement(complexPart, "urn:uriTwo", "elementTwo");
    assertEquals("ones", two.getValue());
  }
  @Test
  public void invoke() throws Exception {

    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage request = messageFactory.createMessage();
    request
        .getSOAPBody()
        .addBodyElement(QName.valueOf("{http://springframework.org/spring-ws}Request"));
    MessageContext messageContext =
        new DefaultMessageContext(
            new SaajSoapMessage(request), new SaajSoapMessageFactory(messageFactory));
    DefaultMethodEndpointAdapter adapter = new DefaultMethodEndpointAdapter();
    adapter.afterPropertiesSet();

    MessageDispatcher messageDispatcher = new SoapMessageDispatcher();
    messageDispatcher.setApplicationContext(applicationContext);
    messageDispatcher.setEndpointMappings(Collections.<EndpointMapping>singletonList(mapping));
    messageDispatcher.setEndpointAdapters(Collections.<EndpointAdapter>singletonList(adapter));

    messageDispatcher.receive(messageContext);

    MyEndpoint endpoint = applicationContext.getBean("endpoint", MyEndpoint.class);
    assertTrue("doIt() not invoked on endpoint", endpoint.isDoItInvoked());

    LogAspect aspect = (LogAspect) applicationContext.getBean("logAspect");
    assertTrue("log() not invoked on aspect", aspect.isLogInvoked());
  }
Ejemplo n.º 9
0
  public SecurityToken logon(
      String anEndpointReference, String aUserName, String aPassword, String anApplicationID)
      throws LogonManagerException, SOAPException, IOException {
    SecurityToken result;
    SOAPMessage message;
    SOAPConnection conn = null;

    try {
      result = null;
      String request =
          REQUEST_FORMAT.format(
              ((Object) (new Object[] {fURL, aUserName, aPassword, anEndpointReference})));
      message =
          MessageFactory.newInstance()
              .createMessage(new MimeHeaders(), new ByteArrayInputStream(request.getBytes()));
      conn = SOAPConnectionFactory.newInstance().createConnection();
      SOAPMessage response = conn.call(message, fURL);
      SOAPBody body = response.getSOAPBody();
      if (body.hasFault()) throw new LogonManagerException(body.getFault());
      result = new SecurityToken();
      result.setSOAPBody(body);
      for (Iterator it = body.getChildElements(); it.hasNext(); fill(result, (Node) it.next())) ;
      return result;
    } finally {
      if (conn != null) conn.close();
    }
  }
Ejemplo n.º 10
0
 @Override
 public EnumValutesXMLResponse parseEnumValutesXMLResponse(SOAPMessage soapMessage)
     throws Exception {
   Node root = soapMessage.getSOAPBody().extractContentAsDocument();
   JAXBContext jaxbContext = JAXBContext.newInstance(EnumValutesFactory.class);
   Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
   return (EnumValutesXMLResponse) unmarshaller.unmarshal(root);
 }
Ejemplo n.º 11
0
 @Override
 public GetCursOnDateXMLResponse parseGetCursOnDateXMLResponse(SOAPMessage soapMessage)
     throws Exception {
   Node root = soapMessage.getSOAPBody().extractContentAsDocument();
   JAXBContext jaxbContext = JAXBContext.newInstance(GetCursOnDateFactory.class);
   Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
   GetCursOnDateXMLResponse result = (GetCursOnDateXMLResponse) unmarshaller.unmarshal(root);
   return result;
 }
Ejemplo n.º 12
0
 private void soapToRpcResult(SOAPMessage response, RpcInvokeAction action, SimpleRpcResult result)
     throws Exception {
   logMessage("Response message:", response);
   SOAPBody responseBody = response.getSOAPBody();
   checkForFailureReponse(responseBody);
   actionData =
       WsRpcActionUtil.getWsRpcActionData(((SimpleRpcInvokeAction) action).getProperties());
   getFields(action.getFields(), responseBody.getChildElements());
   result.setRpcFields(action.getFields());
 }
Ejemplo n.º 13
0
  public void testWriteFault_saaj() throws Exception {
    SOAPMessage soapMessage = writeFault();

    SOAPBody body = soapMessage.getSOAPBody();
    // SOAPFault fault = body.getFault();
    SOAPElement fault = SoapUtil.getElement(body, SOAPConstants.URI_NS_SOAP_ENVELOPE, "Fault");

    testFaultCode(fault);
    testFaultString(fault);
    testDetail(fault);
  }
Ejemplo n.º 14
0
  @Override
  public String toString(SOAPMessage soapMessage) throws SOAPException, IOException {
    ByteArrayOutputStream output = new ByteArrayOutputStream();

    soapMessage.writeTo(output);

    if (formatter != null) {
      // return formatter.format(output.toString(charset));
      return formatter.format(soapMessage.getSOAPBody().getOwnerDocument());
    }

    return output.toString(charset);
  }
Ejemplo n.º 15
0
  /**
   * Creates a SOAPBody element from SOS response
   *
   * @param soapResponseMessage SOAPBody element
   * @param sosResponse SOS response
   * @param actionURI the action URI
   * @return the action URI
   * @throws SOAPException if an error occurs.
   */
  protected String createSOAPBody(
      SOAPMessage soapResponseMessage, XmlObject sosResponse, String actionURI)
      throws SOAPException {

    if (sosResponse != null) {
      addAndRemoveSchemaLocationForSOAP(sosResponse, soapResponseMessage);
      soapResponseMessage.getSOAPBody().addDocument((Document) sosResponse.getDomNode());
      return actionURI;
    } else {
      SoapFault fault = new SoapFault();
      fault.setFaultCode(SOAPConstants.SOAP_RECEIVER_FAULT);
      fault.setFaultSubcode(
          new QName(
              OWSConstants.NS_OWS,
              OwsExceptionCode.NoApplicableCode.name(),
              OWSConstants.NS_OWS_PREFIX));
      fault.setFaultReason(DEFAULT_FAULT_REASON);
      fault.setLocale(Locale.ENGLISH);
      fault.setDetailText(MISSING_RESPONSE_DETAIL_TEXT);
      createSOAPFault(soapResponseMessage.getSOAPBody().addFault(), fault);
    }
    return null;
  }
Ejemplo n.º 16
0
  public static void main(String[] args) throws SOAPException {
    // Service helloService = new HelloService();
    QName serviceName = new QName(targetNamespace, serName);
    QName portName = new QName(targetNamespace, pName);
    // Hello hello = helloService.getPortName();
    javax.xml.ws.Service service = Service.create(serviceName);
    service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
    Dispatch<SOAPMessage> dispatch =
        service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);
    BindingProvider bp = (BindingProvider) dispatch;
    Map<String, Object> rc = bp.getRequestContext();
    rc.put(BindingProvider.SOAPACTION_USE_PROPERTY, Boolean.TRUE);
    rc.put(BindingProvider.SOAPACTION_URI_PROPERTY, OPER_NAME);
    MessageFactory factory = ((SOAPBinding) bp.getBinding()).getMessageFactory();

    SOAPMessage request = factory.createMessage();
    SOAPBody body = request.getSOAPBody();
    QName payloadName = new QName(targetNamespace, OPER_NAME, "ns1");
    SOAPBodyElement payload = body.addBodyElement(payloadName);
    SOAPElement message = payload.addChildElement(INPUT_NAME);
    message.addTextNode("x");
    //		String value = "<people>" +
    //				"<name>TimLu</name>"+
    //				"<age>26</age>"+
    //				"</people>";
    //		message.setValue(value);
    SOAPMessage reply = null;
    try {
      reply = dispatch.invoke(request);
    } catch (WebServiceException wse) {
      wse.printStackTrace();
    }
    SOAPBody soapBody = reply.getSOAPBody();
    SOAPBodyElement nextSoapBodyElement = (SOAPBodyElement) soapBody.getChildElements().next();
    SOAPElement soapElement = (SOAPElement) nextSoapBodyElement.getChildElements().next();
    System.out.println("Return repsone value=" + soapElement.getValue());
  }
Ejemplo n.º 17
0
 /**
  * Print out a SOAPMessage to System.out.
  *
  * @param message
  */
 public static void print(SOAPMessage message) {
   try {
     Transformer transformer = TransformerFactory.newInstance().newTransformer();
     transformer.setOutputProperty(OutputKeys.INDENT, "yes");
     transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
     transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
     transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
     StreamResult result = new StreamResult(new StringWriter());
     DOMSource source = new DOMSource(message.getSOAPBody().getOwnerDocument());
     transformer.transform(source, result);
     System.out.println(result.getWriter().toString());
   } catch (Exception exception) {
     System.out.println("Failed to print message: " + exception.getLocalizedMessage());
   }
 }
 private QName getOperationName(MessageContext msgContext) {
   SOAPMessageContext soapMessageContext = (SOAPMessageContext) msgContext;
   SOAPMessage soapMessage = soapMessageContext.getMessage();
   SOAPBody soapBody;
   try {
     soapBody = soapMessage.getSOAPBody();
     Node child = soapBody.getFirstChild();
     String childNamespace = child.getNamespaceURI();
     String childName = child.getLocalName();
     return new QName(childNamespace, childName);
   } catch (SOAPException e) {
     if (trace) log.trace("Exception using backup method to get op name=", e);
   }
   return null;
 }
  public Document invokeMethod(DynamicBinder dBinder, Document inputDoc) throws ComponentException {
    try {
      logger.info(
          "URI : "
              + dBinder.wsdlURI
              + "\n porttype: "
              + dBinder.portType
              + " \n operation: "
              + dBinder.operation
              + "\n endpoint: "
              + dBinder.endPoint);

      QName serviceName = new QName(dBinder.targetNS, dBinder.serviceName);
      Service serv = Service.create(serviceName);

      QName portQName = new QName(dBinder.targetNS, dBinder.portType);
      serv.addPort(portQName, SOAPBinding.SOAP11HTTP_BINDING, dBinder.endPoint);

      MessageFactory factory = MessageFactory.newInstance();
      SOAPMessage message = factory.createMessage();

      // TODO: add namespaces declared on the SOAPBody level to the envelope
      message.getSOAPPart().getEnvelope().addNamespaceDeclaration("tns1", dBinder.targetNS);
      message.getSOAPBody().addDocument(inputDoc);
      message.getMimeHeaders().addHeader("SOAPAction", dBinder.operation);
      message.saveChanges();

      Dispatch<SOAPMessage> smDispatch =
          serv.createDispatch(portQName, SOAPMessage.class, Service.Mode.MESSAGE);

      List<Handler> handlers = smDispatch.getBinding().getHandlerChain();
      handlers.add(new SOAPLoggingHandler());
      smDispatch.getBinding().setHandlerChain(handlers);

      SOAPMessage soapResponse = null;
      try {
        soapResponse = smDispatch.invoke(message);
      } catch (Exception e) {
        logger.error("Fault has been returned in SOAP message!!!");
        return null;
      }

      return toDocument(soapResponse);
    } catch (Exception e) {
      logger.error(e.getMessage());
      throw new ComponentException(e.getMessage());
    }
  }
Ejemplo n.º 20
0
 private SOAPBody getSOAPBody(String request)
     throws UnsupportedEncodingException, SoapExceptionClient, IOException {
   SOAPMessage soapMessage = null;
   SOAPBody soapBody = null;
   try {
     MessageFactory factory = MessageFactory.newInstance();
     soapMessage =
         factory.createMessage(
             new MimeHeaders(), new ByteArrayInputStream(request.getBytes("UTF-8")));
     soapBody = soapMessage.getSOAPBody();
   } catch (SOAPException e) {
     throw new SoapExceptionClient(
         e.getLocalizedMessage() + " Cause: " + e.getCause().toString(), e);
   }
   return soapBody;
 }
Ejemplo n.º 21
0
 private static Collection<String> parseSoapResponseForUrls(byte[] data)
     throws SOAPException, IOException {
   // System.out.println(new String(data));
   final Collection<String> urls = new ArrayList<>();
   MessageFactory factory = MessageFactory.newInstance(WS_DISCOVERY_SOAP_VERSION);
   final MimeHeaders headers = new MimeHeaders();
   headers.addHeader("Content-type", WS_DISCOVERY_CONTENT_TYPE);
   SOAPMessage message = factory.createMessage(headers, new ByteArrayInputStream(data));
   SOAPBody body = message.getSOAPBody();
   for (Node node : getNodeMatching(body, ".*:XAddrs")) {
     if (node.getTextContent().length() > 0) {
       urls.addAll(Arrays.asList(node.getTextContent().split(" ")));
     }
   }
   return urls;
 }
Ejemplo n.º 22
0
 /**
  * Normal response case,just tests if the endpoint accepts non-anon FaultTo
  *
  * @throws Exception
  */
 public void testNonAnonymousFaultTo1() throws Exception {
   SOAPMessage response =
       invoke(
           createDispatchWithoutAddressing(),
           TestMessages.NON_ANONYMOUS_FAULT_TO_COMPLETE_MESSAGE,
           S11_NS,
           nonAnonAddress,
           action,
           endpointAddress,
           "testNonAnonymousReplyTo");
   SOAPBody sb = response.getSOAPBody();
   Iterator itr =
       sb.getChildElements(
           new QName("http://server.responses.wsa.fromjava/", "addNumbersResponse"));
   assertTrue(itr.hasNext());
 }
Ejemplo n.º 23
0
  private SOAPElement assertResponseXML(SOAPMessage msg, String expectedText) throws Exception {
    assertTrue(msg != null);
    SOAPBody body = msg.getSOAPBody();
    assertTrue(body != null);

    Node invokeElement = (Node) body.getFirstChild();
    assertTrue(invokeElement instanceof SOAPElement);
    assertEquals("outMessage", invokeElement.getLocalName());

    String text = invokeElement.getValue();

    System.out.println("Received: " + text);
    assertEquals("Found (" + text + ") but expected (" + expectedText + ")", expectedText, text);

    return (SOAPElement) invokeElement;
  }
Ejemplo n.º 24
0
  @Override
  protected boolean handleInbound(SOAPMessageContext msgContext) {
    try {
      SOAPMessage soapMessage = msgContext.getMessage();
      SOAPBody soapBody = soapMessage.getSOAPBody();

      SOAPBodyElement soapBodyElement = (SOAPBodyElement) soapBody.getChildElements().next();
      if (soapBodyElement.getChildElements().hasNext()) {
        SOAPElement payload = (SOAPElement) soapBodyElement.getChildElements().next();
        String value = payload.getValue();
        payload.setValue(value + "World");
      }
    } catch (SOAPException e) {
      throw new WebServiceException(e);
    }
    return true;
  }
Ejemplo n.º 25
0
  @Override
  public SOAPMessage getRequestSOAPMessage(String serviceNumber, RequestInfo requestInfo)
      throws Exception {
    String xChangeType = "";
    String applierNumber = "";
    String receiverNumber = "";
    String exchangeAmount = "";
    if (!StringUtils.isEmpty(requestInfo.getRequestBody().getExtParameters())) {
      JSONObject extParametersJson =
          new JSONObject(requestInfo.getRequestBody().getExtParameters());
      if (extParametersJson.has("xChangeType")) {
        xChangeType = extParametersJson.getString("xChangeType");
      } else {
        throw new Exception("xChangeType is null");
      }
      if (extParametersJson.has("applierNumber")) {
        applierNumber = extParametersJson.getString("applierNumber");
      } else {
        throw new Exception("applierNumber is null");
      }
      if (extParametersJson.has("receiverNumber")) {
        receiverNumber = extParametersJson.getString("receiverNumber");
      } else {
        throw new Exception("applierNumber is null");
      }
      if (extParametersJson.has("exchangeAmount")) {
        exchangeAmount = extParametersJson.getString("exchangeAmount");
      } else {
        throw new Exception("exchangeAmount is null");
      }
    }

    SOAPMessage message = SoapCallUtils.getMessageFactory().createMessage();
    this.getCBSArsHeader("XchangePromotionRequestMsg", message);
    SOAPBodyElement bodyElement = (SOAPBodyElement) message.getSOAPBody().getChildElements().next();
    SOAPElement reqestElement = bodyElement.addChildElement("XchangePromotionRequest");
    reqestElement.addChildElement("XchangeType", "arc").addTextNode(xChangeType);
    reqestElement.addChildElement("applierNumber", "arc").addTextNode(applierNumber);
    ;
    reqestElement.addChildElement("receiverNumber", "arc").addTextNode(receiverNumber);
    ;
    reqestElement.addChildElement("exchangeAmount", "arc").addTextNode(exchangeAmount);
    ;
    return message;
  }
  private void serializeProtocolException() throws WebServiceException {
    if (_protocolException instanceof SOAPFaultException) {
      SOAPFaultException sfe = (SOAPFaultException) _protocolException;
      SOAPFault fault = sfe.getFault();

      try {
        MessageFactory factory = _soapContext.getMessageFactory();
        SOAPMessage message = factory.createMessage();
        message.getSOAPBody().addChildElement(fault);
        _soapContext.setMessage(message);
        _source = _soapContext.getMessage().getSOAPPart().getContent();
      } catch (SOAPException se) {
        throw new WebServiceException(se);
      }
    } else {
      throw new WebServiceException(L.l("Unsupported ProtocolException: {0}", _protocolException));
    }
  }
Ejemplo n.º 27
0
  public void testWriteOutput_saaj_doc() throws Exception {
    SOAPMessage soapMessage = writeDocOutput();

    // soap body
    SOAPBody bodyElem = soapMessage.getSOAPBody();

    // element part
    SOAPElement elementPart =
        SoapUtil.getElement(bodyElem, BpelConstants.NS_EXAMPLES, "responseElement");
    // attributes
    assertEquals("hi", elementPart.getAttribute("attributeOne"));
    assertEquals("ho", elementPart.getAttribute("attributeTwo"));
    // child elements
    SOAPElement one = SoapUtil.getElement(elementPart, "urn:uriOne", "elementOne");
    assertEquals("ram", one.getValue());
    SOAPElement two = SoapUtil.getElement(elementPart, "urn:uriTwo", "elementTwo");
    assertEquals("ones", two.getValue());
  }
  public boolean handleMessage(SOAPMessageContext mCtx) {
    Boolean outbound = (Boolean) mCtx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if (outbound) {
      try {
        SOAPMessage soapMessage = mCtx.getMessage();
        SOAPBody soapBody = soapMessage.getSOAPBody();
        Node firstChild = soapBody.getFirstChild(); // operation name

        String timeStamp = getTimestamp();
        String signature = getSignature(firstChild.getLocalName(), timeStamp, secretBytes);
        append(firstChild, "Signature", signature);
        append(firstChild, "Timestamp", timeStamp);
      } catch (Exception e) {
        throw new RuntimeException("SOAPException thrown.", e);
      }
    }
    return true; // continue down the handler chain
  }
Ejemplo n.º 29
0
  /**
   * Sets the return object for a response as the param.
   *
   * @param context the message context
   * @param param the object to set as the return object
   * @throws SoapFault
   */
  protected void setSOAPResponseObject(SOAPMessageContext context, Object newResponse) {
    if (newResponse == null) {
      return;
    }
    // Extract the SOAP Message
    SOAPMessage message = context.getMessage();

    // Get the envelope body
    SOAPElement body;
    try {
      body = message.getSOAPBody();
      SOAPElement response = getSOAPResponseNode(context);
      body.removeChild(response);
      marshall(newResponse, body);
    } catch (SOAPException e) {
      logger.error("Problem changing SOAP message contents", e);
      throw CXFUtility.getFault(e);
    }
  }
  @Test
  public void testCopyNamespacesSOAP11() throws Exception {
    _composer.setCopyNamespaces(true);
    SOAPMessage soapMessage =
        SOAPUtil.createMessage(javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING);
    soapMessage.getSOAPPart().getEnvelope().addNamespaceDeclaration("foobarns", "urn:foobarns");
    soapMessage.getSOAPBody().addBodyElement(new QName("urn:test", "foobar"));
    logger.info(
        String.format("before compose:[\n%s]", XMLHelper.toPretty(soapMessage.getSOAPPart())));

    SOAPBindingData sbd = new SOAPBindingData(soapMessage);
    Node res = _composer.compose(sbd, _exchange).getContent(Node.class);
    logger.info(String.format("after compose:[\n%s]", XMLHelper.toPretty(res)));
    String envPrefix = soapMessage.getSOAPPart().getEnvelope().getPrefix();
    String envNS = soapMessage.getSOAPPart().getEnvelope().getNamespaceURI(envPrefix);
    String resNS = res.lookupNamespaceURI(envPrefix);
    Assert.assertEquals(envNS, resNS);
    Assert.assertEquals("urn:foobarns", res.lookupNamespaceURI("foobarns"));
  }