Saturday, September 12, 2015

axis 1.6.3 webclient access

 // TODO Auto-generated method stub
        String END_POINT = "http://localhost:8080/axis2/services/MyService";
        StockQuoteStub stub = new StockQuoteStub();
        StockQuoteStub.GetQuote getQuote = new StockQuoteStub.GetQuote();
        getQuote.setSymbol("10");
        try {
            StockQuoteStub.GetQuoteResponse resp = stub.getQuote(getQuote);
            System.out.println("result :: " + resp);
        } catch (RemoteException e) {
            // TODO Auto-generated catch block e.printStackTrace
        }

Sunday, September 6, 2015

axiom secure https webservices access

http://blog.facilelogin.com/2008/11/secure-your-service-with-http-basic.html

working with custom soap headers

http://wso2.com/library/3156/

Axiom API Soap Header Addition

http://charithaka.blogspot.in/2008/10/how-to-add-custom-soap-header-to.html

Apache Axis Direct API

https://today.java.net/article/2006/12/08/invoking-web-services-using-apache-axis2%20

Calling Direct API

/** * */
package net.webservicex.www;
import java.rmi.RemoteException;
import org.apache.axiom.om.*;
import org.apache.axis2.client.*;
import org.apache.axis2.addressing.*;
import org.apache.axis2.AxisFault;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.client.OperationClient;
import org.apache.axiom.soap.SOAP12Constants;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axis2.context.MessageContext;
import javax.xml.namespace.QName;
import org.apache.axis2.AxisFault;
import org.apache.axis2.wsdl.WSDLConstants; /** * @author Bala * */
public class TestWS { /** * @param args * @throws AxisFault */
    public static void main(String[] args) throws AxisFault {

        // TODO Auto-generated method stub
        // String END_POINT = "http://localhost:8080/axis2/services/MyService";

     /*   StockQuoteStub stub = new StockQuoteStub();
        StockQuoteStub.GetQuote getQuote = new StockQuoteStub.GetQuote();
        getQuote.setSymbol("10");
        try {
            StockQuoteStub.GetQuoteResponse resp = stub.getQuote(getQuote);
            System.out.println("result :: " + resp);
        } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); }
            String wsdlDocument = "http://www.webservicex.net/stockquote.asmx?WSDL";
            EndpointReference targetEPR = new EndpointReference(wsdlDocument);
            OMFactory fac = OMAbstractFactory.getOMFactory();
            OMNamespace omNs = fac.createOMNamespace("http://www.webserviceX.NET/", "ns1");
            OMElement method = fac.createOMElement("GetQuote", omNs);
            OMElement paramOne = fac.createOMElement("symbol", omNs);
            paramOne.setText("12");
            method.addChild(paramOne);
            ServiceClient client = new ServiceClient();
            Options opts = new Options();
            opts.setTo(targetEPR);
            client.setOptions(opts);
            System.out.println("req " + method);
            OMElement res = client.sendReceive(method);
            String result = res.getFirstElement().getText();
            System.out.println("Result: " + result);*/


            QName ANON_OUT_IN_OP = new QName("http://ws.apache.org/namespaces/axis2", "anonOutInOp", "axis2");
            EndpointReference targetEPR = new EndpointReference("http://www.webservicex.net/stockquote.asmx?WSDL");
            SOAPFactory soapFac = OMAbstractFactory.getSOAP12Factory();
            ServiceClient sender = new ServiceClient();
            Options options = new Options();
            OMNamespace omNs = soapFac.createOMNamespace("http://www.webserviceX.NET/", "ns1");
            OMElement method = soapFac.createOMElement("GetQuote", omNs);
            OMElement value = soapFac.createOMElement("symbol", omNs);
            value.addChild(soapFac.createOMText(value, "10"));
            method.addChild(value);
            System.out.println("WEBSERVICE METHOD PARAMETER - " + method);
            options.setTo(targetEPR);
            sender.setOptions(options);
            OMElement result = sendSOAPReceive(ANON_OUT_IN_OP, method, sender, soapFac);
            System.out.println("WEBSERVICE RESULT - " + result);
        }
        public static OMElement sendSOAPReceive(QName operationQName, OMElement xmlPayload, ServiceClient service, SOAPFactory soapFac) throws AxisFault {
            MessageContext messageContext = new MessageContext();
            SOAPEnvelope envelope = soapFac.getDefaultEnvelope();
            if (xmlPayload != null) {
                envelope.getBody().addChild(xmlPayload);
            }
            messageContext.setEnvelope(envelope);
            System.out.println("SOAP REQUEST MESSAGE - " + messageContext.getEnvelope());
            OperationClient operationClient = service.createClient(operationQName);
            operationClient.addMessageContext(messageContext);
            operationClient.execute(true);
            MessageContext response = operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
            return response.getEnvelope().getBody().getFirstElement();
        }
    }

Calling direct webservice method using axis2 API in Scripts

https://scn.sap.com/thread/3504220

http://tutorial-wizard.blogspot.in/

http://tutorial-wizard.blogspot.in/

apache axis web service - tutorial 1

//ADD.JAVA

 package addition; public class add{ public int add(int a,int b){ return a+b; } }

 //inside your service package place that add.class file

 //services dir -addition dir-add.class

 //SERVICES.XML addition program addition.add

//services dir--addition dir--META-INF dir- services.xml /

//test the your web services http://localhost:8080/axis2/services/arithmatic

 //the previous links show wsdl file means your service working file...

 //if it show fault services means your services have some problem..

 //the error may be services.xml syntax problem(so careful in writing services.xml)

 //CLIENT PROGRAM

 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.OMText;
 import org.apache.axis2.client.Options;
 import org.apache.axis2.client.ServiceClient;
 import org.apache.axis2.addressing.EndpointReference;
 public class client {
     public static void main(String args[]) throws Exception {
         System.out.println("client program..");
         // //10 //20 //
         OMFactory fac = OMAbstractFactory.getOMFactory();
         OMNamespace omns = fac.createOMNamespace("http://addition", "arith1");
         OMElement add = fac.createOMElement("add", omns);
         //create a xml request element with child element 'a' and 'b'
         OMElement a = fac.createOMElement("a", omns);
         a.setText("10");
         add.addChild(a);
         OMElement b = fac.createOMElement("b", omns);
         b.setText("20");
         add.addChild(b);
         System.out.println("xml request: " + add);
         EndpointReference epr = new EndpointReference(
             "http://localhost:8080/axis2/services/arithmatic?wsdl");
         Options op = new Options();
         op.setTo(epr);
         ServiceClient sc = new ServiceClient();
         //using this class invoke web service
         sc.setOptions(op);
         OMElement result = sc.sendReceive(add);
         //this method for request and response
         System.out.println("service response: " + result);
         //print the response xml in console
     }
 }


 //complile the java program with apache axis package as class path otherwise you get class definions not found error ex: javac cp "c:/tomcat/webapps/axis2/services/webinf/lib/*;" client.java
 //execute the java program with apache axis package as class path ex: java cp "c:/tomcat/webapps/axis2/services/webinf/lib/*;" client OMELEMENT METHODS(); string getText();
 //retrive the element value setText(string);
 //set the element value getFirstElement();
 //retrive the first child element OMFACTORY METHODS(); OMNamespace createOMNamespace("URI","namespace"); OMElement createOMElement("element name",namespace); OMText createOMText("text value"); OPTIONS METHOD(); setTo(EndpointReference);
 // set the target web service address using endpoint reference class ServiceClient methods(); setOptions(OPTIONS); OMElement send(OMElement);
 //for sending oly OMElement SendReceive(OMElement);
 //for sending receving xml request and response

 }

apache axis web service tutorial2

//ADDITION.JAVA package additionService; import java.util.Iterator; import org.apache.axiom.om.*; public class addition { public addition() { } public OMElement add(OMElement omelement) { OMFactory omfactory = OMAbstractFactory.getOMFactory(); org.apache.axiom.om.OMNamespace omnamespace = omfactory.createOMNamespace("http://www.example.org/additionService/", "additionService"); OMElement omelement1 = omfactory.createOMElement("sum", omnamespace); Iterator iterator = omelement.getChildren(); int i = Integer.parseInt(((OMElement)iterator.next()).getText()) + Integer.parseInt(((OMElement)iterator.next()).getText()); omelement1.addChild(omfactory.createOMText((new StringBuilder()).append("").append(i).toString())); return omelement1; } } //SERVICES.XML additionService.addition http://localhost:8080/axis2/services/additionService //CLIENT.JAVA import java.io.StringWriter; import javax.xml.stream.*; import org.apache.axiom.om.*; import org.apache.axis2.*; import org.apache.axis2.client.*; import org.apache.axis2.addressing.*; public class addClient { private static EndpointReference targetEPR = new EndpointReference( "http://localhost:8080/axis2/services/additionService"); public static void main(String[] args) { try { OMFactory fac = OMAbstractFactory.getOMFactory(); OMNamespace omNs = fac.createOMNamespace( "http://www.example.org/additionService1/", "additionService1"); OMElement add = fac.createOMElement("add", omNs); OMElement number1 = fac.createOMElement("number", omNs); number1.addChild(fac.createOMText("1")); add.addChild(number1); OMElement number2 = fac.createOMElement("number", omNs); number2.addChild(fac.createOMText("2")); add.addChild(number2); System.out.println(add); Options options = new Options(); options.setTo(targetEPR); options.setTransportInProtocol(Constants.TRANSPORT_HTTP); options.setAction("http://localhost:8080/axis2/services/additionService"); ServiceClient sender = new ServiceClient(); sender.setOptions(options); OMElement result = sender.sendReceive(add); StringWriter writer = new StringWriter(); result.serialize(XMLOutputFactory.newInstance() .createXMLStreamWriter(writer)); writer.flush(); System.out.println(writer.toString()); } catch (AxisFault axisFault) { axisFault.printStackTrace(); } catch (XMLStreamException e) { e.printStackTrace(); } } }

Apache axis wsdl2java with specified package Command

E:\Softwares\Developer Tools\Java\axis2-1.6.3-bin\axis2-1.6.3\bin>wsdl2java.bat -uri http://www.webservicex.net/stockquote.asmx?WSDL -d adb -o cl ient -p com.org.citi

example of apache axis2 service client consumption

http://briansjavablog.blogspot.in/2013/01/axis2-web-service-client-tutorial.html 1: package com.org.samples.webservices.client; 2: import java.rmi.RemoteException; 3: import com.org.webservices.client.AccountDetailsServicesStub; 4: import com.org.webservices.client.AccountDetailsServicesStub.AccountDetailsRequest; 5: import com.org.webservices.client.AccountDetailsServicesStub.AccountDetailsResponse; 6: public class SynchronousWebServiceClientTest 7: { 8: public static void main (String [] args) throws RemoteException 9: { 10: AccountDetailsServicesStub servicesStub = new AccountDetailsServicesStub(WebServiceCientUtils.SERVICE_ENDPOINT); 11: AccountDetailsRequest accountDetailsRequest = new AccountDetailsRequest(); 12: accountDetailsRequest.setAccountNumber("12345"); 13: AccountDetailsResponse accountDetailsResponse = servicesStub.accountDetails(accountDetailsRequest); 14: WebServiceCientUtils.logAccountDetails(accountDetailsResponse.getAccountDetails()); 15: } 16: }

changing the end point in axis client java


String END_POINT = "http://localhost:8080/axis2/services/MyService";
 StockQuoteStub stub = new StockQuoteStub(END_POINT);

Axis2 Eclipse plugin configuration

Axis2 Eclipse plugin runtime configuration Referance Blog

Command to generate wsdl2java in Apache axis

Pre requisites: set path for java set JAVA_HOME -> java jdk location set AXIS_HOME -> Axis location// command inside axis bin folder then axis home not needed wsdl2java.bat -uri http://www.webservicex.net/stockquote.asmx?WSDL -d adb -o com.citi.crm.service create one java project import the java service stub client files in the project and use import all the jars from axis bin folder to remove compilation issue /** * */ package net.webservicex.www; import java.rmi.RemoteException; import org.apache.axis2.AxisFault; /** * @author Bala * */ public class TestWS { /** * @param args * @throws AxisFault */ public static void main(String[] args) throws AxisFault { // TODO Auto-generated method stub StockQuoteStub stub = new StockQuoteStub(); StockQuoteStub.GetQuote getQuote = new StockQuoteStub.GetQuote() ; getQuote.setSymbol("10"); try { StockQuoteStub.GetQuoteResponse resp = stub.getQuote(getQuote); System.out.println("result :: " + resp.getGetQuoteResult()); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }

apache axis web service...



1. create server code
2. create client code


first download axis2.war and then apache tomcat webapps directory...


it will deploy automatically... produce axis2 directory


first create the class file...

package arith;


public class arithint
{

public arithint()
{
}

public int add(int i, int j)
{
return i + j;
}
}

F:\tomcat7\webapps\axis2\WEB-INF\services\arith

place the class file inside this arith folder....


F:\tomcat7\webapps\axis2\WEB-INF\services\arith\META-INF

create the meta inf folder inside that add service configuration file..


உப்பு மாங்காய்

சுருக்குப்பை கிழவி. சுருக்கங்கள் சூழ் கிழவி. பார்க்கும் போதெல்லாம் கூடையுடனே குடியிருப்பாள். கூடை நிறைய குட்டி குட்டி மாங்காய்கள். வெட்டிக்க...