i have a service of SOAP webservice that return ArrayList<String[]>. When i call it from client, eclipse says me that service don't return ArrayList<String[]> but List<StringArray>.
StringArray don't seems to be a java data type, and i would know how i can convert it to String[] and extract data from it.
this is client imported file contains method for retrieve data:
#WebService(name = "Functions", targetNamespace = "http://example.com/")
#XmlSeeAlso({
ObjectFactory.class
})
public interface Functions {
/**
*
* #return
* returns java.util.List<com.example.StringArray>
*/
#WebMethod
#WebResult(targetNamespace = "")
#RequestWrapper(localName = "getData", targetNamespace = "http://example.com/", className = "com.example.GetData")
#ResponseWrapper(localName = "getDataResponse", targetNamespace = "http://example.com/", className = "com.example.GetDataResponse")
#Action(input = "http://example.com/Functions/getDataRequest", output = "http://example.com/Functions/getDataResponse")
public List<String[]> getData();
this is how this function is declared on server:
#WebMethod
public ArrayList<String[]> getData() {
// invoked by android app
dataStore = DatastoreServiceFactory.getDatastoreService();
ArrayList<Entity> list = (ArrayList<Entity>) dataStore.prepare(query).asList(FetchOptions.Builder.withLimit(100));
if (!list.isEmpty()) {
ArrayList<String[]> res=new ArrayList<String[]>();
String[] to_add;
// convert entity into strings
for (Entity current : list) {
to_add=new String[3];
to_add[0]=String.valueOf(current.getProperty(TEMP_ROW));
to_add[1]=String.valueOf(current.getProperty(HUM_ROW));
to_add[2]=String.valueOf(current.getProperty(DATE_ROW));
res.add(to_add);
}
return res;
}
return null;
}
You can use the toArray() method from the Collection
List<String> myList = myClient.getData();
String[] myArray = myList.toArray();
Related
#Path("/submit")
public List<SaveCResponse> submitC(List<Long> ids) {
ICService cService = CServiceBootstrap.getCService();
List<SaveCResponse> cResponses = new ArrayList<>();
for (Long id : ids) {
SaveCResponse cResponse = cService.reSubmitC(id);
cResponses.add(cResponse);
}
return cResponses;
}
How to call the above method using postman. I mean how to pass list of IDs ?
I am able to create order using square(v2/locations/location_id/orders)api and getting order id. But I am not able to get this order details and also how I can see this created order on square dashboard? please help me.
I am using the below method for doing it:
public CreateOrderResponse createOrder(String locationId, CreateOrderRequest body) throws ApiException {
Object localVarPostBody = body;
// verify the required parameter 'locationId' is set
if (locationId == null) {
throw new ApiException(400, "Missing the required parameter 'locationId' when calling createOrder");
}
// verify the required parameter 'body' is set
if (body == null) {
throw new ApiException(400, "Missing the required parameter 'body' when calling createOrder");
}
// create path and map variables
String localVarPath = "/v2/locations/{location_id}/orders".replaceAll("\\{" + "location_id" + "\\}",
apiClient.escapeString(locationId.toString()));
// query params
List<Pair> localVarQueryParams = new ArrayList<Pair>();
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
final String[] localVarAccepts = { "application/json" };
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
final String[] localVarContentTypes = { "application/json" };
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
String[] localVarAuthNames = new String[] { "oauth2" };
GenericType<CreateOrderResponse> localVarReturnType = new GenericType<CreateOrderResponse>() {
};
CompleteResponse<CreateOrderResponse> completeResponse = (CompleteResponse<CreateOrderResponse>) apiClient
.invokeAPI(localVarPath, "POST", localVarQueryParams, localVarPostBody, localVarHeaderParams,
localVarFormParams, localVarAccept, localVarContentType, localVarAuthNames,
localVarReturnType);
return completeResponse.getData();
}
Thanks
The orders endpoint is only for creating itemized orders for e-commerce transactions. You won't see them anywhere until you charge them, and then you'll see the itemizations for the order in your dashboard with the transaction.
I am trying to make a client connect to a web service and use a SetFlight method on the server.
The environment is Intellij Ultimate, Java 7, and JAXWS. The generation of the classes from the WSDL has been done.
Among the generated classes I have two services:
#WebServiceClient(name = "FOService", targetNamespace = "http://temporaryuri.org.au/", wsdlLocation = "http://fovanil.com/FOService.svc?wsdl")
public class FOService
extends Service
{
private final static URL FOSERVICE_WSDL_LOCATION;
private final static WebServiceException FOSERVICE_EXCEPTION;
private final static QName FOSERVICE_QNAME = new QName("http://temporaryuri.org.au/", "FOService");
static {
...
And the IFO service
#WebService(name = "IFOService", targetNamespace = "urn:fo.com.au/schema/common")
#SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
#XmlSeeAlso({
ObjectFactory.class
})
public interface IFOService {
/**
*
* #param parameters
* #return
* returns svc.SetFlightResponse
*/
#WebMethod(operationName = "SetFlight", action = "http://fo.com.au/SetFlight")
#WebResult(name = "SetFlightResponse", targetNamespace = "urn:fo.com.au/schema/common/types", partName = "parameters")
public SetFlightResponse SetFlight(
#WebParam(name = "SetFlightRequest", targetNamespace = "urn:fo.com.au/schema/common/types", partName = "parameters")
SetFlightRequest parameters);
}
I have looked at some examples of implementing a client https://docs.oracle.com/javaee/5/tutorial/doc/bnayn.html however this differs.
I would have thought using this would be:
IFOSerice service = new IFOService();
service.SetFlight(someinstanceofflight); //setFlight is not a available method
How do I make a client and use the SetFlight method?
This code worked:
SetFORequest request = new SetFORequest();
SetFOResponse response = new SetFOResponse();
request.setFO(flight);
FOService foService = new FOService();
IfoService ifoService = foService.getWSHttpBindingIFOService();
ifoService.setFO(request);
I have these two classes and I want to make them work. The problem is this line:
TranslationResult translationResult = service.translate(lista.get(0).toString(), Language.PORTUGUESE, Language.ENGLISH).execute();
I want it to receive a list containing a list value something like:
TranslationResult translationResult = service.translate(lista.get(0).toString(), lista.get(1).toString() , lista.get(2).toString()).execute();
I want it to receive a list containing a list value something like:
import com.ibm.watson.developer_cloud.language_translation.v2.model.TranslationResult;
import Teste.Watson;
import java.util.Map;
public class Cognitive implements Serializable {
static public String Translate(ArrayList lista) {
LanguageTranslation service = new LanguageTranslation();
service.setUsernameAndPassword(lista.get(3).toString(), lista.get(4).toString());
TranslationResult translationResult = service.translate(lista.get(0).toString(), Language.PORTUGUESE, Language.ENGLISH).execute();
String translation = translationResult.getFirstTranslation();
return translation;
}
}
Class Test:
public class Watson {
public static void main(String[] args) {
ArrayList<Object> lista = new ArrayList<>();
lista.add("Isse texto vai virar ingles");
lista.add(Language.PORTUGUESE);
lista.add(Language.ITALIAN);
lista.add("adm");
lista.add("password");
String result= Cognitive.Translate(lista);
System.out.println(result);
}
}
I tried that way but gives this error:
static public String Translate(ArrayList lista){
LanguageTranslation service = new LanguageTranslation();
final Language srcLang;
final Language srcDest;
srcLang = (Language) lista.get(1);
srcDest = (Language) lista.get(2);
service.setUsernameAndPassword(lista.get(3).toString(), lista.get(4).toString());
TranslationResult translationResult = service.translate(lista.get(0).toString(), srcLang, srcDest).execute();
String translation = translationResult.getFirstTranslation();
return translation;
}
Error:
jun 30, 2016 10:09:50 AM com.ibm.watson.developer_cloud.service.WatsonService processServiceCall
GRAVE: POST https://gateway.watsonplatform.net/language- translation/api/v2/translate, status: 404, error: cannot find service matching the request data
Exception in thread "main" com.ibm.watson.developer_cloud.service.exception.NotFoundException: cannot find service matching the request data
at com.ibm.watson.developer_cloud.service.WatsonService.processServiceCall(WatsonService.java:381)
at com.ibm.watson.developer_cloud.service.WatsonService$1.execute(WatsonService.java:170)
at ibm.Cognitive.Translate(Cognitive.java:28)
at Teste.Watson.main(Watson.java:21)
Instead of using a List which is a strange and hacky solution, you should instead just have parameters for your method:
public class Cognitive implements Serializable {
public static String translate(final String text, final Language srcLang, final Language destLang, final String username, final String password) {
LanguageTranslation service = new LanguageTranslation();
service.setUsernameAndPassword(username, password);
TranslationResult translationResult = service.translate(text, srcLang, destLang).execute();
return translationResult.getFirstTranslation();
}
}
I have generated a Metro/JAXB client from a WSDL before and the marshalling/unmarshalling of the Java classes to/from SOAP/XML worked without any issues. I have generated a new client and there seems to be unmarshalling issues and I'm not sure why. The WSDL is very large (> 27,000 lines) and I had to use -B-XautoNameResolution because of some element names being the same except for case.
I am trying to execute this method/operation:
#WebService(name = "servicePortType", targetNamespace = "urn:service")
#XmlSeeAlso({
ObjectFactory.class
})
public interface ServicePortType {
/**
* Service definition of function unsp__GetSubscriberList
*
* #param result
* #param totalSubsFound
* #param getSubListReq
* #param paginatedInfo
* #param getSubscriberListData
*/
#WebMethod(operationName = "GetSubscriberList")
#RequestWrapper(localName = "GetSubscriberList", targetNamespace = "urn:service", className = "service.GetSubscriberList")
#ResponseWrapper(localName = "GetSubscriberListResult", targetNamespace = "urn:service", className = "service.GetSubscriberListResult")
public void getSubscriberList(
#WebParam(name = "GetSubListReq", targetNamespace = "")
GetSubscriberListRequest getSubListReq,
#WebParam(name = "Result", targetNamespace = "", mode = WebParam.Mode.OUT)
Holder<ResultCodeStruct> result,
#WebParam(name = "PaginatedInfo", targetNamespace = "", mode = WebParam.Mode.OUT)
Holder<PaginatedInfo> paginatedInfo,
#WebParam(name = "TotalSubsFound", targetNamespace = "", mode = WebParam.Mode.OUT)
Holder<Integer> totalSubsFound,
#WebParam(name = "GetSubscriberListData", targetNamespace = "", mode = WebParam.Mode.OUT)
Holder<GetSubscriberListData> getSubscriberListData);
}
This method will return the subscriber data and also the total number of subscribers. My call looks like this:
public int getTotalSubscriptions()
throws Exception
{
GetSubscriberListRequest subscriberListRequest = factory.createGetSubscriberListRequest();
Holder<ResultCodeStruct> result = null;
Holder<PaginatedInfo> paginatedInfo = null;
Holder<Integer> totalSubsFound = null;
Holder<GetSubscriberListData> subscriberListData = null;
subscriberListRequest.setMaxSubscribers(factory.createGetSubscriberListRequestMaxSubscribers(1));
port.getSubscriberList(subscriberListRequest,
result,
paginatedInfo,
totalSubsFound,
subscriberListData);
if (result.value.getResultCode() != CODE_SUCCESS)
{
throw new Exception("Failed call");
}
return totalSubsFound.value.intValue();
}
I get a NullPointerException on the result object. I have traced the SOAP call and the XML being returned is as expected including a Result element.
I have never encountered WebParam.Mode.OUT before. Should the Holder<> instances be initialized before I make the call? To what?
Those elements are wrapped in a GetSubscriberListResult element in the SOAP, but since the interface method has that defined in the #ResponseWrapper, I was expecting them to be unmarshalled into the objects passed in. Maybe I need to do something else?
Any advice/help is greatly appreciated!
Spent quite a bit of time searching on the internet and found an older reference stating that the Holder objects do need to be initialized. So, the corrected method calls looks like this:
public int getTotalSubscriptions()
throws Exception
{
GetSubscriberListRequest subscriberListRequest = factory.createGetSubscriberListRequest();
Holder<ResultCodeStruct> result = new Holder<ResultCodeStruct>(factory.createResultCodeStruct());
Holder<PaginatedInfo> paginatedInfo = new Holder<PaginatedInfo>(factory.createPaginatedInfo());
Holder<Integer> totalSubsFound = new Holder<Integer>(new Integer(0));
Holder<GetSubscriberListData> subscriberListData = new Holder<GetSubscriberListData>(factory.createGetSubscriberListData());
subscriberListRequest.setMaxSubscribers(factory.createGetSubscriberListRequestMaxSubscribers(1));
port.getSubscriberList(subscriberListRequest,
result,
paginatedInfo,
totalSubsFound,
subscriberListData);
if (result.value.getResultCode() != CODE_SUCCESS)
{
throw new Exception("Failed call");
}
return totalSubsFound.value.intValue();
}
Hope this helps others who may have encountered the same issue.