Package org.jboss.ws.core

Examples of org.jboss.ws.core.CommonBinding


   /** Test unbinding of the response message with bound header
    */
   public void testUnbindResponseMessageWithBoundHeader() throws Exception
   {
      CommonBindingProvider bindingProvider = new CommonBindingProvider(CommonSOAPBinding.SOAP12HTTP_BINDING, Type.JAXRPC);
      CommonBinding binding = (CommonBinding)bindingProvider.getCommonBinding();

      ByteArrayInputStream inputStream = new ByteArrayInputStream(resEnvelopeWithBoundHeader.getBytes());

      MessageFactory factory = new MessageFactoryImpl();
      SOAPMessageImpl resMessage = (SOAPMessageImpl)factory.createMessage(null, inputStream);

      CommonMessageContext msgContext = MessageContextAssociation.peekMessageContext();
      msgContext.setSOAPMessage(resMessage);

      // Add bound header
      QName xmlName = new QName("http://somens", "OutHeader");
      ParameterMetaData paramMetaData = new ParameterMetaData(opMetaData, xmlName, Constants.TYPE_LITERAL_STRING, "java.lang.String");
      paramMetaData.setMode(ParameterMode.OUT);
      paramMetaData.setInHeader(true);
      paramMetaData.setIndex(1);
      opMetaData.addParameter(paramMetaData);

      EndpointInvocation epInv = new EndpointInvocation(opMetaData);
      binding.unbindResponseMessage(opMetaData, resMessage, epInv, null);
      assertEquals("Hello World!", epInv.getReturnValue());

      Object headerValue = epInv.getResponseParamValue(xmlName);
      assertEquals("OUT header message", headerValue);
   }
View Full Code Here


   /** Test unbinding of the response message with unbound header
    */
   public void testUnbindResponseMessageWithUnboundHeader() throws Exception
   {
      CommonBindingProvider bindingProvider = new CommonBindingProvider(CommonSOAPBinding.SOAP12HTTP_BINDING, Type.JAXRPC);
      CommonBinding binding = (CommonBinding)bindingProvider.getCommonBinding();

      ByteArrayInputStream inputStream = new ByteArrayInputStream(resEnvelopeWithUnboundHeader.getBytes());

      MessageFactory factory = new MessageFactoryImpl();
      SOAPMessageImpl resMessage = (SOAPMessageImpl)factory.createMessage(null, inputStream);

      CommonMessageContext msgContext = MessageContextAssociation.peekMessageContext();
      msgContext.setSOAPMessage(resMessage);

      QName xmlName = new QName("http://somens", "OutHeader");
      UnboundHeader header = new UnboundHeader(xmlName, Constants.TYPE_LITERAL_STRING, String.class, ParameterMode.OUT);

      Map headers = new HashMap();
      headers.put(xmlName, header);

      EndpointInvocation epInv = new EndpointInvocation(opMetaData);
      binding.unbindResponseMessage(opMetaData, resMessage, epInv, headers);
      assertEquals("Hello World!", epInv.getReturnValue());

      assertEquals("OUT header message", header.getHeaderValue());
   }
View Full Code Here

   /** Test unbinding of the response message with unbound header
    */
   public void testUnbindFaultResponse() throws Exception
   {
      CommonBindingProvider bindingProvider = new CommonBindingProvider(CommonSOAPBinding.SOAP12HTTP_BINDING, Type.JAXRPC);
      CommonBinding binding = (CommonBinding)bindingProvider.getCommonBinding();

      ByteArrayInputStream inputStream = new ByteArrayInputStream(resEnvelopeWithFault.getBytes());

      MessageFactory factory = new MessageFactoryImpl();
      SOAPMessageImpl resMessage = (SOAPMessageImpl)factory.createMessage(null, inputStream);

      CommonMessageContext msgContext = MessageContextAssociation.peekMessageContext();
      msgContext.setSOAPMessage(resMessage);

      try
      {
         EndpointInvocation epInv = new EndpointInvocation(opMetaData);
         binding.unbindResponseMessage(opMetaData, resMessage, epInv, null);
         fail("SOAPFaultException expected");
      }
      catch (SOAPFaultException faultEx)
      {
         assertEquals("Sender", faultEx.getFaultCode().getLocalPart());
View Full Code Here

      SOAPMessageContextJAXRPC messageContext = new SOAPMessageContextJAXRPC();
      MessageContextAssociation.pushMessageContext(messageContext);
      messageContext.setOperationMetaData(opMetaData);

      CommonBindingProvider bindingProvider = new CommonBindingProvider(CommonSOAPBinding.SOAP11HTTP_BINDING, Type.JAXRPC);
      CommonBinding binding = (CommonBinding)bindingProvider.getCommonBinding();

      EndpointInvocation epInv = new EndpointInvocation(opMetaData);
      epInv.initInputParams(new Object[]{"Hello World!", "hi"});
     
      SOAPMessage reqMessage = (SOAPMessage)binding.bindRequestMessage(opMetaData, epInv, null);

      ByteArrayOutputStream stream = new ByteArrayOutputStream();

      reqMessage.saveChanges();
      reqMessage.writeTo(stream);

      ByteArrayInputStream in = new ByteArrayInputStream(stream.toByteArray());

      String type = reqMessage.getMimeHeaders().getHeader(MimeConstants.CONTENT_TYPE)[0];

      MimeHeaders headers = new MimeHeaders();
      headers.addHeader(MimeConstants.CONTENT_TYPE, type);
      SOAPMessageImpl msg2 = (SOAPMessageImpl)new MessageFactoryImpl().createMessage(headers, in);

      epInv = binding.unbindRequestMessage(opMetaData, msg2);

      assertEquals(epInv.getRequestParamValue(new QName("String_1")).toString(), "Hello World!");
      assertEquals(epInv.getRequestParamValue(new QName("foo")).toString(), "hi");

      epInv.setReturnValue("test");

      SOAPMessage responseMessage = (SOAPMessage)binding.bindResponseMessage(opMetaData, epInv);

      stream = new ByteArrayOutputStream();
      responseMessage.writeTo(stream);

      in = new ByteArrayInputStream(stream.toByteArray());

      type = responseMessage.getMimeHeaders().getHeader(MimeConstants.CONTENT_TYPE)[0];

      headers = new MimeHeaders();
      headers.addHeader(MimeConstants.CONTENT_TYPE, type);
      SOAPMessageImpl msg3 = (SOAPMessageImpl)new MessageFactoryImpl().createMessage(headers, in);

      binding.unbindResponseMessage(opMetaData, msg3, epInv, null);

      assertEquals("test", epInv.getReturnValue());
   }
View Full Code Here

         // In case we have an exception before the invoker is called
         // we create the fault message here.
         if (resMessage == null || resMessage.isFaultMessage() == false)
         {
            CommonBindingProvider bindingProvider = new CommonBindingProvider(sepMetaData);
            CommonBinding binding = bindingProvider.getCommonBinding();
            resMessage = binding.bindFaultMessage(ex);
         }

         if (resMessage != null)
            postProcessResponse(headerSource, resMessage);
View Full Code Here

      try
      {
         boolean oneway = false;
         EndpointInvocation sepInv = null;
         OperationMetaData opMetaData = null;
         CommonBinding binding = bindingProvider.getCommonBinding();
         binding.setHeaderSource(delegate);

         // call the request handler chain
         boolean handlersPass = callRequestHandlerChain(sepMetaData, handlerType[0]);

         // Unbind the request message
         if (handlersPass)
         {
            // Get the operation meta data from the SOAP message
            opMetaData = getDispatchDestination(sepMetaData, reqMessage);
            msgContext.setOperationMetaData(opMetaData);
            oneway = opMetaData.isOneWay();

            /*
             * From JAX-WS 10.2.1 - "7. If the node does not understand how to process
             * the message, then neither handlers nor the endpoint
             * are invoked and instead the binding generates a SOAP must
             * understand exception"
             *
             * Therefore, this must precede the ENDPOINT chain; however, The PRE
             * chain still must happen first since the message may be encrypted, in which
             * case the operation is still not known. Without knowing the operation, it
             * is not possible to determine what headers are understood by the endpoint.
             */
            if (binding instanceof CommonSOAPBinding)
               ((CommonSOAPBinding)binding).checkMustUnderstand(opMetaData);

            // Unbind the request message
            sepInv = binding.unbindRequestMessage(opMetaData, reqMessage);
         }

         handlersPass = handlersPass && callRequestHandlerChain(sepMetaData, handlerType[1]);
         handlersPass = handlersPass && callRequestHandlerChain(sepMetaData, handlerType[2]);

         if (handlersPass)
         {
            msgContext.put(CommonMessageContext.ALLOW_EXPAND_TO_DOM, Boolean.TRUE);
            try
            {
               // Check if protocol handlers modified the payload
               if (msgContext.isModified())
               {
                  log.debug("Handler modified payload, unbind message again");
                  reqMessage = msgContext.getMessageAbstraction();
                  sepInv = binding.unbindRequestMessage(opMetaData, reqMessage);
               }

               // Invoke an instance of the SEI implementation bean
               Invocation inv = setupInvocation(endpoint, sepInv, invContext);
               InvocationHandler invHandler = endpoint.getInvocationHandler();
              
               try
               {
                  invHandler.invoke(endpoint, inv);
               }
               catch (InvocationTargetException th)
               {
                  //Unwrap the throwable raised by the service endpoint implementation
                  Throwable targetEx = th.getTargetException();
                  throw (targetEx instanceof Exception ? (Exception)targetEx : new UndeclaredThrowableException(targetEx));
               }

               // Handler processing might have replaced the endpoint invocation
               sepInv = inv.getInvocationContext().getAttachment(EndpointInvocation.class);
            }
            finally
            {
               msgContext.remove(CommonMessageContext.ALLOW_EXPAND_TO_DOM);
            }

            // Reverse the message direction
            msgContext = processPivotInternal(msgContext, direction);

            // Set the required outbound context properties
            setOutboundContextProperties();

            if (binding instanceof CommonSOAPBinding)
               XOPContext.setMTOMEnabled(((CommonSOAPBinding)binding).isMTOMEnabled());

            // Bind the response message
            MessageAbstraction resMessage = binding.bindResponseMessage(opMetaData, sepInv);
            msgContext.setMessageAbstraction(resMessage);
         }
         else
         {
            // Reverse the message direction without calling the endpoint
            MessageAbstraction resMessage = msgContext.getMessageAbstraction();
            msgContext = processPivotInternal(msgContext, direction);
            msgContext.setMessageAbstraction(resMessage);
         }

         boolean isWsrmMessage = msgContext.get(RMConstant.RESPONSE_CONTEXT) != null;
         if ((oneway == false) || (isWsrmMessage)) // RM hack
         {
            // call the  response handler chain, removing the fault type entry will not call handleFault for that chain
            handlersPass = callResponseHandlerChain(sepMetaData, handlerType[2]);
            faultType[2] = null;
            handlersPass = handlersPass && callResponseHandlerChain(sepMetaData, handlerType[1]);
            faultType[1] = null;
            handlersPass = handlersPass && callResponseHandlerChain(sepMetaData, handlerType[0]);
            faultType[0] = null;
         }
      }
      catch (Exception ex)
      {
         // Reverse the message direction
         processPivotInternal(msgContext, direction);
        
         CommonBinding binding = bindingProvider.getCommonBinding();
         try
         {
            binding.bindFaultMessage(ex);

            // call the fault handler chain
            boolean handlersPass = true;
            if (faultType[2] != null)
               handlersPass = handlersPass && callFaultHandlerChain(sepMetaData, faultType[2], ex);
            if (faultType[1] != null)
               handlersPass = handlersPass && callFaultHandlerChain(sepMetaData, faultType[1], ex);
            if (faultType[0] != null)
               handlersPass = handlersPass && callFaultHandlerChain(sepMetaData, faultType[0], ex);
         }
         catch (RuntimeException subEx)
         {
            log.warn("Exception while processing handleFault: ", ex);
            binding.bindFaultMessage(subEx);
            ex = subEx;
         }
         throw ex;
      }
      finally
View Full Code Here

      try
      {
         boolean oneway = false;
         EndpointInvocation sepInv = null;
         OperationMetaData opMetaData = null;
         CommonBinding binding = bindingProvider.getCommonBinding();
         binding.setHeaderSource(delegate);

         if (binding instanceof CommonSOAPBinding)
            XOPContext.setMTOMEnabled(((CommonSOAPBinding)binding).isMTOMEnabled());
        
         // call the request handler chain
         boolean handlersPass = callRequestHandlerChain(sepMetaData, handlerType[0]);

         // Unbind the request message
         if (handlersPass)
         {
            // Get the operation meta data from the SOAP message
            opMetaData = getDispatchDestination(sepMetaData, reqMessage);
            msgContext.setOperationMetaData(opMetaData);
            oneway = opMetaData.isOneWay();

            /*
             * From JAX-WS 10.2.1 - "7. If the node does not understand how to process
             * the message, then neither handlers nor the endpoint
             * are invoked and instead the binding generates a SOAP must
             * understand exception"
             *
             * Therefore, this must precede the ENDPOINT chain; however, The PRE
             * chain still must happen first since the message may be encrypted, in which
             * case the operation is still not known. Without knowing the operation, it
             * is not possible to determine what headers are understood by the endpoint.
             */
            if (binding instanceof CommonSOAPBinding)
               ((CommonSOAPBinding)binding).checkMustUnderstand(opMetaData);

            // Unbind the request message
            sepInv = binding.unbindRequestMessage(opMetaData, reqMessage);
         }

         handlersPass = handlersPass && callRequestHandlerChain(sepMetaData, handlerType[1]);
         handlersPass = handlersPass && callRequestHandlerChain(sepMetaData, handlerType[2]);

         if (handlersPass)
         {
            msgContext.put(CommonMessageContext.ALLOW_EXPAND_TO_DOM, Boolean.TRUE);
            try
            {
               // Check if protocol handlers modified the payload
               if (msgContext.isModified())
               {
                  log.debug("Handler modified payload, unbind message again");
                  reqMessage = msgContext.getMessageAbstraction();
                  sepInv = binding.unbindRequestMessage(opMetaData, reqMessage);
               }
               //JBWS-2969:check if the RPC/Lit input paramter is null
               if (opMetaData.getEndpointMetaData().getType() != EndpointMetaData.Type.JAXRPC
                     && opMetaData.isRPCLiteral() && sepInv.getRequestParamNames() != null)
               { 
                 
                  for (QName qname : sepInv.getRequestParamNames())
                  {
                     ParameterMetaData paramMetaData = opMetaData.getParameter(qname);
                     if ((paramMetaData.getMode().equals(ParameterMode.IN) || paramMetaData.getMode().equals(ParameterMode.INOUT)) && sepInv.getRequestParamValue(qname) == null)
                     {
                        throw new WebServiceException("The RPC/Literal Operation [" + opMetaData.getQName()
                              + "] parameters can not be null");
                     }
                  }
               }
              
               // Invoke an instance of the SEI implementation bean
               Invocation inv = setupInvocation(endpoint, sepInv, invContext);
               InvocationHandler invHandler = endpoint.getInvocationHandler();
              
               try
               {
                  invHandler.invoke(endpoint, inv);
                 
               }
               catch (InvocationTargetException th)
               {
                  //Unwrap the throwable raised by the service endpoint implementation
                  Throwable targetEx = th.getTargetException();
                  throw (targetEx instanceof Exception ? (Exception)targetEx : new UndeclaredThrowableException(targetEx));
               }
               finally
               {
                  // JBWS-2486
                  if (endpoint.getAttachment(Object.class) == null)
                  {
                     endpoint.addAttachment(Object.class, inv.getInvocationContext().getTargetBean());
                  }
               }

               // Handler processing might have replaced the endpoint invocation
               sepInv = inv.getInvocationContext().getAttachment(EndpointInvocation.class);
            }
            finally
            {
               msgContext.remove(CommonMessageContext.ALLOW_EXPAND_TO_DOM);
            }

            // Reverse the message direction
            msgContext = processPivotInternal(msgContext, direction);

            // Set the required outbound context properties
            setOutboundContextProperties();
              
            // Bind the response message
            MessageAbstraction resMessage = binding.bindResponseMessage(opMetaData, sepInv);
            msgContext.setMessageAbstraction(resMessage);
         }
         else
         {
            // Reverse the message direction without calling the endpoint
            MessageAbstraction resMessage = msgContext.getMessageAbstraction();
            msgContext = processPivotInternal(msgContext, direction);
            msgContext.setMessageAbstraction(resMessage);
         }

         if (oneway == false)
         {
            // call the  response handler chain, removing the fault type entry will not call handleFault for that chain
            handlersPass = callResponseHandlerChain(sepMetaData, handlerType[2]);
            faultType[2] = null;
            handlersPass = handlersPass && callResponseHandlerChain(sepMetaData, handlerType[1]);
            faultType[1] = null;
            handlersPass = handlersPass && callResponseHandlerChain(sepMetaData, handlerType[0]);
            faultType[0] = null;
         }
      }
      catch (Exception ex)
      {
         // Reverse the message direction
         processPivotInternal(msgContext, direction);
        
         CommonBinding binding = bindingProvider.getCommonBinding();
         try
         {
            MessageContextAssociation.peekMessageContext().put("Exception", ex);
            binding.bindFaultMessage(ex);

            // call the fault handler chain
            boolean handlersPass = true;
            if (faultType[2] != null)
               handlersPass = handlersPass && callFaultHandlerChain(sepMetaData, faultType[2], ex);
            if (faultType[1] != null)
               handlersPass = handlersPass && callFaultHandlerChain(sepMetaData, faultType[1], ex);
            if (faultType[0] != null)
               handlersPass = handlersPass && callFaultHandlerChain(sepMetaData, faultType[0], ex);
         }
         catch (RuntimeException subEx)
         {
            log.warn("Exception while processing handleFault: ", ex);
            binding.bindFaultMessage(subEx);
            ex = subEx;
         }
         throw ex;
      }
      finally
View Full Code Here

         SOAPMessageContextJAXRPC messageContext = new SOAPMessageContextJAXRPC();
         MessageContextAssociation.pushMessageContext(messageContext);
         messageContext.setOperationMetaData(opMetaData);
  
         CommonBindingProvider bindingProvider = new CommonBindingProvider(CommonSOAPBinding.SOAP11HTTP_BINDING, Type.JAXRPC);
         CommonBinding binding = (CommonBinding)bindingProvider.getCommonBinding();
  
         EndpointInvocation epInv = new EndpointInvocation(opMetaData);
         epInv.initInputParams(new Object[]{"Hello World!", "hi"});
        
         SOAPMessage reqMessage = (SOAPMessage)binding.bindRequestMessage(opMetaData, epInv, null);
  
         ByteArrayOutputStream stream = new ByteArrayOutputStream();
  
         reqMessage.saveChanges();
         reqMessage.writeTo(stream);
  
         ByteArrayInputStream in = new ByteArrayInputStream(stream.toByteArray());
  
         String type = reqMessage.getMimeHeaders().getHeader(MimeConstants.CONTENT_TYPE)[0];
  
         MimeHeaders headers = new MimeHeaders();
         headers.addHeader(MimeConstants.CONTENT_TYPE, type);
         SOAPMessageImpl msg2 = (SOAPMessageImpl)new MessageFactoryImpl().createMessage(headers, in);
  
         epInv = binding.unbindRequestMessage(opMetaData, msg2);
  
         assertEquals(epInv.getRequestParamValue(new QName("String_1")).toString(), "Hello World!");
         assertEquals(epInv.getRequestParamValue(new QName("foo")).toString(), "hi");
  
         epInv.setReturnValue("test");
  
         SOAPMessage responseMessage = (SOAPMessage)binding.bindResponseMessage(opMetaData, epInv);
  
         stream = new ByteArrayOutputStream();
         responseMessage.writeTo(stream);
  
         in = new ByteArrayInputStream(stream.toByteArray());
  
         type = responseMessage.getMimeHeaders().getHeader(MimeConstants.CONTENT_TYPE)[0];
  
         headers = new MimeHeaders();
         headers.addHeader(MimeConstants.CONTENT_TYPE, type);
         SOAPMessageImpl msg3 = (SOAPMessageImpl)new MessageFactoryImpl().createMessage(headers, in);
  
         binding.unbindResponseMessage(opMetaData, msg3, epInv, null);
  
         assertEquals("test", epInv.getReturnValue());
      }
      finally
      {
View Full Code Here

   /** Test binding of the request message
    */
   public void testBindRequestMessage() throws Exception
   {
      CommonBindingProvider bindingProvider = new CommonBindingProvider(CommonSOAPBinding.SOAP12HTTP_BINDING, Type.JAXRPC);
      CommonBinding binding = (CommonBinding)bindingProvider.getCommonBinding();

      EndpointInvocation epInv = new EndpointInvocation(opMetaData);
      epInv.initInputParams(new Object[]{"Hello World!"});

      SOAPMessage reqMessage = (SOAPMessage)binding.bindRequestMessage(opMetaData, epInv, null);

      ByteArrayOutputStream outs = new ByteArrayOutputStream();
      reqMessage.writeTo(outs);

      String retString = new String(outs.toByteArray());
View Full Code Here

   /** Test binding of the request message with bound header
    */
   public void testBindRequestMessageWithBoundHeader() throws Exception
   {
      CommonBindingProvider bindingProvider = new CommonBindingProvider(CommonSOAPBinding.SOAP12HTTP_BINDING, Type.JAXRPC);
      CommonBinding binding = (CommonBinding)bindingProvider.getCommonBinding();

      // Add bound header
      QName xmlName = new QName("http://somens", "String_2");
      ParameterMetaData paramMetaData = new ParameterMetaData(opMetaData, xmlName, Constants.TYPE_LITERAL_STRING, "java.lang.String");
      opMetaData.addParameter(paramMetaData);
      paramMetaData.setInHeader(true);
      paramMetaData.setIndex(1);

      EndpointInvocation epInv = new EndpointInvocation(opMetaData);
      epInv.initInputParams(new Object[]{"Hello World!", "IN header message"});

      SOAPMessage reqMessage = (SOAPMessage)binding.bindRequestMessage(opMetaData, epInv, null);

      ByteArrayOutputStream outs = new ByteArrayOutputStream();
      reqMessage.writeTo(outs);

      String retString = new String(outs.toByteArray());
View Full Code Here

TOP

Related Classes of org.jboss.ws.core.CommonBinding

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.