• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Whether JAX-RPC Calls are supported from a Portlet?

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Iam Accessing a webservice from a portlet using the RPC Calls for which the code is as shown below.

Call call = _service.createCall(_port,"sayHi");
QName qn = new QName( "urn:SampleService", "strHello" );
call.setOperationName( new QName("SampleService", "sayHi") );
call.addParameter( "strHello", _qnameNS_XSD, ParameterMode.IN);
call.setReturnType( org.apache.axis.encoding.XMLType.XSD_STRING );
String str = "HI";
String strVal = (String)call.invoke( new Object[] {str} );

Iam getting the below error

[#|2008-04-03T11:55:43.597+0530|WARNING|sun-appserver9.1|javax.enterprise.system.stream.err|_ThreadID=37;_ThreadName=httpSSLWorkerThread-8080-1;_RequestID=04cd65a4-840f-4f24-b758-3b11e919c5ba;|
com.test.HelloServiceException: Can not get hello: operation style: "rpc" not supported
at com.test.HelloService.getHello(HelloService.java:107)

Any hints?

Thanks & regards
Srikanth
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
one could use that createCall(PortName) on a Service with a full wsdl and invoke a setOperationName() on it and have a fully funtional Call object. Now users will need to set all the information in that Call instance including parameter types, endpoint address, encoding type and so on...
 
viswam konkepudi
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The createCall(String portName) API from the Service interface when created with a full WSDL information will no longer return a fully initialize Call object that could be used directly after setting the operation name with the setOperationName(String operationName) API. Call instances returned from the createCall(String portName) will be uninitialized and all the parameter types, return type, encoding style and endpoint address will need to be set before the invoke() API is used.
 
Srikanth Ganji
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have set all the parameters before Invoking but not able to Invoke the webservice method.
Any Idea how to Invoke?
Below is the code
=============
Iam calling the below class from the portlets doView Method.

public void doView(RenderRequest request,RenderResponse response) throws PortletException,IOException {
//Uncomment below lines to see the output
response.setContentType("text/html");
PrintWriter writer = response.getWriter();
String strHello ="HISRI";
try{
System.out.println("Before Invoking the Hello Service get hello Method");
String str = _helloService.getHello(strHello);
System.out.println("After Invoking the Hello Service get hello Method");
//String strHi = new HelloWebServiceServiceLocator().getHelloWebServicePort().sayHi(strHello);
writer.print(str);
}
catch(Exception e){
e.printStackTrace();
}
PortletRequestDispatcher requestdispatch =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/HelloWorld_help.jsp");

requestdispatch.include(request, response);
writer.println("View Mode");
}

package com.test;

import javax.xml.rpc.ServiceException;
import javax.xml.rpc.ServiceFactory;
import javax.xml.rpc.Service;
import javax.xml.rpc.Call;
import javax.xml.rpc.ParameterMode;
import javax.xml.namespace.QName;
import javax.xml.*;


public class HelloService {

private static String ENCODING_STYLE_PROPERTY =
"javax.xml.rpc.encodingstyle.namespace.uri";
private static String NS_XSD =
"http://www.w3.org/2001/XMLSchema";
private static String URI_ENCODING =
"http://schemas.xmlsoap.org/soap/encoding/";
private static String NAMESPACE_URI = "urn:xmethods-Hello-Demo";
private static String HELLO_SERVICE = "HelloWebService";
private static String HELLO_PORT = "HelloWebPort";

private Service _service;
private QName _port;
private String _endPointAddr;
private QName _qnameTypeFloat;
private QName _qnameNamespaceURI;
private QName _qnameNS_XSD;
private String _defTemp;

public HelloService(String endPointAddr) throws
HelloServiceException {
try {
ServiceFactory factory = ServiceFactory.newInstance();
_service = factory.createService(new QName(HELLO_SERVICE));
_port = new QName(HELLO_PORT);
} catch (ServiceException se) {
throw new HelloServiceException("Can not create Hello service: " + se.getMessage());
}

_endPointAddr = endPointAddr;
_qnameTypeFloat = new QName(NS_XSD, "float");
_qnameNamespaceURI = new QName(NAMESPACE_URI, "sayHi");
_qnameNS_XSD = new QName(NS_XSD, "string");
_defTemp = "HiSri";
}

public String getHello(String strHello)
throws HelloServiceException {
Object result = null;
String[] params = {"Hi"};

try {
Call call = _service.createCall(_port);
call.setTargetEndpointAddress(_endPointAddr);
call.setProperty(Call.SOAPACTION_USE_PROPERTY,
Boolean.TRUE);
call.setProperty(Call.SOAPACTION_URI_PROPERTY, "");
call.setProperty(ENCODING_STYLE_PROPERTY, URI_ENCODING);
call.setOperationName(_qnameNamespaceURI);
call.addParameter("String_1", _qnameNS_XSD, ParameterMode.IN);

call.setReturnType(_qnameTypeFloat);
// Call call = _service.createCall(_port);
result = call.invoke((Object[])params);
} catch (Exception ex) {
throw new HelloServiceException("Can not get Hello: " + ex.getMessage());

}

String temp = _defTemp;
if (result != null) {
temp = result.toString();
}

return temp;
}

public void destroy() {
_service = null;
_port = null;
_endPointAddr = null;
_qnameTypeFloat = null;
_qnameNamespaceURI = null;
_qnameNS_XSD = null;
_defTemp = null;
}

}
=============
Regards
Srikanth
 
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
use WSDL2JAVA to create the client stub. most of the proxy and client side
code is generated automatically. What you need to do is to retrieve
whatever you need from the web service and do what ever you want to do.
Try wsdl2java first in google.
[ April 28, 2008: Message edited by: damu liu ]
 
Weeds: because mother nature refuses to be your personal bitch. But this tiny ad is willing:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic