Прочтите заголовки http-сообщений

Привет, у меня возникли проблемы, я пытаюсь изучить службы отдыха. Я создал веб-службу с использованием jax-rs, которая показана ниже

@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();
}
}

Я использую следующий тестовый клиент для проверки службы

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();
}
}

Я хочу использовать пароль в заголовке на стороне сервера и выполнить поиск в базе данных.Проблема, с которой я столкнулся, заключается в том, как читать заголовки на сервере.

6
задан luckysing_noobster 13 March 2012 в 01:53
поделиться