Unable to access web service from android - java

My server is running in Tomcat. Here is my WSDL path:
http://10.99.60.52:8082/rjWebServices/wsdl/UserAuthenticationService.wsdl
SOAP address location in WSDL:
<soap:address location="http://localhost:8082/rjWebServices/services/UserAuthenticationService" />
When trying to access the service from SOAP UI, I'm getting proper response.
But when trying to create a new SoapObject in android, I'm getting InvocationTargetException.
Here is my Android Code:
String SOAP_ACTION = "http://10.99.60.52:8082/rjWebServices/services/UserAuthenticationService";
String METHOD_NAME = "PasswordValidation";
String NAMESPACE = "http://10.99.60.52:8082/rjWebServices/services/UserAuthenticationService/";
String URL = "com.retailJava.webServices.services.UserAuthenticationService";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
What am I missing or doing wrong?
My IP is: 10.99.60.52

10.0.2.2:8082 would be the solution if you are trying to run your app on the emulator on the same machine where tomcat is installed!
If you are running the app on the device make sure that your device is on the same network or you have the route to your server from your device's network.
10.x.x.x is a private network and isnt valid on the internet. Download terminal emulator app and see of you can ping your server!

String SOAP_ACTION = "http://10.99.60.52:8082/rjWebServices/services/UserAuthenticationService";
I don't think, this is your soap action.
Search operation "PasswordValidation" in your wsdl, under bindings , you can find correct soap action.
String URL = "com.retailJava.webServices.services.UserAuthenticationService";
I think here you should provide your end point url.
Can you paste rest of your code where you are calling the webservice url.
InovcationTargetException means that the method that you invoked threw an exception. To figure out what the problem is with your method itself, wrap the invoke method call around a try-catch block and log
invocationTargetException.getTargetException().

use that code
String SOAP_ACTION = "http://10.99.60.52/rjWebServices/services/UserAuthenticationService";
10.99.60.52 is your ip address..

Related

How can I connect my splunk using Splunk SDK Java?

I am getting Getting URI can't be null when trying with the url
Below is my code,
HttpService.setSslSecurityProtocol(SSLSecurityProtocol.SSLv3);
//Tried the below one also
//HttpService.setSslSecurityProtocol(SSLSecurityProtocol.TLSv1_2);
ServiceArgs loginArgs = new ServiceArgs();
loginArgs.setUsername("username");
loginArgs.setPassword("password");
loginArgs.setHost("my splunk url"); //for eg http://splunkdet.mysite.com:8000/login
loginArgs.setPort(8000);
Service service = Service.connect(loginArgs);
for (Application app: service.getApplications().values()) {
System.out.println(app.getName());
}
Getting Exception "URI can't be null" Service service = Service.connect(loginArgs);
What is wrong with my code?
Since your using http and not https you don't need to use HttpService.setSslSecurityProtocol.
Instead add the scheme to your ServiceArgs
example : loginArgs.setScheme("http");
And don't include http:// or https:// in the URL you pass to setHost.

Issue with recording from the Open ONVIF (Network Video Interface Forum ) device

I'm working on Open Network Video Interface Forum-Java project and following the steps described in the ONVIF Application Programmer's Guide.
I have generated sources from the wsdls provided in ONVIF site. I'm able to retrieve the live stream URI using the media.wsdl. Now I have an issue with recording. The codes that I have tried is given below:
RecordingService recording_ervice = new RecordingService();
RecordingPort record_port = recording_ervice.getRecordingPort();
BindingProvider bindingProvider = (BindingProvider) record_port;
// Add a security handler for the credentials
final Binding binding = bindingProvider.getBinding();
List<Handler> handlerList = binding.getHandlerChain();
if (handlerList == null) {
handlerList = new ArrayList<Handler>();
}
handlerList.add(new RecordStream.SecurityHandler());
// binding.setHandlerChain(handlerList);
// Set the actual web services address instead of the mock service
Map<String, Object> requestContext = bindingProvider.getRequestContext();
requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://" + deviceip + "/onvif/media_service");
requestContext.put(BindingProvider.USERNAME_PROPERTY, user);
requestContext.put(BindingProvider.PASSWORD_PROPERTY, pass);
Recordings recordings = record_port.getRecordings();
The above code on run gives an error as:
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Method 'ns11:GetServiceCapabilities' not implemented: method name or namespace not recognized
I also tried with media service, then the error is:
Exception in thread "main" com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 405: Method Not Allowed
When you tried with the media source, you requested an unauthorized action apparently since the server returned Error code 405. Either the method is prohibited from use, or you need a credential to use the method.
As for Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Method 'ns11:GetServiceCapabilities' not implemented: method name or namespace not recognized, #Sigismondo is right about the fact that most ip cameras don't support it. You will need an alternative recording method(literal and pun) to record from an ip camera.
You are using http://" + deviceip + "/onvif/media_service to reach the Recording service, but this is a media.wsdl service. So when you try to call getRecordings on the media service it seems normal you receive an error.
The url for recording.wsdl service should be http://" + deviceip + "/onvif/recording_service.
In order to get the corect URL to reach the recording service you should request it from the GetCapabilities method of the devicemgmt.wsdl service.
HTTP 405 - Resource not allowed usually occurs in IIS.
This problem occurs if the following conditions are true:
You do not specify the file name. For example, you do not specify
http ://Server/Web/...
The Scripting Object Model (SOM) is enabled.
A DTC event is called.
So, when the SOM is enabled a < form > tag is inserted in the page the tag is invalid means it does not contain any action.

google app engine for java- using low level API to fetch data- some difficulties

In a Google App Engine for Java web app, I am trying to use the low level api to invoke an XML RPC ...After looking at the docs, I figured out the following code to connect using low level API-the reason why I want to use Low Level API is so that I can set the timeout value myself--
String mrtime="120";
java.lang.Double maxresponsetime;
maxresponsetime = Double.valueOf(mrtime).doubleValue();
HTTPRequest req= new HTTPRequest(url, HTTPMethod.GET, disallowTruncate().setDeadline(maxresponsetime));
HTTPResponse response= com.google.appengine.api.urlfetch.URLFetchServiceFactory.getURLFetchService().fetch(req);
String line="";
String resp="";
resp=new String(response.getContent(), "UTF-8");
The above code is suitable for a scenario where the remote URL is accessed by GAE...However I have to also send an XML message containing name of function as well as input parameters (these are stored in variable named 'message')... How do I send that message to the remote URL, and after that obtain the response?
You should post the call method and parameters instead of GET. The method name and parameters go as XML.
See this http://xmlrpc.scripting.com/spec.html

google app engine server reports error but on local server the code works fine

String sourceUrlString="http://maps.googleapis.com/maps/api/geocode/xml?address="+searchWord+"&sensor=true";//searchWord-parameter to be passed
Source source=new Source(new URL(sourceUrlString));
Element alpha=source.getFirstElement("location");
String beta[]=new String[100];
String lat=alpha.getContent().getFirstElement("lat").getContent().toString();
String lng=alpha.getContent().getFirstElement("lng").getContent().toString();
THE error pointed out by google app engine is in the above bold statements it says null pointer exception but on local server it returns the value and the code works fine.
wat are the possible solution to the above problem?and as of what i have come to conclusion is google app engine does not support Http request .is it true?
You need to use URL Fetch service to issue HTTP requests and receive responses:
One example:
import urllib2
url = "http://www.google.com/"
try:
result = urllib2.urlopen(url)
doSomethingWithResult(result)
except urllib2.URLError, e:
handleError(e)

SOAP web service calls from Javascript

I'm struggling to successfully make a web service call to a SOAP web service from a web page. The web service is a Java web service that uses JAX-WS.
Here is the web method that I'm trying to call:
#WebMethod
public String sayHi(#WebParam(name="name") String name)
{
System.out.println("Hello "+name+"!");
return "Hello "+name+"!";
}
I've tried doing the web service call using the JQuery library jqSOAPClient (http://plugins.jquery.com/project/jqSOAPClient).
Here is the code that I've used:
var processResponse = function(respObj)
{
alert("Response received: "+respObj);
};
SOAPClient.Proxy = url;
var body = new SOAPObject("sayHi");
body.ns = ns;
body.appendChild(new SOAPObject("name").val("Bernhard"));
var sr = new SOAPRequest(ns+"sayHi",body);
SOAPClient.SendRequest(sr,processResponse);
No response seems to be coming back. When in jqSOAPClient.js I log the xData.responseXML data member I get 'undefined'. In the web service I see the warning
24 Mar 2011 10:49:51 AM com.sun.xml.ws.transport.http.server.WSHttpHandler handleExchange
WARNING: Cannot handle HTTP method: OPTIONS
I've also tried using a javascript library, soapclient.js (http://www.codeproject.com/kb/Ajax/JavaScriptSOAPClient.aspx). The client side code that I use here is
var processResponse = function(respObj)
{
alert("Response received: "+respObj);
};
var paramaters = new SOAPClientParameters();
paramaters.add("name","Bernhard");
SOAPClient.invoke(url,"sayHi",paramaters,true,processResponse);
I've bypassed the part in soapclient.js that fetches the WSDL, since it doesn't work
(I get an: IOException: An established connection was aborted by the software in your host machine on the web service side). The WSDL is only retrieved for the appropriate name space to use, so I've just replaced the variable ns with the actual name space.
I get exactly the same warning on the web service as before (cannot handle HTTP method: OPTIONS) and in the browser's error console I get the error "document is null". When I log the value of req.responseXML in soapclient.js I see that it is null.
Could anyone advise on what might be going wrong and what I should do to get this to work?
I found out what was going on here. It is the same scenario as in this thread: jQuery $.ajax(), $.post sending "OPTIONS" as REQUEST_METHOD in Firefox.
Basically I'm using Firefox and when one is doing a cross domain call (domain of the address of the web service is not the same as the domain of the web page) from Firefox using AJAX, Firefox first sends an OPTIONS HTTP-message (before it transmits the POST message), to determine from the web service if the call should be allowed or not. The web service must then respond to this OPTIONS message to tell if it allows the request to come through.
Now, the warning from JAX-WS ("Cannot handle HTTP method: OPTIONS") suggests that it won't handle any OPTIONS HTTP-messages. That's ok - the web service will eventually run on Glassfish.
The question now is how I can configure Glassfish to respond to the OPTIONS message.
In the thread referenced above Juha says that he uses the following code in Django:
def send_data(request):
if request.method == "OPTIONS":
response = HttpResponse()
response['Access-Control-Allow-Origin'] = '*'
response['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS'
response['Access-Control-Max-Age'] = 1000
response['Access-Control-Allow-Headers'] = '*'
return response
if request.method == "POST":
# ...
Access-Control-Allow-Origin gives a pattern which indicates which origins (recipient addresses) will be accepted (mine might be a bit more strict than simply allowing any origin) and Access-Control-Max-Age tells after how many seconds the client will have to request permission again.
How do I do this in Glassfish?
Have you actually tested that ws is working properly?
You can use SoapUI for inspecting request/response etc.
When you confirm that ws is working from SoapUI, inspect what is format of raw Soap message. Then try to inspect how it looks before sending with .js method, and compare them.
It might help you understand what is wrong.
Check if this helps
http://bugs.jquery.com/attachment/ticket/6029/jquery-disable-firefox3-cross-domain-magic.patch
it's marked as invalid
http://bugs.jquery.com/ticket/6029
but it might give you some hint
On the other hand, instead to override proper settings for cross-domain scripting might be better if you can create and call local page that will do request to ws and return result.
Or even better, you can create page that will receive url as param and do request to that url and just return result. That way it will be more generic and reusable.

Categories