Hi, I'm having problems. I am trying to learn soothing services. I created a web service using jax-rs which is shown below
@Path("/users") public class Welcome { @POST @Consumes("text/xml") @Produces("text/xml") public Response welcome(String incomingXML){ return Response.status(200).entity("timestamp : " + incomingXML).build(); } }
I use the following test client to test the service
public class TestService { public static void main(String args[]) throws ParserConfigurationException, SAXException, IOException { ClientConfig config = new DefaultClientConfig(); Client client=Client.create(config); WebResource service=client.resource(getBaseURI()); String urlString = "http://localhost:8080/JaXRSDemo/rest/users"; URL url = new URL( urlString ); HttpURLConnection con = (HttpURLConnection) url.openConnection(); // set up url connection to get retrieve information back con.setRequestMethod( "POST" ); con.setDoInput( true ); // stuff the Authorization request header byte[] encodedPassword = ( userName + ":" + password ).getBytes(); con.setRequestProperty( "Authorization",encodedPassword.toString() ); Customer customer=new Customer(); customer.setName("noobstre"); customer.setPin(123455); ClientResponse response=service.path("rest").path("users").type(MediaType.APPLICATION_XML).post(ClientResponse.class,customer); System.out.println(" response " + response.getEntity(String.class)); } private static URI getBaseURI() { return UriBuilder.fromUri("http://localhost:8080/JaXRSDemo").build(); } }
I want to use the password in the header on the server side and search using the database. The problem I ran into is how to read the headers on the server.
source share