use of jakarta.xml.ws.soap.SOAPBinding in project metro-jax-ws by eclipse-ee4j.
the class HttpTransportPipe method createResponsePacket.
private Packet createResponsePacket(Packet request, HttpClientTransport con) throws IOException {
// throws IOE
con.readResponseCodeAndMessage();
recordCookies(request, con);
InputStream responseStream = con.getInput();
if (dump || LOGGER.isLoggable(Level.FINER)) {
ByteArrayBuffer buf = new ByteArrayBuffer();
if (responseStream != null) {
buf.write(responseStream);
responseStream.close();
}
dump(buf, "HTTP response - " + request.endpointAddress + " - " + con.statusCode, con.getHeaders());
responseStream = buf.newInputStream();
}
// Check if stream contains any data
int cl = con.contentLength;
InputStream tempIn = null;
if (cl == -1) {
// No Content-Length header
tempIn = StreamUtils.hasSomeData(responseStream);
if (tempIn != null) {
responseStream = tempIn;
}
}
if (cl == 0 || (cl == -1 && tempIn == null)) {
if (responseStream != null) {
// No data, so close the stream
responseStream.close();
responseStream = null;
}
}
// Allows only certain http status codes for a binding. For all
// other status codes, throws exception
// throws ClientTransportException
checkStatusCode(responseStream, con);
// To avoid zero-length chunk for One-Way
if (cl == -1 && con.statusCode == 202 && "Accepted".equals(con.statusMessage) && responseStream != null) {
ByteArrayBuffer buf = new ByteArrayBuffer();
// What is within the responseStream?
buf.write(responseStream);
responseStream.close();
responseStream = (buf.size() == 0) ? null : buf.newInputStream();
buf.close();
}
Packet reply = request.createClientResponse(null);
reply.wasTransportSecure = con.isSecure();
if (responseStream != null) {
String contentType = con.getContentType();
if (contentType != null && contentType.contains("text/html") && binding instanceof SOAPBinding) {
throw new ClientTransportException(ClientMessages.localizableHTTP_STATUS_CODE(con.statusCode, con.statusMessage));
}
codec.decode(responseStream, contentType, reply);
}
return reply;
}
use of jakarta.xml.ws.soap.SOAPBinding in project metro-jax-ws by eclipse-ee4j.
the class HttpTransportPipe method process.
@Override
public Packet process(Packet request) {
HttpClientTransport con;
try {
// get transport headers from message
Map<String, List<String>> reqHeaders = new Headers();
@SuppressWarnings("unchecked") Map<String, List<String>> userHeaders = (Map<String, List<String>>) request.invocationProperties.get(MessageContext.HTTP_REQUEST_HEADERS);
boolean addUserAgent = true;
if (userHeaders != null) {
// userHeaders may not be modifiable like SingletonMap, just copy them
reqHeaders.putAll(userHeaders);
// application wants to use its own User-Agent header
if (userHeaders.get("User-Agent") != null) {
addUserAgent = false;
}
}
if (addUserAgent) {
reqHeaders.put("User-Agent", USER_AGENT);
}
addBasicAuth(request, reqHeaders);
addCookies(request, reqHeaders);
con = getTransport(request, reqHeaders);
request.addSatellite(new HttpResponseProperties(con));
ContentType ct = codec.getStaticContentType(request);
if (ct == null) {
ByteArrayBuffer buf = new ByteArrayBuffer();
ct = codec.encode(request, buf);
// data size is available, set it as Content-Length
reqHeaders.put("Content-Length", Collections.singletonList(Integer.toString(buf.size())));
reqHeaders.put("Content-Type", Collections.singletonList(ct.getContentType()));
if (ct.getAcceptHeader() != null) {
reqHeaders.put("Accept", Collections.singletonList(ct.getAcceptHeader()));
}
if (binding instanceof SOAPBinding) {
writeSOAPAction(reqHeaders, ct.getSOAPActionHeader());
}
if (dump || LOGGER.isLoggable(Level.FINER)) {
dump(buf, "HTTP request", reqHeaders);
}
buf.writeTo(con.getOutput());
} else {
// Set static Content-Type
reqHeaders.put("Content-Type", Collections.singletonList(ct.getContentType()));
if (ct.getAcceptHeader() != null) {
reqHeaders.put("Accept", Collections.singletonList(ct.getAcceptHeader()));
}
if (binding instanceof SOAPBinding) {
writeSOAPAction(reqHeaders, ct.getSOAPActionHeader());
}
if (dump || LOGGER.isLoggable(Level.FINER)) {
ByteArrayBuffer buf = new ByteArrayBuffer();
codec.encode(request, buf);
dump(buf, "HTTP request - " + request.endpointAddress, reqHeaders);
OutputStream out = con.getOutput();
if (out != null) {
buf.writeTo(out);
}
} else {
OutputStream os = con.getOutput();
if (os != null) {
codec.encode(request, os);
}
}
}
con.closeOutput();
return createResponsePacket(request, con);
} catch (WebServiceException wex) {
throw wex;
} catch (Exception ex) {
throw new WebServiceException(ex);
}
}
use of jakarta.xml.ws.soap.SOAPBinding in project metro-jax-ws by eclipse-ee4j.
the class EndToEndTest method testAllRoles.
/*
* Test the allRoles boolean argument of getHeaders()
* method in SOAPMessageContext.
*/
public void testAllRoles() throws Exception {
TestService_Service service = getService();
TestService testStub = getTestStub(service);
ReportService reportStub = getReportStub(service);
HandlerTracker tracker = HandlerTracker.getClientInstance();
// these lines make calls to the server
reportStub.clearHandlerTracker();
reportStub.setInstruction(SERVER_PREFIX + 4, HA_ADD_HEADER_OUTBOUND_CLIENT_ROLE1);
// so we clear out the client handlers afterwards
tracker.clearAll();
tracker.setHandlerAction(CLIENT_PREFIX + 7, HA_CHECK_SMC_ALL_ROLES);
// first check with the client1 role
int result = testStub.testInt(5);
// now check without the known role (should get no headers in handler)
SOAPBinding sBinding = (SOAPBinding) ((BindingProvider) testStub).getBinding();
sBinding.setRoles(new HashSet<String>());
result = testStub.testInt(5);
}
use of jakarta.xml.ws.soap.SOAPBinding in project metro-jax-ws by eclipse-ee4j.
the class MtomCidTest method setUp.
@Override
public void setUp() throws Exception {
HelloService helloService = new HelloService();
Object obj = helloService.getHelloPort();
assertTrue(obj != null);
// set Mtom optimization.
SOAPBinding binding = (SOAPBinding) ((BindingProvider) obj).getBinding();
binding.setMTOMEnabled(true);
port = (Hello) obj;
address = (String) ((BindingProvider) obj).getRequestContext().get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
}
Aggregations