Response over HTTP
max5432 May 7, 2010 10:20 AMHow to send the response from a service over http?
I send a request over http with username and password. In the action-Method I
check username and password and have to send 'true' odr 'false' as String back.
Here is the Action-Class:
package demo; import java.util.Map; import org.jboss.soa.esb.actions.AbstractActionPipelineProcessor; import org.jboss.soa.esb.actions.ActionProcessingException; import org.jboss.soa.esb.helpers.ConfigTree; import org.jboss.soa.esb.http.HttpRequest; import org.jboss.soa.esb.message.Message; import org.jboss.soa.esb.message.format.MessageFactory; public class LoginHandler extends AbstractActionPipelineProcessor{ private ConfigTree configTree; public LoginHandler(ConfigTree configTree) { this.configTree = configTree; } public Message process(Message message) throws ActionProcessingException { String answer = "login failed"; HttpRequest req = HttpRequest.getRequest(message); Map<String, String[]> params = req.getQueryParams(); if (params != null) { String user = params.get("user")[0]; String password = params.get("pwd")[0]; System.out.println("User: " + user + ", Password: " + password); if (user.equals("joe") && pwd.equals("secret")){ answer = "login successfully"; } } else { System.out.println("ParameterMap is null!"); } /* for demo */ Message responseMessage = MessageFactory.getInstance().getMessage(); responseMessage.getBody().add(answer); return responseMessage; } }
And here is the jboss-esb.xml
<?xml version="1.0"?> <jbossesb parameterReloadSecs="5" xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.2.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.2.0.xsd http://anonsvn.jboss.org/repos/labs/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.2.0.xsd"> <services> <service category="DemoServices" description="" invmScope="GLOBAL" name="Login"> <listeners> <http-gateway name="Http"/> </listeners> <actions mep="RequestResponse"> <action name="LoginAction" process="process"/> </actions> </service> </services> </jbossesb>
I tried to call the service from browser:
http://localhost:8080/logintest/http/DemoServices/Login?user=joe&pwd=secret
I see the output:
15:19:29,037 INFO [STDOUT] User: joe, Password: secret
following with error message:
15:19:29,037 WARN [ActionProcessingPipeline] No response message for RequestResponse mep! To: InVMEpr [ PortReference < <wsa:Address invm://4461746168616e64656c53657276696365732424242424242424242424244461746152657175657374/false?false#10000/>, <wsa:ReferenceProperties jbossesb:passByValue : false/> > ] ReplyTo: InVMEpr [ PortReference < <wsa:Address invm://thread-137-43/>, <wsa:ReferenceProperties jbossesb:passByValue : false/>, <wsa:ReferenceProperties jbossesb:temporaryEPR : true/> > ] MessageID: 6330ee62-1112-4b77-81c8-0b1eb545449d 15:19:59,036 INFO [ServiceInvoker] Unresponsive EPR: InVMEpr [ PortReference < <wsa:Address invm://4461746168616e64656c53657276696365732424242424242424242424244461746152657175657374/false?false#10000/>, <wsa:ReferenceProperties jbossesb:passByValue : false/> > ] for message: header: [ ] 15:19:59,036 INFO [ServiceInvoker] Delivering message [header: [ ]] to DLQ. 15:19:59,121 ERROR [[Http]] Servlet.service() for servlet Http threw exception
I tried to call the same service from a simple java program:
URL url = new URL("http://localhost:8080/logintest/http/DemoServices/Login?user=joe&pwd=secret"); URLConnection connection = url.openConnection(); connection.setDoOutput(true); PrintStream outStream = new PrintStream(connection.getOutputStream()); outStream.println("string=" + "test"); outStream.close(); DataInputStream inStream = new DataInputStream(connection.getInputStream()); // ...
I see username and password, and short time after that I get the error message:
Server returned HTTP response code: 500 for URL: http://localhost:8080/logintest/http/DemoServices/Login?user=joe&pwd=secret
What have I to do, to get response as a String? How to set configuration in jboss-esb.xml for 'response message'?