Basic Authentication Java SOAP WebService Client - java

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.

Related

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?

Can't cast ServiceClient to WSBindingProvider

So I have this web service(based on axis2) which is supposed to act as a client to other web service. But when trying to cast my servicePort (docManClient) to WSBindingProvider I get ClassCastException error:
com.sun.proxy.$Proxy283 cannot be cast to com.sun.xml.internal.ws.developer.WSBindingProvider
What confuses me is that this code works ok when execution from simple java application, but when execution from web service it fails. Also I've noticed that when executed from simple java application docManClient is a SEIStub object but when this code is executed inside my axis2 webservice, docManClient is JAXWSProxyHandler. I don't know if that helps or what should I do.
How can I fix or analyse deeply this classcast exception? Is there a way to avoid casting it to WSBindingProvider and set headers with JAXWSProxyHandler?
Thanks in advance.
DocumentManagement_Service docManService = new DocumentManagement_Service();
DocumentManagement docManClient = docManService.getBasicHttpBindingDocumentManagement();
DocumentManagement docManClientP = docManService.getBasicHttpBindingDocumentManagement(null);
try
{
// The namespace of the OTAuthentication object
final String ECM_API_NAMESPACE = "urn:api.ecm.opentext.com";
// Create a SOAP header
SOAPHeader header = MessageFactory.newInstance().createMessage().getSOAPPart().getEnvelope().getHeader();
// Add the OTAuthentication SOAP header element
SOAPHeaderElement otAuthElement = header.addHeaderElement(new QName(ECM_API_NAMESPACE, "OTAuthentication"));
// Add the AuthenticationToken SOAP element
SOAPElement authTokenElement = otAuthElement.addChildElement(new QName(ECM_API_NAMESPACE, "AuthenticationToken"));
authTokenElement.addTextNode(authToken);
// Set the SOAP header on the docManClient
//Object pt = docManService.getPort(do);
//ServiceClient sc = docManService.getServiceClient(docManService.getServiceName())
//BindingProvider bp = ((BindingProvider) docManClient);
((WSBindingProvider) docManClient).setOutboundHeaders(Headers.create(otAuthElement));
...
DocumentManagement:
/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.2.9-b130926.1035
* Generated source version: 2.2
*
*/
"urn:xxxx")
#XmlSeeAlso({
com.opentext.ecm.api.ObjectFactory.class,
com.opentext.livelink.service.core.ObjectFactory.class,
com.opentext.livelink.service.docman.ObjectFactory.class
})
public interface DocumentManagement {
/**
*
* #param nodeID
*/
#WebMethod(operationName = "RemoveFavorite", action = "urn:xxxx/RemoveFavorite")
#RequestWrapper(localName = "RemoveFavorite", targetNamespace = "urn:xxx", className = "xxxx.RemoveFavorite")
#ResponseWrapper(localName = "RemoveFavoriteResponse", targetNamespace = "urn:xxxx", className = "xxxx.RemoveFavoriteResponse")
public void removeFavorite(
#WebParam(name = "nodeID", targetNamespace = "urn:xxxx")
long nodeID);
DocumentManagement_Service:
/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.2.9-b130926.1035
* Generated source version: 2.2
*
*/
#WebServiceClient(name = "DocumentManagement", targetNamespace = "urn:xxx", wsdlLocation = "xxxx")
public class DocumentManagement_Service
extends Service
{
static {
URL url = null;
WebServiceException e = null;
try {
url = new URL("xxxx");
} catch (MalformedURLException ex) {
e = new WebServiceException(ex);
}
DOCUMENTMANAGEMENT_WSDL_LOCATION = url;
DOCUMENTMANAGEMENT_EXCEPTION = e;
}

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

What to put in default wsdl2java implementation?

I'm trying to implement a SOAP Web Service that generates a SOAP message for managing Address Book entries. The SOAP API is from Blackboard ConnectTxt and provides a single service -"addressbook" to maintain address book entries. This service permits developers to request additions, updates and deletes to an address book by creating an appropriate SOAP message.
Using Apache CXF 2.6.1 I've generated objects from their WSDL and a default impl (below)
#javax.jws.WebService(
serviceName = "TxttoolsAddressbookServiceService",
portName = "TxttoolsAddressbookServicePort",
targetNamespace = "http://www.txttools.co.uk/connectors/soap/addressbook/definitions",
wsdlLocation = "file:/C:/Users/me/Workspaces/work/bbtxttools/src/main/resources/wsdl/txttoolsAddressbook.wsdl",
endpointInterface = "uk.co.txttools.connectors.soap.addressbook.definitions.TxttoolsAddressbookService")
public class TxttoolsAddressbookServiceImpl implements TxttoolsAddressbookService {
private static final Logger LOG = Logger.getLogger(TxttoolsAddressbookServiceImpl.class.getName());
/* (non-Javadoc)
* #see uk.co.txttools.connectors.soap.addressbook.definitions.TxttoolsAddressbookService#addressbook(uk.co.txttools.connectors.soap.addressbook.schemas.AddressbookRequest addressbookRequest )*
*/
public uk.co.txttools.connectors.soap.addressbook.schemas.AddressbookResponse addressbook(uk.co.txttools.connectors.soap.addressbook.schemas.AddressbookRequest addressbookRequest) {
LOG.info("Executing operation addressbook");
System.out.println(addressbookRequest);
try {
uk.co.txttools.connectors.soap.addressbook.schemas.AddressbookResponse _return = null;
return _return;
} catch (java.lang.Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex);
}
}
}
The addressbook method simply returns an empty response. I'm baffled as to what should go in here. I would have expected to code some DAOs to provide data but the method appears to do nothing. I'm obviously missing a trick somewhere. The AddressBookService is included:
#WebService(targetNamespace = "http://www.txttools.co.uk/connectors/soap/addressbook/definitions", name = "TxttoolsAddressbookService")
#XmlSeeAlso({uk.co.txttools.connectors.soap.addressbook.schemas.ObjectFactory.class})
#SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
public interface TxttoolsAddressbookService {
#WebResult(name = "AddressbookResponse", targetNamespace = "http://www.txttools.co.uk/connectors/soap/addressbook/schemas", partName = "AddressbookResponse")
#WebMethod(operationName = "Addressbook")
public uk.co.txttools.connectors.soap.addressbook.schemas.AddressbookResponse addressbook(
#WebParam(partName = "AddressbookRequest", name = "AddressbookRequest", targetNamespace = "http://www.txttools.co.uk/connectors/soap/addressbook/schemas")
uk.co.txttools.connectors.soap.addressbook.schemas.AddressbookRequest addressbookRequest
);
}
Any suggestions would be appreciated.
Andrew

Soap Mismatch between Java model and WSDL model found

I'm developing an SOAP Service in Java but i encountered this error:
WARNING: Mismatch between Java model and WSDL model found, For wsdl operation
{http://database.unitn.it/}isLoginOkay,There is no matching wsdl fault with detail
QName {http://interfaces.database.unitn.it/}Exception
com.sun.xml.internal.ws.spi.db.DatabindingException: Unknown JAXBContext
implementation: class com.sun.xml.bind.v2.runtime.JAXBContextImpl
at com.sun.xml.internal.ws.spi.db.BindingContextFactory.getJAXBFactory(BindingContextFactory.j
ava:192)
at com.sun.xml.internal.ws.spi.db.BindingContextFactory.create(BindingContextFactory.java:134)
at com.sun.xml.internal.ws.message.jaxb.JAXBMessage.create(JAXBMessage.java:152)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createSOAPFaultMessage(SOAPFaultBuilder.java:241)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createSOAPFaultMessage(SOAPFaultBuilder.java:224)
at com.sun.xml.internal.ws.wsdl.PayloadQNameBasedOperationFinder.getWSDLOperationMapping(PayloadQNameBasedOperationFinder.java:143)
at com.sun.xml.internal.ws.wsdl.OperationDispatcher.getWSDLOperationMapping(OperationDispatcher.java:82)
at com.sun.xml.internal.ws.api.message.Packet.getWSDLOperationMapping(Packet.java:285)
at com.sun.xml.internal.ws.api.message.Message.getOperation(Message.java:284)
at com.sun.xml.internal.ws.api.message.Message.getOperation(Message.java:302)
at com.sun.xml.internal.ws.api.message.Message.isOneWay(Message.java:379)
...
I am working with java 1.8 and everything run on localhost. The wsdl seams to work fine.
I do not know what the problem could be. I tried a lot to solve the problem but I have not four no one thread that talk about this problem.
Please help.
EDIT:
Here the publisher:
private static final String mUrl = "http://localhost:" + Ports.MASTER_DATABASE_SERVICE + "/database";
public static void launch() throws Exception
{
System.out.println("----Starting on ..." + mUrl);
Endpoint.publish(mUrl, new Database());
System.out.println("----SOAP Service started!!!!");
}
Here the interface for the client part:
#WebService
#SOAPBinding(style = Style.RPC)
public interface DatabaseAPIsInterface
{
#WebMethod
public User isLoginOkay(String password, String email) throws Exception;
}
Here the implementation of the method isLoginOkay(...)
#Override
public User isLoginOkay(String password, String email) throws Exception
{
Database db = null;
try
{
db = fromConnectionPool();
Dao<User, Integer> dao = createPersonDAO(db);
throwIfSomeNull(password, email);
QueryBuilder<User, Integer> builder = dao.queryBuilder();
User user = builder.where().eq(User.FIELD_NAME_EMAIL, email).and().eq(User.FIELD_NAME_PASSWORD, password).queryForFirst();
if (user != null) return user;
else throw new FileNotFoundException("User does not exist");
} finally
{
close(db);
}
}
And here the client part:
String mUrl = "http://localhost:" + Ports.MASTER_DATABASE_SERVICE + "/database?wsdl";
URL url = new URL(mUrl);
QName qname = new QName("http://database.unitn.it/", "DatabaseService");
Service service = Service.create(url, qname);
DatabaseInterface database = service.getPort(new QName("http://database.unitn.it/", "DatabasePort"), DatabaseAPIsInterface.class);
User user = database.isLoginOkay(password, email);
System.out.println(user);

Categories

Resources