I have created a RESTful web service. It is working fine when I run it. But whenever I pass any parameter to that web service through the URL created, I am not able to access that parameter.
The URL of web service is:
http://localhost:8080/Web_service/path/simple/sam
where sam is the parameter passed by me and path is used for accessing the class.
In my web service, I am trying to access the passed parameter as shown in the screenshot below:
This is my code's screenshot
I do not get back the parameter concatenated with "Hello " as I desire, but I only get "Hello " returned.
Please help !
#Get
#Produces(MediaType.TEXT_PLAIN)
#Path("/simple/{tem}")
public String test(#PathVariable("tem") String tem) {
String t = "Hello " + tem;
return t;
}
Related
Does anyone know how to access the test.parameters key-value pairs passed as input to the ScheduleRun API?
This is what I am doing:
Passing the input for the test to be run under test.filter.
Passing the parameters I need for my test under test.parameters. I have ensured it is a valid JSON object.
I am not passing any yaml file, so a "standard" test run gets triggered on DeviceFarm.
Here is my code that I use to retrieve the data:
final Bundle bundle = InstrumentationRegistry.getArguments();
for (final String key : bundle.keySet())
{
final Object obj = bundle.get(key);
Log.i(TAG, "Key - '" + key + "' ; Value - '" + obj.toString() + "'");
}
I know the test.filter part works because the InstrumentationRegistry.getArguments() bundle is able to retrieve the class value which is the test that needs to be run. Unfortunately, the test.parameters values are not present in the bundle.
Is there anything that I am missing or should I use some other mechanism to retrieve the test.parameters ?
Got confirmation from the AWS team that, at this point, they don't support this feature for Custom environments.
I am trying to add a new endpoint to a WCF based REST service with the following URL template:
/books/{bookId}/pdf
but it gives an error saying:
The UriTemplate '/books/*/pdf' is not valid; the wildcard ('*') cannot appear in a variable name or literal, unless as a construct for a wildcard segment. Note that a wildcard segment, either a literal or a variable, is valid only as the last path segment in the template; the wildcard can appear only once. See the documentation for UriTemplate for more details.'
Here's the service contract:
[OperationContract]
[WebInvoke(UriTemplate = "/books/{bookId}/pdf", Method = "POST")]
Message GetBookPDF(string bookId);
Is this a limitation that the variable is only valid as the last part of the url? I couldn't find any link that confirms that.
I am sure that the variable needn’t configured in the last part of the URL.
My service contract
public interface ITestService
{
[OperationContract]
[WebInvoke(Method ="POST",UriTemplate ="/books/{id}/pdf")]
string Test(string id);
}
Result.
Please have a look at this link.
https://stackoverflow.com/questions/13956889/in-wcf-can-i-have-a-wildcard-character-in-a-literal-segment-of-my-uritemplate
The most likely scenario is that the UriTemplate can match multiple OperationContract, thus the error happened.
Feel free to let me know if the problem still exists.
I have a simple restful web services (Jersey framework) that handles a get request. I fired a request from soapUI (v4.6.4) that passes Authorization token in the request header. From the log statement in the service end, I noticed that it was called twice. First time base64 encoded token is captured and its value is printed then it got called again printing null value. I am trying to understand why this is happening. I read a few threads about it in the web but I was not able to find a clear answer for this case.
I wonder if the soapUI fires a request twice somehow...
#Path("/testservice")
public class MyTestService {
#GET
#Produces(MediaType.APPLICATION_XML)
#Path("/")
public String test(#Context HttpHeader headers) {
String token = headers.getRequestHeader().getFirst("Authorization");
System.out.println("token: " + token);
return token;
}
...
}
We have a Java Web Service (WSDL) and a ASP Client. We are using SOAP Toolkit 3.0 to make calls to the Java web service. The Java web service is exposing objects, so I need to use complex type mappers.
When I am trying this, I am getting the error -
SoapMapper:Saving SoapMapper account failed HRESULT=0x80004002: No such interface supported - Client:Unspecified client error. HRESULT=0x80004002: No such interface supported
The code for this is:
On Error Resume Next
Dim objWebSvcClient
Dim strSuccess
Dim myaccount
set objWebSvcClient = server.CreateObject("MSSOAP.SoapClient30")
objWebSvcClient.ClientProperty("ServerHTTPRequest") = True
objWebSvcClient.MSSoapInit ("c:\TestAsp.wsdl")
class Account
Dim maccid 'As String
Dim maccName 'As String
Public Property Get accId() 'As String
accId = maccid
End Property
Public Property Let accId(ByVal Value )
maccid = Value
End Property
Public Property Get accName() 'As String
accName = maccName
End Property
Public Property Let accName(ByVal Value )
maccName = Value
End Property
End class
Set myaccount = new Account
myaccount.accId = "ABC"
myaccount.accName = "ABC"
strSuccess = objWebSvcClient.setAccount(myaccount)
Please let me know If I am missing out some Information.
Reference to some examples doing the same implementation would also be helpfull.
the statement objWebSvcClient.MSSoapInit ("c:\TestAsp.wsdl") is setting a physical file as a URL. You can parse WSDL this way but the URLs given in the wsdl itself may not working or are with relatively path which will fail.
Try giving the full http url even for the wsdl file.
We are developing a restful api using jersey (1.9.1) and tomcat 5.5.
A given resource is identified with a urn and we would like to address a specific instance of that resource. In order to achieve this, we used the following code:
#Path("/XXXs")
public interface XXXResource {
#GET
#Path("{id}")
#Produces({ MediaType.APPLICATION_JSON })
XXXInfo getXXX(#PathParam("id") String id);
}
The idea is to address this resource using the following url:
http://localhost:8080/restapi/XXXs/http%3A%2F%2Fns.something.com%2FXXX%2F2
The decoded path param value should be:
http://ns.something.com/XXX/2
However, when I make the request using the encoded url I get a bad request message from tomcat. So my questions are:
Is it correct to use a Urn as a path parameter?
Why is tomcat considering this request as a bad request?
Just in case, I changed the signature of the method so that the parameter is taken from the query string and it worked fine, but I want the parameter to be part of the path.
Thanks.
Ok, I solved it by adding the following line in catalina.properties:
org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true