0 Replies Latest reply on Jan 11, 2011 1:25 AM by Himaja Thovi

    Errors in implementing WS Security

    Himaja Thovi Newbie

      Hi All,

      I created a Web Application as WS need to encrypt and sign SOAP message using WS Security in jboss 5.1.0GA.I followed steps from Jboss In Action.

      My Web Service and jars i'm using are jbossws-core.jar, servlet-api.jar.

       

      import javax.jws.WebService;
      import javax.jws.soap.SOAPBinding;
      import org.jboss.ws.annotation.EndpointConfig;
      
      @WebService()
      @SOAPBinding(style=SOAPBinding.Style.RPC)
      @EndpointConfig(configName="Standard WSSecurity Endpoint")public class NewWebService {
         public String getMessage(){
               return "hello";
         }
      }
      

       

      My client is standalone class as and jars used are mail.jar, policy.jar, concurrent.jar, javassist.jar, jboss-common.jar, jaxb-impl.jar, jboss-remoting.jar, jboss-xml-binding.jar, jbossws-client.jar, log4j.jar, wsdl4j.jar, jbossws-spi.jar

       

      import org.jboss.ws.annotation.EndpointConfig;
      @EndpointConfig(configName="Standard WSSecurity Client")
      public class Main {
        public static void main(String[] args) {     try { // Call Web Service Operation
                  com.ws.NewWebServiceService service = new com.ws.NewWebServiceService();
                  com.ws.NewWebService port = service.getNewWebServicePort();
                  java.lang.String result = port.getMessage();
                  System.out.println("Result = "+result);
              } catch (Exception ex) {
                 ex.printStackTrace();
              }
          }
      }
      

       

      My config files are as

      At client

      standard-jaxws-client-config.xml

      <?xml version="1.0" encoding="UTF-8"?> 
      <jaxws-config xmlns="urn:jboss:jaxws-config:2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:javaee="http://java.sun.com/xml/ns/javaee"
        xsi:schemaLocation="urn:jboss:jaxws-config:2.0 jaxws-config_2_0.xsd">
      <client-config>
          <config-name>Standard WSSecurity Client</config-name>
          <post-handler-chains>
            <javaee:handler-chain>
              <javaee:protocol-bindings>##SOAP11_HTTP ##SOAP11_HTTP_MTOM</javaee:protocol-bindings>
              <javaee:handler>
                <javaee:handler-name>WSSecurityHandlerOutbound</javaee:handler-name>
                <javaee:handler-class>org.jboss.ws.extensions.security.jaxws.WSSecurityHandlerClient</javaee:handler-class>
              </javaee:handler>
            </javaee:handler-chain>
          </post-handler-chains>
        </client-config>
      </jaxws-config>
      

       

      Another file jboss-wsse-client.xml

       

      <?xml version="1.0" encoding="UTF-8"?>
      <jboss-ws-security
       xmlns="http://www.jboss.com/ws-security/config"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.jboss.com/ws-security/config
       http://www.jboss.com/ws-security/schema/jboss-ws-security_1_0.xsd">
           <key-store-file>META-INF/wsseClient.keystore</key-store-file>
           <key-store-type>jks</key-store-type>
           <key-store-password>client</key-store-password>
           <trust-store-file>META-INF/wsseClient.truststore</trust-store-file>
           <trust-store-type>jks</trust-store-type>
           <trust-store-password>client</trust-store-password>
           <key-passwords>
             <key-password alias="client" password="client" />
           </key-passwords>
           <config>
              <encrypt type="x509v3" alias="wsseServer"/>
           <requires>                                            
           <encryption/> 
         </requires>          
        </config>
      </jboss-ws-security>
      

       

      At server we have file

      jboss-wsse-server.xml

       

      <jboss-ws-security
       xmlns="http://www.jboss.com/ws-security/config"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.jboss.com/ws-security/config
      http://www.jboss.com/ws-security/schema/jboss-ws-security_1_0.xsd">
       <key-store-file>WEB-INF/wsse.keystore</key-store-file>
       <key-store-type>jks</key-store-type>
       <key-store-password>wsseServer</key-store-password>
       <trust-store-file>WEB-INF/wsse.truststore</trust-store-file>
       <trust-store-type>jks</trust-store-type>
       <trust-store-password>wsseServer</trust-store-password>
       <key-passwords>
         <key-password alias="wsseServer" password="wsseServer" />
       </key-passwords>
       <config>
         <encrypt type="x509v3" alias="wsseClient"/>
         <requires>
          <encryption />
         </requires>
       </config>
      </jboss-ws-security>
      

       

      At client side the output in log is like

       

      DEBUG [main] (JAXWSClientMetaDataBuilder.java:77) - START buildMetaData: [service={http://ws.com/}NewWebServiceService]DEBUG [main] (WSDLDefinitionsFactory.java:102) - parse: http://127.0.0.1:9898/TrialWSApplication/NewWebService?wsdl
      DEBUG [main] (JAXWSClientMetaDataBuilder.java:102) - END buildMetaData: 
      UnifiedMetaData: 
       implementation: jbossws-3.0.1-native-2.0.4.GA (build=200803312044)
       deploymentName: null
       securityDomain: null
      
      ServiceMetaData:
       qname={http://ws.com/}NewWebServiceService
       refName=null
       wsdName=null
       wsdlFile=null
       wsdlLocation=http://127.0.0.1:9898/TrialWSApplication/NewWebService?wsdl
       jaxrpcMapping=null
       publishLocation=null
       securityConfig=null
       properties=null
      
      TypesMetaData: 
      
      ClientEndpointMetaData:
       type=JAXWS
       qname={http://ws.com/}NewWebServicePort
       address=http://127.0.0.1:9898/TrialWSApplication/NewWebService
       binding=http://schemas.xmlsoap.org/wsdl/soap/http
       seiName=null
       configFile=META-INF/standard-jaxws-client-config.xml
       configName=Standard Client
       authMethod=null
       properties={}
      
      OperationMetaData:
       qname={http://ws.com/}getMessage
       javaName={http://ws.com/}getMessage
       style=rpc/literal
       oneWay=false
       soapAction=
      DEBUG [main] (JAXWSClientMetaDataBuilder.java:276) - START: rebuildMetaData
      DEBUG [main] (EndpointMetaData.java:321) - setParameterStyle: null
      DEBUG [main] (JAXWSMetaDataBuilder.java:134) - processSOAPBinding on: com.ws.NewWebService
      DEBUG [main] (EndpointMetaData.java:321) - setParameterStyle: WRAPPED
      DEBUG [main] (EndpointMetaData.java:812) - Create new config [name=Standard Client,file=META-INF/standard-jaxws-client-config.xml]
      DEBUG [main] (JBossWSConfigFactory.java:125) - getConfig: [name=Standard Client,url=META-INF/standard-jaxws-client-config.xml]
      DEBUG [main] (JBossWSConfigFactory.java:71) - parse: jar:file:/home/himaja/project/jars/jbossws-client.jar!/META-INF/standard-jaxws-client-config.xml
      DEBUG [main] (SaxJBossXBParser.java:241) - Created parser: org.apache.xerces.jaxp.SAXParserImpl@14e8cee, isNamespaceAware: true, isValidating: true, isXIncludeAware: true
      DEBUG [main] (SaxJBossXBParser.java:157) - http://xml.org/sax/features/validation set to: true
      DEBUG [main] (SaxJBossXBParser.java:157) - http://xml.org/sax/features/namespaces set to: true
      DEBUG [main] (SaxJBossXBParser.java:157) - http://apache.org/xml/features/validation/dynamic set to: true
      DEBUG [main] (SaxJBossXBParser.java:157) - http://xml.org/sax/features/validation set to: true
      DEBUG [main] (SaxJBossXBParser.java:157) - http://apache.org/xml/features/validation/schema set to: true
      DEBUG [main] (SaxJBossXBParser.java:241) - Created parser: org.apache.xerces.jaxp.SAXParserImpl@14e8cee, isNamespaceAware: true, isValidating: true, isXIncludeAware: true
      DEBUG [main] (EndpointMetaData.java:867) - Configure EndpointMetaData
      DEBUG [main] (EndpointMetaData.java:879) - Added 0 PRE handlers
      DEBUG [main] (EndpointMetaData.java:880) - Added 0 ENDPOINT handlers
      DEBUG [main] (EndpointMetaData.java:881) - Added 0 POST handlers
      DEBUG [main] (JAXWSMetaDataBuilder.java:938) - JAXBContext [types=[class java.lang.String],tns=http://ws.com/]
      DEBUG [main] (OperationMetaData.java:208) - Found best matching java method: public abstract java.lang.String com.ws.NewWebService.getMessage()
      DEBUG [main] (JAXWSClientMetaDataBuilder.java:322) - END: rebuildMetaData
      
      ServiceMetaData:
       qname={http://ws.com/}NewWebServiceService
       refName=null
       wsdName=null
       wsdlFile=null
       wsdlLocation=http://127.0.0.1:9898/TrialWSApplication/NewWebService?wsdl
       jaxrpcMapping=null
       publishLocation=null
       securityConfig=null
       properties=null
      
      TypesMetaData: 
        [complexType={http://www.w3.org/2001/XMLSchema}string,javaType=java.lang.String]
      
      ClientEndpointMetaData:
       type=JAXWS
       qname={http://ws.com/}NewWebServicePort
       address=http://127.0.0.1:9898/TrialWSApplication/NewWebService
       binding=http://schemas.xmlsoap.org/wsdl/soap/http
       seiName=com.ws.NewWebService
       configFile=META-INF/standard-jaxws-client-config.xml
       configName=Standard Client
       authMethod=null
       properties={}
      
      OperationMetaData:
       qname={http://ws.com/}getMessage
       javaName=getMessage
       style=rpc/literal
       oneWay=false
       soapAction=
      ReturnMetaData:
       xmlName=return
       partName=return
       xmlType={http://www.w3.org/2001/XMLSchema}string
       javaType=java.lang.String
       mode=OUT
       inHeader=false
       index=-1
      DEBUG [main] (EndpointMetaData.java:732) - Configure SOAPBinding
      DEBUG [main] (HandlerResolverImpl.java:125) - initHandlerChain: PRE
      DEBUG [main] (HandlerResolverImpl.java:125) - initHandlerChain: ENDPOINT
      DEBUG [main] (HandlerResolverImpl.java:125) - initHandlerChain: POST
      DEBUG [main] (HandlerResolverImpl.java:99) - getHandlerChain: [type=PRE,info=[service={http://ws.com/}NewWebServiceService,port={http://ws.com/}NewWebServicePort,binding=http://schemas.xmlsoap.org/wsdl/soap/http]]
      DEBUG [main] (HandlerResolverImpl.java:99) - getHandlerChain: [type=POST,info=[service={http://ws.com/}NewWebServiceService,port={http://ws.com/}NewWebServicePort,binding=http://schemas.xmlsoap.org/wsdl/soap/http]]
      DEBUG [main] (HandlerResolverImpl.java:99) - getHandlerChain: [type=ENDPOINT,info=[service={http://ws.com/}NewWebServiceService,port={http://ws.com/}NewWebServicePort,binding=http://schemas.xmlsoap.org/wsdl/soap/http]]
      DEBUG [main] (BindingImpl.java:94) - setHandlerChain: []
      DEBUG [main] (ServiceDelegateImpl.java:434) - No port configuration for: {http://ws.com/}NewWebServicePort
      DEBUG [main] (MessageContextAssociation.java:46) - pushMessageContext: org.jboss.ws.core.jaxws.handler.SOAPMessageContextJAXWS@f892a4 (Thread main)
      DEBUG [main] (CommonSOAPBinding.java:144) - bindRequestMessage: {http://ws.com/}getMessage
      DEBUG [main] (CommonSOAPBinding.java:189) - Create RPC body element: {http://ws.com/}getMessage
      DEBUG [main] (HandlerChainExecutor.java:84) - Create a handler executor: []
      DEBUG [main] (HandlerChainExecutor.java:84) - Create a handler executor: []
      DEBUG [main] (HandlerChainExecutor.java:84) - Create a handler executor: []
      DEBUG [main] (HTTPRemotingConnection.java:176) - Get locator for: [addr=http://127.0.0.1:9898/TrialWSApplication/NewWebService,props={javax.xml.ws.service.endpoint.address=http://127.0.0.1:9898/TrialWSApplication/NewWebService}]
      DEBUG [main] (MicroRemoteClientInvoker.java:298) - org.jboss.remoting.transport.http.HTTPClientInvoker@35bb0f connecting
      DEBUG [main] (MicroRemoteClientInvoker.java:312) - org.jboss.remoting.transport.http.HTTPClientInvoker@35bb0f connected
      DEBUG [main] (HTTPRemotingConnection.java:220) - Remoting metadata: {NoThrowOnError=true, HEADER={SOAPAction="", Content-Type=text/xml; charset=UTF-8}}
      DEBUG [main] (HTTPClientInvoker.java:313) - Setting request header with SOAPAction : ""
      DEBUG [main] (HTTPClientInvoker.java:313) - Setting request header with Content-Type : text/xml; charset=UTF-8
      DEBUG [main] (SOAPMessageUnMarshallerHTTP.java:123) - getMimeHeaders from: {Date=[Tue, 11 Jan 2011 05:24:08 GMT], NoThrowOnError=true, Content-Length=[0], HEADER={SOAPAction="", Content-Type=text/xml; charset=UTF-8}, ResponseCode=200, ResponseCodeMessage=OK, ResponseHeaders={null=[HTTP/1.1 200 OK], Date=[Tue, 11 Jan 2011 05:24:08 GMT], Content-Length=[0], Server=[Apache-Coyote/1.1], X-Powered-By=[Servlet 2.5; JBoss-5.0/JBossWeb-2.1]}, X-Powered-By=[Servlet 2.5; JBoss-5.0/JBossWeb-2.1], Server=[Apache-Coyote/1.1]}
      DEBUG [main] (MessageFactoryImpl.java:215) - createMessage: [contentType=text/xml]
      [Fatal Error] :-1:-1: Premature end of file.
      DEBUG [main] (InvokerRegistry.java:631) - removed org.jboss.remoting.transport.http.HTTPClientInvoker@35bb0f from registry
      DEBUG [main] (MessageContextJAXWS.java:105) - Begin response processing
      DEBUG [main] (MessageContextAssociation.java:75) - popMessageContext: org.jboss.ws.core.jaxws.handler.SOAPMessageContextJAXWS@f892a4 (Thread main)
      DEBUG [main] (MessageContextAssociation.java:46) - pushMessageContext: org.jboss.ws.core.jaxws.handler.SOAPMessageContextJAXWS@1342a67 (Thread main)
      DEBUG [main] (CommonSOAPBinding.java:542) - unbindResponseMessage: {http://ws.com/}getMessage
      DEBUG [main] (CommonClient.java:391) - Handler modified body payload, unbind message again
      DEBUG [main] (CommonSOAPBinding.java:542) - unbindResponseMessage: {http://ws.com/}getMessage
      DEBUG [main] (EndpointInvocation.java:190) - getReturnValue
      DEBUG [main] (EndpointInvocation.java:268) - transformPayloadValue: null -> null
      DEBUG [main] (HandlerChainExecutor.java:96) - close
      DEBUG [main] (HandlerChainExecutor.java:96) - close
      DEBUG [main] (HandlerChainExecutor.java:96) - close
      DEBUG [main] (MessageContextAssociation.java:75) - popMessageContext: org.jboss.ws.core.jaxws.handler.SOAPMessageContextJAXWS@1342a67 (Thread main)
      Result = null
      BUILD SUCCESSFUL (total time: 2 seconds)
      
      

       

      configName= Standard Client (doubting at this point as it is not using proper configuration as it should use Standard WSSecurity Client)

       

       

      At server side the error are

       

       ERROR [SOAPFaultHelperJAXWS] SOAP request exception
      java.lang.ClassCastException: org.jboss.ws.core.soap.EnvelopeBuilderDOM
          at org.jboss.ws.core.soap.MessageFactoryImpl.createMessage(MessageFactoryImpl.java:289)
      
      ERROR [RequestHandlerImpl] Error processing web service request
      org.jboss.ws.WSException: java.lang.ClassCastException: org.jboss.ws.core.soap.MessageFactoryImpl
          at org.jboss.ws.WSException.rethrow(WSException.java:68)
      
       ERROR [[NewWebService]] Servlet.service() for servlet NewWebService threw exception
      java.lang.ClassCastException: org.jboss.ws.core.soap.MessageFactoryImpl
          at org.jboss.ws.core.jaxws.SOAPFaultHelperJAXWS.createSOAPMessage(SOAPFaultHelperJAXWS.java:288)
      

       

      Waiting for the reply.

       

      Thanks in advance.

      Regards,