I'm trying to create a secure webservice server and client using Rampart. Web service server was created successful. But when I created client side, I got NoSuchMethodError in ServiceClient.engageModule("rampart").
Here is my client side code:
public static void main(String arg[]) throws Exception
{
ConfigurationContext ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem("E:\\axis2-1.6.2\\repository", "E:\\axis2-1.6.2\\conf\\axis2.xml");
TestStub stub = new TestStub(ctx,"http://localhost:8080/Axis2WS/services/Test");
ServiceClient sc = stub._getServiceClient();
Options options = sc.getOptions();
options.setUserName("test");
options.setPassword("pass");
options.setProperty(RampartMessageData.KEY_RAMPART_POLICY,
loadPolicy("policy.xml"));
sc.engageModule("rampart");
Test test = new Test();
test.setA(1);
stub.test(test);
stub.addWS();
}
private static Policy loadPolicy(String xmlPath) throws FileNotFoundException, XMLStreamException{
StAXOMBuilder builder = new StAXOMBuilder(xmlPath);
return PolicyEngine.getPolicy(builder.getDocumentElement());
}
Message Error:
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.axiom.soap.SOAPFaultClassifier.getValueAsQName()Ljavax/xml/namespace/QName;
at org.apache.rampart.util.RampartUtil.isSecurityFaultCode(RampartUtil.java:1929)
at org.apache.rampart.util.RampartUtil.isSecurityFault(RampartUtil.java:1919)
at org.apache.rampart.RampartEngine.isSecurityFault(RampartEngine.java:306)
at org.apache.rampart.RampartEngine.process(RampartEngine.java:73)
at org.apache.rampart.handler.RampartReceiver.invoke(RampartReceiver.java:92)
at org.apache.axis2.engine.Phase.invokeHandler(Phase.java:340)
at org.apache.axis2.engine.Phase.invoke(Phase.java:313)
at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:262)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:168)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:364)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at com.ex.TestStub.test(TestStub.java:204)
at com.ex.service.testWS.main(testWS.java:39)
This is policy I used.
Thank for your help.
Related
We are facing an error while running the sample program given below using java API CORBA on InDesign server. we have enabled CORBA on the server. Exception occurred during document create method, also upon calling other app methods like getChildDocuments() or getName(), etc. you help will be appreciated.
Program giving exception(IDL:com/adobe/ids/IdsException) at this line:
Document myDoc = myApp.addDocument(OptArg.noDocumentPreset());
ORBD service running with port 1050.
Exception details:
"C:\Program Files\Java\jdk1.8.0_301\bin\java.exe"
Exception #30465:
com.adobe.ids.IdsException: IDL:com/adobe/ids/IdsException:1.0
at com.adobe.ids.IdsExceptionHelper.read(Unknown Source)
at com.adobe.ids.basics._ApplicationStub.getFullName(Unknown Source)
at com.adobe.ids.sdk.ImprovedHelloWorld.main(ImprovedHelloWorld.java:40)
Exception in thread "main" com.adobe.ids.IdsException: IDL:com/adobe/ids/IdsException:1.0
at com.adobe.ids.IdsExceptionHelper.read(Unknown Source)
at com.adobe.ids.basics._ApplicationStub.consoleout(Unknown Source)
at com.adobe.ids.sdk.ImprovedHelloWorld.main(ImprovedHelloWorld.java:85)
Program sample:
public static void main(String[] args) throws Exception
{
String iorFile = "d:\\ior.txt";
Properties props = new Properties();
props.put("port", "1050");
props.put("org.omg.CORBA.ORBInitialHost", "localhost");
BufferedReader iorIn = new BufferedReader(new FileReader(iorFile));
String application_IOR = iorIn.readLine();
ORB orb = ORB.init(new String [] {iorFile}, props);
Object object = orb.string_to_object(application_IOR);
Application myApp = ApplicationHelper.narrow(object);
Document arr[] = myApp.getAllChildDocuments();
Document myDoc = myApp.addDocument(OptArg.noDocumentPreset());
orb.shutdown(true); // true to wait for completion
orb.destroy();
}
I am getting the following exception when I am trying to execute the following code that uses ribbon and tries to get server list from eureka.
Exception
3122 [main] WARN com.netflix.loadbalancer.RoundRobinRule - No up servers available from load balancer: DynamicServerListLoadBalancer:{NFLoadBalancer:name=origin,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:DiscoveryEnabledNIWSServerList:; clientName:origin; Effective vipAddresses:localhost; isSecure:false; datacenter:null
Exception in thread "main" com.netflix.client.ClientException: LoadBalancer returned null Server for :origin
at com.netflix.client.LoadBalancerContext.computeFinalUriWithLoadBalancer(LoadBalancerContext.java:418)
at com.netflix.client.AbstractLoadBalancerAwareClient.executeWithLoadBalancer(AbstractLoadBalancerAwareClient.java:166)
at com.netflix.zuul.RibbonTest.main(RibbonTest.java:23)
Code
public static void main(String[] args) throws Exception {
ConfigurationManager.loadPropertiesFromResources("ribbon-client.properties");
RestClient client = (RestClient) ClientFactory.getNamedClient("origin");
HttpRequest request = HttpRequest.newBuilder().uri(new URI("/serviceContext/api/v1/")).build();
for (int i = 0; i < 20; i++) {
HttpResponse response = client.executeWithLoadBalancer(request);
}
}
ribbon-client.properties
origin.ribbon.NIWSServerListClassName=com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList
#also tried unsuccessfully with localhost:8091, localhost:8091/serviceContext
origin.ribbon.DeploymentContextBasedVipAddresses=localhost
The service is a Spring-Boot (not using Spring-Cloud) app using eureka-client.properties:
eureka-client.properties
eureka.registration.enabled=true
eureka.preferSameZone=true
eureka.shouldUseDns=false
eureka.serviceUrl.default=http://localhost:9080/eureka/v2/
eureka.region=default
eureka.name=service-Eureka
eureka.vipAddress=localhost
eureka.port=8091
eureka.instanceId=CHNSHL119363L
The service gets registered successfully with eureka deployed in local tomcat#port 9080 and is discover-able # http://localhost:9080/eureka/ and http://localhost:9080/eureka/v2/apps/
W/O using Spring-Cloud what needs to be fixed in the above code/configuration to be able to get list of servers dynamically from eureka using ribbon?
The following post served useful.
The issue is solved by
1. Correcting vipAddress configuration for service and ribbon
2. Configuring and registering ribbon as eureka-client
1. Changes for vipAddress
eureka-client.properties (service)
eureka.vipAddress=my.eureka.local
ribbon-client.properties
origin.ribbon.DeploymentContextBasedVipAddresses=my.eureka.local
2. Changes to register ribbon as eureka-client
public static void main(String[] args) throws Exception {
ConfigurationManager.loadPropertiesFromResources("ribbon-client.properties");
**InstanceInfo instanceInfo = new EurekaConfigBasedInstanceInfoProvider(instanceConfig).get();
applicationInfoManager = new ApplicationInfoManager(instanceConfig, instanceInfo);
eurekaClient = new DiscoveryClient(applicationInfoManager, clientConfig);**
RestClient client = (RestClient) ClientFactory.getNamedClient("origin");
HttpRequest request = HttpRequest.newBuilder().uri(new URI("/serviceContext/api/v1/")).build();
for (int i = 0; i < 20; i++) {
HttpResponse response = client.executeWithLoadBalancer(request);
}
}
If i call this server method with the client from different location iam getting following error.If i run the client from same location where the server is there I am getting output.
Please give some soltuions to call my rmi server with rmi client from different location.
Error
Exception in thread "main" java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: com.transform.xsl.XslFoTransformer_Stub (no security manager: RMI class loader disabled)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at java.rmi.Naming.lookup(Naming.java:101)
at com.transform.xsl.RmiClient.main(RmiClient.java:15)
Caused by: java.lang.ClassNotFoundException: com.transform.xsl.XslFoTransformer_Stub (no security manager: RMI class loader disabled)
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:394)
at sun.rmi.server.LoaderHandler.loadClass(LoaderHandler.java:184)
at java.rmi.server.RMIClassLoader$2.loadClass(RMIClassLoader.java:637)
at java.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:264)
at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.java:222)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1610)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1515)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1769)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1348)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)
... 3 more
Code ======
import java.io.File;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface XslFoTransformerInterface extends Remote {
public byte[] doTransform(File stylesheet, File datafile) throws Throwable,RemoteException;
}
public class XslFoTransformer extends UnicastRemoteObject implements XslFoTransformerInterface {
protected XslFoTransformer() throws RemoteException {
super();
}
public byte[] doTransform(File stylesheet, File datafile) throws Exception {
String fileName = datafile.getName();
int pos = fileName.lastIndexOf(".");
if (pos > 0) {
fileName = fileName.substring(0, pos);
}
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
File file = new File(fileName + ".xsl-fo");
try {
// File stylesheet = new
// File("C:\\Users\\Q811213\\Documents\\XSLT\\files\\ECGSearchResultsPDF_changed1.xsl");
// File datafile = new
// File("C:\\Users\\Q811213\\Documents\\XSLT\\files\\NEWDATA.xml");
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(datafile);
TransformerFactory tFactory = TransformerFactory.newInstance();
StreamSource stylesource = new StreamSource(stylesheet);
Transformer transformer = tFactory.newTransformer(stylesource);
DOMSource source = new DOMSource(document);
ByteArrayOutputStream bos=new ByteArrayOutputStream();
StreamResult result=new StreamResult(bos);
transformer.transform(source, result);
byte [] array=bos.toByteArray();
return array;
} catch (Exception e) {
throw e;
}}}
--Rmi server class
public class RmiServer {
public static void main(String args[]) throws Exception{
try{
XslFoTransformerInterface stub=new XslFoTransformer();
Naming.rebind("rmi://localhost:1099/Xsl-Fo_Transform",stub);
}catch(Exception e){
throw e;
}
}
}
--Rmi client created in different location
public class RmiClient {
public static void main(String args[]) throws Throwable {
try {
XslFoTransformerInterface stub = (XslFoTransformerInterface) Naming
.lookup("rmi://localhost:1099/Xsl-Fo_Transform");
System.out.println("stub is ready" + stub);
File f1 = new File(
"C:\\Users\\s811213\\osbwstest\\XSL-FO_Transformer\\files\\ECGSearchResultsPDF_changed1.xsl");
File f2 = new File(`enter code here`
"C:\\Users\\s811213\\osbwstest\\XSL-FO_Transformer\\files\\NEWDATA.xml");
try {
byte[] f = stub.doTransform(f1, f2);
}cartch(){}
}}
If i call this server method with the client from different location iam getting following error.If i run the client from same location where the server is there i am getting output.
Please give some soltuions to call my rmi server with rmi client from different location.
You need to deploy the stub class named in the exception to the client.
In RMI client
XslFoTransformerInterface stub = (XslFoTransformerInterface) Naming
.lookup("rmi://localhost:1099/Xsl-Fo_Transform");
you need to change localhost to server ip
I'm not sure if you running your program in different locations (no the server machine) with the updated version of your code for ip which you hard coded for localhost.
If this is not the problem, you must be sure that you placed the XslFoTransformerInterface class in your client codes in the same package as it is in server codes.
Also in the future if you have some Serializable POJO classes as the arguments or the return types of you remote methods, same rule is applied for them. Always put them in the same package as they reside is the server codes.
Good Luck.
magento api using soap doesn't work due to missing magento-api.properties files, can someone help?
public class testConnection {
public static void main(String[] args) throws AxisFault {
String user = "rajeshvishnani";
String pass = "123456";
String host = "http://cypherincorporated.co.in/magento/index.php/api/soap?wsdl";
SoapConfig soapConfig = new SoapConfig(user, pass, host);
MagentoSoapClient magentoSoapClient = MagentoSoapClient.getInstance(soapConfig);
magentoSoapClient.setConfig(soapConfig);
}
}
Exception in thread "main" java.lang.IllegalArgumentException: could not load [magento-api.properties] as a classloader resource
at com.google.code.magja.utils.PropertyLoader.loadProperties(PropertyLoader.java:106)
at com.google.code.magja.utils.PropertyLoader.loadProperties(PropertyLoader.java:123)
at com.google.code.magja.soap.MagentoSoapClient.getInstance(MagentoSoapClient.java:69)
at magentomanager.testConnection.main(testConnection.java:15)
Try changing the url to 'http://yoursite.com/api/v2_soap/index?wsdl=1'.
Please provide more details.
Not sure about java exception but you can try following link.
Link
I want to send an email with Java and Microsoft exchange server API. I followed the instruction from the documents, but I always get an exception.
All parameter (username, password, domain and uri are correct). I have tested this parameter with EWS Editor from Microsoft, and with the editor I get a connection.
My code is this:
import microsoft.exchange.webservices.data.EmailMessage;
import microsoft.exchange.webservices.data.ExchangeCredentials;
import microsoft.exchange.webservices.data.ExchangeService;
import microsoft.exchange.webservices.data.ExchangeVersion;
import microsoft.exchange.webservices.data.MessageBody;
import microsoft.exchange.webservices.data.WebCredentials;
public class Mail {
ExchangeService service = new ExchangeService(
ExchangeVersion.Exchange2010_SP2);
ExchangeCredentials credentials = new WebCredentials("user",
"passwort", "domain");
public void sendMail() throws Exception {
service.setTraceEnabled(true);
java.net.URI uri = new java.net.URI(
"https://********/ews/exchange.asmx");
service.setCredentials(credentials);
service.setUrl(uri);
System.out.println(service.getServerInfo());
EmailMessage msg = new EmailMessage(service);
msg.setBody(MessageBody
.getMessageBodyFromText("Sent using the EWS Managed API."));
msg.getToRecipients().add("send mail to ");
msg.send();
}
public static void main(String[] args) throws Exception {
Mail mail = new Mail();
mail.sendMail();
}
The exception is this:
Exception in thread "main" microsoft.exchange.webservices.data.EWSHttpException: Connection not established
at microsoft.exchange.webservices.data.HttpClientWebRequest.throwIfConnIsNull(HttpClientWebRequest.java:394)
at microsoft.exchange.webservices.data.HttpClientWebRequest.getResponseCode(HttpClientWebRequest.java:370)
at microsoft.exchange.webservices.data.EwsUtilities.formatHttpResponseHeaders(EwsUtilities.java:597)
at microsoft.exchange.webservices.data.ExchangeServiceBase.traceHttpResponseHeaders(ExchangeServiceBase.java:467)
at microsoft.exchange.webservices.data.ExchangeServiceBase.processHttpResponseHeaders(ExchangeServiceBase.java:1043)
at microsoft.exchange.webservices.data.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:58)
at microsoft.exchange.webservices.data.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:144)
at microsoft.exchange.webservices.data.ExchangeService.internalCreateItems(ExchangeService.java:464)
at microsoft.exchange.webservices.data.ExchangeService.createItem(ExchangeService.java:535)
at microsoft.exchange.webservices.data.Item.internalCreate(Item.java:215)
at microsoft.exchange.webservices.data.EmailMessage.internalSend(EmailMessage.java:125)
at microsoft.exchange.webservices.data.EmailMessage.send(EmailMessage.java:253)
at de.ruv.SendMail.Mail.sendMail(Mail.java:40)
at de.ruv.SendMail.Mail.main(Mail.java:45)
Change
ExchangeCredentials credentials = new WebCredentials("user", "password", "domain");
to
service.Credentials = new NetworkCredential("user", "password", "domain");