WSDL Client from Intellij generated code - java

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);

Related

FeignClient duplicate invoke remote method

i want use invoke a remote method by use feignclient,but the remote method was execute duplicate ,this is my code(i'm not good at english,so fogive me)
#ViewScoped
#ManagedBean
#Named("cdProductTemplateView")
public class CdProductTemplateView extends BaseView {
public void cdPost() {
//cdProTempContext,just a bean
cdProductClient.cdPost(cdProTempContext);
}
}
client:
#FeignClient(value = "service", path = "/cdproduct")
public interface CdProductClient {
#RequestMapping("/cdPost")
CdProduct cdPost(#RequestBody CdProductTemplateContext
cdProTempContext) throws BusinessException, SystemException;
}
controller:
#RequestMapping("/cdproduct")
#RestController
public class CdProductController{
public CdProduct cdPostProduct(CdProductTemplateContext cdProTempContext, String resPath)
throws BusinessException, SystemException {
return cdProductService.cdPostProduct(cdProTempContext, resPath);
}
#RequestMapping("/cdPost")
public CdProduct cdPost(#RequestBody CdProductTemplateContext cdProTempContext, HttpServletRequest request) {
return cdPostProduct(cdProTempContext, resPath);
}
}
serviceImpl:
#Named("cdProductService")
public class CdProductServiceImpl implements CdProductService {
#Override
public CdProduct cdPostProduct(CdProductTemplateContext
cdProTempContext, String resPath) throws BusinessException, SystemException {
//proPkgRequset: a bean ProductPackageRequest
cdProService.submitProductPackage(proPkgRequset);
//this just invoke method(ICDMarketplaceAPIService.submitProductPackage )
}
}
ICDMarketplaceAPIService
#WebService(targetNamespace = "http://www.***.com", name = "IMarketplaceAPIService")
#XmlSeeAlso({ObjectFactory.class})
public interface ICDMarketplaceAPIService {
#WebMethod(operationName = "SubmitProductPackage")
#Action(input = "http://www.***.com/IMarketplaceAPIService/SubmitProductPackage", output = "http://www.***.com/IMarketplaceAPIService/SubmitProductPackageResponse")
#RequestWrapper(localName = "SubmitProductPackage", targetNamespace = "http://www.***.com", className = "SubmitProductPackage")
#ResponseWrapper(localName = "SubmitProductPackageResponse", targetNamespace = "http://www.***.com", className = "SubmitProductPackageResponse")
#WebResult(name = "SubmitProductPackageResult", targetNamespace = "http://www.***.com")
public ProductIntegrationReportMessage submitProductPackage(
#WebParam(name = "headerMessage", targetNamespace = "http://www.***.com")
HeaderMessage headerMessage,
#WebParam(name = "productPackageRequest", targetNamespace = "http://www.***.com")
ProductPackageRequest productPackageRequest
);
}
when client invoke remote method,the remote method(controller.cdPost,it was execute duplicate ),but if i remove method(ICDMarketplaceAPIService.submitProductPackage, or not use it) or invoke other method (like query),it's ok.What causes the situation to happen, can anyone help me?
Just add the following code in application.yml:
ribbon:
# Max number of retries on the same server (excluding the first try)
MaxAutoRetries: 0
# Max number of next servers to retry (excluding the first server)
MaxAutoRetriesNextServer: 0

WebService client returns null if run under Java 8

I have a Web Service (C#, under IIS) and WebService Client (Java code) inside a servlet which is hosted by Apache Tomcat. If Tomcat uses Java 7 then communication with the Web Service works OK, but if Tomcat uses Java 8, Web Service client method (WebMethod) returns null (for complex data). In both cases method of Web Service is invoked and works correctly (I've debugged it under Visual Studio). Here some snippets from my client's code:
proxy:
/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.1.3.1-hudson-749-SNAPSHOT
* Generated source version: 2.1
*
*/
#WebService(name = "BluePrint", targetNamespace = "artifact.wsclient.vuelink.cimmetry.com")
#XmlSeeAlso({
ObjectFactory.class
})
public interface BluePrint {
************
/**
*
* #param arg1
* #param arg0
* #return
* returns com.cimmetry.vuelink.wsclient.artifact.WsDocID
*/
#WebMethod
#WebResult(targetNamespace = "")
#RequestWrapper(localName = "openFile", targetNamespace = "artifact.wsclient.vuelink.cimmetry.com", className = "com.cimmetry.vuelink.wsclient.artifact.OpenFile")
#ResponseWrapper(localName = "openFileResponse", targetNamespace = "artifact.wsclient.vuelink.cimmetry.com", className = "com.cimmetry.vuelink.wsclient.artifact.OpenFileResponse")
public WsDocID openFile(
#WebParam(name = "arg0", targetNamespace = "")
String arg0,
#WebParam(name = "arg1", targetNamespace = "")
SessionData arg1);
and call to Web Service:
BluePrint proxy = getWSClient(beSession);
*****
WsDocID docID = proxy.openFile(orginalUrl, data);
In case of Java 8 docID variable is null.

cast StringArray to String[] inside SOAP client

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();

wsimport not using complex input types

When I use wsimport to generate proxies for some services, the resulting method signature for each port does not seem to use the complex types specified in the WSDL; but yet I've noticed that with some other services it does.
This has happened on multiple services, but the most recent example is Amazon's AWSEConsumerService (link to WSDL). When I generate the service proxy code using wsimport, I get method signatures such as the following for each port.
#WebMethod(operationName = "ItemLookup", action = "http://soap.amazon.com/ItemLookup")
#RequestWrapper(localName = "ItemLookup", targetNamespace = "http://webservices.amazon.com/AWSECommerceService/2011-08-01", className = "com.aws.CommerceService.ItemLookup")
#ResponseWrapper(localName = "ItemLookupResponse", targetNamespace = "http://webservices.amazon.com/AWSECommerceService/2011-08-01", className = "com.aws.CommerceService.ItemLookupResponse")
public void itemLookup(
#WebParam(name = "MarketplaceDomain", targetNamespace = "http://webservices.amazon.com/AWSECommerceService/2011-08-01")
String marketplaceDomain,
#WebParam(name = "AWSAccessKeyId", targetNamespace = "http://webservices.amazon.com/AWSECommerceService/2011-08-01")
String awsAccessKeyId,
#WebParam(name = "AssociateTag", targetNamespace = "http://webservices.amazon.com/AWSECommerceService/2011-08-01")
String associateTag,
#WebParam(name = "Validate", targetNamespace = "http://webservices.amazon.com/AWSECommerceService/2011-08-01")
String validate,
#WebParam(name = "XMLEscaping", targetNamespace = "http://webservices.amazon.com/AWSECommerceService/2011-08-01")
String xmlEscaping,
#WebParam(name = "Shared", targetNamespace = "http://webservices.amazon.com/AWSECommerceService/2011-08-01")
ItemLookupRequest shared,
#WebParam(name = "Request", targetNamespace = "http://webservices.amazon.com/AWSECommerceService/2011-08-01")
List<ItemLookupRequest> request,
#WebParam(name = "OperationRequest", targetNamespace = "http://webservices.amazon.com/AWSECommerceService/2011-08-01", mode = WebParam.Mode.OUT)
Holder<OperationRequest> operationRequest,
#WebParam(name = "Items", targetNamespace = "http://webservices.amazon.com/AWSECommerceService/2011-08-01", mode = WebParam.Mode.OUT)
Holder<List<Items>> items);
I would expect this method take the single complex parameter specified by the WSDL (in this case an ItemLookup object). Am I fundamentally misunderstanding something or is there something abnormal happening with the code generation?
I ran into a similar problem with AWS. I followed the API setup description for Java (page 10 of this pdf
In step 2 (it says for Eclipse 3.2) you should create a file (sugessted name is jaxws-custom.xml) with the following content:
<jaxws:bindings wsdlLocation="http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl" xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
<jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>
</jaxws:bindings>
and then run the wsimport command with the option -b jaxws-custom.xml
I haven't figured out what exactly the problem is, but that did the trick for me.

Problems parsing webservice response (Metro/JAXB)

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.

Categories