apache-axisaxiommsf4jwso2-identity-server

MSF4J micoservice trying to communicate with a SOAP service


I am trying to develop a microservice using MSF4J. The service gets the header details of the input request and try to communicate with a SOAP service for further operations. This logic when written as a normal application works fine but when converted to a microservice it throws the following the exception

[org.apache.axis2.context.AbstractContext] : OnDemandLogger initialized for class org.apache.axis2.context.AbstractContext is:org.apache.commons.logging.internal.JclLogger@6b972f62
[org.apache.axis2.util.Loader] : Trying to find [org/apache/axis2/deployment/axis2_default.xml] using sun.misc.Launcher$AppClassLoader@73d16e93 class loader.
2016-07-21 17:45:48 ERROR ChannelChunkResponder:103 - Resource method threw an exception
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.wso2.msf4j.internal.router.HttpMethodInfo.invoke(HttpMethodInfo.java:95)
    at org.wso2.msf4j.internal.router.HttpDispatcher.channelRead0(HttpDispatcher.java:53)
    at org.wso2.msf4j.internal.router.HttpDispatcher.channelRead0(HttpDispatcher.java:31)
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
    at org.wso2.msf4j.internal.router.RequestRouter.channelRead0(RequestRouter.java:83)
    at org.wso2.msf4j.internal.router.RequestRouter.channelRead0(RequestRouter.java:44)
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
    at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:244)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:110)
    at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoSuchMethodError: org.apache.axiom.om.OMAbstractFactory.getMetaFactory()Lorg/apache/axiom/om/OMMetaFactory;
    at org.apache.axiom.om.OMXMLBuilderFactory.createOMBuilder(OMXMLBuilderFactory.java:87)
    at org.apache.axiom.om.OMXMLBuilderFactory.createOMBuilder(OMXMLBuilderFactory.java:73)
    at org.apache.axis2.util.XMLUtils.toOM(XMLUtils.java:590)
    at org.apache.axis2.util.XMLUtils.toOM(XMLUtils.java:575)
    at org.apache.axis2.deployment.DescriptionBuilder.buildOM(DescriptionBuilder.java:97)
    at org.apache.axis2.deployment.AxisConfigBuilder.populateConfig(AxisConfigBuilder.java:91)
    at org.apache.axis2.deployment.DeploymentEngine.populateAxisConfiguration(DeploymentEngine.java:887)
    at org.apache.axis2.deployment.FileSystemConfigurator.getAxisConfiguration(FileSystemConfigurator.java:116)
    at org.apache.axis2.context.ConfigurationContextFactory.createConfigurationContext(ConfigurationContextFactory.java:64)
    at org.apache.axis2.context.ConfigurationContextFactory.createConfigurationContextFromFileSystem(ConfigurationContextFactory.java:210)
    at org.apache.axis2.client.ServiceClient.configureServiceClient(ServiceClient.java:150)
    at org.apache.axis2.client.ServiceClient.<init>(ServiceClient.java:143)
    at org.wso2.carbon.identity.oauth2.stub.OAuth2TokenValidationServiceStub.<init>(OAuth2TokenValidationServiceStub.java:103)
    at org.wso2.carbon.identity.oauth2.stub.OAuth2TokenValidationServiceStub.<init>(OAuth2TokenValidationServiceStub.java:89)
    at com.wipro.oauth.manager.IDManagementClient.validateToken(IDManagementClient.java:220)
    at com.wipro.oauth.manager.IdentityServerRest.getOAuthToken(IdentityServerRest.java:126)
    ... 37 more

The SOAP service, the microservice tries to communicate with is the "OAuth2TokenValidationService" of the WSO2 Identity Server.

The method the incorporates the call to the SAOP service is as follows

 public OAuth2TokenValidationResponseDTO validateToken(
                String accessTokenIdentifier)
                throws RemoteException, LoginAuthenticationExceptionException {


            OAuth2TokenValidationServiceStub stub = new OAuth2TokenValidationServiceStub(
                    null, server
                            + "/services/OAuth2TokenValidationService");

            ServiceClient e3 = stub._getServiceClient();
            Options option3 = e3.getOptions();
            HttpTransportProperties.Authenticator auth1 = new HttpTransportProperties.Authenticator();
            auth1.setUsername(utUsername);
            auth1.setPassword(utPassword);
            auth1.setPreemptiveAuthentication(true);
            option3.setManageSession(true);
            /*option2.setProperty(Constants.Configuration.MESSAGE_TYPE,HTTPConstants.MEDIA_TYPE_APPLICATION_ECHO_XML);
            option2.setProperty(Constants.Configuration.DISABLE_SOAP_ACTION,Boolean.TRUE);*/
            option3.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth1);
            /*option2.setProperty("Cookie", authCookie);*/
            e3.setOptions(option3);

            OAuth2TokenValidationRequestDTO oauthReq = new OAuth2TokenValidationRequestDTO();

            OAuth2TokenValidationRequestDTO_OAuth2AccessToken accessToken = new OAuth2TokenValidationRequestDTO_OAuth2AccessToken();
            accessToken.setTokenType("Bearer");
            accessToken.setIdentifier(accessTokenIdentifier);
            oauthReq.setAccessToken(accessToken);
            oauthReq.setRequiredClaimURIs(null);

            OAuth2TokenValidationResponseDTO resp = stub.validate(oauthReq);


return resp;
    }

The following dependency has been added while converting the normal application to microservice.

<dependency>
            <groupId>org.wso2.carbon</groupId>
            <artifactId>org.wso2.carbon.transport</artifactId>
            <version>5.0.0-alpha</version>
             <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

The dependencies related to the AXIOM are

    <dependency>
                    <groupId>org.apache.ws.commons.axiom.wso2</groupId>
                    <artifactId>axiom</artifactId>
                    <version>1.2.11.wso2v4</version>
                </dependency> 
    <dependency>
        <groupId>org.apache.woden</groupId>
        <artifactId>woden-impl-dom</artifactId>
        <version>1.0M8</version>
</dependency>

Any help for resolving this issue will be greatly appreciated.


Solution

  • Can you please try with the latest MSF4J 2.0 release?

    The root cause of this issue is: Caused by: java.lang.NoSuchMethodError: org.apache.axiom.om.OMAbstractFactory.getMetaFactory()Lorg/apache/axiom/om/OMMetaFactory;

    What this means is, in the dependency tree, most probably another version of Axiom is getting pulled in as a transitive dependency.

    Run; mvn dependency:tree and find out what other versions of Axiom are getting pulled in and exclude those version from the Maven build.