Rampart Client throwing exception when trying to consume the service - java

I am trying to invoke a axis2 web service enabled with Rampart security. When I try to invoke the service through the client I am getting the following exception, (I have also included Jaxen Jar in my project)
Exception in thread "main" org.apache.axis2.AxisFault: java.lang.NoClassDefFoundError: org/jaxen/JaxenException
at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:446)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:371)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:417)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at com.tcs.secure.SecureServiceStub.add(SecureServiceStub.java:186)
at com.tcs.secure.Client.main(Client.java:16)
I have generated stubs for my password call back class and my sample class and imported it to my client. Here is my sample client.
public class Client {
public static void main(String[] args) throws RemoteException {
SecureServiceStub stub = new SecureServiceStub();
Add request = new Add();
request.setA(23);
request.setB(389);
AddResponse response = stub.add(request);
System.out.println(response);
}
}

Related

Apache CXF WS-Security: Security processing failed (actions mismatch)

I'm following this example to create a web service secured with signature only: https://github.com/apache/cxf/blob/master/distribution/src/main/release/samples/ws_security/sign_enc/src/main/java/demo/wssec/server/Server.java
This is what my code looks like:
public static void main(String[] args) {
FooService service = new FooService();
String address = "http://localhost:1235/foo";
EndpointImpl endpoint = (EndpointImpl) javax.xml.ws.Endpoint.publish(address, service);
Map<String,Object> inProps = new HashMap<>();
inProps.put(WSHandlerConstants.ACTION, "Signature");
inProps.put(WSHandlerConstants.SIG_PROP_FILE, Server.class.getResource("./server_sign.properties"));
inProps.put("signatureKeyIdentifier", "DirectReference");
inProps.put("encryptionKeyTransportAlgorithm", "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p");
inProps.put("signatureAlgorithm", "http://www.w3.org/2000/09/xmldsig#rsa-sha1");
endpoint.getInInterceptors().add(new WSS4JInInterceptor(inProps));}
When I send a soap messge to the server it throws an error:
org.apache.wss4j.common.ext.WSSecurityException: An error was discovered processing the <wsse:Security> header
Also it shows the message
Security processing failed (actions mismatch)
Why does this happen?

restygwt - get original server error on client site

I have an application build on GWT + RestyGWT with Spring
I'm trying to make some user friendly exception handling on client site.
I have some method on server side that throws an exception:
#PostMapping(...)
#Transactional(...)
public long withdraw(#PathVariable(value = "amount) long amount) throws CustomException {
if (amount < 0) {
throw new CustomException("Amount is negative");
}
account.withdraw(amount);
return account.balance;
}
It's called async from client side and handled there:
... new MethodCallback<...>() {
#Override
public void onFailure(Method method, Throwable throwable) {
// here should be error handling
}
How can I get original error message and class ("Amount is negative" and CustomException)? All I could get from method and throwable variables were:
errorCode = 500
response message = "Internal Server Error"
throwable is org.fusesource.restygwt.client.FailedResponseException
You cannot receive the same Exception in RestyGWT (this can be done using GWT RPC). But, you can handle exceptions uniformly in the server side (in jersey you can use an exception mapper in spring is called exception handler) and return an error response with a known JSON format. Then you can get this error response using the FailedResponseException (this is the exception you are receiving right now), this exception contains the response, so you can do MyKnownErrorResponse o = JSON.parse(failedResponseException.getResponse().getText()).

How to send a Message object type via CXF Jax-ws

i want to send an org.apache.cxf.message.Message object via CXF Jax-ws. For example:
A service declared:
#WebService
public interface HelloWorld {
void send(Message msg);
}
Implementation of this service:
public class HelloWorldImpl implements HelloWorld {
public void send(Message msg) {
System.out.println("receives msg id:" +((MessageImpl)msg).getId());
}
}
Server:
HelloWorldImpl implementor = new HelloWorldImpl();
JaxWsServerFactoryBean svrFactory1 = new JaxWsServerFactoryBean();
svrFactory1.setServiceClass(HelloWorld.class);
svrFactory1.setAddress("http://192.168.56.1:9000/HelloWorld");
svrFactory1.setServiceBean(implementor);
org.apache.cxf.endpoint.Server server1 = svrFactory1.create();
server1.start();
Client:
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setAddress("http://192.168.56.1:9000/HelloWorld");
HelloWorld client = factory.create(HelloWorld.class);
Message msg = new MessageImpl();
msg.setId("abc");
client.send(msg);
I receive an error when running as follows:
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Fault occurred while processing.
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:160)
at com.sun.proxy.$Proxy37.sayHiToUser(Unknown Source)
at objecttype.Client.main(Client.java:60)
Caused by: org.apache.cxf.binding.soap.SoapFault: Fault occurred while processing.
.......
How to correct this error ?
Regards,

SOAPAction header value Exception java web services

created the web service source using WSDL in netbeans IDE. Then in servlet class generated code to call web service method. I got code like this:
private void getSomething() {
com.bla.bla.SomeService service = new com.bla.bla.SomeService();
QName portQName = new QName("http://bla.com/test/services", "SomeServiceSoap");
String req = "<getSomething xmlns="\url\"><a id=\"5\"/></getSomething>";
try {
Dispatch<Source> dispatch = null;
dispatch = service.createDispatch(portQName, Source.class, Service.Mode.PAYLOAD);
Source result = dispatch.invoke(new StreamSource(new StringReader(req)));
} catch (Exception ex) {
ex.printStackTrace();
}
}
But when I call this method, I am getting an Exception: javax.xml.ws.soap.SOAPFaultException: System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP header SOAPAction: .
How to solve this problem? Any help is appreciated! thanks!
That error means, though there is some webservice running at the endpoint http://bla.com/test/services there is no operation is available on that purticular service.
OR
client didnt supply any operation to invoke on SimpleSoapService

Jetty + Jersey embeded server not working if launched from JAR

I am trying to launch a Jetty server from a class. When I try to run it from eclipse it works fine. If I embed it to a JAR the jetty server starts, but when I make a request it return a 500 code response. Here is my class:
#GET
#Path("test")
#Produces(MediaType.APPLICATION_JSON)
public String echo(#QueryParam("testParam")String test){
return test;
}
private Server server;
public synchronized void start(int port) throws Exception {
if (server != null) {
throw new IllegalStateException("Server is already running");
}
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
Map<String,Object> initMap = new HashMap<String, Object>();
initMap.put("com.sun.jersey.api.json.POJOMappingFeature", "true");
initMap.put("com.sun.jersey.config.property.packages", "the.class.package");
context.addServlet(new ServletHolder(new ServletContainer(new PackagesResourceConfig(initMap))), "/*");
this.server = new Server(port);
this.server.setHandler(context);
this.server.start();
}
public static void main(String[] args) throws Exception {
if(args.length != 1) {
System.out.println("AnnotatorServer <port>");
System.exit(-1);
}
JettyServer server = new JettyServer();
server.start(Integer.parseInt(args[0]));
}
When I try to launch it embedded in a JAR, the server starts, but when I access the method, I get the following exception:
Caused by: com.sun.jersey.api.MessageException: A message body writer for Java class java.lang.String, and Java type class java.lang.String, and MIME media type application/octet-stream was not found
Do you have any idea why is this happening?? Thank you!
The problem was on the POM file. The dependency was overwriting some files in Meta-Inf/service. Found the solution to Jersey exception only thrown when depencencies assembled into a single jar

Categories

Resources