Wednesday 24 August 2016

JAS

JAS - Java Authentication Server

This time i been assigned with such  a wonderful task.. JASzzzzzzz
Initially, i given the requirement of authenticating username & password in the server and returning user functionalities, and according to that show the menu items..

With that i start the work.. 

SERVER Side 

i created a new dynamic project in eclipse.. Dynamic web module 2.5.. caz, AXIS 2 support only for this.. 
convert it a maven project..
-- include the AXIS 2 dependencies.. // not required

set the Axis 2 runtime location in  windows - preference - webservices - Axis 2.x Preference - "D:\Siva\AXIS2 "
Saying about AXIS 2, 
   - it is used to convert my class file to WSDL file
   - expose my class as a webservice.
yes most of my work done by itself.. thanks for all AXIS 2

so, i was saying.. create a interface and implement it in a class  in your package and do your business logic

Right click interface file which need to be expose - web services - create web service-  set the server environment and set the webservice environment as AXIS 2 - click finish.

Thats it.. you application is now deployed.. You have created soap server application.
to check it is working fine.. check your WSDL file is generating in the server.

Save the WSDL file. From this WSDL file we gonna generate the java file

Client Side

create a dynamic web project - convert it a maven project - in pom.xml add cxf dependency 

Saying abt CXF, it helps us to generate the java file from WSDL file we have.

<properties>
<cxf.version>3.1.0</cxf.version>
</properties>

<dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-frontend-jaxws</artifactId>
            <version>${cxf.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http</artifactId>
            <version>${cxf.version}</version>
        </dependency>

<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>

</dependency>

add the plugin

<!-- Generate Java classes from WSDL during build -->
            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>${cxf.version}</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <configuration>
                            <!-- which source folder the generated classes should be placed in a package -->
<!--                             <sourceRoot>${project.basedir}/src/main/java</sourceRoot> -->
                      <sourceRoot>${project.build.directory}/generated-sources/cxf</sourceRoot>
                            <wsdlOptions>
                                <wsdlOption>
                                    <!-- put the wsdl file in this location -->
                                    <wsdl>${project.basedir}/src/main/resources/wsdl/Login.wsdl</wsdl>
                                    <extraargs>
                                        <extraarg>-client</extraarg>
                                    </extraargs>
                                </wsdlOption>
                            </wsdlOptions>
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>

            </plugin>

 this ll generate the java file in the target folder.

from the generated end points, use that code to connect to the server. 

change the wsdl location,
 wsdlLocation = "http://localhost:9001/demo-server/services/DemoClass?wsdl",

Thats it. 

thats what i thought..

But.. 

It ll not finish that easy.. after reviewing i understand, the client requirement, they need the older version of axis.. ie.. AXIS 1.4 

AXIS 1.4 

Server side

hooooo.. got chance to do R&D on that..

same way i started.. of implementing it with AXIS 1.4

Road blocks:

  - In the server side, i cannot expose the webservice as before. it give me..

IWAB0398E Error in generating WSDL from Java:  java.lang.ClassCastException: org.apache.axis.encoding.ser.BeanSerializer cannot be cast to org.apache.axis.encoding.Serializer

  - Without the server running, i cannot generate the java files in the client side. caz, there is no end point.. 

so im struck here.. 

then got an idea of do everything manually, caz, at the starting of the internet, they did like that.. 
there was not ANT, Maven or Gradle.. 

so started.. with the reference 

http://www.digizol.com/2008/07/web-service-axis-tutorial-client-server.html

1. i compiled all the java files in commad promet | terminal.. 

javac -d classes test\com\admin\service\*.java 

2. generate wsdl file from the compiled classes

java org.apache.axis.wsdl.Java2WSDL  -o wsdl/Login.wsdl -n http://service.admin.com.test/  -l http://localhost:8080/admin/services/Login?wsdl=Login.wsdl test.com.admin.service.Login

3. Then created the deployment war file manually and deployed it in the server.

4. Finally linq the WSDL to the server

java org.apache.axis.client.AdminClient src\test\com\admin\service\generated\deploy.wsdd

now got struck here.. it is showing connection timeout.. means, it cannot find that deployed environment.. finding way to resolve it..

thanks to this site..
https://cuppajavamattiz.wordpress.com/2013/10/04/creating-a-simple-web-service-using-apache-axis-1-4/

caz of this i can able to continue with, what i was doing.. also gave me a bit confidence of, i going in the right path..

so 4th step gave me an error.. 
so this site was saying, to comment the following line in web.xml

<!--
 <servlet-mapping>
   <servlet-name>AdminServlet</servlet-name>
   <url-pattern>/servlet/AdminServlet</url-pattern>
 </servlet-mapping>
-->
did that. and did the 4th step again.. this time the error changed to
D:\WSDL2JAVA>java org.apache.axis.client.AdminClient src\sg\com\jp\admin\service \generated\deploy.wsdd Processing file src\sg\com\jp\admin\service\generated\deploy.wsdd Exception: AxisFault faultCode: {http://xml.apache.org/axis/}HTTP faultSubcode: faultString: (404)Not Found faultActor: faultNode: faultDetail: {}:return code: 404 &lt;html&gt;&lt;head&gt;&lt;title&gt;Apache Tomcat/7.0.67 - Error report&lt;/tit le&gt;&lt;style&gt;&lt;!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;ba ckground-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif; color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Ari al,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-f amily:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-famil y:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family: Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--&gt;&lt;/style&gt; &lt;/hea d&gt;&lt;body&gt;&lt;h1&gt;HTTP Status 404 - /axis/services/AdminService&lt;/h1& gt;&lt;HR size=&quot;1&quot; noshade=&quot;noshade&quot;&gt;&lt;p&gt;&lt;b&gt;ty pe&lt;/b&gt; Status report&lt;/p&gt;&lt;p&gt;&lt;b&gt;message&lt;/b&gt; &lt;u&gt ;/axis/services/AdminService&lt;/u&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;description&lt ;/b&gt; &lt;u&gt;The requested resource is not available.&lt;/u&gt;&lt;/p&gt;&lt ;HR size=&quot;1&quot; noshade=&quot;noshade&quot;&gt;&lt;h3&gt;Apache Tomcat/7. 0.67&lt;/h3&gt;&lt;/body&gt;&lt;/html&gt; {http://xml.apache.org/axis/}HttpErrorCode:404

i changed the project name to axis, created folder services, put my compiled class file in adminservice folder then i did the 4th step again, this time...

D:\WSDL2JAVA>java org.apache.axis.client.AdminClient src\test\com\admin\service \generated\deploy.wsdd Processing file src\test\com\admin\service\generated\deploy.wsdd <Admin>Done processing</Admin>

Yaaayyyyyyyyy... i have successfully exposed my web service.. also i can see my wdsl

So the Server part is completed, since we already had generated the java file from WSDL, i believe, we can directly connect to the end points through that. So the task moved to done.



No comments:

Post a Comment