[
https://issues.apache.org/jira/browse/AXIS2-4361?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12723446#action_12723446
]
Asit Jaiswal commented on AXIS2-4361:
-------------------------------------
Hello Deepal,
When I used the Same Service client through out the invocation, the transport
session scope act as application scope,
here is the listing which i modified.....as per your comments
initializing the ServiceClient object sc in the init method of servlet
please help me with this,
sorry for the late reply
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.swing.Icon;
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.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.tomcat.util.http.Cookies;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* Servlet implementation class Support
*/
public class Support extends HttpServlet {
static ServiceClient sc=null;
String ansfinal="";
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Support() {
super();
// TODO Auto-generated constructor stub
}
public void init(){
System.out.println("I am init method");
try {
sc = new ServiceClient();
System.out.println("i am in try catch of init "+sc);
} catch (AxisFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* @see HttpServlet#doGet(HttpServletRequest request,
HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
// TODO Auto-generated method stub
//System.out.println("the session id is "+h.getId());
String arg1 = (request.getParameter("n1"));
String arg2 = (request.getParameter("n2"));
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
Support support = new Support();
support.setCacheExpireDate(response,1);
System.out.println("hello i am one");
String ans=support.usingaxiom(arg1,arg2);
pw.println("the answer is "+ans);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request,
HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
public String usingaxiom(String param1,String param2){
String response="";
try{
//sc.engageModule("addressing");
Options opts = new Options();
opts.setTo(new
EndpointReference("http://localhost:8080/Calculator/services/Addition"));
//opts.setAction("urn:add");
opts.setManageSession(true);
sc.setOptions(opts);
OMElement omle = sc.sendReceive(createPayLoad(param1,param2));
response = omle.getFirstElement().getText();
}catch(Exception e){
System.out.println("the error is "+e);
}
return response;
}
public OMElement createPayLoad(String p1,String p2){
OMFactory omf = OMAbstractFactory.getOMFactory();
OMNamespace omNs =
omf.createOMNamespace("http://ws.apache.org/axis2","ns1");
OMElement method = omf.createOMElement("add",omNs);
OMElement value1 = omf.createOMElement("n1",omNs);
value1.addChild(omf.createOMText(value1,p1));
method.addChild(value1);
OMElement value2 = omf.createOMElement("n2",omNs);
value2.addChild(omf.createOMText(value2,p2));
method.addChild(value2);
return method;
}
public static void setCacheExpireDate(HttpServletResponse response,int
seconds) {
if (response != null) {
Calendar cal = new GregorianCalendar();
cal.roll(Calendar.SECOND, seconds);
response.setHeader("Cache-Control", "PUBLIC, max-age="
+ seconds + ", must-revalidate");
response.setHeader("Expires",
htmlExpiresDateFormat().format(cal.getTime()));
}
}
public static DateFormat htmlExpiresDateFormat() {
DateFormat httpDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy
HH:mm:ss z", Locale.US);
httpDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
return httpDateFormat;
}
}
> Problem in transportsession on the client side AXIS 2 1.3 JDK 1.6
> -----------------------------------------------------------------
>
> Key: AXIS2-4361
> URL: https://issues.apache.org/jira/browse/AXIS2-4361
> Project: Axis 2.0 (Axis2)
> Issue Type: Bug
> Affects Versions: 1.3
> Environment: WIndows XP SP3,
> Reporter: Asit Jaiswal
> Attachments: Addition.java, services.xml, Support.java
>
> Original Estimate: 96h
> Remaining Estimate: 96h
>
> Using Axis2 1.3
> Java 6
> I have created one web service which adds two number but the session is not
> working when using serlvet as client
> : here is the listing for web service:
> public class Addition{
> public int add(int n1 ,int n2){
> MessageContext mctx = MessageContext.getCurrentMessageContext();
> ServiceContext serviceContext = mctx.getServiceContext();
> if((Integer) serviceContext.getProperty("VALUE") == null){
> serviceContext.setProperty("VALUE", new Integer(n1+n2));
> return((Integer) serviceContext.getProperty("VALUE")).intValue();
> }
> else{
> serviceContext.setProperty("VALUE1", (Integer)
> serviceContext.getProperty("VALUE"));
> int result = ((Integer)
> serviceContext.getProperty("VALUE1")).intValue()+((Integer) serviceContext.
> getProperty("VALUE")).intValue();
> serviceContext.setProperty("VALUE", (Integer) result);
> return result;
> }
> }
> }
> I modified the services.xml as :
> <service name="Addition" scope="transportsession" >
> ......
> ..... no modification here
> .....
> </service>
> For client Side I created a Servlet using AXIOM here is the listing
> Options opts = new Options();
> opts.setTo(new
> EndpointReference("http://localhost:8080/Calculator/services/Addition"));
> opts.setAction("urn:add");
> opts.setManageSession(true);
> sc.setOptions(opts);
> If I invoke the web service using below url transport session is working fine
> http://localhost:8080/Calculator/services/Addition/add?n1=5&n2=9
> but using the AXIOM in servlet its not working (transport session)
> Note:(if I Put scope="application" then it working with Servlet)
> Please help me............
> Thanks in Advance
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.