You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by juliocest <ju...@gmail.com> on 2007/11/14 21:00:44 UTC
How to get a URL from a Client when it connects to service
provider?
Hi,
I would like to kwow how can I get the client URL, (for example:
http://192.168.2.3) when the client make a invocation to the service in a
service provider?
For example, I have the service called MyService, then when the cliente
MyClient make a connection to MyService, I would like to get the MyClient IP
Address.
I would be grateful if someone could explain how to make it.
Thanks.
Júlio
São Carlos - SP - Brazil
--
View this message in context: http://www.nabble.com/How-to-get-a-URL-from-a-Client-when-it-connects-to-service-provider--tf4807674.html#a13755297
Sent from the Axis - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org
RE: How to get a URL from a Client when it connects to service
provider?
Posted by Nathan Hook <ho...@hotmail.com>.
You have to get a reference to the MessageContext.
MessageContext messageContext = MessageContext.getCurrentMessageContext();
String remoteAddress = (String)messageContext.getProperty("REMOTE_ADDR"):
or
MessageContext messageContext = MessageContext.getCurrentMessageContext();
HttpServletRequest httpServletRequest = (HttpServletRequest)msgCtx.getProperty("transport.http.servletRequest"):
String remoteAddress = httpServletRequest.getRemoteHost();
Buenas tardes. :)
> Date: Wed, 14 Nov 2007 12:36:02 -0800
> From: juliocest@gmail.com
> To: axis-user@ws.apache.org
> Subject: Re: How to get a URL from a Client when it connects to service provider?
>
>
> Hi Deepal!
>
> Bellow, the code of my service:
>
> ------------------------------------------------------------------------------------------------
> import javax.xml.stream.XMLStreamException;
> import org.apache.axiom.om.OMAbstractFactory;
> import org.apache.axiom.om.OMElement;
> import org.apache.axiom.om.OMFactory;
> import org.apache.axiom.om.OMNamespace;
>
> public class Servicos {
>
> public OMElement fatorial(OMElement elemento)
> throws XMLStreamException {
> //OMElement metodo = null;
> elemento.build();
> elemento.detach();
>
> String rootName = elemento.getLocalName();
> System.out.println("Reading "+rootName+" element");
>
> OMElement elementoFilho = elemento.getFirstElement();
>
> String valorxml = elementoFilho.getText();
> long valrecebido = Long.parseLong(valorxml);
>
> long inicio = System.nanoTime();
>
> String resultado = Fatorial.retornaFatorial(valrecebido);
>
> OMFactory fac = OMAbstractFactory.getOMFactory();
> OMNamespace omNs =
> fac.createOMNamespace("http://examplo1.org/exemplo1", "exemplo");
> OMElement metodo = fac.createOMElement("fatorialResposta",omNs);
> OMElement valor = fac.createOMElement("greeting", omNs);
> valor.addChild(fac.createOMText(valor, "Resultado do Fatorial:
> "+resultado));
> metodo.addChild(valor);
>
> long fim = System.nanoTime();
>
> double diferenca = (double)(fim-inicio)/1000000000;
> String diferencafile = Double.toString(diferenca);
>
> // Grava no arquivo o tempo necessário para a computação
> Arquivo arquivo = new Arquivo();
> arquivo.Escreve(diferencafile+"\n");
>
> return metodo;
> }
>
> }
> -------------------------------------------------------------------------------------------------------------------
>
> I need to obtain the IP address when a client or many clients to access this
> service. Then I have to write some routine inside the code that represents
> the service.
>
> Could you help me?
>
> Thanks!
>
> Julio
>
>
> Deepal Jayasinghe-2 wrote:
>>
>> http://wso2.org/library/480
>>
>> Thanks
>> deepal
>>> Hi,
>>>
>>> I would like to kwow how can I get the client URL, (for example:
>>> http://192.168.2.3) when the client make a invocation to the service in a
>>> service provider?
>>>
>>> For example, I have the service called MyService, then when the cliente
>>> MyClient make a connection to MyService, I would like to get the MyClient
>>> IP
>>> Address.
>>>
>>> I would be grateful if someone could explain how to make it.
>>>
>>> Thanks.
>>>
>>> Júlio
>>>
>>> São Carlos - SP - Brazil
>>>
>>
>>
>> --
>> Thanks,
>> Deepal
>> ................................................................
>> "The highest tower is built one brick at a time"
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
>> For additional commands, e-mail: axis-user-help@ws.apache.org
>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/How-to-get-a-URL-from-a-Client-when-it-connects-to-service-provider--tf4807674.html#a13755800
> Sent from the Axis - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
_________________________________________________________________
Windows Live Hotmail and Microsoft Office Outlook – together at last. Get it now.
http://office.microsoft.com/en-us/outlook/HA102225181033.aspx?pid=CL100626971033
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org
Re: How to get a URL from a Client when it connects to service provider?
Posted by Deepal jayasinghe <de...@gmail.com>.
Hi
If you want to get the client IP address inside your service method you
can do that as follows;
public OMElement fatorial(OMElement elemento)
throws XMLStreamException {
MessageContext msgCtx = MessageContext.getCurrentContext();
String remoteAddress = (String)msgCtx.getProperty("REMOTE_ADDR"):
// REST of you client code
}
> Hi Deepal!
>
> Bellow, the code of my service:
>
> ------------------------------------------------------------------------------------------------
> import javax.xml.stream.XMLStreamException;
> import org.apache.axiom.om.OMAbstractFactory;
> import org.apache.axiom.om.OMElement;
> import org.apache.axiom.om.OMFactory;
> import org.apache.axiom.om.OMNamespace;
>
> public class Servicos {
>
> public OMElement fatorial(OMElement elemento)
> throws XMLStreamException {
> //OMElement metodo = null;
> elemento.build();
> elemento.detach();
>
> String rootName = elemento.getLocalName();
> System.out.println("Reading "+rootName+" element");
>
> OMElement elementoFilho = elemento.getFirstElement();
>
> String valorxml = elementoFilho.getText();
> long valrecebido = Long.parseLong(valorxml);
>
> long inicio = System.nanoTime();
>
> String resultado = Fatorial.retornaFatorial(valrecebido);
>
> OMFactory fac = OMAbstractFactory.getOMFactory();
> OMNamespace omNs =
> fac.createOMNamespace("http://examplo1.org/exemplo1", "exemplo");
> OMElement metodo = fac.createOMElement("fatorialResposta",omNs);
> OMElement valor = fac.createOMElement("greeting", omNs);
> valor.addChild(fac.createOMText(valor, "Resultado do Fatorial:
> "+resultado));
> metodo.addChild(valor);
>
> long fim = System.nanoTime();
>
> double diferenca = (double)(fim-inicio)/1000000000;
> String diferencafile = Double.toString(diferenca);
>
> // Grava no arquivo o tempo necessário para a computação
> Arquivo arquivo = new Arquivo();
> arquivo.Escreve(diferencafile+"\n");
>
> return metodo;
> }
>
> }
> -------------------------------------------------------------------------------------------------------------------
>
> I need to obtain the IP address when a client or many clients to access this
> service. Then I have to write some routine inside the code that represents
> the service.
>
> Could you help me?
>
> Thanks!
>
> Julio
>
>
> Deepal Jayasinghe-2 wrote:
>
>> http://wso2.org/library/480
>>
>> Thanks
>> deepal
>>
>>> Hi,
>>>
>>> I would like to kwow how can I get the client URL, (for example:
>>> http://192.168.2.3) when the client make a invocation to the service in a
>>> service provider?
>>>
>>> For example, I have the service called MyService, then when the cliente
>>> MyClient make a connection to MyService, I would like to get the MyClient
>>> IP
>>> Address.
>>>
>>> I would be grateful if someone could explain how to make it.
>>>
>>> Thanks.
>>>
>>> Júlio
>>>
>>> São Carlos - SP - Brazil
>>>
>>>
>> --
>> Thanks,
>> Deepal
>> ................................................................
>> "The highest tower is built one brick at a time"
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
>> For additional commands, e-mail: axis-user-help@ws.apache.org
>>
>>
>>
>>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org
Re: How to get a URL from a Client when it connects to service
provider?
Posted by juliocest <ju...@gmail.com>.
Hi Deepal!
Bellow, the code of my service:
------------------------------------------------------------------------------------------------
import javax.xml.stream.XMLStreamException;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
public class Servicos {
public OMElement fatorial(OMElement elemento)
throws XMLStreamException {
//OMElement metodo = null;
elemento.build();
elemento.detach();
String rootName = elemento.getLocalName();
System.out.println("Reading "+rootName+" element");
OMElement elementoFilho = elemento.getFirstElement();
String valorxml = elementoFilho.getText();
long valrecebido = Long.parseLong(valorxml);
long inicio = System.nanoTime();
String resultado = Fatorial.retornaFatorial(valrecebido);
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs =
fac.createOMNamespace("http://examplo1.org/exemplo1", "exemplo");
OMElement metodo = fac.createOMElement("fatorialResposta",omNs);
OMElement valor = fac.createOMElement("greeting", omNs);
valor.addChild(fac.createOMText(valor, "Resultado do Fatorial:
"+resultado));
metodo.addChild(valor);
long fim = System.nanoTime();
double diferenca = (double)(fim-inicio)/1000000000;
String diferencafile = Double.toString(diferenca);
// Grava no arquivo o tempo necessário para a computação
Arquivo arquivo = new Arquivo();
arquivo.Escreve(diferencafile+"\n");
return metodo;
}
}
-------------------------------------------------------------------------------------------------------------------
I need to obtain the IP address when a client or many clients to access this
service. Then I have to write some routine inside the code that represents
the service.
Could you help me?
Thanks!
Julio
Deepal Jayasinghe-2 wrote:
>
> http://wso2.org/library/480
>
> Thanks
> deepal
>> Hi,
>>
>> I would like to kwow how can I get the client URL, (for example:
>> http://192.168.2.3) when the client make a invocation to the service in a
>> service provider?
>>
>> For example, I have the service called MyService, then when the cliente
>> MyClient make a connection to MyService, I would like to get the MyClient
>> IP
>> Address.
>>
>> I would be grateful if someone could explain how to make it.
>>
>> Thanks.
>>
>> Júlio
>>
>> São Carlos - SP - Brazil
>>
>
>
> --
> Thanks,
> Deepal
> ................................................................
> "The highest tower is built one brick at a time"
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/How-to-get-a-URL-from-a-Client-when-it-connects-to-service-provider--tf4807674.html#a13755800
Sent from the Axis - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org
Re: How to get a URL from a Client when it connects to service provider?
Posted by Deepal jayasinghe <de...@gmail.com>.
http://wso2.org/library/480
Thanks
deepal
> Hi,
>
> I would like to kwow how can I get the client URL, (for example:
> http://192.168.2.3) when the client make a invocation to the service in a
> service provider?
>
> For example, I have the service called MyService, then when the cliente
> MyClient make a connection to MyService, I would like to get the MyClient IP
> Address.
>
> I would be grateful if someone could explain how to make it.
>
> Thanks.
>
> Júlio
>
> São Carlos - SP - Brazil
>
--
Thanks,
Deepal
................................................................
"The highest tower is built one brick at a time"
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org
RE: How to get a URL from a Client when it connects to service
provider?
Posted by juliocest <ju...@gmail.com>.
Thanks!
It works!
Julio
tcort wrote:
>
> Here's what we use for logging client IP addresses in our axis 1.4
> service....
>
> /**
> * Helper method to Log a client's IP address.
> *
> * @param msg
> * the message to log along with the IP or null for no message.
> */
> private void logIP(String msg) {
>
> HttpServletRequest req = null;
> MessageContext context = MessageContext.getCurrentContext();
> req = (HttpServletRequest) context
>
> .getProperty(org.apache.axis.transport.http.HTTPConstants.MC_HTTP_SERVLETREQUEST);
>
> String logMsg = "";
>
> if (req != null) {
> logMsg += req.getRemoteAddr();
> } else {
> logMsg += "0.0.0.0";
> }
>
> if (msg != null) {
> logMsg += " | " + msg;
> }
>
> LOG.info(logMsg);
> }
>
>
> Source:
> http://gateway.svn.sourceforge.net/viewvc/*checkout*/gateway/trunk/sstp-server/src/main/java/net/sf/gateway/sstp/rule/Rule000023.java?revision=1072
>
> | -----Original Message-----
> | From: juliocest [mailto:juliocest@gmail.com]
> | Sent: Wednesday, November 14, 2007 3:01 PM
> | To: axis-user@ws.apache.org
> | Subject: How to get a URL from a Client when it connects to service
> | provider?
> |
> |
> | Hi,
> |
> | I would like to kwow how can I get the client URL, (for example:
> | http://192.168.2.3) when the client make a invocation to the service in
> a
> | service provider?
> |
> | For example, I have the service called MyService, then when the cliente
> | MyClient make a connection to MyService, I would like to get the
> MyClient
> | IP
> | Address.
> |
> | I would be grateful if someone could explain how to make it.
> |
> | Thanks.
> |
> | Júlio
> |
> | São Carlos - SP - Brazil
> | --
> | View this message in context:
> http://www.nabble.com/How-to-get-a-URL-from-
> | a-Client-when-it-connects-to-service-provider--tf4807674.html#a13755297
> | Sent from the Axis - User mailing list archive at Nabble.com.
> |
> |
> | ---------------------------------------------------------------------
> | To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> | For additional commands, e-mail: axis-user-help@ws.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/How-to-get-a-URL-from-a-Client-when-it-connects-to-service-provider--tf4807674.html#a13767147
Sent from the Axis - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org
RE: How to get a URL from a Client when it connects to service provider?
Posted by "Cort, Tom" <To...@state.vt.us>.
Here's what we use for logging client IP addresses in our axis 1.4 service....
/**
* Helper method to Log a client's IP address.
*
* @param msg
* the message to log along with the IP or null for no message.
*/
private void logIP(String msg) {
HttpServletRequest req = null;
MessageContext context = MessageContext.getCurrentContext();
req = (HttpServletRequest) context
.getProperty(org.apache.axis.transport.http.HTTPConstants.MC_HTTP_SERVLETREQUEST);
String logMsg = "";
if (req != null) {
logMsg += req.getRemoteAddr();
} else {
logMsg += "0.0.0.0";
}
if (msg != null) {
logMsg += " | " + msg;
}
LOG.info(logMsg);
}
Source:
http://gateway.svn.sourceforge.net/viewvc/*checkout*/gateway/trunk/sstp-server/src/main/java/net/sf/gateway/sstp/rule/Rule000023.java?revision=1072
| -----Original Message-----
| From: juliocest [mailto:juliocest@gmail.com]
| Sent: Wednesday, November 14, 2007 3:01 PM
| To: axis-user@ws.apache.org
| Subject: How to get a URL from a Client when it connects to service
| provider?
|
|
| Hi,
|
| I would like to kwow how can I get the client URL, (for example:
| http://192.168.2.3) when the client make a invocation to the service in a
| service provider?
|
| For example, I have the service called MyService, then when the cliente
| MyClient make a connection to MyService, I would like to get the MyClient
| IP
| Address.
|
| I would be grateful if someone could explain how to make it.
|
| Thanks.
|
| Júlio
|
| São Carlos - SP - Brazil
| --
| View this message in context: http://www.nabble.com/How-to-get-a-URL-from-
| a-Client-when-it-connects-to-service-provider--tf4807674.html#a13755297
| Sent from the Axis - User mailing list archive at Nabble.com.
|
|
| ---------------------------------------------------------------------
| To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
| For additional commands, e-mail: axis-user-help@ws.apache.org