Amazon API SOAP code generation from WSDL, Intellij - java

I generated Java code from the Amazon WSDL found here in Intellij. It appeared to have worked great. However, as I followed the tutorial found on this page I encountered a problem. The last line of the java code is calling a method itemSearch from the AWSECommerceServicePortType class. The only method description that was generated for that method was
#WebMethod(operationName = "ItemSearch", action = "http://soap.amazon.com/ItemSearch")
#RequestWrapper(localName = "ItemSearch", targetNamespace = "http://webservices.amazon.com/AWSECommerceService/2011-08-01", className = "com.shopit.amazon.ItemSearch")
#ResponseWrapper(localName = "ItemSearchResponse", targetNamespace = "http://webservices.amazon.com/AWSECommerceService/2011-08-01", className = "com.shopit.amazon.ItemSearchResponse")
public void itemSearch(
#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 = "XMLEscaping", targetNamespace = "http://webservices.amazon.com/AWSECommerceService/2011-08-01")
String xmlEscaping,
#WebParam(name = "Validate", targetNamespace = "http://webservices.amazon.com/AWSECommerceService/2011-08-01")
String validate,
#WebParam(name = "Shared", targetNamespace = "http://webservices.amazon.com/AWSECommerceService/2011-08-01")
ItemSearchRequest shared,
#WebParam(name = "Request", targetNamespace = "http://webservices.amazon.com/AWSECommerceService/2011-08-01")
List<ItemSearchRequest> 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);
It requires that I pass a lot more parameters than just the one it does in the example and it gives and error when compiling. Do I need to use a different setting for generating the java code.

you can use amazon-ecs.jar for amazon product api

I think much better to use official aws sdk for java: http://aws.amazon.com/sdkforjava/

Related

wsdl2java - how to force wrapped response return type instead of using out parameters wrapped in Holders?

Using wsdl2java tool to generate client classes, I can't seem to able to force to wrap Web Service response in a return type - the return type is always void and OUT parameters wrapped in Holders are generated. Auth.java auto-generated client interface looks like this:
#WebService(targetNamespace = "http://xml.kamsoft.pl/ws/auth", name = "Auth")
#XmlSeeAlso({pl.kamsoft.xml.ws.common.ObjectFactory.class, pl.kamsoft.xml.ws.kaas.login_types.ObjectFactory.class})
#SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public interface Auth {
// [...] - `logout`, `changePassword`, `changePasswordLog` methods
#WebMethod(action = "login")
public void login(
#WebParam(partName = "request", name = "login", targetNamespace = "http://xml.kamsoft.pl/ws/kaas/login_types")
pl.kamsoft.xml.ws.kaas.login_types.LoginRequest request,
#WebParam(partName = "response", mode = WebParam.Mode.OUT, name = "loginReturn", targetNamespace = "http://xml.kamsoft.pl/ws/kaas/login_types")
jakarta.xml.ws.Holder<java.lang.String> response,
#WebParam(partName = "session", mode = WebParam.Mode.OUT, name = "session", targetNamespace = "http://xml.kamsoft.pl/ws/common", header = true)
jakarta.xml.ws.Holder<pl.kamsoft.xml.ws.common.Session> session,
#WebParam(partName = "token", mode = WebParam.Mode.OUT, name = "authToken", targetNamespace = "http://xml.kamsoft.pl/ws/common", header = true)
jakarta.xml.ws.Holder<pl.kamsoft.xml.ws.common.AuthToken> token
) throws pl.kamsoft.wsdl.common.AuthenticationExceptionMsg, pl.kamsoft.wsdl.common.ServerExceptionMsg, PassExpiredExceptionMsg, pl.kamsoft.wsdl.common.AuthTokenExceptionMsg, pl.kamsoft.wsdl.common.InputExceptionMsg, pl.kamsoft.wsdl.common.AuthorizationExceptionMsg;
}
Minimal example (build.gradle.kts file with Gradle configuration):
plugins {
java
id("com.yupzip.wsdl2java") version "3.0.0"
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
repositories {
mavenCentral()
}
dependencies {
implementation("org.apache.cxf:cxf-rt-frontend-jaxws:4.0.0")
implementation("org.apache.cxf:cxf-rt-transports-http-hc5:4.0.0")
wsdl2java("com.sun.xml.bind:jaxb-impl:4.0.1")
wsdl2java("org.apache.cxf.xjc-utils:cxf-xjc-runtime:4.0.0")
wsdl2java("jakarta.xml.ws:jakarta.xml.ws-api:4.0.0")
wsdl2java("com.sun.xml.ws:rt:4.0.0")
wsdl2java("org.jvnet.jaxb2_commons:jaxb2-namespace-prefix:2.0")
wsdl2java("codes.rafael.jaxb2_commons:jaxb2-basics-runtime:3.0.0")
wsdl2java("codes.rafael.jaxb2_commons:jaxb2-basics:3.0.0")
}
wsdl2java {
wsdlDir = file("$projectDir/src/main/resources/")
includeJava8XmlDependencies = false
cxfVersion = "4.0.0"
cxfPluginVersion = "4.0.0"
wsdlsToGenerate = listOf(
listOf(
"-wsdlLocation", "https://ewus.nfz.gov.pl/ws-broker-server-ewus-auth-test/services/Auth?wsdl",
"-autoNameResolution",
"https://ewus.nfz.gov.pl/ws-broker-server-ewus-auth-test/services/Auth?wsdl",
)
)
}
How can I force wsdl2java tool to generate LoginResponse class of which instance would be returned on Auth#login invocation?
I've tried to include binding file (bindings.xml):
<bindings
wsdlLocation="https://ewus.nfz.gov.pl/ws-broker-server-ewus-auth-test/services/Auth?wsdl"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://java.sun.com/xml/ns/jaxws">
<enableWrapperStyle>false</enableWrapperStyle>
</bindings>
but neither setting enableWrapperStyle to false or true did change anything. Here is how my configuration looked like (build.gradle.kts):
wsdl2java {
wsdlDir = file("$projectDir/src/main/resources/")
includeJava8XmlDependencies = false
cxfVersion = "4.0.0"
cxfPluginVersion = "4.0.0"
wsdlsToGenerate = listOf(
listOf(
"-b", "$projectDir/src/main/resources/wsdl/bindings.xml",
"-wsdlLocation", "https://ewus.nfz.gov.pl/ws-broker-server-ewus-auth-test/services/Auth?wsdl",
"-autoNameResolution",
"https://ewus.nfz.gov.pl/ws-broker-server-ewus-auth-test/services/Auth?wsdl",
)
)
}
Can the fact that both session and token are declared as wsdlsoap:header have impact on the resulting generated Java code?

Dropwizard-Jaxws library soap client request

I am consuming a soap service using dropwizard-jaxws.
Managed to generate the relevant java classes using Apache CXF 3.4. Here's the generated interface IService.
#WebService(targetNamespace = "http://tempuri.org/", name = "IService")
#XmlSeeAlso({ObjectFactory.class})
#SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public interface IService {
#WebMethod(operationName = "PayBill", action = "http://tempuri.org/IService/PayBill")
#Action(input = "http://tempuri.org/IService/PayBill", output = "http://tempuri.org/IService/PayBillResponse")
#WebResult(name = "PayBillResponse", targetNamespace = "http://tempuri.org/", partName = "parameters")
public PayBillResponse payBill(
#WebParam(partName = "parameters", name = "PayBill", targetNamespace = "http://tempuri.org/")
PayBill parameters
);
I wrote this implementing class IserviceImpl in kotlin
#WebService(endpointInterface = "com.mmm.platform.utility.easy.IService",
targetNamespace = "http://tempuri.org/",
name = "IService",
wsdlLocation = "wsdl/mmm-easy.wsdl")
class IServiceImpl: IService {
override fun payBill(parameters: PayBill?): PayBillResponse {
var response = PayBillResponse();
response.setSctrxnid(parameters?.sctxnid);
return response;
}
This is my dropwizard Application class in kotlin
class UtilityServiceApplication : Application<UtilityServiceConfiguration>() {
private val jaxWsBundle = JAXWSBundle<Any>()
override fun initialize(bootstrap: Bootstrap<UtilityServiceConfiguration>?) {
bootstrap?.addBundle(jaxWsBundle)
}
override fun run(configuration: UtilityServiceConfiguration?, environment: Environment?) {
environment!!.jersey().register(
AccessEasyServiceResource(
jaxWsBundle.getClient(
ClientBuilder(IService::class.java,
"http://mmm.hhhhh.xyz/EMTerminalAPI/wsdl.svc")
.handlers(AccessEasyClientHandler()))))
}
}
Dropwizard resource class AccessServiceResource in kotlin for end-point /paybillone
#Path("/paybillone")
#Produces(MediaType.APPLICATION_JSON)
public class AccessServiceResource {
var serviceClient: IService? = null
constructor(serviceClient: IService) {
this.serviceClient = serviceClient;
}
#GET
#Timed
fun getFoo(): String {
val of = ObjectFactory()
var payBill = of.createPayBill()
payBill.sctxnid = of.createPayBillSctxnid(RandomStringUtils.randomAlphanumeric(15))
payBill.txntype = of.createPayBillTxntype("1")
payBill.payeecode = of.createPayBillPayeecode("POWER")
payBill.accountno = of.createPayBillAccountno("04246483624")
payBill.phoneno = of.createPayBillPhoneno("0700252181")
payBill.amount = of.createPayBillAmount("5000")
var payBillResponse = serviceClient?.payBill(payBill)
return payBillResponse?.receiptno?.value.toString()
}
This call var payBillResponse = serviceClient?.payBill(payBill) unfortunately returned an error response message missing mandatory values yet I clearly added them to the payBill object.
Qn 1 Is this the correct way of creating the request object, so I get the correct corresponding response payBillResponse?
Qn 2 How and where should I pass payBill so I get the correct response to that call?
Qn 3 The other issue is most likely my implementation of IServiceImpl is wrong, is it even required?

InvocationTargetException with target: javax.xml.ws.WebServiceException: java.util.NoSuchElementException

I am receiving:
InvocationTargetException with target:
javax.xml.ws.WebServiceException: java.util.NoSuchElementException.
The exception is thrown on:
#WebMethod(operationName = "AliveTest")
#WebResult(name = "AliveTestAcknowledgement", targetNamespace = "http://.../AfterSalesPackageCatalogueService/V2")
#RequestWrapper(localName = "ProcessAliveTest", targetNamespace = "http://.../V2", className = "com....aftersalespackagecatalogueservice.v2.ProcessAliveTestType")
#ResponseWrapper(localName = "AcknowledgeAliveTest", targetNamespace = "http://.../AfterSalesPackageCatalogueService/V2", className = "com.....aftersalespackagecatalogueservice.v2.AcknowledgeAliveTestType")
public AliveTestAcknowledgementType AliveTest()
throws Fault
;
The response object comes properly.

Basic Authentication Java SOAP WebService Client

java artifacts for Soap Web Service Client using wsimport from a WSDL. Which produced:
AppPortalSMupdate.java with some sample code from it
public interface AppPortalSMupdate {
#WebMethod(operationName = "RetrieveAppPortalSMupdate", action = "Retrieve")
#WebResult(name = "RetrieveAppPortalSMupdateResponse", targetNamespace = "http://schemas.hp.com/SM/7", partName = "RetrieveAppPortalSMupdateResponse")
public RetrieveAppPortalSMupdateResponse retrieveAppPortalSMupdate(
#WebParam(name = "RetrieveAppPortalSMupdateRequest", targetNamespace = "http://schemas.hp.com/SM/7", partName = "RetrieveAppPortalSMupdateRequest")
RetrieveAppPortalSMupdateRequest retrieveAppPortalSMupdateRequest);
AppPortalSMupdate_Service.java
#WebServiceClient(name = "AppPortalSMupdate", targetNamespace = "http://schemas.hp.com/SM/7", wsdlLocation ="http://ss_user:sqzblsft#msmapptst001.lvh.com:13088/SM/7/AppPortalSMupdate.wsdl")
public class AppPortalSMupdate_Service extends Service{
private final static URL APPPORTALSMUPDATE_WSDL_LOCATION;
private final static WebServiceException APPPORTALSMUPDATE_EXCEPTION;
private final static QName APPPORTALSMUPDATE_QNAME = new QName("http://schemas.hp.com/SM/7", "AppPortalSMupdate");
static {
URL url = null;
WebServiceException e = null;
try {
url = new URL("http://ss_user:sqzblsft#msmapptst001.lvh.com:13088/SM/7/AppPortalSMupdate.wsdl");
} catch (MalformedURLException ex) {
e = new WebServiceException(ex);
}
APPPORTALSMUPDATE_WSDL_LOCATION = url;
APPPORTALSMUPDATE_EXCEPTION = e;
This is the call to in my main from test client class:
AppPortalSMupdate appUpdate = calc.getAppPortalSMupdate();
UpdateAppPortalSMupdateResponse appResponse = appUpdate.updateAppPortalSMupdate(requestMessage);
My question is the web service needs a user id and password. How do I add a user id and password in my call in the main. This is being used inside a liferay portlet.
use #HandlerChain annotation and configure them by implementing the SOAPHandler interface.
Let me know if you need more clarification.

long response time of webservice using ibatis and jaxws

I have a web service using JAX-WS and Ibatis, when analyzed with the New Relic tool can see that the running time is 17 seconds. Seeing the detail of the report shows that the database calls are fast, but what is delaying is this: JAXWSWebAppServlet.service (). Someone has an idea that can be ??
Thanks x your help.
PD: I would like to know where to locate JAXWSWebAppServlet.service () in my code. Any ideas??
The WS code:
#WebService(name = "WS_XXXXXX", portName = "WS_XXXXXSoap12HttpPort")
#BindingType(SOAPBinding.SOAP12HTTP_BINDING)
public class WS_GetPlanUsage {
#WebMethod(operationName = "xxxxxx")
#javax.jws.soap.SOAPBinding(parameterStyle = javax.jws.soap.SOAPBinding.ParameterStyle.WRAPPED)
public GetPlanUsageMapBean getPlanUsage(#WebParam(name = "phoneNumber", partName = "request") String phoneNumber,
#WebParam(name = "initialDate", partName = "request") String initialDate,
#WebParam(name = "finalDate", partName = "request") String finalDate) {
BReturn oBReturn = null;
GetPlanUsageResponse response = new GetPlanUsageResponse();
GetPlanUsageRequest rq = new GetPlanUsageRequest();
rq.setPhoneNumber(phoneNumber);
rq.setInitialDate(initialDate);
rq.setFinalDate(finalDate);
oBReturn = new GetPlanUsageBL().getPlanUsage(rq);
GetPlanUsageMapBean getPlanUsage = (GetPlanUsageMapBean)oBReturn.getObject();
return getPlanUsage;
}

Categories

Resources