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.
Related
I am using Java OPC-UA client Eclipse Milo. Whenever I create a session using endpoint URL of server, method UaTcpStackClient.getEndpoints() changes URL to localhost.
String endpointUrl = "opc.tcp://10.8.0.104:48809";
EndpointDescription[] endpoints = UaTcpStackClient.getEndpoints(endpointUrl).get();
EndpointDescription endpoint = Arrays.stream(endpoints)
.filter(e -> e.getSecurityPolicyUri().equals(securityPolicy.getSecurityPolicyUri()))
.findFirst().orElseThrow(() -> new Exception("no desired endpoints returned"));
However value of endpoint.getEndpointUrl() returns opc.tcp://127.0.0.1:4880/ which results failure in connection.
I have no idea why my OPC URL gets changed?
This is a pretty common problem when implementing a UA client.
The server is ultimately responsible for the contents of the endpoints you get back, and the one you're connecting to is (mis)configured to return 127.0.0.1 in the endpoint URLs, apparently.
You need to check the endpoints you get from the server and then depending on the nature of your application either just replace them right away with new copied EndpointDescriptions containing URLs that you've modified or let the user know and ask them for permission first.
Either way, you need to create a new set of EndpointDescriptions in which you've corrected the URL before you go on to create the OpcUaClient.
Alternatively... you could figure out how to get your server configured properly so it returns endpoints containing a publicly reachable hostname or IP address.
Update 2:
Since v0.2.2 there has been EndpointUtil.updateUrl that can be used to modify EndpointDescriptions.
Update:
The code to replace the endpoint URL could be some variation of this:
private static EndpointDescription updateEndpointUrl(
EndpointDescription original, String hostname) throws URISyntaxException {
URI uri = new URI(original.getEndpointUrl()).parseServerAuthority();
String endpointUrl = String.format(
"%s://%s:%s%s",
uri.getScheme(),
hostname,
uri.getPort(),
uri.getPath()
);
return new EndpointDescription(
endpointUrl,
original.getServer(),
original.getServerCertificate(),
original.getSecurityMode(),
original.getSecurityPolicyUri(),
original.getUserIdentityTokens(),
original.getTransportProfileUri(),
original.getSecurityLevel()
);
}
Caveat: this works in most cases, but one notable case it does not work is when the remote endpoint URL contains characters that aren't allowed in a URL hostname (according to the RFC), such as underscore (a '_'), which unfortunately IS allowed in e.g. the hostname of a Windows machine. So you may need to use some other method of parsing the endpoint URL rather than relying on the URI class to do it.
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..
Hi My code for the same is
// Initialize Web Service
HandlerResolver handlerResolver=new AwsHandlerResolver(credentials.getAWSSecretKey());
AWSECommerceService service = new AWSECommerceService();
service.setHandlerResolver(handlerResolver);
// Create Web Service Connection
AWSECommerceServicePortType port = service.getAWSECommerceServicePort();
// Add Parameters for the Item Lookup
ItemLookupRequest itemLookup = new ItemLookupRequest();
itemLookup.setIdType("ASIN");
itemLookup.getItemId().add("B000RE216U");
// Wrap Request in Lookup Body
ItemLookup lookup = new ItemLookup();
lookup.setAWSAccessKeyId(credentials.getAWSAccessKeyId());
lookup.getRequest().add(itemLookup);
ItemLookupResponse response = port.itemLookup(lookup);
System.out.println("response: " + response.toString());
I keep getting the error cannot convert from Void to AWSECommerceService in the beginning. I have the AWSHandlerResolver file and codec jar installed and configured.
Error Message:
Exception in thread "main" javax.xml.ws.WebServiceException: {http://webservices.amazon.com/AWSECommerceService/2010-11-01}AWSECommerceService is not a valid service. Valid services are: {http://webservices.amazon.com/AWSECommerceService/2011-08-01}AWSECommerceService
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:223)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:168)
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:96)
at javax.xml.ws.Service.<init>(Service.java:77)
at com.ECS.client.jax.AWSECommerceService.<init>(AWSECommerceService.java:46)
I have been searching online. I might have to change target namespace for AWSECommerceService. But cannot find how. Please help me
You are using the wrong namespace (actually, the wrong version of WS) for your Webservice client and its port.
Go to AWSECommerceService and AWSECommerceServicePortType classes and replace all namespaces which look like http://webservices.amazon.com/AWSECommerceService/2010-11-01 with http://webservices.amazon.com/AWSECommerceService/2013-08-01.
The below code snippet is using to call my web service using restful API.
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
String uri= "https://127.0.0.1:8443/cas-server-webapp-3.5.0/login";
WebResource resource = client.resource(URLEncoder.encode(uri));
MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
queryParams.add("username", "suresh");
queryParams.add("password", "suresh");
resource.queryParams(queryParams);
ClientResponse response = resource.type(
"application/x-www-form-urlencoded").get(ClientResponse.class);
String en = response.getEntity(String.class);
System.out.println(en);
And getting this exception while running the above code
com.sun.jersey.api.client.ClientHandlerException: java.lang.IllegalArgumentException: URI is not absolute
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:151)
at com.sun.jersey.api.client.Client.handle(Client.java:648)
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:680)
I googled many articles and did'nt get where i am doing wrong .
Side note :cas-server-webapp-3.5.0 war deployed on my machine in Apache tomacat7
An absolute URI specifies a scheme; a URI that is not absolute is said to be relative.
http://docs.oracle.com/javase/8/docs/api/java/net/URI.html
So, perhaps your URLEncoder isn't working as you're expecting (the https bit)?
URLEncoder.encode(uri)
For others who landed in this error and it's not 100% related to the OP question, please check that you are passing the value and it is not null in case of spring-boot: #Value annotation.
The problem is likely that you are calling URLEncoder.encode() on something that already is a URI.
Maybe the problem only in your IDE encoding settings. Try to set UTF-8 everywhere:
In an API Key Authorization Scenario...
You may be performing the 2nd REST call after getting an AUTH_TOKEN and ENDPOINT_URL from the first REST call.
Check your concatenation of "<ENDPOINT_URL> + <API_METHOD_URI>", you may be sending only the API_METHOD_URI.
This happened to me using the Streamsets integration platform trying to connect to Oracle's Responsys API.
For me, I was getting this error, when configuation in yaml files, which composed my URL was changed. oops,
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.